UNPKG

webcreate-cli

Version:
97 lines (86 loc) 3.4 kB
#! /usr/bin/env node const shell = require('shelljs'); const os = require('os'); const chalk = require("chalk"); const arg = require('arg'); const boxen = require("boxen"); const args = arg({ // Types '--project': String, '--component': String, '--v': String, '--help': Boolean, }); const DownloadMSG = chalk.gray.bold("✓ Template Downloaded & Dependency installing..."); const boxenOptions = { padding: 1, borderStyle: "round", color: 'white' }; const msgBox = boxen(DownloadMSG, boxenOptions); function afterDownloadTemplate() { if (os.platform() === 'darwin') { shell.exec('mv WebStarterKit ' + args['--project']); shell.cd(args['--project']); console.log(msgBox); shell.exec('npm install'); shell.rm('-rf', '.idea'); shell.rm('-rf', '.git'); shell.rm('-rf', 'root_package.json'); } else { shell.exec('Rename WebStarterKit ' + args['--project']); console.log(msgBox); shell.cd(args['--project']); shell.exec('npm install'); shell.rm('-rf', '.idea'); shell.rm('-rf', '.git'); shell.rm('-rf', 'root_package.json'); } } if (args['--help'] === true) { const helpObject = {}; function Help(Parameter_Name, Parameter_Value) { this.Parameter_Name = '--' + Parameter_Name; this.Parameter_Value = Parameter_Value; } helpObject.project = new Help("project", "Project Name"); helpObject.component = new Help("component", "Component Name"); helpObject.version = new Help("v", "{deprecated} for the old files || Nothing for the latest files"); console.table(helpObject); } else if (!args['--project'] && !args['--component']) { console.log('missing required argument: --project=Project Name or --component=Component Name. Type "webcreate --help" to know more.'); } else { if (args['--project']) { if (args['--v'] === 'deprecated') { shell.exec('git clone -b Deprecated https://github.com/ajoykarmakar459/WebStarterKit'); afterDownloadTemplate(); } else { shell.exec('git clone https://github.com/ajoykarmakar459/WebStarterKit'); afterDownloadTemplate(); } } else if (args['--component']) { if (os.platform() === 'darwin') { shell.cd('src/components'); shell.exec('mkdir ' + args['--component']); shell.cd(args['--component']); shell.exec('touch ' + args['--component'] + '.html && touch ' + args['--component'] + '.scss'); shell.cd('..'); shell.cd('..'); shell.cd('..'); shell.exec('echo @import \'"./' + args['--component'] + "/" + args['--component'] + '";\' >> src/components/components.scss;'); shell.cd('src/components'); console.log(msgBox); } else { shell.cd('src/components'); shell.exec('md ' + args['--component']); shell.cd(args['--component']); shell.exec('cd. > ' + args['--component'] + '.html && cd. > ' + args['--component'] + '.scss'); shell.cd('..'); shell.cd('..'); shell.cd('..'); shell.exec('echo @import \"./' + args['--component'] + "/" + args['--component'] + '";\ >> src/components/components.scss'); console.log(msgBox); } } }