-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·39 lines (32 loc) · 939 Bytes
/
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
#!/usr/bin/env node
const path = require('path');
const { existsSync } = require('fs');
const spawnComponent = require('./spawnComponent');
const args = process.argv.slice(2);
const appDir = process.env.PWD;
const baseOutDir = path.join(appDir, 'src', 'components');
const appPackage = path.join(appDir, 'package.json');
if (!existsSync(appPackage)) {
const { name } = require('./package.json');
console.error(`Please run ${name} from your app root`);
process.exit(1);
}
if (args.length === 0) {
console.error('You have to provide a name for at least one component');
process.exit(1);
}
const templateDir = [
path.join(appDir, '.spawn-templates'),
path.join(__dirname, 'default-templates'),
].find(existsSync);
if (templateDir == null) {
console.error('Template directory not found');
process.exit(1);
}
for (const arg of args) {
spawnComponent({
componentName: arg,
templateDir,
baseOutDir,
});
}