glass-app-manager
Version:
Informatica's Glass Framework CLI for bootstrapping
38 lines (26 loc) • 1.68 kB
JavaScript
const del = require('del');
const ora = require("ora");
module.exports = async (dest, productName, action) => {
// delete all the folders before proceeding
const FOLDER_TO_BE_DELETED = `${dest}/**`; // current folder/product_name (all folders where user initliazes project)
// but we don't have to delete the folder where user will write their codes i.e. cwd/product/src/product/
// for that we need to exclude folders before passing it to del function
// exclude parent folder first =>
const EXCLUDE_PARENT_FOLDER = `!${dest}`;
// exclude src inside parent folder
const EXCLUDE_PARENT_SRC_FOLDER = `!${dest}/src`;
// exclude product folder inside src
const EXCLUDE_PARENT_SRC_PRODUCT_FOLDER = `!${dest}/src/${productName}/**`;
// exclude node_modules to make deletion process faster, anyway new npm install will update node_modules
const EXCLUDE_NODE_MODULES_FOLDER = `!${dest}/node_modules/**`;
// first param is source, rest of the parents with !, to be excluded
// in del function, we need to provide all the parent folder which shouldn't be deleted
const DELETE_ACTION_ARRAY = [FOLDER_TO_BE_DELETED, EXCLUDE_PARENT_FOLDER, EXCLUDE_NODE_MODULES_FOLDER];
// if update then don't delete src/product folder
if(action.toLowerCase() === 'update') {
DELETE_ACTION_ARRAY.push(EXCLUDE_PARENT_SRC_FOLDER, EXCLUDE_PARENT_SRC_PRODUCT_FOLDER);
}
const promise = del(DELETE_ACTION_ARRAY, {dot: true});
ora.promise(promise, `Deleting all the folders, subfolder & files at ${dest}, except ${dest}\\src\\${productName}\\**`);
await promise;
};