UNPKG

yahoi

Version:

Yet Another Highly Opinionated Isomorphic Framework

164 lines (146 loc) 6.05 kB
#!/usr/bin/env node var program = require('commander-plus'); var shell = require('shelljs'); var c = require('colors'); var path = require('path'); const VERSION = '0.2'; const prjRoot = process.cwd(); program.version(VERSION) program .command('install') .action(function() { header(); console.log(c.yellow('This will setup the following file/folder structure:')); br(); console.log(c.yellow('|-- .babelrc')); console.log(c.yellow('|-- .npmignore')); console.log(c.yellow('|-- config')); console.log(c.yellow('| |-- webpack.dev.config.js')); console.log(c.yellow('| `-- webpack.prod.config.js')); console.log(c.yellow('|-- dist')); console.log(c.yellow('|-- src')); console.log(c.yellow('| |-- app.js')); console.log(c.yellow('| |-- Client')); console.log(c.yellow('| | `-- index.js')); console.log(c.yellow('| |-- Components')); console.log(c.yellow('| | |-- Footer')); console.log(c.yellow('| | | `-- index.js')); console.log(c.yellow('| | |-- SimpleGrid')); console.log(c.yellow('| | | `-- index.js')); console.log(c.yellow('| | `-- index.js')); console.log(c.yellow('| |-- Containers')); console.log(c.yellow('| | |-- ExamplePage')); console.log(c.yellow('| | | `-- index.js')); console.log(c.yellow('| | `-- index.js')); console.log(c.yellow('| |-- Controller')); console.log(c.yellow('| | |-- ExampleController.js')); console.log(c.yellow('| | `-- IndexController.js')); console.log(c.yellow('| |-- Environments')); console.log(c.yellow('| | |-- Development.js')); console.log(c.yellow('| | `-- Production.js')); console.log(c.yellow('| |-- Public')); console.log(c.yellow('| | |-- Images')); console.log(c.yellow('| | | `-- ...')); console.log(c.yellow('| | `-- Stylesheets')); console.log(c.yellow('| | `-- ...')); console.log(c.yellow('| |-- Reducers')); console.log(c.yellow('| | |-- ExampleReducer.js')); console.log(c.yellow('| | `-- index.js')); console.log(c.yellow('| |-- Routing')); console.log(c.yellow('| | |-- DefaultRouter.js')); console.log(c.yellow('| | `-- ExampleRouter.js')); console.log(c.yellow('| |-- Store')); console.log(c.yellow('| | `-- index.js')); console.log(c.yellow('| |-- Util')); console.log(c.yellow('| | |-- apis')); console.log(c.yellow('| | | |-- ExampleApi')); console.log(c.yellow('| | | `-- ...')); console.log(c.yellow('| | `-- index.js')); console.log(c.yellow('| `-- Views')); console.log(c.yellow('| |-- Client')); console.log(c.yellow('| | |-- index.handlebars')); console.log(c.yellow('| `-- Examples')); console.log(c.yellow('| |-- exampleView.handlebars')); console.log(c.yellow('| `-- index.handlebars')); br(); console.log(c.red('This will overwrite any existing file!')); program.confirm(c.red('Do you wish to continue?'), function(ok) { if(!ok) { console.log(c.green('Aborted!')); process.exit(1) } else { console.log(c.yellow('Setting up your yahoi file structure ...')); shell.exec(`cp -R ./node_modules/yahoi/prjtmp/ ${prjRoot}/`); br(); console.log(c.green('Done! :-)')); br(); console.log(c.green('Type ') + c.yellow('`yahoi start`') + c.green(' to start the example app')); console.log(c.green('Type ') + c.yellow('`yahoi dev`') + c.green(' to start developing')); console.log(c.green('Type ') + c.yellow('`yahoi build`') + c.green(' to build your project')); br(); process.exit() } }); }); program .command('start') .action(function() { header(); console.log(c.green('Starting your project')); br(); shell.exec(`cross-env NODE_ENV=production node ${prjRoot}/dist/app.js`); }); program .command('update') .action(function() { console.log('Updating yahoi ...'); }); program .command('build') .action(function() { header(); console.log(c.yellow('Building your yahoi project ...')); br(); shell.exec(`rm -rf ${prjRoot}/dist/Public && cp -R ${prjRoot}/src/Public ${prjRoot}/dist/Public`); shell.exec(`rm -rf ${prjRoot}/dist/Translations && cp -R ${prjRoot}/src/Translations ${prjRoot}/dist/Translations`); shell.exec(`cross-env NODE_ENV=production babel --ignore ${prjRoot}/src/Public/Javascript src --out-dir ${prjRoot}/dist`); shell.exec(`cross-env NODE_ENV=production webpack --config ${prjRoot}/config/webpack.prod.config.js`); shell.exec(`rm -rf ${prjRoot}/dist/Views && cp -R ${prjRoot}/src/Views ${prjRoot}/dist/Views`); shell.exec(`cross-env NODE_ENV=client-prod babel --out-file ${prjRoot}/dist/Client/index.js ${prjRoot}/src/Client/index.js`); shell.exec(`cross-env NODE_ENV=client-prod babel --out-dir ${prjRoot}/dist/Containers ${prjRoot}/src/Containers`); shell.exec(`cross-env NODE_ENV=client-prod babel --out-dir ${prjRoot}/dist/Components ${prjRoot}/src/Components`); }); program .command('dev') .action(function() { header(); console.log(c.yellow('Starting your yahoi dev environment ...')); br(); shell.exec('cross-env NODE_ENV=development babel-node src/app.js'); }); /* program .command('post-install') .action(function() { var fs = require('fs'); var fileName = `${prjRoot}/package.json`; var file = require(fileName); file.scripts.yahoi = "yahoi"; try { fs.writeFileSync(fileName, JSON.stringify(file)); console.log(`Congratulations! You have successfully downloaded yahoi@${VERSION}!`); } catch(e) { console.log(`Error!`, e); } }); */ function br() { console.log(''); } function header() { console.log(''); console.log(''); console.log(c.green(`yahoi cli - v${VERSION}`)); console.log(''); } program.parse(process.argv);