-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
100 lines (89 loc) · 3.5 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
97
98
99
100
const inquirer = require('inquirer');
const _ = require('lodash');
const fs = require('fs');
function validate(answer) {
// if (answer.length < 1) {
// return 'You must choose at least one topping.';
// }
return true;
}
function convertComponentName(value) {
value.split(" ")
.map(_.startCase)
.join("")
}
/**
* Render path from list name separated with semicolon (Eg. eggs,mango,apple)
*/
function renderPath(values) {
values.split(',')
}
module.exports = function (plop) {
// TODO: adding a custom inquirer prompt type
plop.addPrompt('directory', require('inquirer-directory'));
// TODO: controller generator
plop.setGenerator('components', {
description: 'Add Components',
prompts: [
{
type: 'directory',
name: 'path',
message: 'where would you like to put this component?',
basePath: plop.getPlopfilePath()
},
{
type: 'checkbox',
message: 'Select components',
name: 'components',
choices: [
new inquirer.Separator(),
new inquirer.Separator('GENERAL'),
'Typography',
'Button',
'Icon',
new inquirer.Separator(),
new inquirer.Separator('LAYOUT'),
'Header',
new inquirer.Separator(),
new inquirer.Separator('DATA ENTRY'),
'Input',
'Checkbox',
'Date Picker',
new inquirer.Separator(),
new inquirer.Separator('Display'),
'Avatar',
new inquirer.Separator(),
new inquirer.Separator('NAVIGATION'),
'Menu',
],
validate
}],
actions: [
function copyComponents(answers) {
// move the current working directory to the plop file path
// this allows this action to work even when the generator is
// executed from inside a subdirectory
process.chdir(plop.getPlopfilePath());
const components = plop.renderString('{{components}}', answers).split(',').map(_.startCase);
const path = plop.renderString('{{path}}', answers)
// do a synchronous copy via node fs
components.forEach(component => {
fs.writeFileSync(`${path}/${component}.js`, fs.readFileSync('plop-components/controller.js'));
})
return 'Wrote';
},
function appendDependencies(answers) {
// move the current working directory to the plop file path
// this allows this action to work even when the generator is
// executed from inside a subdirectory
process.chdir(plop.getPlopfilePath());
let packageStr = fs.readFileSync('package.json');
let packageObj = JSON.parse(packageStr);
packageObj = { ...packageObj, dependencies: { "react-native": "^0.60.4", ...packageObj.dependencies, } }
packageStr = JSON.stringify(packageObj, null, '\t');
// TODO: Write package.json file
fs.writeFileSync('package.json', packageStr);
return packageObj;
}],
});
};