Struct Npm

Source
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

Source

pub fn init(self) -> Self

Same behaviour as npm-init -y. Initializes a package, creating a package.json file with the default template.

Source

pub fn install(self, args: Option<&[&str]>) -> Self

Same behaviour as npm-install.

  • If args =None: Installs all the dependencies listed in package.json into the local node_modules folder.
  • If args =Some: Installs any package in args into the local node_modules folder.
Source

pub fn uninstall(self, pkg: &[&str]) -> Self

Same behaviour as npm-uninstall. Uninstalls the given packages in pkg.

Source

pub fn update(self, pkg: Option<&[&str]>) -> Self

Same behaviour as npm-update.

  • If args =None: Updates all the local dependencies (local node_modules folder).
  • If args =Some: Updates any package in pkg.
Source

pub fn run(self, command: &str) -> Self

Same behaviour as npm-run-script. Runs an arbitrary command from package.json’s “scripts” object.

Source

pub fn custom(self, command: &str, args: Option<&[&str]>) -> Self

Runs a custom npm command.

§Arguments
  • command: command to execute.
  • args: arguments of command.
§Example
use npm_rs::*;

Npm::default().custom("audit", None).exec()?; // Equivalent to `npm audit`.
Source

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§

Source§

impl Default for Npm

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.