@achil/npm-programmatic 中文文档教程

发布于 5年前 浏览 12 项目主页 更新于 3年前

npm-programmatic Build Status

NPM

npm-programmatic 是一个允许您从 javascript 以编程方式访问 npm 命令的库,

Usage

每个函数都返回一个 Bluebird promise。
CWD 指的是当前工作目录,允许您确保命令在文件系统中的某个文件夹中执行。 如果设置了输出,npm 的输出将显示在控制台中。

Installation of Packages

    npm.install(packages, opts).then(function)
NameTypeValue
packagesArraypackages to be installed
optsObjectsave:true/false; global:true/false; cwd:string; saveDev:true/false; noOptional:true/false; legacyBundling: true/false; output:true/false

Example

    var npm = require('npm-programmatic');
    npm.install(['left-pad'], {
        cwd:'/path/to/my/project',
        save:true
    })
    .then(function(){
        console.log("SUCCESS!!!");
    })
    .catch(function(){
        console.log("Unable to install package");
    });

Unistallation of Packages

    npm.uninstall(packages, opts).then(function)
NameTypeValue
packagesArraypackages to be uninstalled
optsObjectsave:true/false; global:true/false; cwd:string; saveDev:true/false; output:true/false

Example

    var npm = require('npm-programmatic');
    npm.uninstall(['left-pad'], {
        cwd:'/path/to/my/project',
        save:true
    })
    .then(function(){
        console.log("SUCCESS!!!");
    })
    .catch(function(){
        console.log("Unable to uninstall package");
    });

List Installed Packages

    npm.list(path).then(function)
NameTypeValue
pathStringpath at which to look

Example

    var npm = require('npm-programmatic');
    npm.list('/path/to/project')
    .then(function(arrayOfPackages){
        console.log(arrayOfPackages);
    })
    .catch(function(){
        console.log("Unable to uninstall package");
    });

Tests

安装 mocha 和 dev 依赖项。 然后运行 <代码>npm 测试

npm-programmatic Build Status

NPM

npm-programmatic is a library that allows you to access npm commands programmatically from javascript

Usage

Every function returns a Bluebird promise.
CWD refers to current working directory, allowing you to ensure the command executes in a certain folder in the filesystem. If output is set, the output of npm will be shown in the console.

Installation of Packages

    npm.install(packages, opts).then(function)
NameTypeValue
packagesArraypackages to be installed
optsObjectsave:true/false; global:true/false; cwd:string; saveDev:true/false; noOptional:true/false; legacyBundling: true/false; output:true/false

Example

    var npm = require('npm-programmatic');
    npm.install(['left-pad'], {
        cwd:'/path/to/my/project',
        save:true
    })
    .then(function(){
        console.log("SUCCESS!!!");
    })
    .catch(function(){
        console.log("Unable to install package");
    });

Unistallation of Packages

    npm.uninstall(packages, opts).then(function)
NameTypeValue
packagesArraypackages to be uninstalled
optsObjectsave:true/false; global:true/false; cwd:string; saveDev:true/false; output:true/false

Example

    var npm = require('npm-programmatic');
    npm.uninstall(['left-pad'], {
        cwd:'/path/to/my/project',
        save:true
    })
    .then(function(){
        console.log("SUCCESS!!!");
    })
    .catch(function(){
        console.log("Unable to uninstall package");
    });

List Installed Packages

    npm.list(path).then(function)
NameTypeValue
pathStringpath at which to look

Example

    var npm = require('npm-programmatic');
    npm.list('/path/to/project')
    .then(function(arrayOfPackages){
        console.log(arrayOfPackages);
    })
    .catch(function(){
        console.log("Unable to uninstall package");
    });

Tests

install mocha and dev dependencies. Then run npm test

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文