mirror of
https://github.com/danbulant/bpm
synced 2026-05-19 04:08:47 +00:00
Custom script running
This commit is contained in:
parent
8c9157ad7c
commit
080769d916
2 changed files with 30 additions and 0 deletions
|
|
@ -109,6 +109,10 @@ module.exports = class Package {
|
|||
}
|
||||
|
||||
run(args){
|
||||
var script = args.contents[0];
|
||||
if(script == "run")script = args.contents[1];
|
||||
|
||||
parser.load();
|
||||
parser.start(script);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,10 +6,36 @@ const path = require("path");
|
|||
const http = require("http");
|
||||
const https = require("https");
|
||||
const targz = require('targz');
|
||||
const { spawn } = require('child_process');
|
||||
const config = require("./config")();
|
||||
var console = new Console;
|
||||
|
||||
module.exports = class PackageParser {
|
||||
start(script){
|
||||
if(!this.pkg.scripts)throw Error("No scripts are defined");
|
||||
|
||||
if(!this.pkg.scripts[script])throw Error("The script `" + script + "` is not defined in package.json");
|
||||
|
||||
console.output("");
|
||||
console.output(" > " + this.pkg.scripts[script]);
|
||||
console.output("");
|
||||
|
||||
var scr = this.pkg.scripts[script].split(" ");
|
||||
const child = spawn(scr.shift(), scr, { stdio: "inherit" });
|
||||
|
||||
child.on('close', (code) => {
|
||||
console.output("");
|
||||
if(code){
|
||||
console.error("Script exited with code " + code + ".");
|
||||
console.error("This is not a problem with BPM, there's likely output above.");
|
||||
console.error("");
|
||||
console.error("Failed at `" + script + "` script of " + this.pkg.name);
|
||||
} else {
|
||||
console.log("Done, process exited with code 0.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
load(path){
|
||||
if(!path) path = process.cwd() + "/package.json";
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue