mirror of
https://github.com/danbulant/bpm
synced 2026-07-05 11:00:40 +00:00
Allow installation with inline args
This commit is contained in:
parent
40c00e7160
commit
94ea018158
2 changed files with 44 additions and 2 deletions
|
|
@ -101,8 +101,10 @@ module.exports = class Package {
|
||||||
console.log("Done");
|
console.log("Done");
|
||||||
}
|
}
|
||||||
|
|
||||||
install(flags, ...packages){
|
async install(flags, packages){
|
||||||
parser.load();
|
parser.load();
|
||||||
|
await parser.addDependencies(packages);
|
||||||
parser.install((flags.dev | false));
|
parser.install((flags.dev | false));
|
||||||
|
parser.saveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,6 +21,7 @@ module.exports = class PackageParser {
|
||||||
throw Error("Invalid JSON file");
|
throw Error("Invalid JSON file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.path = path;
|
||||||
this.pkg = json;
|
this.pkg = json;
|
||||||
|
|
||||||
this.verify();
|
this.verify();
|
||||||
|
|
@ -28,6 +29,45 @@ module.exports = class PackageParser {
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async addDependencies(deps){
|
||||||
|
if(!deps)return;
|
||||||
|
|
||||||
|
for(var i = 0; i < deps.length; i++){
|
||||||
|
var depi = deps[i].split(/[a-z]@/gi);
|
||||||
|
var dep = depi[0];
|
||||||
|
var version = depi[1] || null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var pkg = JSON.parse(await request(global.config.repository + dep));
|
||||||
|
} catch(e){
|
||||||
|
console.error("An error occured during parsing information");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pkg.error)throw Error(pkg.error);
|
||||||
|
|
||||||
|
if (!pkg["dist-tags"]) {
|
||||||
|
console.warn("Couldn't install " + deps[i] + " - no published version");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!pkg["dist-tags"].latest) {
|
||||||
|
console.warn("Couldn't install " + deps[i] + " - no published version");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!this.pkg.dependencies)this.pkg.dependencies = {};
|
||||||
|
|
||||||
|
if(!version){
|
||||||
|
this.pkg.dependencies[dep] = "^" + pkg["dist-tags"].latest;
|
||||||
|
} else {
|
||||||
|
this.pkg.dependencies[dep] = version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveChanges(){
|
||||||
|
return fs.writeFileSync(this.path, JSON.stringify(this.pkg, null, 2) + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
verify(){
|
verify(){
|
||||||
var pkg = this.pkg;
|
var pkg = this.pkg;
|
||||||
|
|
||||||
|
|
@ -114,7 +154,7 @@ module.exports = class PackageParser {
|
||||||
fs.mkdirSync(path.dirname(process.cwd() + "/node_modules/" + pk.name));
|
fs.mkdirSync(path.dirname(process.cwd() + "/node_modules/" + pk.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Creating symlink");
|
//console.log("Creating symlink");
|
||||||
fs.symlinkSync(path.relative(process.cwd() + "/node_modules/" + pk.name, this.sanitizeName(pk.name, deps.version)), process.cwd() + "/node_modules/" + pk.name);
|
fs.symlinkSync(path.relative(process.cwd() + "/node_modules/" + pk.name, this.sanitizeName(pk.name, deps.version)), process.cwd() + "/node_modules/" + pk.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue