-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplopfile.js
64 lines (56 loc) · 1.74 KB
/
plopfile.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import fs from 'fs-extra';
import path from 'path';
function findJsonFiles(folderPath) {
const files = fs.readdirSync(folderPath);
const jsonFiles = [];
for (const file of files) {
const filePath = path.join(folderPath, file);
if (fs.statSync(filePath).isDirectory()) {
// 如果是子文件夹,递归查找
const subfolderJsonFiles = findJsonFiles(filePath);
jsonFiles.push(...subfolderJsonFiles);
} else if (file.endsWith('.json')) {
jsonFiles.push(filePath);
}
}
return jsonFiles;
}
export default function (plop) {
// controller generator
plop.setGenerator('component', {
description: 'create a component with your choices',
prompts: [
// 组件类型
{
type: 'list',
name: 'type',
message: '组件类型',
choices: ['map'],
},
],
// actions refer to https://plopjs.com/documentation/#taking-it-further
actions: function (data) {
var actions = [];
if (data.type === 'map') {
const folderPath = `packages/map/src/assets/geoJson`;
const jsonFiles = findJsonFiles(folderPath);
const fileNames = jsonFiles.map((jsonFile) => {
const fileNameWithExtension = path.basename(jsonFile);
const fileNameWithoutExtension = path.parse(fileNameWithExtension).name;
return { fileName: fileNameWithoutExtension, path: path.relative(folderPath, jsonFile) };
});
actions.push({
data: {
fileNames,
},
type: 'addMany',
destination: folderPath,
base: 'examples/hbs/{{type}}',
templateFiles: 'examples/hbs/{{type}}/**',
stripExtensions: ['hbs'],
});
}
return actions;
},
});
}