-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathreactful.ts
More file actions
116 lines (104 loc) · 3.29 KB
/
reactful.ts
File metadata and controls
116 lines (104 loc) · 3.29 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#! /usr/bin/env node
import path from 'path';
import { Command } from 'commander';
import {
createApp,
openApp,
nameFromPath,
generateComponent,
generateTest,
commandExists,
runCommand,
} from '../commands';
const program = new Command();
program
.version(
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('../../package.json').version,
'-v, --version',
'display the version of the current reactful command',
)
.name('npx reactful')
.helpOption('-h, --help', 'display help for the reactful command');
(async function main() {
const yarnExists = commandExists('yarn');
const gitExists = commandExists('git');
let tsProject;
try {
require(path.resolve('tsconfig.json'));
tsProject = true;
} catch (err) {
tsProject = false;
}
program
.command('create <app-name>', { isDefault: true })
.alias('')
.alias('new')
.description('creata a new reactful project')
.option(
'-t, --template <template_name>',
'Template to use: default, typescript, simple',
)
.option('--no-tests', 'Do not include tests dependencies')
.option('--no-git', 'Skip initializing the app as a git repo')
.option('--use-npm', 'Use npm as the package manager for the project')
.action(async (appPath, cmdObj = {}) => {
await createApp({
appPath: appPath,
appName: nameFromPath(appPath),
template: cmdObj.template || 'default',
useGit: !cmdObj.git ? false : gitExists,
useYarn: cmdObj.useNpm ? false : yarnExists,
useTests: cmdObj.tests,
});
});
program
.command('init')
.description('initialize current directory as a reactful project')
.option(
'-t, --template <template_name>',
'Template to use: default, typescript, simple',
)
.option('--no-tests', 'Do not include tests dependencies')
.option('--no-git', 'Skip initializing the app as a git repo')
.option('--use-npm', 'Use npm as the package manager for the project')
.action(async (cmdObj) => {
await createApp({
appPath: '.',
appName: path.basename(path.resolve('.')),
template: cmdObj.template || 'default',
useGit: cmdObj.git ? false : gitExists,
useYarn: cmdObj.useNpm ? false : yarnExists,
useTests: !cmdObj.tests,
});
});
program
.command('gc <component-name>')
.alias('')
.alias('gfc')
.description('generate a function component')
.action((componentName) =>
generateComponent('rfc', componentName, tsProject),
);
program
.command('gcc <component-name>')
.description('generate a class component')
.action((componentName) =>
generateComponent('rcc', componentName, tsProject),
);
program
.command('gt <component-name>')
.description('generate a test for existing component')
.action((componentName) => generateTest(componentName, tsProject));
program
.command('open [port]', { hidden: true })
.description('open browser for the development environment')
.action((port = '1234') => openApp(`http://localhost:${port}`));
program
.command('. <script>')
.description('run a script in the current directroy')
.action((script) => {
runCommand({ useYarn: yarnExists, script });
});
await program.parseAsync();
})();