Skip to content

Instantly share code, notes, and snippets.

@apollwebservices
Forked from GiladShoham/install-collection.js
Last active August 11, 2020 19:59
Show Gist options
  • Select an option

  • Save apollwebservices/68f698acc162370b44da7c33b7a82730 to your computer and use it in GitHub Desktop.

Select an option

Save apollwebservices/68f698acc162370b44da7c33b7a82730 to your computer and use it in GitHub Desktop.
//IMPORTANT - install this before: npm i child-process-promise --save-dev
/*
put this in your package.json script:
"install-collection": "node install-collection.js"
npm run install-collection <user>.<collection>
*/
/*jshint esversion: 6 */
const exec = require('child-process-promise').exec;
const args = process.argv;
const remote = args[2];
console.log('remote', remote);
exec(`bit list ${remote} -j`, {}).then(function(result) {
const list = JSON.parse(result.stdout);
const components = list.map(compToNpmId);
const command = `npm install ${components.join(' ')}`;
installComponents(command);
});
function installComponents(command) {
exec(command)
.then(function(result) {
var stdout = result.stdout;
var stderr = result.stderr;
console.log('stdout: ', stdout);
console.log('stderr: ', stderr);
})
.catch(function(err) {
console.error('ERROR: ', err);
});
}
function compToNpmId(component) {
return bitIdtoNpmId(component.id);
}
function bitIdtoNpmId(bitId) {
const doted = bitId.replace(/\//g, '.');
return `@bit/${doted}`;
}
{
"version": "0.0.4",
"name": "install-bit-collection",
"main": "install-collection.js",
"dependencies": {
"child-process-promise": "^2.2.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment