yahoi
Version:
Yet Another Highly Opinionated Isomorphic Framework
148 lines (133 loc) • 5.56 kB
JavaScript
var program = require('commander-plus');
var shell = require('shelljs');
var c = require('colors');
const VERSION = '0.1.22';
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/ ./');
br();
console.log(c.green('Done! :-)'));
br();
console.log(c.green('Type ') + c.yellow('`npm-do yahoi start`') + c.green(' to start the example app'));
console.log(c.green('Type ') + c.yellow('`npm-do yahoi dev`') + c.green(' to start developing'));
console.log(c.green('Type ') + c.yellow('`npm-do yahoi build`') + c.green(' to build your project'));
br();
process.exit()
}
});
});
program
.command('start')
.action(function() {
header();
console.log(c.green('Starting your project'));
console.log('');
shell.exec('cross-env NODE_ENV=production node 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 ./dist/Public && cp -R ./src/Public ./dist/Public');
shell.exec('rm -rf ./dist/Translations && cp -R ./src/Translations ./dist/Translations');
shell.exec('cross-env NODE_ENV=production babel --ignore ./src/Public/Javascript src --out-dir dist');
shell.exec('cross-env NODE_ENV=production webpack --config ./config/webpack.prod.config.js');
shell.exec('rm -rf ./dist/Views && cp -R ./src/Views ./dist/Views');
shell.exec('cross-env NODE_ENV=client-prod babel --out-file dist/Client/index.js src/Client/index.js');
shell.exec('cross-env NODE_ENV=client-prod babel --out-dir dist/Containers src/Containers');
shell.exec('cross-env NODE_ENV=client-prod babel --out-dir dist/Components 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() {
console.log(`Congratulations! You have successfully downloaded yahoi@${VERSION}!`);
});
function br() {
console.log('');
}
function header() {
console.log('');
console.log('');
console.log(c.green(`yahoi cli - v${VERSION}`));
console.log('');
}
program.parse(process.argv);