generate-react-cli 7.3.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/{generate-react → generate-react.js} +4 -3
- package/package.json +34 -28
- package/readme.md +8 -1
- package/src/cli.js +8 -6
- package/src/cli.test.js +1 -1
- package/src/commands/generateComponent.js +5 -8
- package/src/templates/component/componentCssTemplate.js +1 -1
- package/src/templates/component/componentJsTemplate.js +1 -1
- package/src/templates/component/componentLazyTemplate.js +1 -1
- package/src/templates/component/componentStoryTemplate.js +1 -1
- package/src/templates/component/componentTestDefaultTemplate.js +1 -1
- package/src/templates/component/componentTestEnzymeTemplate.js +1 -1
- package/src/templates/component/componentTestTestingLibraryTemplate.js +1 -1
- package/src/templates/component/componentTsLazyTemplate.js +1 -1
- package/src/templates/component/componentTsTemplate.js +1 -1
- package/src/utils/generateComponentUtils.js +30 -31
- package/src/utils/grcConfigUtils.js +11 -12
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import cli from '../src/cli.js';
|
|
2
3
|
|
|
3
4
|
const isNotValidNodeVersion = () => {
|
|
4
5
|
const currentNodeVersion = process.versions.node;
|
|
5
6
|
const semver = currentNodeVersion.split('.');
|
|
6
7
|
const major = semver[0];
|
|
7
8
|
|
|
8
|
-
if (major <
|
|
9
|
+
if (major < 16) {
|
|
9
10
|
console.error(
|
|
10
11
|
// eslint-disable-next-line
|
|
11
12
|
'You are running Node ' +
|
|
12
13
|
currentNodeVersion +
|
|
13
|
-
' Generate React CLI requires Node
|
|
14
|
+
' Generate React CLI requires Node 16 or higher. Please update your version of Node.'
|
|
14
15
|
);
|
|
15
16
|
|
|
16
17
|
return true;
|
|
@@ -25,4 +26,4 @@ if (isNotValidNodeVersion()) {
|
|
|
25
26
|
process.exit(1);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
cli(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generate-react-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "A simple React CLI to generate components instantly and more.",
|
|
5
5
|
"repository": "https://github.com/arminbro/generate-react-cli",
|
|
6
6
|
"bugs": "https://github.com/arminbro/generate-react-cli/issues",
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"main": "bin/generate-react",
|
|
10
10
|
"bin": {
|
|
11
|
-
"generate-react": "bin/generate-react"
|
|
11
|
+
"generate-react": "bin/generate-react.js"
|
|
12
12
|
},
|
|
13
|
+
"type": "module",
|
|
13
14
|
"files": [
|
|
14
15
|
"bin/",
|
|
15
16
|
"src/",
|
|
@@ -37,30 +38,30 @@
|
|
|
37
38
|
"prepare": "husky install"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"chalk": "
|
|
41
|
-
"commander": "
|
|
42
|
-
"deep-keys": "
|
|
43
|
-
"fs-extra": "
|
|
44
|
-
"inquirer": "
|
|
45
|
-
"lodash": "
|
|
46
|
-
"replace": "
|
|
41
|
+
"chalk": "5.1.2",
|
|
42
|
+
"commander": "9.4.1",
|
|
43
|
+
"deep-keys": "0.5.0",
|
|
44
|
+
"fs-extra": "10.1.0",
|
|
45
|
+
"inquirer": "9.1.4",
|
|
46
|
+
"lodash": "4.17.21",
|
|
47
|
+
"replace": "1.2.2"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
|
-
"@commitlint/cli": "
|
|
50
|
-
"@commitlint/config-conventional": "
|
|
51
|
-
"@semantic-release/commit-analyzer": "
|
|
52
|
-
"@semantic-release/git": "
|
|
53
|
-
"@semantic-release/github": "
|
|
54
|
-
"@semantic-release/npm": "
|
|
55
|
-
"@semantic-release/release-notes-generator": "
|
|
56
|
-
"eslint": "
|
|
57
|
-
"eslint-config-airbnb-base": "
|
|
58
|
-
"eslint-config-prettier": "
|
|
59
|
-
"eslint-plugin-prettier": "
|
|
60
|
-
"husky": "
|
|
61
|
-
"prettier": "2.
|
|
62
|
-
"pretty-quick": "
|
|
63
|
-
"semantic-release": "
|
|
50
|
+
"@commitlint/cli": "17.1.2",
|
|
51
|
+
"@commitlint/config-conventional": "17.1.0",
|
|
52
|
+
"@semantic-release/commit-analyzer": "9.0.2",
|
|
53
|
+
"@semantic-release/git": "10.0.1",
|
|
54
|
+
"@semantic-release/github": "8.0.6",
|
|
55
|
+
"@semantic-release/npm": "9.0.1",
|
|
56
|
+
"@semantic-release/release-notes-generator": "10.0.3",
|
|
57
|
+
"eslint": "8.26.0",
|
|
58
|
+
"eslint-config-airbnb-base": "15.0.0",
|
|
59
|
+
"eslint-config-prettier": "8.5.0",
|
|
60
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
61
|
+
"husky": "8.0.1",
|
|
62
|
+
"prettier": "2.7.1",
|
|
63
|
+
"pretty-quick": "3.1.3",
|
|
64
|
+
"semantic-release": "19.0.5"
|
|
64
65
|
},
|
|
65
66
|
"prettier": {
|
|
66
67
|
"singleQuote": true,
|
|
@@ -98,13 +99,18 @@
|
|
|
98
99
|
"plugin:prettier/recommended"
|
|
99
100
|
],
|
|
100
101
|
"env": {
|
|
101
|
-
"commonjs":
|
|
102
|
-
"es2021": true,
|
|
102
|
+
"commonjs": false,
|
|
103
103
|
"node": true
|
|
104
104
|
},
|
|
105
105
|
"parserOptions": {
|
|
106
|
-
"ecmaVersion":
|
|
106
|
+
"ecmaVersion": "latest"
|
|
107
107
|
},
|
|
108
|
-
"rules": {
|
|
108
|
+
"rules": {
|
|
109
|
+
"import/extensions": [
|
|
110
|
+
{
|
|
111
|
+
"js": "always"
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
109
115
|
}
|
|
110
116
|
}
|
package/readme.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# Generate React CLI
|
|
2
2
|
|
|
3
|
-
[](https://david-dm.org/arminbro/generate-react-cli)
|
|
4
3
|
[](https://github.com/arminbro/generate-react-cli/blob/master/LICENSE)
|
|
5
4
|
|
|
6
5
|
<p align="center">
|
|
@@ -159,6 +158,14 @@ Otherwise, if you don't pass any options, it will just use the default values th
|
|
|
159
158
|
<td width="20%">Boolean</td>
|
|
160
159
|
<td width="20%"><code>false<code></td>
|
|
161
160
|
</tr>
|
|
161
|
+
<tr>
|
|
162
|
+
<td width="20%"><b>--flat</b></td>
|
|
163
|
+
<td width="60%">
|
|
164
|
+
Generate the files in the mentioned path insted of creating new folder for it
|
|
165
|
+
</td>
|
|
166
|
+
<td width="20%">Boolean</td>
|
|
167
|
+
<td width="20%"><code>false<code></td>
|
|
168
|
+
</tr>
|
|
162
169
|
</table>
|
|
163
170
|
|
|
164
171
|
### Custom component types:
|
package/src/cli.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { program } from 'commander';
|
|
2
|
+
import { createRequire } from 'module';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { getCLIConfigFile } = require('./utils/grcConfigUtils');
|
|
4
|
+
import initGenerateComponentCommand from './commands/generateComponent.js';
|
|
5
|
+
import { getCLIConfigFile } from './utils/grcConfigUtils.js';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
export default async function cli(args) {
|
|
8
8
|
const cliConfigFile = await getCLIConfigFile();
|
|
9
|
+
const localRequire = createRequire(import.meta.url);
|
|
10
|
+
const pkg = localRequire('../package.json');
|
|
9
11
|
|
|
10
12
|
// Initialize generate component command
|
|
11
13
|
|
|
@@ -13,4 +15,4 @@ module.exports = async function cli(args) {
|
|
|
13
15
|
|
|
14
16
|
program.version(pkg.version);
|
|
15
17
|
program.parse(args);
|
|
16
|
-
}
|
|
18
|
+
}
|
package/src/cli.test.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
2
|
generateComponent,
|
|
3
3
|
getComponentByType,
|
|
4
4
|
getCorrespondingComponentFileTypes,
|
|
5
|
-
}
|
|
5
|
+
} from '../utils/generateComponentUtils.js';
|
|
6
6
|
|
|
7
|
-
function initGenerateComponentCommand(args, cliConfigFile, program) {
|
|
7
|
+
export default function initGenerateComponentCommand(args, cliConfigFile, program) {
|
|
8
8
|
const selectedComponentType = getComponentByType(args, cliConfigFile);
|
|
9
9
|
|
|
10
10
|
const componentCommand = program
|
|
@@ -18,7 +18,8 @@ function initGenerateComponentCommand(args, cliConfigFile, program) {
|
|
|
18
18
|
'--type <type>',
|
|
19
19
|
'You can pass a component type that you have configured in your GRC config file.',
|
|
20
20
|
'default'
|
|
21
|
-
)
|
|
21
|
+
)
|
|
22
|
+
.option('-f, --flat', 'Generate the files in the mentioned path insted of creating new folder for it', false);
|
|
22
23
|
|
|
23
24
|
// Dynamic component command option defaults.
|
|
24
25
|
|
|
@@ -40,7 +41,3 @@ function initGenerateComponentCommand(args, cliConfigFile, program) {
|
|
|
40
41
|
componentNames.forEach((componentName) => generateComponent(componentName, cmd, cliConfigFile))
|
|
41
42
|
);
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
module.exports = {
|
|
45
|
-
initGenerateComponentCommand,
|
|
46
|
-
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export default `.TemplateName {}`;
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import replace from 'replace';
|
|
4
|
+
import camelCase from 'lodash/camelCase.js';
|
|
5
|
+
import kebabCase from 'lodash/kebabCase.js';
|
|
6
|
+
import snakeCase from 'lodash/snakeCase.js';
|
|
7
|
+
import upperFirst from 'lodash/upperCase.js';
|
|
8
|
+
import fsExtra from 'fs-extra';
|
|
9
|
+
|
|
10
|
+
import componentJsTemplate from '../templates/component/componentJsTemplate.js';
|
|
11
|
+
import componentTsTemplate from '../templates/component/componentTsTemplate.js';
|
|
12
|
+
import componentCssTemplate from '../templates/component/componentCssTemplate.js';
|
|
13
|
+
import componentLazyTemplate from '../templates/component/componentLazyTemplate.js';
|
|
14
|
+
import componentTsLazyTemplate from '../templates/component/componentTsLazyTemplate.js';
|
|
15
|
+
import componentStoryTemplate from '../templates/component/componentStoryTemplate.js';
|
|
16
|
+
import componentTestEnzymeTemplate from '../templates/component/componentTestEnzymeTemplate.js';
|
|
17
|
+
import componentTestDefaultTemplate from '../templates/component/componentTestDefaultTemplate.js';
|
|
18
|
+
import componentTestTestingLibraryTemplate from '../templates/component/componentTestTestingLibraryTemplate.js';
|
|
19
|
+
|
|
20
|
+
const { existsSync, outputFileSync, readFileSync } = fsExtra;
|
|
21
|
+
|
|
22
|
+
export function getComponentByType(args, cliConfigFile) {
|
|
18
23
|
const hasComponentTypeOption = args.find((arg) => arg.includes('--type'));
|
|
19
24
|
|
|
20
25
|
// Check for component type option.
|
|
@@ -48,7 +53,7 @@ function getComponentByType(args, cliConfigFile) {
|
|
|
48
53
|
return cliConfigFile.component.default;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
function getCorrespondingComponentFileTypes(component) {
|
|
56
|
+
export function getCorrespondingComponentFileTypes(component) {
|
|
52
57
|
return Object.keys(component).filter((key) => key.split('with').length > 1);
|
|
53
58
|
}
|
|
54
59
|
|
|
@@ -127,7 +132,7 @@ function componentTemplateGenerator({ cmd, componentName, cliConfigFile }) {
|
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
return {
|
|
130
|
-
componentPath: `${cmd.path}
|
|
135
|
+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
|
|
131
136
|
filename,
|
|
132
137
|
template,
|
|
133
138
|
};
|
|
@@ -162,7 +167,7 @@ function componentStyleTemplateGenerator({ cliConfigFile, cmd, componentName })
|
|
|
162
167
|
}
|
|
163
168
|
|
|
164
169
|
return {
|
|
165
|
-
componentPath: `${cmd.path}
|
|
170
|
+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
|
|
166
171
|
filename,
|
|
167
172
|
template,
|
|
168
173
|
};
|
|
@@ -201,7 +206,7 @@ function componentTestTemplateGenerator({ cliConfigFile, cmd, componentName }) {
|
|
|
201
206
|
}
|
|
202
207
|
|
|
203
208
|
return {
|
|
204
|
-
componentPath: `${cmd.path}
|
|
209
|
+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
|
|
205
210
|
filename,
|
|
206
211
|
template,
|
|
207
212
|
};
|
|
@@ -233,7 +238,7 @@ function componentStoryTemplateGenerator({ cliConfigFile, cmd, componentName })
|
|
|
233
238
|
}
|
|
234
239
|
|
|
235
240
|
return {
|
|
236
|
-
componentPath: `${cmd.path}
|
|
241
|
+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
|
|
237
242
|
filename,
|
|
238
243
|
template,
|
|
239
244
|
};
|
|
@@ -265,7 +270,7 @@ function componentLazyTemplateGenerator({ cmd, componentName, cliConfigFile }) {
|
|
|
265
270
|
}
|
|
266
271
|
|
|
267
272
|
return {
|
|
268
|
-
componentPath: `${cmd.path}
|
|
273
|
+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
|
|
269
274
|
filename,
|
|
270
275
|
template,
|
|
271
276
|
};
|
|
@@ -303,7 +308,7 @@ Please make sure you're pointing to the right custom template path in your gener
|
|
|
303
308
|
filename = customTemplateFilename;
|
|
304
309
|
|
|
305
310
|
return {
|
|
306
|
-
componentPath: `${cmd.path}
|
|
311
|
+
componentPath: `${cmd.path}${cmd.flat ? '' : `/${componentName}`}/${filename}`,
|
|
307
312
|
filename,
|
|
308
313
|
template,
|
|
309
314
|
};
|
|
@@ -329,7 +334,7 @@ const componentTemplateGeneratorMap = {
|
|
|
329
334
|
[buildInComponentFileTypes.LAZY]: componentLazyTemplateGenerator,
|
|
330
335
|
};
|
|
331
336
|
|
|
332
|
-
function generateComponent(componentName, cmd, cliConfigFile) {
|
|
337
|
+
export function generateComponent(componentName, cmd, cliConfigFile) {
|
|
333
338
|
const componentFileTypes = ['component', ...getCorrespondingComponentFileTypes(cmd)];
|
|
334
339
|
|
|
335
340
|
componentFileTypes.forEach((componentFileType) => {
|
|
@@ -427,9 +432,3 @@ function generateComponent(componentName, cmd, cliConfigFile) {
|
|
|
427
432
|
console.log(chalk.yellow(`NOTE: The "dry-run" flag means no changes were made.`));
|
|
428
433
|
}
|
|
429
434
|
}
|
|
430
|
-
|
|
431
|
-
module.exports = {
|
|
432
|
-
generateComponent,
|
|
433
|
-
getComponentByType,
|
|
434
|
-
getCorrespondingComponentFileTypes,
|
|
435
|
-
};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
|
|
3
|
+
import deepKeys from 'deep-keys';
|
|
4
|
+
import inquirer from 'inquirer';
|
|
5
|
+
import merge from 'lodash/merge.js';
|
|
6
|
+
import fsExtra from 'fs-extra';
|
|
7
|
+
|
|
8
|
+
const { accessSync, constants, outputFileSync, readFileSync } = fsExtra;
|
|
9
|
+
const { prompt } = inquirer;
|
|
6
10
|
|
|
7
11
|
// Generate React Config file questions.
|
|
8
12
|
|
|
@@ -35,7 +39,7 @@ const projectLevelQuestions = [
|
|
|
35
39
|
|
|
36
40
|
// --- component level questions.
|
|
37
41
|
|
|
38
|
-
const componentLevelQuestions = [
|
|
42
|
+
export const componentLevelQuestions = [
|
|
39
43
|
{
|
|
40
44
|
type: 'input',
|
|
41
45
|
name: 'component.default.path',
|
|
@@ -162,7 +166,7 @@ async function updateCLIConfigFile(missingConfigQuestions, currentConfigFile) {
|
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
168
|
|
|
165
|
-
async function getCLIConfigFile() {
|
|
169
|
+
export async function getCLIConfigFile() {
|
|
166
170
|
// --- Make sure the cli commands are running from the root level of the project
|
|
167
171
|
|
|
168
172
|
try {
|
|
@@ -200,8 +204,3 @@ async function getCLIConfigFile() {
|
|
|
200
204
|
return process.exit(1);
|
|
201
205
|
}
|
|
202
206
|
}
|
|
203
|
-
|
|
204
|
-
module.exports = {
|
|
205
|
-
componentLevelQuestions,
|
|
206
|
-
getCLIConfigFile,
|
|
207
|
-
};
|