-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
96 lines (89 loc) · 1.84 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const path = require('path');
const glob = require('glob');
const { workspaces = [] } = require('./package.json');
// eslint-disable-next-line unicorn/prefer-module
module.exports = function (plop) {
plop.setGenerator('readmes', {
description: 'Generate root repo readme',
prompts: [],
actions() {
return [
{
type: 'add',
path: 'readme.md',
templateFile: 'templates/root_readme.hbs.md',
force: true,
data: {
packages: getPackages(),
},
},
{
type: 'add',
path: 'packages/browserslist-config/readme.md',
templateFile: 'templates/browserslist-config_readme.hbs.md',
force: true,
data: {
browsers_link: `https://browserl.ist/?q=${encodeURI(
require('./packages/browserslist-config').join(
', ',
),
)}`,
},
},
];
},
});
plop.setGenerator('package', {
description: 'Create a new package',
prompts: [
{
type: 'input',
name: 'name',
message: 'name this package',
},
{
type: 'input',
name: 'description',
message: 'give this a description',
},
{
type: 'list',
name: 'public',
choices: ['true', 'false'],
default: 'true',
},
],
actions() {
return [
{
type: 'addMany',
destination: 'packages/{{ kebabCase name }}',
base: 'templates/package/',
templateFiles: 'templates/package/**/*',
},
];
},
});
};
function getPackages() {
return workspaces
.map((item) => `${item}/package.json`)
.reduce((results, item) => [...results, ...glob.sync(item)], [])
.map((item) => {
const pkg = require(`./${item}`);
return {
folder: path.parse(item).dir,
name: pkg.name,
description: pkg.description,
};
})
.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
}