-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·65 lines (57 loc) · 1.71 KB
/
index.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
#!/usr/bin/env node
const { exec } = require('child_process');
const path = require('path');
const command = process.argv[2];
const layer = process.argv[3];
const sliceName = process.argv[4];
const usageMessage = `
Usage:
fsdgen slice <layer> <sliceName>
fsdgen ui <componentName>
Examples:
fsdgen slice features userProfile
fsdgen slice entities article
fsdgen ui Button
`;
if (!command || (command !== 'slice' && command !== 'ui')) {
console.log(usageMessage);
process.exit(1);
}
if (command === 'slice') {
if (!layer || !sliceName) {
console.error('Usage: fsdgen slice <layer> <sliceName>');
process.exit(1);
}
const sliceScriptPath = path.resolve(__dirname, 'core', 'features', 'createSlice', 'index.js');
exec(`node ${sliceScriptPath} ${layer} ${sliceName}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
console.log(stdout);
});
} else if (command === 'ui') {
const componentName = process.argv[3];
if (!componentName) {
console.error('Usage: fsdgen ui <componentName>');
process.exit(1);
}
const uiScriptPath = path.resolve(__dirname, 'core', 'features', 'createUiComponent', 'index.js');
exec(`node ${uiScriptPath} ${componentName}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
console.log(stdout);
});
} else {
console.log('Hello, World!');
}