Skip to content

Commit

Permalink
feat(cli): scaffold command for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Igmat committed Mar 6, 2018
1 parent 3517bde commit 4bb4534
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/baset-cli/src/commands/scaffold.ts
Original file line number Diff line number Diff line change
@@ -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<T>(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;

0 comments on commit 4bb4534

Please sign in to comment.