[refactor] [m]: update install method
This commit is contained in:
@@ -1,27 +1,28 @@
|
|||||||
const spawn = require('cross-spawn');
|
const spawn = require("cross-spawn");
|
||||||
const { resolve } = require('path');
|
const path = require("path");
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
module.exports = function install(projectName, isYarn){
|
|
||||||
return new Promise((resolve, reject)=>{
|
function install(projectName, isYarn) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
const appPath = [process.cwd(), projectName].join(path.sep);
|
const appPath = [process.cwd(), projectName].join(path.sep);
|
||||||
//change the directory to the app directory
|
//change the directory to the app directory
|
||||||
process.chdir(appPath);
|
process.chdir(appPath);
|
||||||
|
|
||||||
let command = isYarn ? "yarn": "npm";
|
const command = isYarn ? "yarn" : "npm";
|
||||||
let args = isYarn ? [''] : ["install"];
|
const args = isYarn ? [""] : ["install"];
|
||||||
let exec = spawn(command,args, {
|
const exec = spawn(command, args, {
|
||||||
stdio: 'inherit',
|
stdio: "pipe",
|
||||||
env: { ...process.env, ADBLOCK: '1', DISABLE_OPENCOLLECTIVE: '1' },
|
env: { ...process.env, ADBLOCK: "1", DISABLE_OPENCOLLECTIVE: "1" },
|
||||||
})
|
});
|
||||||
|
|
||||||
exec.on('close', (code)=>{
|
exec.on("close", (code) => {
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
reject({ command: `${command} ${args[0]}` })
|
reject({ command: `${command} ${args[0]}` });
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
resolve()
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user