From 4bb45346e6128acbe8e62820535036069ab5caf1 Mon Sep 17 00:00:00 2001 From: Ihor Chulinda Date: Tue, 6 Mar 2018 13:51:02 +0100 Subject: [PATCH] feat(cli): scaffold command for cli --- packages/baset-cli/src/commands/scaffold.ts | 48 +++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 packages/baset-cli/src/commands/scaffold.ts diff --git a/packages/baset-cli/src/commands/scaffold.ts b/packages/baset-cli/src/commands/scaffold.ts new file mode 100644 index 00000000..8d35439d --- /dev/null +++ b/packages/baset-cli/src/commands/scaffold.ts @@ -0,0 +1,48 @@ +import { Scaffolder, utils } from 'baset-core'; +import glob from 'glob-promise'; +import { CommandModule } from 'yargs'; +import { IGlobalArgs } from '../options'; + +interface IAcceptArgs extends IGlobalArgs { + files: string; + specs: string; +} + +function complementArray(arrayA: T[], arrayB: T[]) { + arrayA.forEach(match => { + const index = arrayB.indexOf(match); + + if (index > -1) { + arrayB.splice(index, 1); + } + }); +} + +const scaffoldCommand: CommandModule = { + command: ['scaffold'], + aliases: ['s'], + describe: 'Scaffolding new spec', + builder: { + files: { + alias: 'f', + type: 'string', + describe: 'Glob pattern for project files', + default: '**/*.js', + }, + specs: { + alias: 's', + type: 'string', + describe: 'Glob pattern for spec files', + default: '**/*.spec.js', + }, + }, + handler: async (argv: IAcceptArgs) => { + const files = await glob(argv.files); + const specs = await glob(argv.specs); + complementArray(specs, files); + const scaffolder = new Scaffolder(); + const results = scaffolder.scaffold(files); + console.log(JSON.stringify(await Promise.all(results), undefined, 4)); + }, +}; +export = scaffoldCommand;