Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Commit

Permalink
Update init command
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor-Lopes committed Jun 1, 2018
1 parent da74a63 commit 32b854b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
33 changes: 7 additions & 26 deletions commands/init.js
Original file line number Diff line number Diff line change
@@ -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 <directory>', 'Target Directory')
.description('Generate Express Lib')
.action((cmd, options) => {
init.initProject(options.dir)
})
}
34 changes: 34 additions & 0 deletions libs/init.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
"ejs": "^2.6.1",
"shelljs": "^0.8.2"
}
}
}

0 comments on commit 32b854b

Please sign in to comment.