-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |