[helpers][m]: helper function to copy files and install packages

This commit is contained in:
steveoni 2020-11-24 11:46:49 +01:00
parent 930e666ce8
commit 77294a3460
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,16 @@
const cpy = require("cpy")
const path = require("path");
const fs = require('fs');
module.exports = function copy(root,destination){
const dest_path = [process.cwd(), destination].join(path.sep)
if(fs.existsSync(dest_path)){
if(fs.readdirSync(dest_path).length > 0) return Promise.reject(`directory ${dest_path} exist and not empty`);
}
return cpy(root, dest_path);
}
// (async ()=> {
// await copy([process.cwd(),"templates"].join(path.sep), "newme");
// })().catch(e=> console.log(chalk.red(e)));

View File

@ -0,0 +1,27 @@
const spawn = require('cross-spawn');
const { resolve } = require('path');
const path = require('path');
module.exports = function install(projectName, isYarn){
return new Promise((resolve, reject)=>{
const appPath = [process.cwd(), projectName].join(path.sep);
//change the directory to the app directory
process.chdir(appPath);
let command = isYarn ? "yarn": "npm";
let args = isYarn ? [''] : ["install"];
let exec = spawn(command,args, {
stdio: 'inherit',
env: { ...process.env, ADBLOCK: '1', DISABLE_OPENCOLLECTIVE: '1' },
})
exec.on('close', (code)=>{
if (code !== 0) {
reject({ command: `${command} ${args[0]}` })
return
}
resolve()
});
});
}