diff --git a/commands/init.js b/commands/init.js index 50785b5..24d47d2 100644 --- a/commands/init.js +++ b/commands/init.js @@ -1,31 +1,12 @@ -const log = console.log -const chalk = require('chalk') -require('shelljs/global') + +const init = require('../libs/init.js') module.exports = function initCommand(program) { program - .command('init') - .option('-t', '--target', 'Init project under a new name and/or directory') - .description('Create a Mean Starter Project in current directory') - .action(option => { - - if (!which('git')) { - log(chalk.red('Sorry, this command requires git')) - exit(1) - } - - let shellStr = 'git clone --progress https://github.com/Nucleus-Inc/MeanStarter.git' - - if (typeof (option) === 'string') { - shellStr += ' ' + option - } - - log(chalk.cyan('Started git repo cloning ...')) - - if (exec(shellStr).code !== 0) { - log(chalk.red.bold('Oops ... Something wrong happened, please try again.')) - exit(1) - } - log(chalk.green.bold('Finish cloning Mean Starter !')) + .command('init [cmd]') + .option('-d, --dir ', 'Target Directory') + .description('Generate Express Lib') + .action((cmd, options) => { + init.initProject(options.dir) }) } diff --git a/libs/init.js b/libs/init.js new file mode 100644 index 0000000..47ce147 --- /dev/null +++ b/libs/init.js @@ -0,0 +1,34 @@ +const log = console.log +const chalk = require('chalk') +require('shelljs/global') + +module.exports = { + initProject: (_target) => { + if (!which('git')) { + log(chalk.red('Sorry, this command requires git')) + exit(1) + } + + let dirName = _target || 'MeanStarter' + let gitShell = 'git clone --progress https://github.com/Nucleus-Inc/MeanStarter.git' + let yarnShell = 'cd ' + dirName + '&& yarn install' + + if (_target) { + gitShell += ' ' + _target + } + + log(chalk.cyan('Started git repo cloning ...')) + + if (exec(gitShell).code !== 0) { + log(chalk.red.bold('Oops ... Something wrong happened while cloning the repo.')) + exit(1) + } + + log(chalk.green.bold('Finish cloning Mean Starter !')) + + if (exec(yarnShell).code !== 0) { + log(chalk.red.bold('Oops ... Something wrong happened whily installing dependencies.')) + exit(1) + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index ffdfc82..e93a6b6 100644 --- a/package.json +++ b/package.json @@ -30,4 +30,4 @@ "ejs": "^2.6.1", "shelljs": "^0.8.2" } -} +} \ No newline at end of file