In order to use this plugin, your project must have starflow as a dependency.
$ npm install --save-dev starflow-npm
Using a workflow:
var starflow = require('starflow');
var steps = [
'npm.dependencies'
];
var workflow = new starflow.Workflow(steps);
return workflow
.addPlugin(require('starflow-npm'))
.run();
In an executable:
module.exports = function (starflow) {
var createBranchFactory = require('starflow-npm')(starflow).factories.dependencies;
function MyExecutable() {
starflow.BaseExecutable.call(this, 'myPlugin.myExecutable');
}
MyExecutable.prototype = Object.create(starflow.BaseExecutable.prototype);
MyExecutable.prototype.constructor = MyExecutable;
MyExecutable.prototype.exec = function exec() {
var dependenciesExecutable = this.createExecutable(dependenciesFactory);
return new starflow.Task(dependenciesExecutable)
.run();
};
return function () {
return new MyExecutable();
};
};
Thereafter is the list of all the executable classes provided by this plugin.
Important The titles indicate the name that can be used when writing the steps of a workflow.
Get an array of dependencies and devDependencies names (e.g. ['a', 'b', 'c']
) for a particular package.json.
If asked for, it provides a map of name: version
instead of an array (e.g. {'a': '0.0.0', 'b': '0.0.0'}
).
Usage:
// for a workflow
var withVersions = true;
var steps = [
// if no path is provided, the executable will look at the package.json file at the root of the project
{'npm.dependencies': ['path/to/dirHoldingPackageJson', withVersions]}
// or {'npm.dependencies': 'path/to/dirHoldingPackageJson'} to only get the names
];
// in an executable
var dependenciesFactory = require('starflow-npm')(starflow).factories.dependencies;
var withVersions = true;
var myTask = new starflow.Task(dependenciesFactory, ['path/to/dirHoldingPackageJson', withVersions]);
Update the version of a specific dependency in a given package.json file.
Usage:
// for a workflow
var steps = [
{'npm.updatePackageVersion': ['path/to/package.json', 'dependencyName', 'version']}
];
// in an executable
var updatePackageVersionFactory = require('starflow-npm')(starflow).factories.updatePackageVersion;
var myTask = new starflow.Task(updatePackageVersionFactory, ['path/to/package.json', 'dependencyName', 'version']);
Some of the executables of this plugin store some values in their storage.
-
list Contains either an array of dependency names or a map of
name: version
.Example 1:
var starflow = require('starflow'); var steps = [ 'npm.dependencies', // displays the names of dependencies and devDependencies for the current project {'custom.echo': '{{/npm.dependencies/list}}'} ]; var workflow = new starflow.Workflow(steps); return workflow .addPlugin(require('starflow-npm')) .addPlugin(require('starflow-custom')) // plugin that contains the 'echo' executable .run();
Example 2:
var starflow = require('starflow'); var steps = [ {'npm.dependencies': [null, true]}, // displays the names and their versions of dependencies and devDependencies for the current project {'custom.echo': '{{/npm.dependencies/list}}'} ]; var workflow = new starflow.Workflow(steps); return workflow .addPlugin(require('starflow-npm')) .addPlugin(require('starflow-custom')) // plugin that contains the 'echo' executable .run();
Note: learn more about storage paths on the Starflow documentation page.