/
index.js
44 lines (38 loc) · 1.08 KB
/
index.js
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
'use strict';
const path = require('path');
const Generator = require('yeoman-generator');
const superb = require('superb');
module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);
this.argument('name', {
type: String,
required: true,
description: 'Generator name'
});
}
writing() {
const generatorName = this.fs.readJSON(this.destinationPath('package.json')).name;
this.fs.copyTpl(
this.templatePath('index.js'),
this.destinationPath(path.join('generators', this.options.name, 'index.js')),
{
// Escape apostrophes from superb to not conflict with JS strings
superb: superb().replace('\'', '\\\''),
generatorName
}
);
this.fs.copy(
this.templatePath('templates/**'),
this.destinationPath(path.join('generators', this.options.name, 'templates'))
);
this.fs.copyTpl(
this.templatePath('test.js'),
this.destinationPath('test/' + this.options.name + '.js'),
{
name: this.options.name,
generatorName
}
);
}
};