-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.ts
75 lines (66 loc) · 2.27 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import path from 'node:path';
import Generator from 'yeoman-generator';
import { toPascalCase } from '@terascope/utils';
import { getTemplatePath } from '../utils.js';
import { snakeCase } from '../../helpers/utils.js';
export default class extends Generator {
answers!: any;
constructor(args: string|string[], opts: Record<string, any>) {
super(args, opts);
this.argument('asset_path', { type: String, required: true });
this.option('new', {
type: Boolean
});
this.sourceRoot(getTemplatePath('new-processor'));
}
async prompting(): Promise<void> {
if (this.options.new === true) {
this.answers = await this.prompt([
{
type: 'input',
name: 'name',
message: 'New Processor name',
validate: (value: string) => {
if (value.length < 1) {
return 'Please enter a value';
}
return true;
},
filter: (value: string) => snakeCase(value)
},
{
type: 'list',
name: 'type',
message: 'Select the type of processor',
choices: [
'batch',
'map',
'filter'
]
}
]);
}
}
paths(): void {
this.destinationRoot(path.join(this.options.asset_path));
}
createProcessor(): void {
let name = 'example';
let type = 'batch';
if (this.options.new === true) {
name = this.answers.name;
type = this.answers.type;
}
this.fs.copyTpl(
this.templatePath('base-op/schema.js'),
this.destinationPath(`asset/${name}/schema.js`),
{}
);
this.fs.copyTpl(this.templatePath(`base-op/${type}.js`),
this.destinationPath(`asset/${name}/processor.js`),
{ name: toPascalCase(name) });
this.fs.copyTpl(this.templatePath(`tests/${type}-spec.js`),
this.destinationPath(`test/${name}-spec.js`),
{ name });
}
}