[helpers][m]: helper function to copy files and install packages
This commit is contained in:
16
packages/create-portal-app/helpers/copy.js
Normal file
16
packages/create-portal-app/helpers/copy.js
Normal 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)));
|
||||||
27
packages/create-portal-app/helpers/install.js
Normal file
27
packages/create-portal-app/helpers/install.js
Normal 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()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user