-
Notifications
You must be signed in to change notification settings - Fork 0
/
_toEjs.js
42 lines (35 loc) · 1.05 KB
/
_toEjs.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
/**
* * Created by lee on 2019/7/10
* add ejs suffix
*/
const fs = require('fs');
const { resolve } = require('path');
const { getAllFilesInDir } = require('./utils/fs');
const shell = require('child_process').execSync;
const TEMP = 'templates';
function getAllTemplatesRoot(path, lists = []) {
let items = fs.readdirSync(path);
items.forEach(item => {
let childPath = `${path}/${item}`;
if (fs.statSync(childPath).isDirectory()) {
if (item === TEMP) {
lists.push(childPath);
} else {
getAllTemplatesRoot(childPath, lists);
}
}
});
return lists;
}
function transform(rootPath) {
let templates = getAllTemplatesRoot(rootPath, []);
let files = [];
templates.forEach(tmp => {
files = files.concat(getAllFilesInDir(tmp));
});
files = files.filter(file => file.indexOf('.ejs') === -1);
files.forEach(file => {
shell(`mv ${file} ${file}.ejs`);
});
}
transform(resolve(__dirname, "generators")); // eslint-disable-line