|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const packageJson = require('../package.json'); |
| 4 | + |
| 5 | +const chalk = require('chalk'); |
| 6 | +const commander = require('commander'); |
| 7 | +const fs = require('fs-extra'); |
| 8 | +const path = require('path'); |
| 9 | + |
| 10 | + |
| 11 | +let projectName; |
| 12 | + |
| 13 | +const program = new commander.Command(packageJson.name) |
| 14 | +.version(packageJson.version) |
| 15 | +.arguments('<project-directory>') |
| 16 | +.usage(`${chalk.green('<project-directory>')} [options]`) |
| 17 | +.action(name => { |
| 18 | + projectName = name; |
| 19 | +}) |
| 20 | +.allowUnknownOption() |
| 21 | +.on('--help', () => { |
| 22 | + console.log(` Only ${chalk.green('<project-directory>')} is required.`); |
| 23 | + console.log(); |
| 24 | +}) |
| 25 | +.parse(process.argv); |
| 26 | + |
| 27 | +if (typeof projectName === 'undefined') { |
| 28 | + console.error('Please specify the project directory:'); |
| 29 | + console.log(` ${chalk.cyan(program.name())} ${chalk.green('<project-directory>')}`); |
| 30 | + console.log(); |
| 31 | + console.log('For example:'); |
| 32 | + console.log(` ${chalk.cyan(program.name())} ${chalk.green('my-block')}`); |
| 33 | + console.log(); |
| 34 | + console.log(`Run ${chalk.cyan(`${program.name()} --help`)} to see all options.`); |
| 35 | + process.exit(1); |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +// 1. Create the directory |
| 41 | + |
| 42 | +const root = path.resolve(projectName); |
| 43 | +const appName = path.basename(root); |
| 44 | +const base = path.resolve('./examples/1-simple-block'); |
| 45 | + |
| 46 | +// TODO: Check and validate the appName |
| 47 | + |
| 48 | + |
| 49 | +// 1.1 Create the directory |
| 50 | +fs.ensureDir(root); |
| 51 | + |
| 52 | +console.log(`Creating a new Cloud Block in ${chalk.green(root)}.`); |
| 53 | + |
| 54 | + |
| 55 | +// 1.2 Copy files from the example |
| 56 | +console.log(`Copying files...`); |
| 57 | + |
| 58 | +fs.copySync(base, root); |
| 59 | + |
| 60 | + |
| 61 | +// 1.3 Rename the project files |
| 62 | +console.log(`Renaming the project to ${appName}`); |
| 63 | + |
| 64 | + |
| 65 | +console.log(chalk.green('Done!')); |
0 commit comments