Last active
February 24, 2022 10:07
-
-
Save JoshK2/01218140a64de9ed3706e5ea06fcc0b0 to your computer and use it in GitHub Desktop.
Import all components from a collection at bit.dev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//IMPORTANT - install thie before: npm i child-process-promise --save-dev | |
/* | |
put this in your package.json script: | |
"import-all": "node import-all.js" | |
npm run import-all <user>.<collection> amount | |
*/ | |
const exec = require('child-process-promise').exec; | |
const args = process.argv; | |
const remote = args[2]; | |
let amount = args[3]; | |
console.log('remote', remote); | |
console.log('amount', amount); | |
exec(`bit list ${remote} -j`, {}).then(function (result) { | |
if(!amount) amount = 1; | |
const list = JSON.parse(result.stdout); | |
const components = list.map(comp => { | |
return comp.id; | |
}); | |
const arrayCommands = chunkArrayInGroups(components, amount); | |
arrayCommands.map(_array => { | |
const commands = `bit import ${_array.join(' ')}` | |
console.log(commands); | |
importComponents(commands); | |
}); | |
}); | |
function importComponents(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 chunkArrayInGroups(arr, size) { | |
var newArr=[]; | |
for (var i=0; arr.length>size; i++){ | |
newArr.push(arr.splice(0,size)); | |
} | |
newArr.push(arr.slice(0)); | |
return newArr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment