forked from vuepress/create-vuepress-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicGenerator.js
48 lines (43 loc) · 1.11 KB
/
BasicGenerator.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
45
46
47
48
const { statSync } = require('fs');
const { basename } = require('path');
const Generator = require('yeoman-generator');
const glob = require('glob');
const debug = require('debug')('create-vuepress:BasicGenerator');
function noop() {
return true;
}
class BasicGenerator extends Generator {
constructor(opts) {
super(opts);
this.opts = opts;
this.name = basename(opts.env.cwd);
}
isTsFile(f) {
return (
f.endsWith('.ts') ||
f.endsWith('.tsx') ||
['tsconfig.json', 'tslint.yml'].includes(f)
);
}
writeFiles({ context, filterFiles = noop }) {
debug(`context: ${JSON.stringify(context)}`);
glob
.sync('**/*', {
cwd: this.templatePath(),
dot: true
})
.filter(filterFiles)
.forEach(file => {
debug(`copy ${file}`);
const filePath = this.templatePath(file);
if (statSync(filePath).isFile()) {
this.fs.copyTpl(
this.templatePath(filePath),
this.destinationPath(file.replace(/^_/, '.')),
context
);
}
});
}
}
module.exports = BasicGenerator;