From 5cd37f5d154d6955dd294abaef44d472735a74ad Mon Sep 17 00:00:00 2001 From: Thadeu Cotts Date: Tue, 24 Nov 2020 15:43:13 -0300 Subject: [PATCH] [feat] [s]: add tasks workflow --- packages/create-portal-app/index.js | 122 ++++++++++++++++------------ 1 file changed, 71 insertions(+), 51 deletions(-) diff --git a/packages/create-portal-app/index.js b/packages/create-portal-app/index.js index a03bc788..59b9804d 100755 --- a/packages/create-portal-app/index.js +++ b/packages/create-portal-app/index.js @@ -10,14 +10,14 @@ const copy = require("./helpers/copy"); const Listr = require("listr"); // Output path to create new portal app -let projectPath = '' +let projectPath = ""; // Commander parameters to specify CLI behavior program .name(package.name) .version(package.version) /** - * TODO + * TODO * Add Options * Add Example Options * Add templates @@ -31,7 +31,6 @@ program .allowUnknownOption() .parse(process.argv); - /** * Method to ask a custon name if was not passed as parameter * returns the value passed from terminal input @@ -49,55 +48,76 @@ async function promptPath() { }); } - /** - * Main method to start CLI and validate inputs - */ - async function run(){ - if (typeof projectPath === "string") { - projectPath = projectPath.trim(); +/** + * Main method to start CLI and validate inputs + */ +async function run() { + if (typeof projectPath === "string") { + projectPath = projectPath.trim(); + } + if (!projectPath) { + const response = await promptPath(); + if (typeof response.path === "string") { + projectPath = response.path.trim(); } - if (!projectPath) { - const response = await promptPath(); - if (typeof response.path === "string") { - projectPath = response.path.trim(); - } - } - if (!projectPath) { - //TODO separate log methods - console.log(); - console.log("Please choose a name to your project:"); - console.log(); - console.log("Example:"); - console.log( - `${chalk.cyan(program.name())} ${chalk.yellow("ny-portal-app")}` - ); - console.log(); - - process.exit(1); - } - - /** - * TODO Include workflow to create and manage the files and options - * - * Example: - * createApp() - * .then(installDependencies) - * .then(renameFiles) - * .then(accessFolder) - * .then(checkUpdated) - */ + } + if (!projectPath) { + //TODO separate log methods + console.log(); + console.log("Please choose a name to your project:"); + console.log(); + console.log("Example:"); + console.log( + `${chalk.cyan(program.name())} ${chalk.yellow("ny-portal-app")}` + ); + console.log(); + + process.exit(1); } - //Main CLI execution workflow - run() - .then(`${chalk.greenBright('Project Installed Sucess')}`) - .catch(error => { - if(error.command){ - console.log(`${chalk.cyan('Error on Create App')}`) - }else{ - console.log(`${chalk.red('Unexpected Erro. Please report it as a bug')}`) - console.log(error) + const root = path.join(__dirname + "/../portal"); + + const parsedPath = path.resolve(projectPath); + const project = path.basename(parsedPath); + + console.log(); + console.log( + `Begin Instalation of new portal.js on ${chalk.cyan(projectPath)} folder` + ); + console.log(); + //TODO Move this method to another one to keep more functional and split responsabilites + const tasks = new Listr([ + { + title: "Fetching Content", + task: () => copy(root, project), + }, + { + title: "Updating Content", + task: () => "", + }, + { + title: "Installing Dependencies", + task: () => install(project, true), + }, + { + title: "Git Init", + task: () => initGit(projectPath), + }, + ]); +} + +//Main CLI execution workflow +run() + .then(`${chalk.greenBright("Project Installed Sucess")}`) + .catch((error) => { + if (error.command) { + console.log(`${chalk.cyan("Error on Create App")}`); + } else { + console.log( + `${chalk.red("Unexpected Erro. Please report it as a bug")}` + ); + console.log(error); } - console.log() - process.exit(1) - }) \ No newline at end of file + console.log(); + process.exit(1); + });