pub struct Npm { /* private fields */ }
Expand description
This struct is used to execute npm commands.
Can be created from NpmEnv
of using Default
.
After queuing the desired commands, use Npm::exec()
to execute them.
§Example
use npm_rs::*;
Npm::default().install(Some(&["tailwindcss"])).exec()?;
Implementations§
Source§impl Npm
impl Npm
Sourcepub fn init(self) -> Self
pub fn init(self) -> Self
Same behaviour as npm-init -y.
Initializes a package, creating a package.json
file with the default template.
Sourcepub fn install(self, args: Option<&[&str]>) -> Self
pub fn install(self, args: Option<&[&str]>) -> Self
Same behaviour as npm-install.
Sourcepub fn uninstall(self, pkg: &[&str]) -> Self
pub fn uninstall(self, pkg: &[&str]) -> Self
Same behaviour as npm-uninstall.
Uninstalls the given packages in pkg
.
Sourcepub fn update(self, pkg: Option<&[&str]>) -> Self
pub fn update(self, pkg: Option<&[&str]>) -> Self
Same behaviour as npm-update.
Sourcepub fn run(self, command: &str) -> Self
pub fn run(self, command: &str) -> Self
Same behaviour as npm-run-script.
Runs an arbitrary command
from package.json
’s “scripts” object.
Sourcepub fn exec(self) -> Result<ExitStatus, Error>
pub fn exec(self) -> Result<ExitStatus, Error>
Executes all the commands in the invokation order used, waiting for its completion status.
§Example
use npm_rs::*;
let status = Npm::default().install(None).run("build").exec()?; // Executes npm install && npm run build.
assert!(status.success()); // Will `panic` if not completed successfully.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Npm
impl !RefUnwindSafe for Npm
impl Send for Npm
impl Sync for Npm
impl Unpin for Npm
impl !UnwindSafe for Npm
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more