├── .eslintrc.js
├── .gitignore
├── .npmignore
├── .prettierrc.js
├── LICENSE
├── README.md
├── bin
└── react-generator.js
├── docs
├── CLI.md
└── demo.gif
├── index.js
├── lib
├── classes
│ └── component.js
├── commands
│ └── component.js
├── config.js
├── templates
│ ├── det
│ ├── rafc
│ ├── rafcp
│ ├── rafcpts
│ ├── rafcredux
│ ├── rafcreduxp
│ ├── rafcreduxpts
│ ├── rafcreduxts
│ ├── rafcts
│ ├── rcc
│ ├── rccp
│ ├── rccpts
│ ├── rccts
│ ├── rfc
│ ├── rfcp
│ ├── rfcpts
│ ├── rfcredux
│ ├── rfcreduxp
│ ├── rfcreduxpts
│ ├── rfcreduxts
│ └── rfcts
└── utils.js
├── mocha-parallel.js
├── package-lock.json
├── package.json
└── test
├── support
├── constants.js
└── utils.js
└── tests
├── rafc.js
├── rafcp.js
├── rafcredux.js
├── rafcreduxp.js
├── rcc.js
├── rccp.js
├── rfc.js
├── rfcp.js
├── rfcredux.js
└── rfcreduxp.js
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: {
3 | browser: false,
4 | commonjs: true,
5 | es6: true,
6 | },
7 | extends: "eslint:recommended",
8 | globals: {
9 | Atomics: "readonly",
10 | SharedArrayBuffer: "readonly",
11 | process: true,
12 | console: true,
13 | },
14 | parserOptions: {
15 | ecmaVersion: 2018,
16 | },
17 | rules: {
18 | "linebreak-style": ["error", "unix"],
19 | quotes: ["error", "double", { allowTemplateLiterals: true }],
20 | semi: ["error", "always"],
21 | },
22 | };
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 | *.pid.lock
11 |
12 | # Directory for instrumented libs generated by jscoverage/JSCover
13 | lib-cov
14 |
15 | # Coverage directory used by tools like istanbul
16 | coverage
17 |
18 | # nyc test coverage
19 | .nyc_output
20 |
21 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
22 | .grunt
23 |
24 | # node-waf configuration
25 | .lock-wscript
26 |
27 | # Compiled binary addons (http://nodejs.org/api/addons.html)
28 | build/Release
29 |
30 | # Dependency directories
31 | node_modules
32 | jspm_packages
33 |
34 | # Optional npm cache directory
35 | .npm
36 |
37 | # Optional REPL history
38 | .node_repl_history
39 |
40 | .rgrc.js
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | demo.gif
2 | docs/
3 | .eslintrc.js
4 | .prettierrc.js
5 | test/
6 | mocha-parallel.js
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | trailingComma: "es5",
3 | tabWidth: 2,
4 | semi: true,
5 | singleQuote: false,
6 | };
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) [year] [fullname]
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Welcome to awesome-react-generator 👋
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | > No more clicking around to create files in your react project! Awesome React Generator is Command Line Tool that let's you generate component files/folders without leaving your terminal.
21 |
22 |
23 |
24 |
25 |
26 | ### 🏠 [Homepage](https://github.com/iamtabrezkhan/awesome-react-generator)
27 |
28 | ## Install
29 |
30 | ```sh
31 | npm install awesome-react-generator -g
32 | ```
33 |
34 | ## Usage
35 |
36 | ```sh
37 | rg component rfc hello-world
38 | ```
39 |
40 | ## Commands
41 |
42 | Check out the commands [here](docs/CLI.md)
43 |
44 | ## Override CLI options
45 |
46 | Let's say you don't want to pass `--test` option every time you want to generate a component with test file.
47 | You can create a config file `.rgrc.js` at the root of your project to override CLI options.
48 |
49 | Example below:
50 |
51 | ```js
52 | /* this will generate test file with .spec.js extension
53 | and modular css file for every generated component */
54 | module.exports = {
55 | component: {
56 | options: {
57 | test: true,
58 | cssType: "modular",
59 | testExt: "spec-js",
60 | },
61 | },
62 | };
63 | ```
64 |
65 | or
66 |
67 | ```js
68 | /* this will generate test file with .spec.js extension and modular
69 | css file for every generated component but for rfc type component it
70 | will generate test file with extension .test.js and normal css file */
71 | module.exports = {
72 | component: {
73 | rfc: {
74 | testExt: "test-js",
75 | cssType: "normal",
76 | },
77 | options: {
78 | test: true,
79 | cssType: "modular",
80 | testExt: "spec-js",
81 | },
82 | },
83 | };
84 | ```
85 |
86 | ## Help
87 |
88 | ```sh
89 | rg -h
90 | ```
91 |
92 | ## Run tests
93 |
94 | ```sh
95 | npm run test
96 | ```
97 |
98 | ## Author
99 |
100 | 👤 **Tabrez Khan**
101 |
102 | - Website: https://iamtabrezkhan.github.io
103 | - Twitter: [@TabrezX](https://twitter.com/TabrezX)
104 | - Github: [@iamtabrezkhan](https://github.com/iamtabrezkhan)
105 | - LinkedIn: [@iamtabrezkhan](https://linkedin.com/in/iamtabrezkhan)
106 |
107 | ## 🤝 Contributing
108 |
109 | Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/iamtabrezkhan/awesome-react-generator/issues). You can also take a look at the [contributing guide](https://github.com/iamtabrezkhan/awesome-react-generator/blob/master/CONTRIBUTING.md).
110 |
111 | ## Show your support
112 |
113 | Give a ⭐️ if this project helped you!
114 |
115 | ## 📝 License
116 |
117 | Copyright © 2020 [Tabrez Khan](https://github.com/iamtabrezkhan).
118 | This project is [MIT](https://github.com/iamtabrezkhan/awesome-react-generator/blob/master/LICENSE) licensed.
119 |
120 | ---
121 |
122 | _This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_
123 |
--------------------------------------------------------------------------------
/bin/react-generator.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | const yargs = require("yargs");
4 | yargs
5 | .usage("Usage: $0 [options]")
6 | .command(require("../lib/commands/component"))
7 | .alias("h", "help")
8 | .demandCommand()
9 | .recommendCommands()
10 | .strict()
11 | .help().argv;
12 |
--------------------------------------------------------------------------------
/docs/CLI.md:
--------------------------------------------------------------------------------
1 | ## Commads
2 |
3 | ### component
4 |
5 | This will create a folder in the current working directory with the provided component name and generate component files.
6 |
7 | ```bash
8 | $ rg component [options]
9 | ```
10 |
11 | - **Arguments:**
12 | - `type` - the type of component
13 | - acceptable values:
14 | - `rfc` - react functional component
15 | - `rcc` - react class component
16 | - `rccp` - react class component with proptypes
17 | - `rfcp` - react functional component with proptypes
18 | - `rafc` - react arrow functional component
19 | - `rafcp` - react arrow functional component with proptypes
20 | - `rafcredux` - react arrow functional component with connected redux
21 | - `rafcreduxp` - react arrow functional component with connected redux & proptypes
22 | - `rfcredux` - react functional component with connected redux
23 | - `rfcreduxp` - react functional component with connected redux & proptypes
24 | - **more types coming soon**
25 | - `componentName` - component name in kebab-case, will be converted to PascalCase
26 | - acceptable values:
27 | - any type as long as it is kebab-case
28 | - **Options:**
29 | - `--css` - css extension type
30 | - acceptable values:
31 | - `css` - a general css file with a .css extension
32 | - `less` - a general css file with a .less extension
33 | - `scss` - a general css file with a .scss extension
34 | - default value: `css`
35 | - `--cssType` - type of css file
36 | - acceptable values:
37 | - `normal` - a general css file
38 | - `modular` - modular css files to allow scoping of css
39 | - `--test` - decides if you want to generate a test file along with the component files.
40 | - acceptable values:
41 | - `true`
42 | - `false`
43 | - default value: `false`
44 | - `--testExt` - test file extension type
45 | - acceptable values:
46 | - `test-js`
47 | - `test-tsx`
48 | - `spec-js`
49 | - `spec-tsx`
50 | - default value: `test-js`
51 | - `--cwd` - pass a string if you want to change the current working directory.
52 | - acceptable values:
53 | - string
54 | - `--ext` - component file extension type
55 | - acceptable values:
56 | - `js`
57 | - `jsx`
58 | - `tsx`
59 | - default value: `js`
60 |
--------------------------------------------------------------------------------
/docs/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iamtabrezkhan/awesome-react-generator/4c722b7f3041108d568f6c0b037ec959082f3adb/docs/demo.gif
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const utils = require("./lib/utils");
2 | const Runner = require("awesome-task-runner");
3 | const path = require("path");
4 | const colors = require("ansi-colors");
5 |
6 | class ReactGenerator {
7 | constructor() {
8 | this.runner = new Runner({ silent: true });
9 | this.initializeGeneralTasks(this.runner);
10 | }
11 | initializeGeneralTasks(runner) {
12 | // ============== general tasks ====================
13 | runner.task("get:template", function (done) {
14 | const templateName = runner.get("templateName");
15 | const template = utils.getTemplate(templateName);
16 | runner.set({ template });
17 | done();
18 | });
19 | runner.task("clean", (done) => {
20 | runner.clear();
21 | done();
22 | });
23 | runner.task("create:folder", (done) => {
24 | const { folderName, folderDest } = runner.data;
25 | utils.createFolder(folderDest, folderName);
26 | console.log(
27 | colors.greenBright(`Created: ${path.join(folderDest, folderName)}`)
28 | );
29 | done();
30 | });
31 | runner.task("create:file", (done) => {
32 | const { fileName, fileDest, fileData, ext } = runner.data;
33 | utils.createFile(fileDest, `${fileName}${ext}`, fileData);
34 | console.log(
35 | colors.greenBright(`Created: ${path.join(fileDest, fileName + ext)}`)
36 | );
37 | done();
38 | });
39 | }
40 |
41 | initializeData(data) {
42 | this.runner.set(data);
43 | }
44 |
45 | run(task) {
46 | this.runner.run(["get:template", task, "clean"], (err) => {
47 | if (err) return console.log(err);
48 | });
49 | }
50 | }
51 |
52 | module.exports = ReactGenerator;
53 |
--------------------------------------------------------------------------------
/lib/classes/component.js:
--------------------------------------------------------------------------------
1 | const ReactGenerator = require("../..");
2 | const utils = require("../utils");
3 | const path = require("path");
4 |
5 | class ComponentCommand extends ReactGenerator {
6 | constructor() {
7 | super();
8 | this.initializeTasks(this.runner);
9 | }
10 | initializeTasks(runner) {
11 | // =================================================
12 | // ============== component task ===================
13 | runner.task("component", (done) => {
14 | runner.task("component:init", (initDone) => {
15 | console.log("");
16 | const { fileName, template } = runner.data;
17 | const pascalCaseName = utils.kebabCaseToPascalCase(fileName);
18 | const { cssType, cwd, css, ext } = runner.get("options");
19 | let templateAfterAddingName = utils.setComponentName(
20 | template,
21 | pascalCaseName
22 | );
23 | const i = templateAfterAddingName.indexOf("\n");
24 | const firstLine = templateAfterAddingName.substring(0, i + 1);
25 | const rest = templateAfterAddingName.substring(i + 1);
26 | let importCssLine = `import "./${pascalCaseName}.${css}";\n`;
27 | if (cssType === "modular") {
28 | importCssLine = `import styles from "./${pascalCaseName}.module.${css}";\n`;
29 | }
30 | templateAfterAddingName = firstLine + importCssLine + rest;
31 | runner.set({
32 | folderName: pascalCaseName,
33 | folderDest: utils.resolvePath(cwd),
34 | fileName: pascalCaseName,
35 | fileDest: path.join(utils.resolvePath(cwd), pascalCaseName),
36 | fileData: templateAfterAddingName,
37 | ext: `.${ext}`,
38 | });
39 | initDone();
40 | });
41 | runner.task("component:folder", (folderDone) => {
42 | runner.run("create:folder", (err) => {
43 | if (err) throw err;
44 | folderDone();
45 | });
46 | });
47 | runner.task("component:file", (fileDone) => {
48 | runner.run("create:file", (err) => {
49 | if (err) throw err;
50 | fileDone();
51 | });
52 | });
53 | runner.task("component:css", (cssDone) => {
54 | const { css, cssType } = runner.get("options");
55 | let ext = `.${css}`;
56 | runner.set({
57 | ext: cssType === "modular" ? `.module${ext}` : ext,
58 | fileData: "",
59 | });
60 | runner.run(["create:file"], (err) => {
61 | if (err) throw err;
62 | cssDone();
63 | });
64 | });
65 | runner.task("component:test", (testDone) => {
66 | const { testExt } = runner.get("options");
67 | let ext = `.${testExt.replace("-", ".")}`;
68 | runner.set("templateName", "det");
69 | runner.run("get:template", (err) => {
70 | if (err) throw err;
71 | runner.set({
72 | ext: ext,
73 | fileData: runner.get("template"),
74 | });
75 | runner.run(["create:file"], (err) => {
76 | if (err) throw err;
77 | testDone();
78 | });
79 | });
80 | });
81 | const { test } = runner.get("options");
82 | const tasks = [
83 | "component:init",
84 | "component:folder",
85 | "component:file",
86 | "component:css",
87 | ];
88 | if (test) {
89 | tasks.push("component:test");
90 | }
91 | runner.run(tasks, (err) => {
92 | if (err) throw err;
93 | done();
94 | });
95 | });
96 | // =================================================
97 | }
98 | }
99 |
100 | module.exports = ComponentCommand;
101 |
--------------------------------------------------------------------------------
/lib/commands/component.js:
--------------------------------------------------------------------------------
1 | const { getConfigData } = require("../utils");
2 | const ComponentCommand = require("../classes/component");
3 | const app = new ComponentCommand();
4 |
5 | const validTypes = [
6 | "rfc",
7 | "rcc",
8 | "rccp",
9 | "rfcp",
10 | "rafc",
11 | "rafcp",
12 | "rafcredux",
13 | "rafcreduxp",
14 | "rfcredux",
15 | "rfcreduxp",
16 | ];
17 |
18 | exports.command = ["component ", "c"];
19 |
20 | exports.describe = "Generate a component";
21 |
22 | exports.builder = (yargs) => {
23 | yargs.positional("type", {
24 | describe: `Type of component
25 | rfc --> react function component
26 | rcc --> react class component
27 | rccp --> react class component with proptypes
28 | rfcp --> react functional component with proptypes
29 | rafc --> react arrow functional component
30 | rafcp --> react arrow functional component with proptypes
31 | rafcredux --> react arrow functional component with connected redux
32 | rafcreduxp --> react arrow functional component with connected redux & proptypes
33 | rfcredux --> react functional component with connected redux
34 | rfcreduxp --> react functional component with connected redux & proptypes`,
35 | type: "string",
36 | default: "rfc",
37 | choices: validTypes,
38 | });
39 | yargs.positional("componentName", {
40 | describe: `Name of the component [in kebab-case] --> will be converted to PascalCase
41 | hello-world --> HelloWorld`,
42 | type: "string",
43 | });
44 | yargs.option("cssType", {
45 | describe: `Type of css file, in case of modular, it will create file as ->
46 | componentName.module.css`,
47 | default: "normal",
48 | choices: ["normal", "modular"],
49 | });
50 | yargs.option("test", {
51 | describe: `Test file for component, it will create file as ->
52 | componentName.test.js`,
53 | default: false,
54 | choices: [true, false],
55 | type: "boolean",
56 | });
57 | yargs.option("testExt", {
58 | describe: `Change test file extension`,
59 | type: "string",
60 | default: "test-js",
61 | choices: ["test-js", "spec-js", "test-tsx", "spec-tsx"],
62 | });
63 | yargs.option("cwd", {
64 | describe: `Change current working directory`,
65 | type: "string",
66 | });
67 | yargs.option("css", {
68 | describe: `Change css file extension`,
69 | type: "string",
70 | default: "css",
71 | choices: ["css", "scss", "less"],
72 | });
73 | yargs.option("ext", {
74 | describe: `Change component file extension`,
75 | type: "string",
76 | default: "js",
77 | choices: ["js", "jsx", "tsx"],
78 | });
79 | };
80 |
81 | exports.handler = (argv) => {
82 | const { type, componentName, ...options } = argv;
83 | const { component: configData = {} } = getConfigData();
84 | const typeOptions = configData[type] || {};
85 | const { ext } = options;
86 | const task = `component`;
87 | const data = {
88 | componentType: type,
89 | templateName: ext === "tsx" ? `${type}ts` : type,
90 | fileName: componentName,
91 | options: {
92 | ...options,
93 | ...configData.options,
94 | ...typeOptions,
95 | },
96 | };
97 | app.initializeData(data);
98 | app.run(task);
99 | };
100 |
--------------------------------------------------------------------------------
/lib/config.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iamtabrezkhan/awesome-react-generator/4c722b7f3041108d568f6c0b037ec959082f3adb/lib/config.js
--------------------------------------------------------------------------------
/lib/templates/det:
--------------------------------------------------------------------------------
1 | describe("description", () => {
2 | it("itblock", () => {});
3 | });
4 |
--------------------------------------------------------------------------------
/lib/templates/rafc:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | const <<>> = () => {
4 | return <<>> works!
;
5 | };
6 |
7 | export default <<>>;
--------------------------------------------------------------------------------
/lib/templates/rafcp:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import PropTypes from "prop-types";
3 |
4 | const <<>> = (props) => {
5 | return <<>> works!
;
6 | };
7 |
8 | <<>>.propTypes = {};
9 |
10 | export default <<>>;
11 |
--------------------------------------------------------------------------------
/lib/templates/rafcpts:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import PropTypes from "prop-types";
3 |
4 | const <<>> = (props) => {
5 | return <<>> works!
;
6 | };
7 |
8 | <<>>.propTypes = {};
9 |
10 | export default <<>>;
11 |
--------------------------------------------------------------------------------
/lib/templates/rafcredux:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import { connect } from "react-redux";
3 |
4 | const <<>> = () => {
5 | return <<>> works!
;
6 | };
7 |
8 | const mapStateToProps = (state) => ({});
9 |
10 | const mapDispatchToProps = {};
11 |
12 | export default connect(mapStateToProps, mapDispatchToProps)(<<>>);
--------------------------------------------------------------------------------
/lib/templates/rafcreduxp:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import PropTypes from "prop-types";
3 | import { connect } from "react-redux";
4 |
5 | const <<>> = () => {
6 | return <<>> works!
;
7 | };
8 |
9 | <<>>.propTypes = {
10 | prop: PropTypes,
11 | };
12 |
13 | const mapStateToProps = (state) => ({});
14 |
15 | const mapDispatchToProps = {};
16 |
17 | export default connect(mapStateToProps, mapDispatchToProps)(<<>>);
--------------------------------------------------------------------------------
/lib/templates/rafcreduxpts:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import PropTypes from "prop-types";
3 | import { connect } from "react-redux";
4 |
5 | const <<>> = () => {
6 | return <<>> works!
;
7 | };
8 |
9 | <<>>.propTypes = {
10 | prop: PropTypes,
11 | };
12 |
13 | const mapStateToProps = (state) => ({});
14 |
15 | const mapDispatchToProps = {};
16 |
17 | export default connect(mapStateToProps, mapDispatchToProps)(<<>>);
--------------------------------------------------------------------------------
/lib/templates/rafcreduxts:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import { connect } from "react-redux";
3 |
4 | const <<>> = () => {
5 | return <<>> works!
;
6 | };
7 |
8 | const mapStateToProps = (state) => ({});
9 |
10 | const mapDispatchToProps = {};
11 |
12 | export default connect(mapStateToProps, mapDispatchToProps)(<<>>);
--------------------------------------------------------------------------------
/lib/templates/rafcts:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | interface <<>>Props {}
4 |
5 |
6 | const <<>>: React.FC<<<>>Props> = ({}): ReactElement => {return(
7 | <<>> works!
;
8 | )}
9 |
10 | export default <<>>;
--------------------------------------------------------------------------------
/lib/templates/rcc:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 |
3 | class <<>> extends Component {
4 | render() {
5 | return <<>> works!
;
6 | }
7 | }
8 |
9 | export default <<>>;
10 |
--------------------------------------------------------------------------------
/lib/templates/rccp:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import PropTypes from "prop-types";
3 |
4 | class <<>> extends Component {
5 | render() {
6 | return <<>> works!
;
7 | }
8 | }
9 |
10 | <<>>.propTypes = {};
11 |
12 | export default <<>>;
--------------------------------------------------------------------------------
/lib/templates/rccpts:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import PropTypes from "prop-types";
3 |
4 | class <<>> extends Component {
5 | render() {
6 | return <<>> works!
;
7 | }
8 | }
9 |
10 | <<>>.propTypes = {};
11 |
12 | export default <<>>;
--------------------------------------------------------------------------------
/lib/templates/rccts:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 |
3 | class <<>> extends Component {
4 | render() {
5 | return <<>> works!
;
6 | }
7 | }
8 |
9 | export default <<>>;
10 |
--------------------------------------------------------------------------------
/lib/templates/rfc:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | function <<>>() {
4 | return <<>> works!
;
5 | }
6 |
7 | export default <<>>;
8 |
--------------------------------------------------------------------------------
/lib/templates/rfcp:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import PropTypes from "prop-types";
3 |
4 | function <<>>(props) {
5 | return <<>> works!
;
6 | }
7 |
8 | <<>>.propTypes = {};
9 |
10 | export default <<>>;
--------------------------------------------------------------------------------
/lib/templates/rfcpts:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import PropTypes from "prop-types";
3 |
4 | function <<>>(props) {
5 | return <<>> works!
;
6 | }
7 |
8 | <<>>.propTypes = {};
9 |
10 | export default <<>>;
--------------------------------------------------------------------------------
/lib/templates/rfcredux:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import { connect } from "react-redux";
3 |
4 | function <<>>() {
5 | return <<>> works!
;
6 | }
7 |
8 | const mapStateToProps = (state) => ({});
9 |
10 | const mapDispatchToProps = {};
11 |
12 | export default connect(mapStateToProps, mapDispatchToProps)(<<>>);
--------------------------------------------------------------------------------
/lib/templates/rfcreduxp:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import PropTypes from "prop-types";
3 | import { connect } from "react-redux";
4 |
5 | function <<>>() {
6 | return <<>> works!
;
7 | }
8 |
9 | <<>>.propTypes = {
10 | prop: PropTypes,
11 | };
12 |
13 | const mapStateToProps = (state) => ({});
14 |
15 | const mapDispatchToProps = {};
16 |
17 | export default connect(mapStateToProps, mapDispatchToProps)(<<>>);
--------------------------------------------------------------------------------
/lib/templates/rfcreduxpts:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import PropTypes from "prop-types";
3 | import { connect } from "react-redux";
4 |
5 | function <<>>() {
6 | return <<>> works!
;
7 | }
8 |
9 | <<>>.propTypes = {
10 | prop: PropTypes,
11 | };
12 |
13 | const mapStateToProps = (state) => ({});
14 |
15 | const mapDispatchToProps = {};
16 |
17 | export default connect(mapStateToProps, mapDispatchToProps)(<<>>);
--------------------------------------------------------------------------------
/lib/templates/rfcreduxts:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import { connect } from "react-redux";
3 |
4 | function <<>>() {
5 | return <<>> works!
;
6 | }
7 |
8 | const mapStateToProps = (state) => ({});
9 |
10 | const mapDispatchToProps = {};
11 |
12 | export default connect(mapStateToProps, mapDispatchToProps)(<<>>);
--------------------------------------------------------------------------------
/lib/templates/rfcts:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | function <<>>() {
4 | return <<>> works!
;
5 | }
6 |
7 | export default <<>>;
8 |
--------------------------------------------------------------------------------
/lib/utils.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const path = require("path");
3 | const os = require("os");
4 | const appRoot = require("app-root-path");
5 |
6 | exports.getTemplate = (filename) => {
7 | const templateDir = `${__dirname}/templates`;
8 | const buffer = fs.readFileSync(`${templateDir}/${filename}`);
9 | const fileContent = buffer.toString();
10 | return fileContent;
11 | };
12 |
13 | /**
14 | * Convert the given kebab case `string` to pascal case
15 | *
16 | * ```js
17 | * const pascalCase = kebabCaseToPascalCase('hello-world')
18 | * ```
19 | * @param {String} `string` kebab case string.
20 | * @api public
21 | */
22 | exports.kebabCaseToPascalCase = (string) => {
23 | const stringArray = string.split("-");
24 | let result = "";
25 | for (const str of stringArray) {
26 | if (str) {
27 | const firstLetter = str[0].toUpperCase();
28 | const rest = str.substring(1);
29 | result += firstLetter + rest;
30 | }
31 | }
32 | return result;
33 | };
34 |
35 | exports.setComponentName = (fileContent, name) => {
36 | return fileContent.replace(/<<>>/g, name);
37 | };
38 |
39 | exports.createFolder = (dir, folderName) => {
40 | const dest = path.join(dir, folderName);
41 | if (!fs.existsSync(dest)) {
42 | fs.mkdirSync(dest, { recursive: true });
43 | }
44 | };
45 |
46 | exports.createFile = (dir, fileName, data) => {
47 | if (!fs.existsSync(dir)) {
48 | throw new Error(`dir -> ${dir}: does not exist!`);
49 | return;
50 | }
51 | const dest = path.join(dir, fileName);
52 | fs.writeFileSync(dest, data);
53 | };
54 |
55 | exports.ifExist = (path) => {
56 | return fs.existsSync(path);
57 | };
58 |
59 | exports.resolveTilde = (path) => {
60 | if (!path) {
61 | return "";
62 | }
63 | if (path[0] === "~" && (path[1] === "/" || path.length === 1)) {
64 | return path.replace("~", process.env.HOME || os.homedir());
65 | }
66 | return path;
67 | };
68 |
69 | exports.resolvePath = (p) => {
70 | if (!p) {
71 | return process.cwd();
72 | }
73 | const isWin = os.platform() === "win32";
74 | let newPath = p;
75 | if (!isWin) {
76 | newPath = exports.resolveTilde(p);
77 | }
78 | const result = path.resolve(newPath);
79 | if (!fs.existsSync(result)) {
80 | throw new Error(`Could not resolve path: ${result}`);
81 | }
82 | return result;
83 | };
84 |
85 | exports.getDirContents = (dir) => {
86 | return fs.readdirSync(dir);
87 | };
88 |
89 | exports.getDirContentsCount = (dir) => {
90 | const directory = fs.readdirSync(dir);
91 | return directory.length;
92 | };
93 |
94 | exports.getConfigData = () => {
95 | try {
96 | const configFile = require(appRoot + "/.rgrc.js");
97 | if (!configFile) {
98 | return {};
99 | }
100 | return configFile;
101 | } catch (error) {
102 | return {};
103 | }
104 | };
105 |
--------------------------------------------------------------------------------
/mocha-parallel.js:
--------------------------------------------------------------------------------
1 | // https://gist.github.com/msyea/c402de0c01e2de837153b2fa5e751f9f#file-mocha-parallel-js
2 |
3 | const { promisify } = require("util");
4 | const { spawn } = require("child_process");
5 |
6 | const originalGlob = require("glob");
7 | const { loadOptions } = require("mocha/lib/cli/options");
8 | const unparse = require("yargs-unparser");
9 | const { aliases } = require("mocha/lib/cli/run-option-metadata");
10 |
11 | const mochaPath = require.resolve("mocha/bin/_mocha");
12 |
13 | const glob = promisify(originalGlob);
14 |
15 | const getMochaArgs = (path) => {
16 | if (!Array.isArray(path)) {
17 | path = [path];
18 | }
19 | const mochaArgs = loadOptions([...path, "--timeout", "30000"]);
20 | return [].concat(mochaPath, unparse(mochaArgs, { alias: aliases }));
21 | };
22 |
23 | const children = [];
24 |
25 | const runTests = (testFile) =>
26 | new Promise((resolve, reject) => {
27 | const child = spawn(process.execPath, getMochaArgs(testFile), {
28 | env: {
29 | NODE_ENV: "test",
30 | },
31 | });
32 |
33 | children.push(child);
34 |
35 | child.stdout.on("data", (data) => {
36 | const line = data.toString().trim();
37 | if (line) {
38 | console.log(`${testFile}: ${line}`);
39 | }
40 | });
41 |
42 | child.stderr.on("data", (data) => {
43 | const line = data.toString().trim();
44 | if (line) {
45 | console.error(`${testFile}: ${line}`);
46 | }
47 | });
48 |
49 | child.on("exit", (code, signal) => {
50 | const index = children.indexOf(child);
51 | if (index !== -1) {
52 | children.splice(index, 1);
53 | }
54 | if (code || signal) {
55 | reject(new Error(`something bad happend ${code || signal}`));
56 | } else {
57 | resolve();
58 | }
59 | });
60 | });
61 |
62 | glob("test/tests/**/*.js")
63 | .then((testFiles) => {
64 | return Promise.all(testFiles.map(runTests));
65 | })
66 | .then(() => {
67 | console.log("all tests pass");
68 | process.exit(0);
69 | })
70 | .catch((err) => {
71 | console.error("some tests failed", err);
72 | process.exit(1);
73 | });
74 |
75 | // terminate children.
76 | process.on("SIGINT", () => {
77 | children.forEach((child) => {
78 | child.kill("SIGINT"); // calls runner.abort()
79 | child.kill("SIGTERM"); // if that didn't work, we're probably in an infinite loop, so make it die.
80 | });
81 | });
82 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "awesome-react-generator",
3 | "version": "0.1.8",
4 | "description": "CLI application to generate React components, pages, modules etc",
5 | "main": "index.js",
6 | "bin": {
7 | "rg": "bin/react-generator.js",
8 | "react-generator": "bin/react-generator.js"
9 | },
10 | "scripts": {
11 | "test": "node mocha-parallel.js"
12 | },
13 | "repository": {
14 | "type": "git",
15 | "url": "git+https://github.com/iamtabrezkhan/awesome-react-generator.git"
16 | },
17 | "keywords": [
18 | "app",
19 | "cli",
20 | "boilerplate",
21 | "react",
22 | "react cli",
23 | "facebook react",
24 | "generate components",
25 | "templates",
26 | "project",
27 | "development"
28 | ],
29 | "author": "Tabrez Khan (https://github.com/iamtabrezkhan)",
30 | "license": "MIT",
31 | "bugs": {
32 | "url": "https://github.com/iamtabrezkhan/awesome-react-generator/issues"
33 | },
34 | "homepage": "https://github.com/iamtabrezkhan/awesome-react-generator",
35 | "dependencies": {
36 | "ansi-colors": "^4.1.1",
37 | "app-root-path": "^3.0.0",
38 | "awesome-task-runner": "0.0.5",
39 | "yargs": "15.3.1"
40 | },
41 | "devDependencies": {
42 | "chai": "^4.2.0",
43 | "deep-equal-in-any-order": "^1.0.27",
44 | "glob": "^7.1.6",
45 | "mocha": "^8.1.1",
46 | "rimraf": "^3.0.2",
47 | "yargs-unparser": "^1.6.3"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/test/support/constants.js:
--------------------------------------------------------------------------------
1 | const utils = require("../../lib/utils");
2 |
3 | const componentName = "hello-world";
4 | const pascalName = utils.kebabCaseToPascalCase(componentName);
5 |
6 | exports.fileNames = {
7 | component: {
8 | name: componentName,
9 | pascalName,
10 | js: `${pascalName}.js`,
11 | jsx: `${pascalName}.jsx`,
12 | tsx: `${pascalName}.tsx`,
13 | },
14 | css: {
15 | normal: `${pascalName}.css`,
16 | modular: `${pascalName}.module.css`,
17 | },
18 | test: {
19 | js: `${pascalName}.test.js`,
20 | tsx: `${pascalName}.test.tsx`,
21 | specJs: `${pascalName}.spec.js`,
22 | specTsx: `${pascalName}.spec.tsx`,
23 | },
24 | };
25 |
--------------------------------------------------------------------------------
/test/support/utils.js:
--------------------------------------------------------------------------------
1 | const rimraf = require("rimraf");
2 | const fs = require("fs");
3 | const path = require("path");
4 |
5 | exports.removeFolder = (dir, folderName) => {
6 | if (!fs.existsSync(dir)) {
7 | throw new Error(`dir -> ${dir}: does not exist!`);
8 | return;
9 | }
10 | const dest = path.join(dir, folderName);
11 | rimraf.sync(dest);
12 | };
13 |
14 | exports.getDirContents = (dir) => {
15 | return fs.readdirSync(dir);
16 | };
17 |
18 | exports.getDirContentsCount = (dir) => {
19 | return this.getDirContents(dir).length;
20 | };
21 |
--------------------------------------------------------------------------------
/test/tests/rafc.js:
--------------------------------------------------------------------------------
1 | const support = require("../support/utils");
2 | const utils = require("../../lib/utils");
3 | const rg = "../../bin/react-generator.js";
4 | const { spawnSync } = require("child_process");
5 | const chai = require("chai");
6 | const { assert, expect } = chai;
7 | const should = chai.should();
8 | const { fileNames } = require("../support/constants");
9 |
10 | // Chai plugins
11 | const deepEqualInAnyOrder = require("deep-equal-in-any-order");
12 |
13 | chai.use(deepEqualInAnyOrder);
14 |
15 | const tempDir = "test/rafc";
16 |
17 | describe("component command", () => {
18 | before("create temp folder", () => {
19 | utils.createFolder("test", "rafc");
20 | });
21 | // ========================================
22 | // ========================================
23 | describe(`rg c rafc ${fileNames.component.name}`, () => {
24 | afterEach(() => {
25 | support.removeFolder(tempDir, fileNames.component.pascalName);
26 | });
27 | // ======================================
28 | it("should create correct number of files/folders", () => {
29 | const nodeProcess = spawnSync(
30 | "node",
31 | [rg, "c", "rafc", fileNames.component.name],
32 | {
33 | cwd: tempDir,
34 | }
35 | );
36 | const tempContents = support.getDirContents(tempDir);
37 | assert.equal(tempContents.length, 1);
38 | const componentContents = support.getDirContents(
39 | `${tempDir}/${fileNames.component.pascalName}`
40 | );
41 | assert.equal(componentContents.length, 2);
42 | });
43 | it("should create correct name of files/folders", () => {
44 | const nodeProcess = spawnSync(
45 | "node",
46 | [rg, "c", "rafc", fileNames.component.name],
47 | {
48 | cwd: tempDir,
49 | }
50 | );
51 | const tempContents = support.getDirContents(tempDir);
52 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
53 | const componentContents = support.getDirContents(
54 | `${tempDir}/${fileNames.component.pascalName}`
55 | );
56 | expect(componentContents).to.deep.equalInAnyOrder([
57 | fileNames.component.js,
58 | fileNames.css.normal,
59 | ]);
60 | });
61 | });
62 | // ========================================
63 | describe(`rg c rafc ${fileNames.component.name} --cssType modular`, () => {
64 | afterEach(() => {
65 | support.removeFolder(tempDir, fileNames.component.pascalName);
66 | });
67 | it("should create correct number of files/folders", () => {
68 | const nodeProcess = spawnSync(
69 | "node",
70 | [rg, "c", "rafc", fileNames.component.name, "--cssType", "modular"],
71 | {
72 | cwd: tempDir,
73 | }
74 | );
75 | const tempContents = support.getDirContents(tempDir);
76 | assert.equal(tempContents.length, 1);
77 | const componentContents = support.getDirContents(
78 | `${tempDir}/${fileNames.component.pascalName}`
79 | );
80 | assert.equal(componentContents.length, 2);
81 | });
82 | it("should create correct name of files/folders", () => {
83 | const nodeProcess = spawnSync(
84 | "node",
85 | [rg, "c", "rafc", fileNames.component.name, "--cssType", "modular"],
86 | {
87 | cwd: tempDir,
88 | }
89 | );
90 | const tempContents = support.getDirContents(tempDir);
91 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
92 | const componentContents = support.getDirContents(
93 | `${tempDir}/${fileNames.component.pascalName}`
94 | );
95 | expect(componentContents).to.deep.equalInAnyOrder([
96 | fileNames.component.js,
97 | fileNames.css.modular,
98 | ]);
99 | });
100 | });
101 | // ========================================
102 | describe(`rg c rafc ${fileNames.component.name} --test`, () => {
103 | afterEach(() => {
104 | support.removeFolder(tempDir, fileNames.component.pascalName);
105 | });
106 | it("should create correct number of files/folders", () => {
107 | const nodeProcess = spawnSync(
108 | "node",
109 | [rg, "c", "rafc", fileNames.component.name, "--test"],
110 | {
111 | cwd: tempDir,
112 | }
113 | );
114 | const tempContents = support.getDirContents(tempDir);
115 | assert.equal(tempContents.length, 1);
116 | const componentContents = support.getDirContents(
117 | `${tempDir}/${fileNames.component.pascalName}`
118 | );
119 | assert.equal(componentContents.length, 3);
120 | });
121 | it("should create correct name of files/folders", () => {
122 | const nodeProcess = spawnSync(
123 | "node",
124 | [rg, "c", "rafc", fileNames.component.name, "--test"],
125 | {
126 | cwd: tempDir,
127 | }
128 | );
129 | const tempContents = support.getDirContents(tempDir);
130 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
131 | const componentContents = support.getDirContents(
132 | `${tempDir}/${fileNames.component.pascalName}`
133 | );
134 | expect(componentContents).to.deep.equalInAnyOrder([
135 | fileNames.component.js,
136 | fileNames.css.normal,
137 | fileNames.test.js,
138 | ]);
139 | });
140 | });
141 | // ========================================
142 | describe(`rg c rafc ${fileNames.component.name} --test --testExt test-tsx`, () => {
143 | afterEach(() => {
144 | support.removeFolder(tempDir, fileNames.component.pascalName);
145 | });
146 | it("should create correct number of files/folders", () => {
147 | const nodeProcess = spawnSync(
148 | "node",
149 | [
150 | rg,
151 | "c",
152 | "rafc",
153 | fileNames.component.name,
154 | "--test",
155 | "--testExt",
156 | "test-tsx",
157 | ],
158 | {
159 | cwd: tempDir,
160 | }
161 | );
162 | const tempContents = support.getDirContents(tempDir);
163 | assert.equal(tempContents.length, 1);
164 | const componentContents = support.getDirContents(
165 | `${tempDir}/${fileNames.component.pascalName}`
166 | );
167 | assert.equal(componentContents.length, 3);
168 | });
169 | it("should create correct name of files/folders", () => {
170 | const nodeProcess = spawnSync(
171 | "node",
172 | [
173 | rg,
174 | "c",
175 | "rafc",
176 | fileNames.component.name,
177 | "--test",
178 | "--testExt",
179 | "test-tsx",
180 | ],
181 | {
182 | cwd: tempDir,
183 | }
184 | );
185 | const tempContents = support.getDirContents(tempDir);
186 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
187 | const componentContents = support.getDirContents(
188 | `${tempDir}/${fileNames.component.pascalName}`
189 | );
190 | expect(componentContents).to.deep.equalInAnyOrder([
191 | fileNames.component.js,
192 | fileNames.css.normal,
193 | fileNames.test.tsx,
194 | ]);
195 | });
196 | });
197 | // ========================================
198 | describe(`rg c rafc ${fileNames.component.name} --test --testExt spec-js`, () => {
199 | afterEach(() => {
200 | support.removeFolder(tempDir, fileNames.component.pascalName);
201 | });
202 | it("should create correct number of files/folders", () => {
203 | const nodeProcess = spawnSync(
204 | "node",
205 | [
206 | rg,
207 | "c",
208 | "rafc",
209 | fileNames.component.name,
210 | "--test",
211 | "--testExt",
212 | "spec-js",
213 | ],
214 | {
215 | cwd: tempDir,
216 | }
217 | );
218 | const tempContents = support.getDirContents(tempDir);
219 | assert.equal(tempContents.length, 1);
220 | const componentContents = support.getDirContents(
221 | `${tempDir}/${fileNames.component.pascalName}`
222 | );
223 | assert.equal(componentContents.length, 3);
224 | });
225 | it("should create correct name of files/folders", () => {
226 | const nodeProcess = spawnSync(
227 | "node",
228 | [
229 | rg,
230 | "c",
231 | "rafc",
232 | fileNames.component.name,
233 | "--test",
234 | "--testExt",
235 | "spec-js",
236 | ],
237 | {
238 | cwd: tempDir,
239 | }
240 | );
241 | const tempContents = support.getDirContents(tempDir);
242 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
243 | const componentContents = support.getDirContents(
244 | `${tempDir}/${fileNames.component.pascalName}`
245 | );
246 | expect(componentContents).to.deep.equalInAnyOrder([
247 | fileNames.component.js,
248 | fileNames.css.normal,
249 | fileNames.test.specJs,
250 | ]);
251 | });
252 | });
253 | // ========================================
254 | describe(`rg c rafc ${fileNames.component.name} --test --testExt spec-tsx`, () => {
255 | afterEach(() => {
256 | support.removeFolder(tempDir, fileNames.component.pascalName);
257 | });
258 | it("should create correct number of files/folders", () => {
259 | const nodeProcess = spawnSync(
260 | "node",
261 | [
262 | rg,
263 | "c",
264 | "rafc",
265 | fileNames.component.name,
266 | "--test",
267 | "--testExt",
268 | "spec-tsx",
269 | ],
270 | {
271 | cwd: tempDir,
272 | }
273 | );
274 | const tempContents = support.getDirContents(tempDir);
275 | assert.equal(tempContents.length, 1);
276 | const componentContents = support.getDirContents(
277 | `${tempDir}/${fileNames.component.pascalName}`
278 | );
279 | assert.equal(componentContents.length, 3);
280 | });
281 | it("should create correct name of files/folders", () => {
282 | const nodeProcess = spawnSync(
283 | "node",
284 | [
285 | rg,
286 | "c",
287 | "rafc",
288 | fileNames.component.name,
289 | "--test",
290 | "--testExt",
291 | "spec-tsx",
292 | ],
293 | {
294 | cwd: tempDir,
295 | }
296 | );
297 | const tempContents = support.getDirContents(tempDir);
298 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
299 | const componentContents = support.getDirContents(
300 | `${tempDir}/${fileNames.component.pascalName}`
301 | );
302 | expect(componentContents).to.deep.equalInAnyOrder([
303 | fileNames.component.js,
304 | fileNames.css.normal,
305 | fileNames.test.specTsx,
306 | ]);
307 | });
308 | });
309 | // ========================================
310 | describe(`rg c rafc ${fileNames.component.name} --ext jsx`, () => {
311 | afterEach(() => {
312 | support.removeFolder(tempDir, fileNames.component.pascalName);
313 | });
314 | it("should create correct number of files/folders", () => {
315 | const nodeProcess = spawnSync(
316 | "node",
317 | [rg, "c", "rafc", fileNames.component.name, "--ext", "jsx"],
318 | {
319 | cwd: tempDir,
320 | }
321 | );
322 | const tempContents = support.getDirContents(tempDir);
323 | assert.equal(tempContents.length, 1);
324 | const componentContents = support.getDirContents(
325 | `${tempDir}/${fileNames.component.pascalName}`
326 | );
327 | assert.equal(componentContents.length, 2);
328 | });
329 | it("should create correct name of files/folders", () => {
330 | const nodeProcess = spawnSync(
331 | "node",
332 | [rg, "c", "rafc", fileNames.component.name, "--ext", "jsx"],
333 | {
334 | cwd: tempDir,
335 | }
336 | );
337 | const tempContents = support.getDirContents(tempDir);
338 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
339 | const componentContents = support.getDirContents(
340 | `${tempDir}/${fileNames.component.pascalName}`
341 | );
342 | expect(componentContents).to.deep.equalInAnyOrder([
343 | fileNames.component.jsx,
344 | fileNames.css.normal,
345 | ]);
346 | });
347 | });
348 | // ========================================
349 | describe(`rg c rafc ${fileNames.component.name} --ext tsx`, () => {
350 | afterEach(() => {
351 | support.removeFolder(tempDir, fileNames.component.pascalName);
352 | });
353 | it("should create correct number of files/folders", () => {
354 | const nodeProcess = spawnSync(
355 | "node",
356 | [rg, "c", "rafc", fileNames.component.name, "--ext", "tsx"],
357 | {
358 | cwd: tempDir,
359 | }
360 | );
361 | const tempContents = support.getDirContents(tempDir);
362 | assert.equal(tempContents.length, 1);
363 | const componentContents = support.getDirContents(
364 | `${tempDir}/${fileNames.component.pascalName}`
365 | );
366 | assert.equal(componentContents.length, 2);
367 | });
368 | it("should create correct name of files/folders", () => {
369 | const nodeProcess = spawnSync(
370 | "node",
371 | [rg, "c", "rafc", fileNames.component.name, "--ext", "tsx"],
372 | {
373 | cwd: tempDir,
374 | }
375 | );
376 | const tempContents = support.getDirContents(tempDir);
377 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
378 | const componentContents = support.getDirContents(
379 | `${tempDir}/${fileNames.component.pascalName}`
380 | );
381 | expect(componentContents).to.deep.equalInAnyOrder([
382 | fileNames.component.tsx,
383 | fileNames.css.normal,
384 | ]);
385 | });
386 | });
387 | after("remove temp folder", () => {
388 | support.removeFolder("test", "rafc");
389 | });
390 | });
391 |
--------------------------------------------------------------------------------
/test/tests/rafcp.js:
--------------------------------------------------------------------------------
1 | const support = require("../support/utils");
2 | const utils = require("../../lib/utils");
3 | const rg = "../../bin/react-generator.js";
4 | const { spawnSync } = require("child_process");
5 | const chai = require("chai");
6 | const { assert, expect } = chai;
7 | const should = chai.should();
8 | const { fileNames } = require("../support/constants");
9 |
10 | // Chai plugins
11 | const deepEqualInAnyOrder = require("deep-equal-in-any-order");
12 |
13 | chai.use(deepEqualInAnyOrder);
14 |
15 | const tempDir = "test/rafcp";
16 |
17 | describe("component command", () => {
18 | before("create temp folder", () => {
19 | utils.createFolder("test", "rafcp");
20 | });
21 | // ========================================
22 | // ========================================
23 | describe(`rg c rafcp ${fileNames.component.name}`, () => {
24 | afterEach(() => {
25 | support.removeFolder(tempDir, fileNames.component.pascalName);
26 | });
27 | // ======================================
28 | it("should create correct number of files/folders", () => {
29 | const nodeProcess = spawnSync(
30 | "node",
31 | [rg, "c", "rafcp", fileNames.component.name],
32 | {
33 | cwd: tempDir,
34 | }
35 | );
36 | const tempContents = support.getDirContents(tempDir);
37 | assert.equal(tempContents.length, 1);
38 | const componentContents = support.getDirContents(
39 | `${tempDir}/${fileNames.component.pascalName}`
40 | );
41 | assert.equal(componentContents.length, 2);
42 | });
43 | it("should create correct name of files/folders", () => {
44 | const nodeProcess = spawnSync(
45 | "node",
46 | [rg, "c", "rafcp", fileNames.component.name],
47 | {
48 | cwd: tempDir,
49 | }
50 | );
51 | const tempContents = support.getDirContents(tempDir);
52 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
53 | const componentContents = support.getDirContents(
54 | `${tempDir}/${fileNames.component.pascalName}`
55 | );
56 | expect(componentContents).to.deep.equalInAnyOrder([
57 | fileNames.component.js,
58 | fileNames.css.normal,
59 | ]);
60 | });
61 | });
62 | // ========================================
63 | describe(`rg c rafcp ${fileNames.component.name} --cssType modular`, () => {
64 | afterEach(() => {
65 | support.removeFolder(tempDir, fileNames.component.pascalName);
66 | });
67 | it("should create correct number of files/folders", () => {
68 | const nodeProcess = spawnSync(
69 | "node",
70 | [rg, "c", "rafcp", fileNames.component.name, "--cssType", "modular"],
71 | {
72 | cwd: tempDir,
73 | }
74 | );
75 | const tempContents = support.getDirContents(tempDir);
76 | assert.equal(tempContents.length, 1);
77 | const componentContents = support.getDirContents(
78 | `${tempDir}/${fileNames.component.pascalName}`
79 | );
80 | assert.equal(componentContents.length, 2);
81 | });
82 | it("should create correct name of files/folders", () => {
83 | const nodeProcess = spawnSync(
84 | "node",
85 | [rg, "c", "rafcp", fileNames.component.name, "--cssType", "modular"],
86 | {
87 | cwd: tempDir,
88 | }
89 | );
90 | const tempContents = support.getDirContents(tempDir);
91 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
92 | const componentContents = support.getDirContents(
93 | `${tempDir}/${fileNames.component.pascalName}`
94 | );
95 | expect(componentContents).to.deep.equalInAnyOrder([
96 | fileNames.component.js,
97 | fileNames.css.modular,
98 | ]);
99 | });
100 | });
101 | // ========================================
102 | describe(`rg c rafcp ${fileNames.component.name} --test`, () => {
103 | afterEach(() => {
104 | support.removeFolder(tempDir, fileNames.component.pascalName);
105 | });
106 | it("should create correct number of files/folders", () => {
107 | const nodeProcess = spawnSync(
108 | "node",
109 | [rg, "c", "rafcp", fileNames.component.name, "--test"],
110 | {
111 | cwd: tempDir,
112 | }
113 | );
114 | const tempContents = support.getDirContents(tempDir);
115 | assert.equal(tempContents.length, 1);
116 | const componentContents = support.getDirContents(
117 | `${tempDir}/${fileNames.component.pascalName}`
118 | );
119 | assert.equal(componentContents.length, 3);
120 | });
121 | it("should create correct name of files/folders", () => {
122 | const nodeProcess = spawnSync(
123 | "node",
124 | [rg, "c", "rafcp", fileNames.component.name, "--test"],
125 | {
126 | cwd: tempDir,
127 | }
128 | );
129 | const tempContents = support.getDirContents(tempDir);
130 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
131 | const componentContents = support.getDirContents(
132 | `${tempDir}/${fileNames.component.pascalName}`
133 | );
134 | expect(componentContents).to.deep.equalInAnyOrder([
135 | fileNames.component.js,
136 | fileNames.css.normal,
137 | fileNames.test.js,
138 | ]);
139 | });
140 | });
141 | // ========================================
142 | describe(`rg c rafcp ${fileNames.component.name} --test --testExt test-tsx`, () => {
143 | afterEach(() => {
144 | support.removeFolder(tempDir, fileNames.component.pascalName);
145 | });
146 | it("should create correct number of files/folders", () => {
147 | const nodeProcess = spawnSync(
148 | "node",
149 | [
150 | rg,
151 | "c",
152 | "rafcp",
153 | fileNames.component.name,
154 | "--test",
155 | "--testExt",
156 | "test-tsx",
157 | ],
158 | {
159 | cwd: tempDir,
160 | }
161 | );
162 | const tempContents = support.getDirContents(tempDir);
163 | assert.equal(tempContents.length, 1);
164 | const componentContents = support.getDirContents(
165 | `${tempDir}/${fileNames.component.pascalName}`
166 | );
167 | assert.equal(componentContents.length, 3);
168 | });
169 | it("should create correct name of files/folders", () => {
170 | const nodeProcess = spawnSync(
171 | "node",
172 | [
173 | rg,
174 | "c",
175 | "rafcp",
176 | fileNames.component.name,
177 | "--test",
178 | "--testExt",
179 | "test-tsx",
180 | ],
181 | {
182 | cwd: tempDir,
183 | }
184 | );
185 | const tempContents = support.getDirContents(tempDir);
186 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
187 | const componentContents = support.getDirContents(
188 | `${tempDir}/${fileNames.component.pascalName}`
189 | );
190 | expect(componentContents).to.deep.equalInAnyOrder([
191 | fileNames.component.js,
192 | fileNames.css.normal,
193 | fileNames.test.tsx,
194 | ]);
195 | });
196 | });
197 | // ========================================
198 | describe(`rg c rafcp ${fileNames.component.name} --test --testExt spec-js`, () => {
199 | afterEach(() => {
200 | support.removeFolder(tempDir, fileNames.component.pascalName);
201 | });
202 | it("should create correct number of files/folders", () => {
203 | const nodeProcess = spawnSync(
204 | "node",
205 | [
206 | rg,
207 | "c",
208 | "rafcp",
209 | fileNames.component.name,
210 | "--test",
211 | "--testExt",
212 | "spec-js",
213 | ],
214 | {
215 | cwd: tempDir,
216 | }
217 | );
218 | const tempContents = support.getDirContents(tempDir);
219 | assert.equal(tempContents.length, 1);
220 | const componentContents = support.getDirContents(
221 | `${tempDir}/${fileNames.component.pascalName}`
222 | );
223 | assert.equal(componentContents.length, 3);
224 | });
225 | it("should create correct name of files/folders", () => {
226 | const nodeProcess = spawnSync(
227 | "node",
228 | [
229 | rg,
230 | "c",
231 | "rafcp",
232 | fileNames.component.name,
233 | "--test",
234 | "--testExt",
235 | "spec-js",
236 | ],
237 | {
238 | cwd: tempDir,
239 | }
240 | );
241 | const tempContents = support.getDirContents(tempDir);
242 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
243 | const componentContents = support.getDirContents(
244 | `${tempDir}/${fileNames.component.pascalName}`
245 | );
246 | expect(componentContents).to.deep.equalInAnyOrder([
247 | fileNames.component.js,
248 | fileNames.css.normal,
249 | fileNames.test.specJs,
250 | ]);
251 | });
252 | });
253 | // ========================================
254 | describe(`rg c rafcp ${fileNames.component.name} --test --testExt spec-tsx`, () => {
255 | afterEach(() => {
256 | support.removeFolder(tempDir, fileNames.component.pascalName);
257 | });
258 | it("should create correct number of files/folders", () => {
259 | const nodeProcess = spawnSync(
260 | "node",
261 | [
262 | rg,
263 | "c",
264 | "rafcp",
265 | fileNames.component.name,
266 | "--test",
267 | "--testExt",
268 | "spec-tsx",
269 | ],
270 | {
271 | cwd: tempDir,
272 | }
273 | );
274 | const tempContents = support.getDirContents(tempDir);
275 | assert.equal(tempContents.length, 1);
276 | const componentContents = support.getDirContents(
277 | `${tempDir}/${fileNames.component.pascalName}`
278 | );
279 | assert.equal(componentContents.length, 3);
280 | });
281 | it("should create correct name of files/folders", () => {
282 | const nodeProcess = spawnSync(
283 | "node",
284 | [
285 | rg,
286 | "c",
287 | "rafcp",
288 | fileNames.component.name,
289 | "--test",
290 | "--testExt",
291 | "spec-tsx",
292 | ],
293 | {
294 | cwd: tempDir,
295 | }
296 | );
297 | const tempContents = support.getDirContents(tempDir);
298 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
299 | const componentContents = support.getDirContents(
300 | `${tempDir}/${fileNames.component.pascalName}`
301 | );
302 | expect(componentContents).to.deep.equalInAnyOrder([
303 | fileNames.component.js,
304 | fileNames.css.normal,
305 | fileNames.test.specTsx,
306 | ]);
307 | });
308 | });
309 | // ========================================
310 | describe(`rg c rafcp ${fileNames.component.name} --ext jsx`, () => {
311 | afterEach(() => {
312 | support.removeFolder(tempDir, fileNames.component.pascalName);
313 | });
314 | it("should create correct number of files/folders", () => {
315 | const nodeProcess = spawnSync(
316 | "node",
317 | [rg, "c", "rafcp", fileNames.component.name, "--ext", "jsx"],
318 | {
319 | cwd: tempDir,
320 | }
321 | );
322 | const tempContents = support.getDirContents(tempDir);
323 | assert.equal(tempContents.length, 1);
324 | const componentContents = support.getDirContents(
325 | `${tempDir}/${fileNames.component.pascalName}`
326 | );
327 | assert.equal(componentContents.length, 2);
328 | });
329 | it("should create correct name of files/folders", () => {
330 | const nodeProcess = spawnSync(
331 | "node",
332 | [rg, "c", "rafcp", fileNames.component.name, "--ext", "jsx"],
333 | {
334 | cwd: tempDir,
335 | }
336 | );
337 | const tempContents = support.getDirContents(tempDir);
338 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
339 | const componentContents = support.getDirContents(
340 | `${tempDir}/${fileNames.component.pascalName}`
341 | );
342 | expect(componentContents).to.deep.equalInAnyOrder([
343 | fileNames.component.jsx,
344 | fileNames.css.normal,
345 | ]);
346 | });
347 | });
348 | // ========================================
349 | describe(`rg c rafcp ${fileNames.component.name} --ext tsx`, () => {
350 | afterEach(() => {
351 | support.removeFolder(tempDir, fileNames.component.pascalName);
352 | });
353 | it("should create correct number of files/folders", () => {
354 | const nodeProcess = spawnSync(
355 | "node",
356 | [rg, "c", "rafcp", fileNames.component.name, "--ext", "tsx"],
357 | {
358 | cwd: tempDir,
359 | }
360 | );
361 | const tempContents = support.getDirContents(tempDir);
362 | assert.equal(tempContents.length, 1);
363 | const componentContents = support.getDirContents(
364 | `${tempDir}/${fileNames.component.pascalName}`
365 | );
366 | assert.equal(componentContents.length, 2);
367 | });
368 | it("should create correct name of files/folders", () => {
369 | const nodeProcess = spawnSync(
370 | "node",
371 | [rg, "c", "rafcp", fileNames.component.name, "--ext", "tsx"],
372 | {
373 | cwd: tempDir,
374 | }
375 | );
376 | const tempContents = support.getDirContents(tempDir);
377 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
378 | const componentContents = support.getDirContents(
379 | `${tempDir}/${fileNames.component.pascalName}`
380 | );
381 | expect(componentContents).to.deep.equalInAnyOrder([
382 | fileNames.component.tsx,
383 | fileNames.css.normal,
384 | ]);
385 | });
386 | });
387 | after("remove temp folder", () => {
388 | support.removeFolder("test", "rafcp");
389 | });
390 | });
391 |
--------------------------------------------------------------------------------
/test/tests/rafcredux.js:
--------------------------------------------------------------------------------
1 | const support = require("../support/utils");
2 | const utils = require("../../lib/utils");
3 | const rg = "../../bin/react-generator.js";
4 | const { spawnSync } = require("child_process");
5 | const chai = require("chai");
6 | const { assert, expect } = chai;
7 | const should = chai.should();
8 | const { fileNames } = require("../support/constants");
9 |
10 | // Chai plugins
11 | const deepEqualInAnyOrder = require("deep-equal-in-any-order");
12 |
13 | chai.use(deepEqualInAnyOrder);
14 |
15 | const tempDir = "test/rafcredux";
16 |
17 | describe("component command", () => {
18 | before("create temp folder", () => {
19 | utils.createFolder("test", "rafcredux");
20 | });
21 | // ========================================
22 | // ========================================
23 | describe(`rg c rafcredux ${fileNames.component.name}`, () => {
24 | afterEach(() => {
25 | support.removeFolder(tempDir, fileNames.component.pascalName);
26 | });
27 | // ======================================
28 | it("should create correct number of files/folders", () => {
29 | const nodeProcess = spawnSync(
30 | "node",
31 | [rg, "c", "rafcredux", fileNames.component.name],
32 | {
33 | cwd: tempDir,
34 | }
35 | );
36 | const tempContents = support.getDirContents(tempDir);
37 | assert.equal(tempContents.length, 1);
38 | const componentContents = support.getDirContents(
39 | `${tempDir}/${fileNames.component.pascalName}`
40 | );
41 | assert.equal(componentContents.length, 2);
42 | });
43 | it("should create correct name of files/folders", () => {
44 | const nodeProcess = spawnSync(
45 | "node",
46 | [rg, "c", "rafcredux", fileNames.component.name],
47 | {
48 | cwd: tempDir,
49 | }
50 | );
51 | const tempContents = support.getDirContents(tempDir);
52 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
53 | const componentContents = support.getDirContents(
54 | `${tempDir}/${fileNames.component.pascalName}`
55 | );
56 | expect(componentContents).to.deep.equalInAnyOrder([
57 | fileNames.component.js,
58 | fileNames.css.normal,
59 | ]);
60 | });
61 | });
62 | // ========================================
63 | describe(`rg c rafcredux ${fileNames.component.name} --cssType modular`, () => {
64 | afterEach(() => {
65 | support.removeFolder(tempDir, fileNames.component.pascalName);
66 | });
67 | it("should create correct number of files/folders", () => {
68 | const nodeProcess = spawnSync(
69 | "node",
70 | [
71 | rg,
72 | "c",
73 | "rafcredux",
74 | fileNames.component.name,
75 | "--cssType",
76 | "modular",
77 | ],
78 | {
79 | cwd: tempDir,
80 | }
81 | );
82 | const tempContents = support.getDirContents(tempDir);
83 | assert.equal(tempContents.length, 1);
84 | const componentContents = support.getDirContents(
85 | `${tempDir}/${fileNames.component.pascalName}`
86 | );
87 | assert.equal(componentContents.length, 2);
88 | });
89 | it("should create correct name of files/folders", () => {
90 | const nodeProcess = spawnSync(
91 | "node",
92 | [
93 | rg,
94 | "c",
95 | "rafcredux",
96 | fileNames.component.name,
97 | "--cssType",
98 | "modular",
99 | ],
100 | {
101 | cwd: tempDir,
102 | }
103 | );
104 | const tempContents = support.getDirContents(tempDir);
105 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
106 | const componentContents = support.getDirContents(
107 | `${tempDir}/${fileNames.component.pascalName}`
108 | );
109 | expect(componentContents).to.deep.equalInAnyOrder([
110 | fileNames.component.js,
111 | fileNames.css.modular,
112 | ]);
113 | });
114 | });
115 | // ========================================
116 | describe(`rg c rafcredux ${fileNames.component.name} --test`, () => {
117 | afterEach(() => {
118 | support.removeFolder(tempDir, fileNames.component.pascalName);
119 | });
120 | it("should create correct number of files/folders", () => {
121 | const nodeProcess = spawnSync(
122 | "node",
123 | [rg, "c", "rafcredux", fileNames.component.name, "--test"],
124 | {
125 | cwd: tempDir,
126 | }
127 | );
128 | const tempContents = support.getDirContents(tempDir);
129 | assert.equal(tempContents.length, 1);
130 | const componentContents = support.getDirContents(
131 | `${tempDir}/${fileNames.component.pascalName}`
132 | );
133 | assert.equal(componentContents.length, 3);
134 | });
135 | it("should create correct name of files/folders", () => {
136 | const nodeProcess = spawnSync(
137 | "node",
138 | [rg, "c", "rafcredux", fileNames.component.name, "--test"],
139 | {
140 | cwd: tempDir,
141 | }
142 | );
143 | const tempContents = support.getDirContents(tempDir);
144 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
145 | const componentContents = support.getDirContents(
146 | `${tempDir}/${fileNames.component.pascalName}`
147 | );
148 | expect(componentContents).to.deep.equalInAnyOrder([
149 | fileNames.component.js,
150 | fileNames.css.normal,
151 | fileNames.test.js,
152 | ]);
153 | });
154 | });
155 | // ========================================
156 | describe(`rg c rafcredux ${fileNames.component.name} --test --testExt test-tsx`, () => {
157 | afterEach(() => {
158 | support.removeFolder(tempDir, fileNames.component.pascalName);
159 | });
160 | it("should create correct number of files/folders", () => {
161 | const nodeProcess = spawnSync(
162 | "node",
163 | [
164 | rg,
165 | "c",
166 | "rafcredux",
167 | fileNames.component.name,
168 | "--test",
169 | "--testExt",
170 | "test-tsx",
171 | ],
172 | {
173 | cwd: tempDir,
174 | }
175 | );
176 | const tempContents = support.getDirContents(tempDir);
177 | assert.equal(tempContents.length, 1);
178 | const componentContents = support.getDirContents(
179 | `${tempDir}/${fileNames.component.pascalName}`
180 | );
181 | assert.equal(componentContents.length, 3);
182 | });
183 | it("should create correct name of files/folders", () => {
184 | const nodeProcess = spawnSync(
185 | "node",
186 | [
187 | rg,
188 | "c",
189 | "rafcredux",
190 | fileNames.component.name,
191 | "--test",
192 | "--testExt",
193 | "test-tsx",
194 | ],
195 | {
196 | cwd: tempDir,
197 | }
198 | );
199 | const tempContents = support.getDirContents(tempDir);
200 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
201 | const componentContents = support.getDirContents(
202 | `${tempDir}/${fileNames.component.pascalName}`
203 | );
204 | expect(componentContents).to.deep.equalInAnyOrder([
205 | fileNames.component.js,
206 | fileNames.css.normal,
207 | fileNames.test.tsx,
208 | ]);
209 | });
210 | });
211 | // ========================================
212 | describe(`rg c rafcredux ${fileNames.component.name} --test --testExt spec-js`, () => {
213 | afterEach(() => {
214 | support.removeFolder(tempDir, fileNames.component.pascalName);
215 | });
216 | it("should create correct number of files/folders", () => {
217 | const nodeProcess = spawnSync(
218 | "node",
219 | [
220 | rg,
221 | "c",
222 | "rafcredux",
223 | fileNames.component.name,
224 | "--test",
225 | "--testExt",
226 | "spec-js",
227 | ],
228 | {
229 | cwd: tempDir,
230 | }
231 | );
232 | const tempContents = support.getDirContents(tempDir);
233 | assert.equal(tempContents.length, 1);
234 | const componentContents = support.getDirContents(
235 | `${tempDir}/${fileNames.component.pascalName}`
236 | );
237 | assert.equal(componentContents.length, 3);
238 | });
239 | it("should create correct name of files/folders", () => {
240 | const nodeProcess = spawnSync(
241 | "node",
242 | [
243 | rg,
244 | "c",
245 | "rafcredux",
246 | fileNames.component.name,
247 | "--test",
248 | "--testExt",
249 | "spec-js",
250 | ],
251 | {
252 | cwd: tempDir,
253 | }
254 | );
255 | const tempContents = support.getDirContents(tempDir);
256 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
257 | const componentContents = support.getDirContents(
258 | `${tempDir}/${fileNames.component.pascalName}`
259 | );
260 | expect(componentContents).to.deep.equalInAnyOrder([
261 | fileNames.component.js,
262 | fileNames.css.normal,
263 | fileNames.test.specJs,
264 | ]);
265 | });
266 | });
267 | // ========================================
268 | describe(`rg c rafcredux ${fileNames.component.name} --test --testExt spec-tsx`, () => {
269 | afterEach(() => {
270 | support.removeFolder(tempDir, fileNames.component.pascalName);
271 | });
272 | it("should create correct number of files/folders", () => {
273 | const nodeProcess = spawnSync(
274 | "node",
275 | [
276 | rg,
277 | "c",
278 | "rafcredux",
279 | fileNames.component.name,
280 | "--test",
281 | "--testExt",
282 | "spec-tsx",
283 | ],
284 | {
285 | cwd: tempDir,
286 | }
287 | );
288 | const tempContents = support.getDirContents(tempDir);
289 | assert.equal(tempContents.length, 1);
290 | const componentContents = support.getDirContents(
291 | `${tempDir}/${fileNames.component.pascalName}`
292 | );
293 | assert.equal(componentContents.length, 3);
294 | });
295 | it("should create correct name of files/folders", () => {
296 | const nodeProcess = spawnSync(
297 | "node",
298 | [
299 | rg,
300 | "c",
301 | "rafcredux",
302 | fileNames.component.name,
303 | "--test",
304 | "--testExt",
305 | "spec-tsx",
306 | ],
307 | {
308 | cwd: tempDir,
309 | }
310 | );
311 | const tempContents = support.getDirContents(tempDir);
312 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
313 | const componentContents = support.getDirContents(
314 | `${tempDir}/${fileNames.component.pascalName}`
315 | );
316 | expect(componentContents).to.deep.equalInAnyOrder([
317 | fileNames.component.js,
318 | fileNames.css.normal,
319 | fileNames.test.specTsx,
320 | ]);
321 | });
322 | });
323 | // ========================================
324 | describe(`rg c rafcredux ${fileNames.component.name} --ext jsx`, () => {
325 | afterEach(() => {
326 | support.removeFolder(tempDir, fileNames.component.pascalName);
327 | });
328 | it("should create correct number of files/folders", () => {
329 | const nodeProcess = spawnSync(
330 | "node",
331 | [rg, "c", "rafcredux", fileNames.component.name, "--ext", "jsx"],
332 | {
333 | cwd: tempDir,
334 | }
335 | );
336 | const tempContents = support.getDirContents(tempDir);
337 | assert.equal(tempContents.length, 1);
338 | const componentContents = support.getDirContents(
339 | `${tempDir}/${fileNames.component.pascalName}`
340 | );
341 | assert.equal(componentContents.length, 2);
342 | });
343 | it("should create correct name of files/folders", () => {
344 | const nodeProcess = spawnSync(
345 | "node",
346 | [rg, "c", "rafcredux", fileNames.component.name, "--ext", "jsx"],
347 | {
348 | cwd: tempDir,
349 | }
350 | );
351 | const tempContents = support.getDirContents(tempDir);
352 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
353 | const componentContents = support.getDirContents(
354 | `${tempDir}/${fileNames.component.pascalName}`
355 | );
356 | expect(componentContents).to.deep.equalInAnyOrder([
357 | fileNames.component.jsx,
358 | fileNames.css.normal,
359 | ]);
360 | });
361 | });
362 | // ========================================
363 | describe(`rg c rafcredux ${fileNames.component.name} --ext tsx`, () => {
364 | afterEach(() => {
365 | support.removeFolder(tempDir, fileNames.component.pascalName);
366 | });
367 | it("should create correct number of files/folders", () => {
368 | const nodeProcess = spawnSync(
369 | "node",
370 | [rg, "c", "rafcredux", fileNames.component.name, "--ext", "tsx"],
371 | {
372 | cwd: tempDir,
373 | }
374 | );
375 | const tempContents = support.getDirContents(tempDir);
376 | assert.equal(tempContents.length, 1);
377 | const componentContents = support.getDirContents(
378 | `${tempDir}/${fileNames.component.pascalName}`
379 | );
380 | assert.equal(componentContents.length, 2);
381 | });
382 | it("should create correct name of files/folders", () => {
383 | const nodeProcess = spawnSync(
384 | "node",
385 | [rg, "c", "rafcredux", fileNames.component.name, "--ext", "tsx"],
386 | {
387 | cwd: tempDir,
388 | }
389 | );
390 | const tempContents = support.getDirContents(tempDir);
391 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
392 | const componentContents = support.getDirContents(
393 | `${tempDir}/${fileNames.component.pascalName}`
394 | );
395 | expect(componentContents).to.deep.equalInAnyOrder([
396 | fileNames.component.tsx,
397 | fileNames.css.normal,
398 | ]);
399 | });
400 | });
401 | after("remove temp folder", () => {
402 | support.removeFolder("test", "rafcredux");
403 | });
404 | });
405 |
--------------------------------------------------------------------------------
/test/tests/rafcreduxp.js:
--------------------------------------------------------------------------------
1 | const support = require("../support/utils");
2 | const utils = require("../../lib/utils");
3 | const rg = "../../bin/react-generator.js";
4 | const { spawnSync } = require("child_process");
5 | const chai = require("chai");
6 | const { assert, expect } = chai;
7 | const should = chai.should();
8 | const { fileNames } = require("../support/constants");
9 |
10 | // Chai plugins
11 | const deepEqualInAnyOrder = require("deep-equal-in-any-order");
12 |
13 | chai.use(deepEqualInAnyOrder);
14 |
15 | const tempDir = "test/rafcreduxp";
16 |
17 | describe("component command", () => {
18 | before("create temp folder", () => {
19 | utils.createFolder("test", "rafcreduxp");
20 | });
21 | // ========================================
22 | // ========================================
23 | describe(`rg c rafcreduxp ${fileNames.component.name}`, () => {
24 | afterEach(() => {
25 | support.removeFolder(tempDir, fileNames.component.pascalName);
26 | });
27 | // ======================================
28 | it("should create correct number of files/folders", () => {
29 | const nodeProcess = spawnSync(
30 | "node",
31 | [rg, "c", "rafcreduxp", fileNames.component.name],
32 | {
33 | cwd: tempDir,
34 | }
35 | );
36 | const tempContents = support.getDirContents(tempDir);
37 | assert.equal(tempContents.length, 1);
38 | const componentContents = support.getDirContents(
39 | `${tempDir}/${fileNames.component.pascalName}`
40 | );
41 | assert.equal(componentContents.length, 2);
42 | });
43 | it("should create correct name of files/folders", () => {
44 | const nodeProcess = spawnSync(
45 | "node",
46 | [rg, "c", "rafcreduxp", fileNames.component.name],
47 | {
48 | cwd: tempDir,
49 | }
50 | );
51 | const tempContents = support.getDirContents(tempDir);
52 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
53 | const componentContents = support.getDirContents(
54 | `${tempDir}/${fileNames.component.pascalName}`
55 | );
56 | expect(componentContents).to.deep.equalInAnyOrder([
57 | fileNames.component.js,
58 | fileNames.css.normal,
59 | ]);
60 | });
61 | });
62 | // ========================================
63 | describe(`rg c rafcreduxp ${fileNames.component.name} --cssType modular`, () => {
64 | afterEach(() => {
65 | support.removeFolder(tempDir, fileNames.component.pascalName);
66 | });
67 | it("should create correct number of files/folders", () => {
68 | const nodeProcess = spawnSync(
69 | "node",
70 | [
71 | rg,
72 | "c",
73 | "rafcreduxp",
74 | fileNames.component.name,
75 | "--cssType",
76 | "modular",
77 | ],
78 | {
79 | cwd: tempDir,
80 | }
81 | );
82 | const tempContents = support.getDirContents(tempDir);
83 | assert.equal(tempContents.length, 1);
84 | const componentContents = support.getDirContents(
85 | `${tempDir}/${fileNames.component.pascalName}`
86 | );
87 | assert.equal(componentContents.length, 2);
88 | });
89 | it("should create correct name of files/folders", () => {
90 | const nodeProcess = spawnSync(
91 | "node",
92 | [
93 | rg,
94 | "c",
95 | "rafcreduxp",
96 | fileNames.component.name,
97 | "--cssType",
98 | "modular",
99 | ],
100 | {
101 | cwd: tempDir,
102 | }
103 | );
104 | const tempContents = support.getDirContents(tempDir);
105 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
106 | const componentContents = support.getDirContents(
107 | `${tempDir}/${fileNames.component.pascalName}`
108 | );
109 | expect(componentContents).to.deep.equalInAnyOrder([
110 | fileNames.component.js,
111 | fileNames.css.modular,
112 | ]);
113 | });
114 | });
115 | // ========================================
116 | describe(`rg c rafcreduxp ${fileNames.component.name} --test`, () => {
117 | afterEach(() => {
118 | support.removeFolder(tempDir, fileNames.component.pascalName);
119 | });
120 | it("should create correct number of files/folders", () => {
121 | const nodeProcess = spawnSync(
122 | "node",
123 | [rg, "c", "rafcreduxp", fileNames.component.name, "--test"],
124 | {
125 | cwd: tempDir,
126 | }
127 | );
128 | const tempContents = support.getDirContents(tempDir);
129 | assert.equal(tempContents.length, 1);
130 | const componentContents = support.getDirContents(
131 | `${tempDir}/${fileNames.component.pascalName}`
132 | );
133 | assert.equal(componentContents.length, 3);
134 | });
135 | it("should create correct name of files/folders", () => {
136 | const nodeProcess = spawnSync(
137 | "node",
138 | [rg, "c", "rafcreduxp", fileNames.component.name, "--test"],
139 | {
140 | cwd: tempDir,
141 | }
142 | );
143 | const tempContents = support.getDirContents(tempDir);
144 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
145 | const componentContents = support.getDirContents(
146 | `${tempDir}/${fileNames.component.pascalName}`
147 | );
148 | expect(componentContents).to.deep.equalInAnyOrder([
149 | fileNames.component.js,
150 | fileNames.css.normal,
151 | fileNames.test.js,
152 | ]);
153 | });
154 | });
155 | // ========================================
156 | describe(`rg c rafcreduxp ${fileNames.component.name} --test --testExt test-tsx`, () => {
157 | afterEach(() => {
158 | support.removeFolder(tempDir, fileNames.component.pascalName);
159 | });
160 | it("should create correct number of files/folders", () => {
161 | const nodeProcess = spawnSync(
162 | "node",
163 | [
164 | rg,
165 | "c",
166 | "rafcreduxp",
167 | fileNames.component.name,
168 | "--test",
169 | "--testExt",
170 | "test-tsx",
171 | ],
172 | {
173 | cwd: tempDir,
174 | }
175 | );
176 | const tempContents = support.getDirContents(tempDir);
177 | assert.equal(tempContents.length, 1);
178 | const componentContents = support.getDirContents(
179 | `${tempDir}/${fileNames.component.pascalName}`
180 | );
181 | assert.equal(componentContents.length, 3);
182 | });
183 | it("should create correct name of files/folders", () => {
184 | const nodeProcess = spawnSync(
185 | "node",
186 | [
187 | rg,
188 | "c",
189 | "rafcreduxp",
190 | fileNames.component.name,
191 | "--test",
192 | "--testExt",
193 | "test-tsx",
194 | ],
195 | {
196 | cwd: tempDir,
197 | }
198 | );
199 | const tempContents = support.getDirContents(tempDir);
200 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
201 | const componentContents = support.getDirContents(
202 | `${tempDir}/${fileNames.component.pascalName}`
203 | );
204 | expect(componentContents).to.deep.equalInAnyOrder([
205 | fileNames.component.js,
206 | fileNames.css.normal,
207 | fileNames.test.tsx,
208 | ]);
209 | });
210 | });
211 | // ========================================
212 | describe(`rg c rafcreduxp ${fileNames.component.name} --test --testExt spec-js`, () => {
213 | afterEach(() => {
214 | support.removeFolder(tempDir, fileNames.component.pascalName);
215 | });
216 | it("should create correct number of files/folders", () => {
217 | const nodeProcess = spawnSync(
218 | "node",
219 | [
220 | rg,
221 | "c",
222 | "rafcreduxp",
223 | fileNames.component.name,
224 | "--test",
225 | "--testExt",
226 | "spec-js",
227 | ],
228 | {
229 | cwd: tempDir,
230 | }
231 | );
232 | const tempContents = support.getDirContents(tempDir);
233 | assert.equal(tempContents.length, 1);
234 | const componentContents = support.getDirContents(
235 | `${tempDir}/${fileNames.component.pascalName}`
236 | );
237 | assert.equal(componentContents.length, 3);
238 | });
239 | it("should create correct name of files/folders", () => {
240 | const nodeProcess = spawnSync(
241 | "node",
242 | [
243 | rg,
244 | "c",
245 | "rafcreduxp",
246 | fileNames.component.name,
247 | "--test",
248 | "--testExt",
249 | "spec-js",
250 | ],
251 | {
252 | cwd: tempDir,
253 | }
254 | );
255 | const tempContents = support.getDirContents(tempDir);
256 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
257 | const componentContents = support.getDirContents(
258 | `${tempDir}/${fileNames.component.pascalName}`
259 | );
260 | expect(componentContents).to.deep.equalInAnyOrder([
261 | fileNames.component.js,
262 | fileNames.css.normal,
263 | fileNames.test.specJs,
264 | ]);
265 | });
266 | });
267 | // ========================================
268 | describe(`rg c rafcreduxp ${fileNames.component.name} --test --testExt spec-tsx`, () => {
269 | afterEach(() => {
270 | support.removeFolder(tempDir, fileNames.component.pascalName);
271 | });
272 | it("should create correct number of files/folders", () => {
273 | const nodeProcess = spawnSync(
274 | "node",
275 | [
276 | rg,
277 | "c",
278 | "rafcreduxp",
279 | fileNames.component.name,
280 | "--test",
281 | "--testExt",
282 | "spec-tsx",
283 | ],
284 | {
285 | cwd: tempDir,
286 | }
287 | );
288 | const tempContents = support.getDirContents(tempDir);
289 | assert.equal(tempContents.length, 1);
290 | const componentContents = support.getDirContents(
291 | `${tempDir}/${fileNames.component.pascalName}`
292 | );
293 | assert.equal(componentContents.length, 3);
294 | });
295 | it("should create correct name of files/folders", () => {
296 | const nodeProcess = spawnSync(
297 | "node",
298 | [
299 | rg,
300 | "c",
301 | "rafcreduxp",
302 | fileNames.component.name,
303 | "--test",
304 | "--testExt",
305 | "spec-tsx",
306 | ],
307 | {
308 | cwd: tempDir,
309 | }
310 | );
311 | const tempContents = support.getDirContents(tempDir);
312 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
313 | const componentContents = support.getDirContents(
314 | `${tempDir}/${fileNames.component.pascalName}`
315 | );
316 | expect(componentContents).to.deep.equalInAnyOrder([
317 | fileNames.component.js,
318 | fileNames.css.normal,
319 | fileNames.test.specTsx,
320 | ]);
321 | });
322 | });
323 | // ========================================
324 | describe(`rg c rafcreduxp ${fileNames.component.name} --ext jsx`, () => {
325 | afterEach(() => {
326 | support.removeFolder(tempDir, fileNames.component.pascalName);
327 | });
328 | it("should create correct number of files/folders", () => {
329 | const nodeProcess = spawnSync(
330 | "node",
331 | [rg, "c", "rafcreduxp", fileNames.component.name, "--ext", "jsx"],
332 | {
333 | cwd: tempDir,
334 | }
335 | );
336 | const tempContents = support.getDirContents(tempDir);
337 | assert.equal(tempContents.length, 1);
338 | const componentContents = support.getDirContents(
339 | `${tempDir}/${fileNames.component.pascalName}`
340 | );
341 | assert.equal(componentContents.length, 2);
342 | });
343 | it("should create correct name of files/folders", () => {
344 | const nodeProcess = spawnSync(
345 | "node",
346 | [rg, "c", "rafcreduxp", fileNames.component.name, "--ext", "jsx"],
347 | {
348 | cwd: tempDir,
349 | }
350 | );
351 | const tempContents = support.getDirContents(tempDir);
352 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
353 | const componentContents = support.getDirContents(
354 | `${tempDir}/${fileNames.component.pascalName}`
355 | );
356 | expect(componentContents).to.deep.equalInAnyOrder([
357 | fileNames.component.jsx,
358 | fileNames.css.normal,
359 | ]);
360 | });
361 | });
362 | // ========================================
363 | describe(`rg c rafcreduxp ${fileNames.component.name} --ext tsx`, () => {
364 | afterEach(() => {
365 | support.removeFolder(tempDir, fileNames.component.pascalName);
366 | });
367 | it("should create correct number of files/folders", () => {
368 | const nodeProcess = spawnSync(
369 | "node",
370 | [rg, "c", "rafcreduxp", fileNames.component.name, "--ext", "tsx"],
371 | {
372 | cwd: tempDir,
373 | }
374 | );
375 | const tempContents = support.getDirContents(tempDir);
376 | assert.equal(tempContents.length, 1);
377 | const componentContents = support.getDirContents(
378 | `${tempDir}/${fileNames.component.pascalName}`
379 | );
380 | assert.equal(componentContents.length, 2);
381 | });
382 | it("should create correct name of files/folders", () => {
383 | const nodeProcess = spawnSync(
384 | "node",
385 | [rg, "c", "rafcreduxp", fileNames.component.name, "--ext", "tsx"],
386 | {
387 | cwd: tempDir,
388 | }
389 | );
390 | const tempContents = support.getDirContents(tempDir);
391 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
392 | const componentContents = support.getDirContents(
393 | `${tempDir}/${fileNames.component.pascalName}`
394 | );
395 | expect(componentContents).to.deep.equalInAnyOrder([
396 | fileNames.component.tsx,
397 | fileNames.css.normal,
398 | ]);
399 | });
400 | });
401 | after("remove temp folder", () => {
402 | support.removeFolder("test", "rafcreduxp");
403 | });
404 | });
405 |
--------------------------------------------------------------------------------
/test/tests/rcc.js:
--------------------------------------------------------------------------------
1 | const support = require("../support/utils");
2 | const utils = require("../../lib/utils");
3 | const rg = "../../bin/react-generator.js";
4 | const { spawnSync } = require("child_process");
5 | const chai = require("chai");
6 | const { assert, expect } = chai;
7 | const should = chai.should();
8 | const { fileNames } = require("../support/constants");
9 |
10 | // Chai plugins
11 | const deepEqualInAnyOrder = require("deep-equal-in-any-order");
12 |
13 | chai.use(deepEqualInAnyOrder);
14 |
15 | const tempDir = "test/rcc";
16 |
17 | describe("component command", () => {
18 | before("create temp folder", () => {
19 | utils.createFolder("test", "rcc");
20 | });
21 | // ========================================
22 | // ========================================
23 | describe(`rg c rcc ${fileNames.component.name}`, () => {
24 | afterEach(() => {
25 | support.removeFolder(tempDir, fileNames.component.pascalName);
26 | });
27 | // ======================================
28 | it("should create correct number of files/folders", () => {
29 | const nodeProcess = spawnSync(
30 | "node",
31 | [rg, "c", "rcc", fileNames.component.name],
32 | {
33 | cwd: tempDir,
34 | }
35 | );
36 | const tempContents = support.getDirContents(tempDir);
37 | assert.equal(tempContents.length, 1);
38 | const componentContents = support.getDirContents(
39 | `${tempDir}/${fileNames.component.pascalName}`
40 | );
41 | assert.equal(componentContents.length, 2);
42 | });
43 | it("should create correct name of files/folders", () => {
44 | const nodeProcess = spawnSync(
45 | "node",
46 | [rg, "c", "rcc", fileNames.component.name],
47 | {
48 | cwd: tempDir,
49 | }
50 | );
51 | const tempContents = support.getDirContents(tempDir);
52 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
53 | const componentContents = support.getDirContents(
54 | `${tempDir}/${fileNames.component.pascalName}`
55 | );
56 | expect(componentContents).to.deep.equalInAnyOrder([
57 | fileNames.component.js,
58 | fileNames.css.normal,
59 | ]);
60 | });
61 | });
62 | // ========================================
63 | describe(`rg c rcc ${fileNames.component.name} --cssType modular`, () => {
64 | afterEach(() => {
65 | support.removeFolder(tempDir, fileNames.component.pascalName);
66 | });
67 | it("should create correct number of files/folders", () => {
68 | const nodeProcess = spawnSync(
69 | "node",
70 | [rg, "c", "rcc", fileNames.component.name, "--cssType", "modular"],
71 | {
72 | cwd: tempDir,
73 | }
74 | );
75 | const tempContents = support.getDirContents(tempDir);
76 | assert.equal(tempContents.length, 1);
77 | const componentContents = support.getDirContents(
78 | `${tempDir}/${fileNames.component.pascalName}`
79 | );
80 | assert.equal(componentContents.length, 2);
81 | });
82 | it("should create correct name of files/folders", () => {
83 | const nodeProcess = spawnSync(
84 | "node",
85 | [rg, "c", "rcc", fileNames.component.name, "--cssType", "modular"],
86 | {
87 | cwd: tempDir,
88 | }
89 | );
90 | const tempContents = support.getDirContents(tempDir);
91 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
92 | const componentContents = support.getDirContents(
93 | `${tempDir}/${fileNames.component.pascalName}`
94 | );
95 | expect(componentContents).to.deep.equalInAnyOrder([
96 | fileNames.component.js,
97 | fileNames.css.modular,
98 | ]);
99 | });
100 | });
101 | // ========================================
102 | describe(`rg c rcc ${fileNames.component.name} --test`, () => {
103 | afterEach(() => {
104 | support.removeFolder(tempDir, fileNames.component.pascalName);
105 | });
106 | it("should create correct number of files/folders", () => {
107 | const nodeProcess = spawnSync(
108 | "node",
109 | [rg, "c", "rcc", fileNames.component.name, "--test"],
110 | {
111 | cwd: tempDir,
112 | }
113 | );
114 | const tempContents = support.getDirContents(tempDir);
115 | assert.equal(tempContents.length, 1);
116 | const componentContents = support.getDirContents(
117 | `${tempDir}/${fileNames.component.pascalName}`
118 | );
119 | assert.equal(componentContents.length, 3);
120 | });
121 | it("should create correct name of files/folders", () => {
122 | const nodeProcess = spawnSync(
123 | "node",
124 | [rg, "c", "rcc", fileNames.component.name, "--test"],
125 | {
126 | cwd: tempDir,
127 | }
128 | );
129 | const tempContents = support.getDirContents(tempDir);
130 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
131 | const componentContents = support.getDirContents(
132 | `${tempDir}/${fileNames.component.pascalName}`
133 | );
134 | expect(componentContents).to.deep.equalInAnyOrder([
135 | fileNames.component.js,
136 | fileNames.css.normal,
137 | fileNames.test.js,
138 | ]);
139 | });
140 | });
141 | // ========================================
142 | describe(`rg c rcc ${fileNames.component.name} --test --testExt test-tsx`, () => {
143 | afterEach(() => {
144 | support.removeFolder(tempDir, fileNames.component.pascalName);
145 | });
146 | it("should create correct number of files/folders", () => {
147 | const nodeProcess = spawnSync(
148 | "node",
149 | [
150 | rg,
151 | "c",
152 | "rcc",
153 | fileNames.component.name,
154 | "--test",
155 | "--testExt",
156 | "test-tsx",
157 | ],
158 | {
159 | cwd: tempDir,
160 | }
161 | );
162 | const tempContents = support.getDirContents(tempDir);
163 | assert.equal(tempContents.length, 1);
164 | const componentContents = support.getDirContents(
165 | `${tempDir}/${fileNames.component.pascalName}`
166 | );
167 | assert.equal(componentContents.length, 3);
168 | });
169 | it("should create correct name of files/folders", () => {
170 | const nodeProcess = spawnSync(
171 | "node",
172 | [
173 | rg,
174 | "c",
175 | "rcc",
176 | fileNames.component.name,
177 | "--test",
178 | "--testExt",
179 | "test-tsx",
180 | ],
181 | {
182 | cwd: tempDir,
183 | }
184 | );
185 | const tempContents = support.getDirContents(tempDir);
186 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
187 | const componentContents = support.getDirContents(
188 | `${tempDir}/${fileNames.component.pascalName}`
189 | );
190 | expect(componentContents).to.deep.equalInAnyOrder([
191 | fileNames.component.js,
192 | fileNames.css.normal,
193 | fileNames.test.tsx,
194 | ]);
195 | });
196 | });
197 | // ========================================
198 | describe(`rg c rcc ${fileNames.component.name} --test --testExt spec-js`, () => {
199 | afterEach(() => {
200 | support.removeFolder(tempDir, fileNames.component.pascalName);
201 | });
202 | it("should create correct number of files/folders", () => {
203 | const nodeProcess = spawnSync(
204 | "node",
205 | [
206 | rg,
207 | "c",
208 | "rcc",
209 | fileNames.component.name,
210 | "--test",
211 | "--testExt",
212 | "spec-js",
213 | ],
214 | {
215 | cwd: tempDir,
216 | }
217 | );
218 | const tempContents = support.getDirContents(tempDir);
219 | assert.equal(tempContents.length, 1);
220 | const componentContents = support.getDirContents(
221 | `${tempDir}/${fileNames.component.pascalName}`
222 | );
223 | assert.equal(componentContents.length, 3);
224 | });
225 | it("should create correct name of files/folders", () => {
226 | const nodeProcess = spawnSync(
227 | "node",
228 | [
229 | rg,
230 | "c",
231 | "rcc",
232 | fileNames.component.name,
233 | "--test",
234 | "--testExt",
235 | "spec-js",
236 | ],
237 | {
238 | cwd: tempDir,
239 | }
240 | );
241 | const tempContents = support.getDirContents(tempDir);
242 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
243 | const componentContents = support.getDirContents(
244 | `${tempDir}/${fileNames.component.pascalName}`
245 | );
246 | expect(componentContents).to.deep.equalInAnyOrder([
247 | fileNames.component.js,
248 | fileNames.css.normal,
249 | fileNames.test.specJs,
250 | ]);
251 | });
252 | });
253 | // ========================================
254 | describe(`rg c rcc ${fileNames.component.name} --test --testExt spec-tsx`, () => {
255 | afterEach(() => {
256 | support.removeFolder(tempDir, fileNames.component.pascalName);
257 | });
258 | it("should create correct number of files/folders", () => {
259 | const nodeProcess = spawnSync(
260 | "node",
261 | [
262 | rg,
263 | "c",
264 | "rcc",
265 | fileNames.component.name,
266 | "--test",
267 | "--testExt",
268 | "spec-tsx",
269 | ],
270 | {
271 | cwd: tempDir,
272 | }
273 | );
274 | const tempContents = support.getDirContents(tempDir);
275 | assert.equal(tempContents.length, 1);
276 | const componentContents = support.getDirContents(
277 | `${tempDir}/${fileNames.component.pascalName}`
278 | );
279 | assert.equal(componentContents.length, 3);
280 | });
281 | it("should create correct name of files/folders", () => {
282 | const nodeProcess = spawnSync(
283 | "node",
284 | [
285 | rg,
286 | "c",
287 | "rcc",
288 | fileNames.component.name,
289 | "--test",
290 | "--testExt",
291 | "spec-tsx",
292 | ],
293 | {
294 | cwd: tempDir,
295 | }
296 | );
297 | const tempContents = support.getDirContents(tempDir);
298 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
299 | const componentContents = support.getDirContents(
300 | `${tempDir}/${fileNames.component.pascalName}`
301 | );
302 | expect(componentContents).to.deep.equalInAnyOrder([
303 | fileNames.component.js,
304 | fileNames.css.normal,
305 | fileNames.test.specTsx,
306 | ]);
307 | });
308 | });
309 | // ========================================
310 | describe(`rg c rcc ${fileNames.component.name} --ext jsx`, () => {
311 | afterEach(() => {
312 | support.removeFolder(tempDir, fileNames.component.pascalName);
313 | });
314 | it("should create correct number of files/folders", () => {
315 | const nodeProcess = spawnSync(
316 | "node",
317 | [rg, "c", "rcc", fileNames.component.name, "--ext", "jsx"],
318 | {
319 | cwd: tempDir,
320 | }
321 | );
322 | const tempContents = support.getDirContents(tempDir);
323 | assert.equal(tempContents.length, 1);
324 | const componentContents = support.getDirContents(
325 | `${tempDir}/${fileNames.component.pascalName}`
326 | );
327 | assert.equal(componentContents.length, 2);
328 | });
329 | it("should create correct name of files/folders", () => {
330 | const nodeProcess = spawnSync(
331 | "node",
332 | [rg, "c", "rcc", fileNames.component.name, "--ext", "jsx"],
333 | {
334 | cwd: tempDir,
335 | }
336 | );
337 | const tempContents = support.getDirContents(tempDir);
338 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
339 | const componentContents = support.getDirContents(
340 | `${tempDir}/${fileNames.component.pascalName}`
341 | );
342 | expect(componentContents).to.deep.equalInAnyOrder([
343 | fileNames.component.jsx,
344 | fileNames.css.normal,
345 | ]);
346 | });
347 | });
348 | // ========================================
349 | describe(`rg c rcc ${fileNames.component.name} --ext tsx`, () => {
350 | afterEach(() => {
351 | support.removeFolder(tempDir, fileNames.component.pascalName);
352 | });
353 | it("should create correct number of files/folders", () => {
354 | const nodeProcess = spawnSync(
355 | "node",
356 | [rg, "c", "rcc", fileNames.component.name, "--ext", "tsx"],
357 | {
358 | cwd: tempDir,
359 | }
360 | );
361 | const tempContents = support.getDirContents(tempDir);
362 | assert.equal(tempContents.length, 1);
363 | const componentContents = support.getDirContents(
364 | `${tempDir}/${fileNames.component.pascalName}`
365 | );
366 | assert.equal(componentContents.length, 2);
367 | });
368 | it("should create correct name of files/folders", () => {
369 | const nodeProcess = spawnSync(
370 | "node",
371 | [rg, "c", "rcc", fileNames.component.name, "--ext", "tsx"],
372 | {
373 | cwd: tempDir,
374 | }
375 | );
376 | const tempContents = support.getDirContents(tempDir);
377 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
378 | const componentContents = support.getDirContents(
379 | `${tempDir}/${fileNames.component.pascalName}`
380 | );
381 | expect(componentContents).to.deep.equalInAnyOrder([
382 | fileNames.component.tsx,
383 | fileNames.css.normal,
384 | ]);
385 | });
386 | });
387 | after("remove temp folder", () => {
388 | support.removeFolder("test", "rcc");
389 | });
390 | });
391 |
--------------------------------------------------------------------------------
/test/tests/rccp.js:
--------------------------------------------------------------------------------
1 | const support = require("../support/utils");
2 | const utils = require("../../lib/utils");
3 | const rg = "../../bin/react-generator.js";
4 | const { spawnSync } = require("child_process");
5 | const chai = require("chai");
6 | const { assert, expect } = chai;
7 | const should = chai.should();
8 | const { fileNames } = require("../support/constants");
9 |
10 | // Chai plugins
11 | const deepEqualInAnyOrder = require("deep-equal-in-any-order");
12 |
13 | chai.use(deepEqualInAnyOrder);
14 |
15 | const tempDir = "test/rccp";
16 |
17 | describe("component command", () => {
18 | before("create temp folder", () => {
19 | utils.createFolder("test", "rccp");
20 | });
21 | // ========================================
22 | // ========================================
23 | describe(`rg c rccp ${fileNames.component.name}`, () => {
24 | afterEach(() => {
25 | support.removeFolder(tempDir, fileNames.component.pascalName);
26 | });
27 | // ======================================
28 | it("should create correct number of files/folders", () => {
29 | const nodeProcess = spawnSync(
30 | "node",
31 | [rg, "c", "rccp", fileNames.component.name],
32 | {
33 | cwd: tempDir,
34 | }
35 | );
36 | const tempContents = support.getDirContents(tempDir);
37 | assert.equal(tempContents.length, 1);
38 | const componentContents = support.getDirContents(
39 | `${tempDir}/${fileNames.component.pascalName}`
40 | );
41 | assert.equal(componentContents.length, 2);
42 | });
43 | it("should create correct name of files/folders", () => {
44 | const nodeProcess = spawnSync(
45 | "node",
46 | [rg, "c", "rccp", fileNames.component.name],
47 | {
48 | cwd: tempDir,
49 | }
50 | );
51 | const tempContents = support.getDirContents(tempDir);
52 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
53 | const componentContents = support.getDirContents(
54 | `${tempDir}/${fileNames.component.pascalName}`
55 | );
56 | expect(componentContents).to.deep.equalInAnyOrder([
57 | fileNames.component.js,
58 | fileNames.css.normal,
59 | ]);
60 | });
61 | });
62 | // ========================================
63 | describe(`rg c rccp ${fileNames.component.name} --cssType modular`, () => {
64 | afterEach(() => {
65 | support.removeFolder(tempDir, fileNames.component.pascalName);
66 | });
67 | it("should create correct number of files/folders", () => {
68 | const nodeProcess = spawnSync(
69 | "node",
70 | [rg, "c", "rccp", fileNames.component.name, "--cssType", "modular"],
71 | {
72 | cwd: tempDir,
73 | }
74 | );
75 | const tempContents = support.getDirContents(tempDir);
76 | assert.equal(tempContents.length, 1);
77 | const componentContents = support.getDirContents(
78 | `${tempDir}/${fileNames.component.pascalName}`
79 | );
80 | assert.equal(componentContents.length, 2);
81 | });
82 | it("should create correct name of files/folders", () => {
83 | const nodeProcess = spawnSync(
84 | "node",
85 | [rg, "c", "rccp", fileNames.component.name, "--cssType", "modular"],
86 | {
87 | cwd: tempDir,
88 | }
89 | );
90 | const tempContents = support.getDirContents(tempDir);
91 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
92 | const componentContents = support.getDirContents(
93 | `${tempDir}/${fileNames.component.pascalName}`
94 | );
95 | expect(componentContents).to.deep.equalInAnyOrder([
96 | fileNames.component.js,
97 | fileNames.css.modular,
98 | ]);
99 | });
100 | });
101 | // ========================================
102 | describe(`rg c rccp ${fileNames.component.name} --test`, () => {
103 | afterEach(() => {
104 | support.removeFolder(tempDir, fileNames.component.pascalName);
105 | });
106 | it("should create correct number of files/folders", () => {
107 | const nodeProcess = spawnSync(
108 | "node",
109 | [rg, "c", "rccp", fileNames.component.name, "--test"],
110 | {
111 | cwd: tempDir,
112 | }
113 | );
114 | const tempContents = support.getDirContents(tempDir);
115 | assert.equal(tempContents.length, 1);
116 | const componentContents = support.getDirContents(
117 | `${tempDir}/${fileNames.component.pascalName}`
118 | );
119 | assert.equal(componentContents.length, 3);
120 | });
121 | it("should create correct name of files/folders", () => {
122 | const nodeProcess = spawnSync(
123 | "node",
124 | [rg, "c", "rccp", fileNames.component.name, "--test"],
125 | {
126 | cwd: tempDir,
127 | }
128 | );
129 | const tempContents = support.getDirContents(tempDir);
130 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
131 | const componentContents = support.getDirContents(
132 | `${tempDir}/${fileNames.component.pascalName}`
133 | );
134 | expect(componentContents).to.deep.equalInAnyOrder([
135 | fileNames.component.js,
136 | fileNames.css.normal,
137 | fileNames.test.js,
138 | ]);
139 | });
140 | });
141 | // ========================================
142 | describe(`rg c rccp ${fileNames.component.name} --test --testExt test-tsx`, () => {
143 | afterEach(() => {
144 | support.removeFolder(tempDir, fileNames.component.pascalName);
145 | });
146 | it("should create correct number of files/folders", () => {
147 | const nodeProcess = spawnSync(
148 | "node",
149 | [
150 | rg,
151 | "c",
152 | "rccp",
153 | fileNames.component.name,
154 | "--test",
155 | "--testExt",
156 | "test-tsx",
157 | ],
158 | {
159 | cwd: tempDir,
160 | }
161 | );
162 | const tempContents = support.getDirContents(tempDir);
163 | assert.equal(tempContents.length, 1);
164 | const componentContents = support.getDirContents(
165 | `${tempDir}/${fileNames.component.pascalName}`
166 | );
167 | assert.equal(componentContents.length, 3);
168 | });
169 | it("should create correct name of files/folders", () => {
170 | const nodeProcess = spawnSync(
171 | "node",
172 | [
173 | rg,
174 | "c",
175 | "rccp",
176 | fileNames.component.name,
177 | "--test",
178 | "--testExt",
179 | "test-tsx",
180 | ],
181 | {
182 | cwd: tempDir,
183 | }
184 | );
185 | const tempContents = support.getDirContents(tempDir);
186 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
187 | const componentContents = support.getDirContents(
188 | `${tempDir}/${fileNames.component.pascalName}`
189 | );
190 | expect(componentContents).to.deep.equalInAnyOrder([
191 | fileNames.component.js,
192 | fileNames.css.normal,
193 | fileNames.test.tsx,
194 | ]);
195 | });
196 | });
197 | // ========================================
198 | describe(`rg c rccp ${fileNames.component.name} --test --testExt spec-js`, () => {
199 | afterEach(() => {
200 | support.removeFolder(tempDir, fileNames.component.pascalName);
201 | });
202 | it("should create correct number of files/folders", () => {
203 | const nodeProcess = spawnSync(
204 | "node",
205 | [
206 | rg,
207 | "c",
208 | "rccp",
209 | fileNames.component.name,
210 | "--test",
211 | "--testExt",
212 | "spec-js",
213 | ],
214 | {
215 | cwd: tempDir,
216 | }
217 | );
218 | const tempContents = support.getDirContents(tempDir);
219 | assert.equal(tempContents.length, 1);
220 | const componentContents = support.getDirContents(
221 | `${tempDir}/${fileNames.component.pascalName}`
222 | );
223 | assert.equal(componentContents.length, 3);
224 | });
225 | it("should create correct name of files/folders", () => {
226 | const nodeProcess = spawnSync(
227 | "node",
228 | [
229 | rg,
230 | "c",
231 | "rccp",
232 | fileNames.component.name,
233 | "--test",
234 | "--testExt",
235 | "spec-js",
236 | ],
237 | {
238 | cwd: tempDir,
239 | }
240 | );
241 | const tempContents = support.getDirContents(tempDir);
242 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
243 | const componentContents = support.getDirContents(
244 | `${tempDir}/${fileNames.component.pascalName}`
245 | );
246 | expect(componentContents).to.deep.equalInAnyOrder([
247 | fileNames.component.js,
248 | fileNames.css.normal,
249 | fileNames.test.specJs,
250 | ]);
251 | });
252 | });
253 | // ========================================
254 | describe(`rg c rccp ${fileNames.component.name} --test --testExt spec-tsx`, () => {
255 | afterEach(() => {
256 | support.removeFolder(tempDir, fileNames.component.pascalName);
257 | });
258 | it("should create correct number of files/folders", () => {
259 | const nodeProcess = spawnSync(
260 | "node",
261 | [
262 | rg,
263 | "c",
264 | "rccp",
265 | fileNames.component.name,
266 | "--test",
267 | "--testExt",
268 | "spec-tsx",
269 | ],
270 | {
271 | cwd: tempDir,
272 | }
273 | );
274 | const tempContents = support.getDirContents(tempDir);
275 | assert.equal(tempContents.length, 1);
276 | const componentContents = support.getDirContents(
277 | `${tempDir}/${fileNames.component.pascalName}`
278 | );
279 | assert.equal(componentContents.length, 3);
280 | });
281 | it("should create correct name of files/folders", () => {
282 | const nodeProcess = spawnSync(
283 | "node",
284 | [
285 | rg,
286 | "c",
287 | "rccp",
288 | fileNames.component.name,
289 | "--test",
290 | "--testExt",
291 | "spec-tsx",
292 | ],
293 | {
294 | cwd: tempDir,
295 | }
296 | );
297 | const tempContents = support.getDirContents(tempDir);
298 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
299 | const componentContents = support.getDirContents(
300 | `${tempDir}/${fileNames.component.pascalName}`
301 | );
302 | expect(componentContents).to.deep.equalInAnyOrder([
303 | fileNames.component.js,
304 | fileNames.css.normal,
305 | fileNames.test.specTsx,
306 | ]);
307 | });
308 | });
309 | // ========================================
310 | describe(`rg c rccp ${fileNames.component.name} --ext jsx`, () => {
311 | afterEach(() => {
312 | support.removeFolder(tempDir, fileNames.component.pascalName);
313 | });
314 | it("should create correct number of files/folders", () => {
315 | const nodeProcess = spawnSync(
316 | "node",
317 | [rg, "c", "rccp", fileNames.component.name, "--ext", "jsx"],
318 | {
319 | cwd: tempDir,
320 | }
321 | );
322 | const tempContents = support.getDirContents(tempDir);
323 | assert.equal(tempContents.length, 1);
324 | const componentContents = support.getDirContents(
325 | `${tempDir}/${fileNames.component.pascalName}`
326 | );
327 | assert.equal(componentContents.length, 2);
328 | });
329 | it("should create correct name of files/folders", () => {
330 | const nodeProcess = spawnSync(
331 | "node",
332 | [rg, "c", "rccp", fileNames.component.name, "--ext", "jsx"],
333 | {
334 | cwd: tempDir,
335 | }
336 | );
337 | const tempContents = support.getDirContents(tempDir);
338 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
339 | const componentContents = support.getDirContents(
340 | `${tempDir}/${fileNames.component.pascalName}`
341 | );
342 | expect(componentContents).to.deep.equalInAnyOrder([
343 | fileNames.component.jsx,
344 | fileNames.css.normal,
345 | ]);
346 | });
347 | });
348 | // ========================================
349 | describe(`rg c rccp ${fileNames.component.name} --ext tsx`, () => {
350 | afterEach(() => {
351 | support.removeFolder(tempDir, fileNames.component.pascalName);
352 | });
353 | it("should create correct number of files/folders", () => {
354 | const nodeProcess = spawnSync(
355 | "node",
356 | [rg, "c", "rccp", fileNames.component.name, "--ext", "tsx"],
357 | {
358 | cwd: tempDir,
359 | }
360 | );
361 | const tempContents = support.getDirContents(tempDir);
362 | assert.equal(tempContents.length, 1);
363 | const componentContents = support.getDirContents(
364 | `${tempDir}/${fileNames.component.pascalName}`
365 | );
366 | assert.equal(componentContents.length, 2);
367 | });
368 | it("should create correct name of files/folders", () => {
369 | const nodeProcess = spawnSync(
370 | "node",
371 | [rg, "c", "rccp", fileNames.component.name, "--ext", "tsx"],
372 | {
373 | cwd: tempDir,
374 | }
375 | );
376 | const tempContents = support.getDirContents(tempDir);
377 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
378 | const componentContents = support.getDirContents(
379 | `${tempDir}/${fileNames.component.pascalName}`
380 | );
381 | expect(componentContents).to.deep.equalInAnyOrder([
382 | fileNames.component.tsx,
383 | fileNames.css.normal,
384 | ]);
385 | });
386 | });
387 | after("remove temp folder", () => {
388 | support.removeFolder("test", "rccp");
389 | });
390 | });
391 |
--------------------------------------------------------------------------------
/test/tests/rfc.js:
--------------------------------------------------------------------------------
1 | const support = require("../support/utils");
2 | const utils = require("../../lib/utils");
3 | const rg = "../../bin/react-generator.js";
4 | const { spawnSync } = require("child_process");
5 | const chai = require("chai");
6 | const { assert, expect } = chai;
7 | const should = chai.should();
8 | const { fileNames } = require("../support/constants");
9 |
10 | // Chai plugins
11 | const deepEqualInAnyOrder = require("deep-equal-in-any-order");
12 |
13 | chai.use(deepEqualInAnyOrder);
14 |
15 | const tempDir = "test/rfc";
16 |
17 | describe("component command", () => {
18 | before("create temp folder", () => {
19 | utils.createFolder("test", "rfc");
20 | });
21 | // ========================================
22 | // ========================================
23 | describe(`rg c rfc ${fileNames.component.name}`, () => {
24 | afterEach(() => {
25 | support.removeFolder(tempDir, fileNames.component.pascalName);
26 | });
27 | // ======================================
28 | it("should create correct number of files/folders", () => {
29 | const nodeProcess = spawnSync(
30 | "node",
31 | [rg, "c", "rfc", fileNames.component.name],
32 | {
33 | cwd: tempDir,
34 | }
35 | );
36 | const tempContents = support.getDirContents(tempDir);
37 | assert.equal(tempContents.length, 1);
38 | const componentContents = support.getDirContents(
39 | `${tempDir}/${fileNames.component.pascalName}`
40 | );
41 | assert.equal(componentContents.length, 2);
42 | });
43 | it("should create correct name of files/folders", () => {
44 | const nodeProcess = spawnSync(
45 | "node",
46 | [rg, "c", "rfc", fileNames.component.name],
47 | {
48 | cwd: tempDir,
49 | }
50 | );
51 | const tempContents = support.getDirContents(tempDir);
52 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
53 | const componentContents = support.getDirContents(
54 | `${tempDir}/${fileNames.component.pascalName}`
55 | );
56 | expect(componentContents).to.deep.equalInAnyOrder([
57 | fileNames.component.js,
58 | fileNames.css.normal,
59 | ]);
60 | });
61 | });
62 | // ========================================
63 | describe(`rg c rfc ${fileNames.component.name} --cssType modular`, () => {
64 | afterEach(() => {
65 | support.removeFolder(tempDir, fileNames.component.pascalName);
66 | });
67 | it("should create correct number of files/folders", () => {
68 | const nodeProcess = spawnSync(
69 | "node",
70 | [rg, "c", "rfc", fileNames.component.name, "--cssType", "modular"],
71 | {
72 | cwd: tempDir,
73 | }
74 | );
75 | const tempContents = support.getDirContents(tempDir);
76 | assert.equal(tempContents.length, 1);
77 | const componentContents = support.getDirContents(
78 | `${tempDir}/${fileNames.component.pascalName}`
79 | );
80 | assert.equal(componentContents.length, 2);
81 | });
82 | it("should create correct name of files/folders", () => {
83 | const nodeProcess = spawnSync(
84 | "node",
85 | [rg, "c", "rfc", fileNames.component.name, "--cssType", "modular"],
86 | {
87 | cwd: tempDir,
88 | }
89 | );
90 | const tempContents = support.getDirContents(tempDir);
91 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
92 | const componentContents = support.getDirContents(
93 | `${tempDir}/${fileNames.component.pascalName}`
94 | );
95 | expect(componentContents).to.deep.equalInAnyOrder([
96 | fileNames.component.js,
97 | fileNames.css.modular,
98 | ]);
99 | });
100 | });
101 | // ========================================
102 | describe(`rg c rfc ${fileNames.component.name} --test`, () => {
103 | afterEach(() => {
104 | support.removeFolder(tempDir, fileNames.component.pascalName);
105 | });
106 | it("should create correct number of files/folders", () => {
107 | const nodeProcess = spawnSync(
108 | "node",
109 | [rg, "c", "rfc", fileNames.component.name, "--test"],
110 | {
111 | cwd: tempDir,
112 | }
113 | );
114 | const tempContents = support.getDirContents(tempDir);
115 | assert.equal(tempContents.length, 1);
116 | const componentContents = support.getDirContents(
117 | `${tempDir}/${fileNames.component.pascalName}`
118 | );
119 | assert.equal(componentContents.length, 3);
120 | });
121 | it("should create correct name of files/folders", () => {
122 | const nodeProcess = spawnSync(
123 | "node",
124 | [rg, "c", "rfc", fileNames.component.name, "--test"],
125 | {
126 | cwd: tempDir,
127 | }
128 | );
129 | const tempContents = support.getDirContents(tempDir);
130 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
131 | const componentContents = support.getDirContents(
132 | `${tempDir}/${fileNames.component.pascalName}`
133 | );
134 | expect(componentContents).to.deep.equalInAnyOrder([
135 | fileNames.component.js,
136 | fileNames.css.normal,
137 | fileNames.test.js,
138 | ]);
139 | });
140 | });
141 | // ========================================
142 | describe(`rg c rfc ${fileNames.component.name} --ext jsx`, () => {
143 | afterEach(() => {
144 | support.removeFolder(tempDir, fileNames.component.pascalName);
145 | });
146 | it("should create correct number of files/folders", () => {
147 | const nodeProcess = spawnSync(
148 | "node",
149 | [rg, "c", "rfc", fileNames.component.name, "--ext", "jsx"],
150 | {
151 | cwd: tempDir,
152 | }
153 | );
154 | const tempContents = support.getDirContents(tempDir);
155 | assert.equal(tempContents.length, 1);
156 | const componentContents = support.getDirContents(
157 | `${tempDir}/${fileNames.component.pascalName}`
158 | );
159 | assert.equal(componentContents.length, 2);
160 | });
161 | it("should create correct name of files/folders", () => {
162 | const nodeProcess = spawnSync(
163 | "node",
164 | [rg, "c", "rfc", fileNames.component.name, "--ext", "jsx"],
165 | {
166 | cwd: tempDir,
167 | }
168 | );
169 | const tempContents = support.getDirContents(tempDir);
170 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
171 | const componentContents = support.getDirContents(
172 | `${tempDir}/${fileNames.component.pascalName}`
173 | );
174 | expect(componentContents).to.deep.equalInAnyOrder([
175 | fileNames.component.jsx,
176 | fileNames.css.normal,
177 | ]);
178 | });
179 | });
180 | // ========================================
181 | describe(`rg c rfc ${fileNames.component.name} --ext tsx`, () => {
182 | afterEach(() => {
183 | support.removeFolder(tempDir, fileNames.component.pascalName);
184 | });
185 | it("should create correct number of files/folders", () => {
186 | const nodeProcess = spawnSync(
187 | "node",
188 | [rg, "c", "rfc", fileNames.component.name, "--ext", "tsx"],
189 | {
190 | cwd: tempDir,
191 | }
192 | );
193 | const tempContents = support.getDirContents(tempDir);
194 | assert.equal(tempContents.length, 1);
195 | const componentContents = support.getDirContents(
196 | `${tempDir}/${fileNames.component.pascalName}`
197 | );
198 | assert.equal(componentContents.length, 2);
199 | });
200 | it("should create correct name of files/folders", () => {
201 | const nodeProcess = spawnSync(
202 | "node",
203 | [rg, "c", "rfc", fileNames.component.name, "--ext", "tsx"],
204 | {
205 | cwd: tempDir,
206 | }
207 | );
208 | const tempContents = support.getDirContents(tempDir);
209 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
210 | const componentContents = support.getDirContents(
211 | `${tempDir}/${fileNames.component.pascalName}`
212 | );
213 | expect(componentContents).to.deep.equalInAnyOrder([
214 | fileNames.component.tsx,
215 | fileNames.css.normal,
216 | ]);
217 | });
218 | });
219 | after("remove temp folder", () => {
220 | support.removeFolder("test", "rfc");
221 | });
222 | });
223 |
--------------------------------------------------------------------------------
/test/tests/rfcp.js:
--------------------------------------------------------------------------------
1 | const support = require("../support/utils");
2 | const utils = require("../../lib/utils");
3 | const rg = "../../bin/react-generator.js";
4 | const { spawnSync } = require("child_process");
5 | const chai = require("chai");
6 | const { assert, expect } = chai;
7 | const should = chai.should();
8 | const { fileNames } = require("../support/constants");
9 |
10 | // Chai plugins
11 | const deepEqualInAnyOrder = require("deep-equal-in-any-order");
12 |
13 | chai.use(deepEqualInAnyOrder);
14 |
15 | const tempDir = "test/rfcp";
16 |
17 | describe("component command", () => {
18 | before("create temp folder", () => {
19 | utils.createFolder("test", "rfcp");
20 | });
21 | // ========================================
22 | // ========================================
23 | describe(`rg c rfcp ${fileNames.component.name}`, () => {
24 | afterEach(() => {
25 | support.removeFolder(tempDir, fileNames.component.pascalName);
26 | });
27 | // ======================================
28 | it("should create correct number of files/folders", () => {
29 | const nodeProcess = spawnSync(
30 | "node",
31 | [rg, "c", "rfcp", fileNames.component.name],
32 | {
33 | cwd: tempDir,
34 | }
35 | );
36 | const tempContents = support.getDirContents(tempDir);
37 | assert.equal(tempContents.length, 1);
38 | const componentContents = support.getDirContents(
39 | `${tempDir}/${fileNames.component.pascalName}`
40 | );
41 | assert.equal(componentContents.length, 2);
42 | });
43 | it("should create correct name of files/folders", () => {
44 | const nodeProcess = spawnSync(
45 | "node",
46 | [rg, "c", "rfcp", fileNames.component.name],
47 | {
48 | cwd: tempDir,
49 | }
50 | );
51 | const tempContents = support.getDirContents(tempDir);
52 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
53 | const componentContents = support.getDirContents(
54 | `${tempDir}/${fileNames.component.pascalName}`
55 | );
56 | expect(componentContents).to.deep.equalInAnyOrder([
57 | fileNames.component.js,
58 | fileNames.css.normal,
59 | ]);
60 | });
61 | });
62 | // ========================================
63 | describe(`rg c rfcp ${fileNames.component.name} --cssType modular`, () => {
64 | afterEach(() => {
65 | support.removeFolder(tempDir, fileNames.component.pascalName);
66 | });
67 | it("should create correct number of files/folders", () => {
68 | const nodeProcess = spawnSync(
69 | "node",
70 | [rg, "c", "rfcp", fileNames.component.name, "--cssType", "modular"],
71 | {
72 | cwd: tempDir,
73 | }
74 | );
75 | const tempContents = support.getDirContents(tempDir);
76 | assert.equal(tempContents.length, 1);
77 | const componentContents = support.getDirContents(
78 | `${tempDir}/${fileNames.component.pascalName}`
79 | );
80 | assert.equal(componentContents.length, 2);
81 | });
82 | it("should create correct name of files/folders", () => {
83 | const nodeProcess = spawnSync(
84 | "node",
85 | [rg, "c", "rfcp", fileNames.component.name, "--cssType", "modular"],
86 | {
87 | cwd: tempDir,
88 | }
89 | );
90 | const tempContents = support.getDirContents(tempDir);
91 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
92 | const componentContents = support.getDirContents(
93 | `${tempDir}/${fileNames.component.pascalName}`
94 | );
95 | expect(componentContents).to.deep.equalInAnyOrder([
96 | fileNames.component.js,
97 | fileNames.css.modular,
98 | ]);
99 | });
100 | });
101 | // ========================================
102 | describe(`rg c rfcp ${fileNames.component.name} --test`, () => {
103 | afterEach(() => {
104 | support.removeFolder(tempDir, fileNames.component.pascalName);
105 | });
106 | it("should create correct number of files/folders", () => {
107 | const nodeProcess = spawnSync(
108 | "node",
109 | [rg, "c", "rfcp", fileNames.component.name, "--test"],
110 | {
111 | cwd: tempDir,
112 | }
113 | );
114 | const tempContents = support.getDirContents(tempDir);
115 | assert.equal(tempContents.length, 1);
116 | const componentContents = support.getDirContents(
117 | `${tempDir}/${fileNames.component.pascalName}`
118 | );
119 | assert.equal(componentContents.length, 3);
120 | });
121 | it("should create correct name of files/folders", () => {
122 | const nodeProcess = spawnSync(
123 | "node",
124 | [rg, "c", "rfcp", fileNames.component.name, "--test"],
125 | {
126 | cwd: tempDir,
127 | }
128 | );
129 | const tempContents = support.getDirContents(tempDir);
130 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
131 | const componentContents = support.getDirContents(
132 | `${tempDir}/${fileNames.component.pascalName}`
133 | );
134 | expect(componentContents).to.deep.equalInAnyOrder([
135 | fileNames.component.js,
136 | fileNames.css.normal,
137 | fileNames.test.js,
138 | ]);
139 | });
140 | });
141 | // ========================================
142 | describe(`rg c rfcp ${fileNames.component.name} --test --testExt test-tsx`, () => {
143 | afterEach(() => {
144 | support.removeFolder(tempDir, fileNames.component.pascalName);
145 | });
146 | it("should create correct number of files/folders", () => {
147 | const nodeProcess = spawnSync(
148 | "node",
149 | [
150 | rg,
151 | "c",
152 | "rfcp",
153 | fileNames.component.name,
154 | "--test",
155 | "--testExt",
156 | "test-tsx",
157 | ],
158 | {
159 | cwd: tempDir,
160 | }
161 | );
162 | const tempContents = support.getDirContents(tempDir);
163 | assert.equal(tempContents.length, 1);
164 | const componentContents = support.getDirContents(
165 | `${tempDir}/${fileNames.component.pascalName}`
166 | );
167 | assert.equal(componentContents.length, 3);
168 | });
169 | it("should create correct name of files/folders", () => {
170 | const nodeProcess = spawnSync(
171 | "node",
172 | [
173 | rg,
174 | "c",
175 | "rfcp",
176 | fileNames.component.name,
177 | "--test",
178 | "--testExt",
179 | "test-tsx",
180 | ],
181 | {
182 | cwd: tempDir,
183 | }
184 | );
185 | const tempContents = support.getDirContents(tempDir);
186 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
187 | const componentContents = support.getDirContents(
188 | `${tempDir}/${fileNames.component.pascalName}`
189 | );
190 | expect(componentContents).to.deep.equalInAnyOrder([
191 | fileNames.component.js,
192 | fileNames.css.normal,
193 | fileNames.test.tsx,
194 | ]);
195 | });
196 | });
197 | // ========================================
198 | describe(`rg c rfcp ${fileNames.component.name} --test --testExt spec-js`, () => {
199 | afterEach(() => {
200 | support.removeFolder(tempDir, fileNames.component.pascalName);
201 | });
202 | it("should create correct number of files/folders", () => {
203 | const nodeProcess = spawnSync(
204 | "node",
205 | [
206 | rg,
207 | "c",
208 | "rfcp",
209 | fileNames.component.name,
210 | "--test",
211 | "--testExt",
212 | "spec-js",
213 | ],
214 | {
215 | cwd: tempDir,
216 | }
217 | );
218 | const tempContents = support.getDirContents(tempDir);
219 | assert.equal(tempContents.length, 1);
220 | const componentContents = support.getDirContents(
221 | `${tempDir}/${fileNames.component.pascalName}`
222 | );
223 | assert.equal(componentContents.length, 3);
224 | });
225 | it("should create correct name of files/folders", () => {
226 | const nodeProcess = spawnSync(
227 | "node",
228 | [
229 | rg,
230 | "c",
231 | "rfcp",
232 | fileNames.component.name,
233 | "--test",
234 | "--testExt",
235 | "spec-js",
236 | ],
237 | {
238 | cwd: tempDir,
239 | }
240 | );
241 | const tempContents = support.getDirContents(tempDir);
242 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
243 | const componentContents = support.getDirContents(
244 | `${tempDir}/${fileNames.component.pascalName}`
245 | );
246 | expect(componentContents).to.deep.equalInAnyOrder([
247 | fileNames.component.js,
248 | fileNames.css.normal,
249 | fileNames.test.specJs,
250 | ]);
251 | });
252 | });
253 | // ========================================
254 | describe(`rg c rfcp ${fileNames.component.name} --test --testExt spec-tsx`, () => {
255 | afterEach(() => {
256 | support.removeFolder(tempDir, fileNames.component.pascalName);
257 | });
258 | it("should create correct number of files/folders", () => {
259 | const nodeProcess = spawnSync(
260 | "node",
261 | [
262 | rg,
263 | "c",
264 | "rfcp",
265 | fileNames.component.name,
266 | "--test",
267 | "--testExt",
268 | "spec-tsx",
269 | ],
270 | {
271 | cwd: tempDir,
272 | }
273 | );
274 | const tempContents = support.getDirContents(tempDir);
275 | assert.equal(tempContents.length, 1);
276 | const componentContents = support.getDirContents(
277 | `${tempDir}/${fileNames.component.pascalName}`
278 | );
279 | assert.equal(componentContents.length, 3);
280 | });
281 | it("should create correct name of files/folders", () => {
282 | const nodeProcess = spawnSync(
283 | "node",
284 | [
285 | rg,
286 | "c",
287 | "rfcp",
288 | fileNames.component.name,
289 | "--test",
290 | "--testExt",
291 | "spec-tsx",
292 | ],
293 | {
294 | cwd: tempDir,
295 | }
296 | );
297 | const tempContents = support.getDirContents(tempDir);
298 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
299 | const componentContents = support.getDirContents(
300 | `${tempDir}/${fileNames.component.pascalName}`
301 | );
302 | expect(componentContents).to.deep.equalInAnyOrder([
303 | fileNames.component.js,
304 | fileNames.css.normal,
305 | fileNames.test.specTsx,
306 | ]);
307 | });
308 | });
309 | // ========================================
310 | describe(`rg c rfcp ${fileNames.component.name} --ext jsx`, () => {
311 | afterEach(() => {
312 | support.removeFolder(tempDir, fileNames.component.pascalName);
313 | });
314 | it("should create correct number of files/folders", () => {
315 | const nodeProcess = spawnSync(
316 | "node",
317 | [rg, "c", "rfcp", fileNames.component.name, "--ext", "jsx"],
318 | {
319 | cwd: tempDir,
320 | }
321 | );
322 | const tempContents = support.getDirContents(tempDir);
323 | assert.equal(tempContents.length, 1);
324 | const componentContents = support.getDirContents(
325 | `${tempDir}/${fileNames.component.pascalName}`
326 | );
327 | assert.equal(componentContents.length, 2);
328 | });
329 | it("should create correct name of files/folders", () => {
330 | const nodeProcess = spawnSync(
331 | "node",
332 | [rg, "c", "rfcp", fileNames.component.name, "--ext", "jsx"],
333 | {
334 | cwd: tempDir,
335 | }
336 | );
337 | const tempContents = support.getDirContents(tempDir);
338 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
339 | const componentContents = support.getDirContents(
340 | `${tempDir}/${fileNames.component.pascalName}`
341 | );
342 | expect(componentContents).to.deep.equalInAnyOrder([
343 | fileNames.component.jsx,
344 | fileNames.css.normal,
345 | ]);
346 | });
347 | });
348 | // ========================================
349 | describe(`rg c rfcp ${fileNames.component.name} --ext tsx`, () => {
350 | afterEach(() => {
351 | support.removeFolder(tempDir, fileNames.component.pascalName);
352 | });
353 | it("should create correct number of files/folders", () => {
354 | const nodeProcess = spawnSync(
355 | "node",
356 | [rg, "c", "rfcp", fileNames.component.name, "--ext", "tsx"],
357 | {
358 | cwd: tempDir,
359 | }
360 | );
361 | const tempContents = support.getDirContents(tempDir);
362 | assert.equal(tempContents.length, 1);
363 | const componentContents = support.getDirContents(
364 | `${tempDir}/${fileNames.component.pascalName}`
365 | );
366 | assert.equal(componentContents.length, 2);
367 | });
368 | it("should create correct name of files/folders", () => {
369 | const nodeProcess = spawnSync(
370 | "node",
371 | [rg, "c", "rfcp", fileNames.component.name, "--ext", "tsx"],
372 | {
373 | cwd: tempDir,
374 | }
375 | );
376 | const tempContents = support.getDirContents(tempDir);
377 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
378 | const componentContents = support.getDirContents(
379 | `${tempDir}/${fileNames.component.pascalName}`
380 | );
381 | expect(componentContents).to.deep.equalInAnyOrder([
382 | fileNames.component.tsx,
383 | fileNames.css.normal,
384 | ]);
385 | });
386 | });
387 | after("remove temp folder", () => {
388 | support.removeFolder("test", "rfcp");
389 | });
390 | });
391 |
--------------------------------------------------------------------------------
/test/tests/rfcredux.js:
--------------------------------------------------------------------------------
1 | const support = require("../support/utils");
2 | const utils = require("../../lib/utils");
3 | const rg = "../../bin/react-generator.js";
4 | const { spawnSync } = require("child_process");
5 | const chai = require("chai");
6 | const { assert, expect } = chai;
7 | const should = chai.should();
8 | const { fileNames } = require("../support/constants");
9 |
10 | // Chai plugins
11 | const deepEqualInAnyOrder = require("deep-equal-in-any-order");
12 |
13 | chai.use(deepEqualInAnyOrder);
14 |
15 | const tempDir = "test/rfcredux";
16 |
17 | describe("component command", () => {
18 | before("create temp folder", () => {
19 | utils.createFolder("test", "rfcredux");
20 | });
21 | // ========================================
22 | // ========================================
23 | describe(`rg c rfcredux ${fileNames.component.name}`, () => {
24 | afterEach(() => {
25 | support.removeFolder(tempDir, fileNames.component.pascalName);
26 | });
27 | // ======================================
28 | it("should create correct number of files/folders", () => {
29 | const nodeProcess = spawnSync(
30 | "node",
31 | [rg, "c", "rfcredux", fileNames.component.name],
32 | {
33 | cwd: tempDir,
34 | }
35 | );
36 | const tempContents = support.getDirContents(tempDir);
37 | assert.equal(tempContents.length, 1);
38 | const componentContents = support.getDirContents(
39 | `${tempDir}/${fileNames.component.pascalName}`
40 | );
41 | assert.equal(componentContents.length, 2);
42 | });
43 | it("should create correct name of files/folders", () => {
44 | const nodeProcess = spawnSync(
45 | "node",
46 | [rg, "c", "rfcredux", fileNames.component.name],
47 | {
48 | cwd: tempDir,
49 | }
50 | );
51 | const tempContents = support.getDirContents(tempDir);
52 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
53 | const componentContents = support.getDirContents(
54 | `${tempDir}/${fileNames.component.pascalName}`
55 | );
56 | expect(componentContents).to.deep.equalInAnyOrder([
57 | fileNames.component.js,
58 | fileNames.css.normal,
59 | ]);
60 | });
61 | });
62 | // ========================================
63 | describe(`rg c rfcredux ${fileNames.component.name} --cssType modular`, () => {
64 | afterEach(() => {
65 | support.removeFolder(tempDir, fileNames.component.pascalName);
66 | });
67 | it("should create correct number of files/folders", () => {
68 | const nodeProcess = spawnSync(
69 | "node",
70 | [rg, "c", "rfcredux", fileNames.component.name, "--cssType", "modular"],
71 | {
72 | cwd: tempDir,
73 | }
74 | );
75 | const tempContents = support.getDirContents(tempDir);
76 | assert.equal(tempContents.length, 1);
77 | const componentContents = support.getDirContents(
78 | `${tempDir}/${fileNames.component.pascalName}`
79 | );
80 | assert.equal(componentContents.length, 2);
81 | });
82 | it("should create correct name of files/folders", () => {
83 | const nodeProcess = spawnSync(
84 | "node",
85 | [rg, "c", "rfcredux", fileNames.component.name, "--cssType", "modular"],
86 | {
87 | cwd: tempDir,
88 | }
89 | );
90 | const tempContents = support.getDirContents(tempDir);
91 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
92 | const componentContents = support.getDirContents(
93 | `${tempDir}/${fileNames.component.pascalName}`
94 | );
95 | expect(componentContents).to.deep.equalInAnyOrder([
96 | fileNames.component.js,
97 | fileNames.css.modular,
98 | ]);
99 | });
100 | });
101 | // ========================================
102 | describe(`rg c rfcredux ${fileNames.component.name} --test`, () => {
103 | afterEach(() => {
104 | support.removeFolder(tempDir, fileNames.component.pascalName);
105 | });
106 | it("should create correct number of files/folders", () => {
107 | const nodeProcess = spawnSync(
108 | "node",
109 | [rg, "c", "rfcredux", fileNames.component.name, "--test"],
110 | {
111 | cwd: tempDir,
112 | }
113 | );
114 | const tempContents = support.getDirContents(tempDir);
115 | assert.equal(tempContents.length, 1);
116 | const componentContents = support.getDirContents(
117 | `${tempDir}/${fileNames.component.pascalName}`
118 | );
119 | assert.equal(componentContents.length, 3);
120 | });
121 | it("should create correct name of files/folders", () => {
122 | const nodeProcess = spawnSync(
123 | "node",
124 | [rg, "c", "rfcredux", fileNames.component.name, "--test"],
125 | {
126 | cwd: tempDir,
127 | }
128 | );
129 | const tempContents = support.getDirContents(tempDir);
130 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
131 | const componentContents = support.getDirContents(
132 | `${tempDir}/${fileNames.component.pascalName}`
133 | );
134 | expect(componentContents).to.deep.equalInAnyOrder([
135 | fileNames.component.js,
136 | fileNames.css.normal,
137 | fileNames.test.js,
138 | ]);
139 | });
140 | });
141 | // ========================================
142 | describe(`rg c rfcredux ${fileNames.component.name} --test --testExt test-tsx`, () => {
143 | afterEach(() => {
144 | support.removeFolder(tempDir, fileNames.component.pascalName);
145 | });
146 | it("should create correct number of files/folders", () => {
147 | const nodeProcess = spawnSync(
148 | "node",
149 | [
150 | rg,
151 | "c",
152 | "rfcredux",
153 | fileNames.component.name,
154 | "--test",
155 | "--testExt",
156 | "test-tsx",
157 | ],
158 | {
159 | cwd: tempDir,
160 | }
161 | );
162 | const tempContents = support.getDirContents(tempDir);
163 | assert.equal(tempContents.length, 1);
164 | const componentContents = support.getDirContents(
165 | `${tempDir}/${fileNames.component.pascalName}`
166 | );
167 | assert.equal(componentContents.length, 3);
168 | });
169 | it("should create correct name of files/folders", () => {
170 | const nodeProcess = spawnSync(
171 | "node",
172 | [
173 | rg,
174 | "c",
175 | "rfcredux",
176 | fileNames.component.name,
177 | "--test",
178 | "--testExt",
179 | "test-tsx",
180 | ],
181 | {
182 | cwd: tempDir,
183 | }
184 | );
185 | const tempContents = support.getDirContents(tempDir);
186 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
187 | const componentContents = support.getDirContents(
188 | `${tempDir}/${fileNames.component.pascalName}`
189 | );
190 | expect(componentContents).to.deep.equalInAnyOrder([
191 | fileNames.component.js,
192 | fileNames.css.normal,
193 | fileNames.test.tsx,
194 | ]);
195 | });
196 | });
197 | // ========================================
198 | describe(`rg c rfcredux ${fileNames.component.name} --test --testExt spec-js`, () => {
199 | afterEach(() => {
200 | support.removeFolder(tempDir, fileNames.component.pascalName);
201 | });
202 | it("should create correct number of files/folders", () => {
203 | const nodeProcess = spawnSync(
204 | "node",
205 | [
206 | rg,
207 | "c",
208 | "rfcredux",
209 | fileNames.component.name,
210 | "--test",
211 | "--testExt",
212 | "spec-js",
213 | ],
214 | {
215 | cwd: tempDir,
216 | }
217 | );
218 | const tempContents = support.getDirContents(tempDir);
219 | assert.equal(tempContents.length, 1);
220 | const componentContents = support.getDirContents(
221 | `${tempDir}/${fileNames.component.pascalName}`
222 | );
223 | assert.equal(componentContents.length, 3);
224 | });
225 | it("should create correct name of files/folders", () => {
226 | const nodeProcess = spawnSync(
227 | "node",
228 | [
229 | rg,
230 | "c",
231 | "rfcredux",
232 | fileNames.component.name,
233 | "--test",
234 | "--testExt",
235 | "spec-js",
236 | ],
237 | {
238 | cwd: tempDir,
239 | }
240 | );
241 | const tempContents = support.getDirContents(tempDir);
242 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
243 | const componentContents = support.getDirContents(
244 | `${tempDir}/${fileNames.component.pascalName}`
245 | );
246 | expect(componentContents).to.deep.equalInAnyOrder([
247 | fileNames.component.js,
248 | fileNames.css.normal,
249 | fileNames.test.specJs,
250 | ]);
251 | });
252 | });
253 | // ========================================
254 | describe(`rg c rfcredux ${fileNames.component.name} --test --testExt spec-tsx`, () => {
255 | afterEach(() => {
256 | support.removeFolder(tempDir, fileNames.component.pascalName);
257 | });
258 | it("should create correct number of files/folders", () => {
259 | const nodeProcess = spawnSync(
260 | "node",
261 | [
262 | rg,
263 | "c",
264 | "rfcredux",
265 | fileNames.component.name,
266 | "--test",
267 | "--testExt",
268 | "spec-tsx",
269 | ],
270 | {
271 | cwd: tempDir,
272 | }
273 | );
274 | const tempContents = support.getDirContents(tempDir);
275 | assert.equal(tempContents.length, 1);
276 | const componentContents = support.getDirContents(
277 | `${tempDir}/${fileNames.component.pascalName}`
278 | );
279 | assert.equal(componentContents.length, 3);
280 | });
281 | it("should create correct name of files/folders", () => {
282 | const nodeProcess = spawnSync(
283 | "node",
284 | [
285 | rg,
286 | "c",
287 | "rfcredux",
288 | fileNames.component.name,
289 | "--test",
290 | "--testExt",
291 | "spec-tsx",
292 | ],
293 | {
294 | cwd: tempDir,
295 | }
296 | );
297 | const tempContents = support.getDirContents(tempDir);
298 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
299 | const componentContents = support.getDirContents(
300 | `${tempDir}/${fileNames.component.pascalName}`
301 | );
302 | expect(componentContents).to.deep.equalInAnyOrder([
303 | fileNames.component.js,
304 | fileNames.css.normal,
305 | fileNames.test.specTsx,
306 | ]);
307 | });
308 | });
309 | // ========================================
310 | describe(`rg c rfcredux ${fileNames.component.name} --ext jsx`, () => {
311 | afterEach(() => {
312 | support.removeFolder(tempDir, fileNames.component.pascalName);
313 | });
314 | it("should create correct number of files/folders", () => {
315 | const nodeProcess = spawnSync(
316 | "node",
317 | [rg, "c", "rfcredux", fileNames.component.name, "--ext", "jsx"],
318 | {
319 | cwd: tempDir,
320 | }
321 | );
322 | const tempContents = support.getDirContents(tempDir);
323 | assert.equal(tempContents.length, 1);
324 | const componentContents = support.getDirContents(
325 | `${tempDir}/${fileNames.component.pascalName}`
326 | );
327 | assert.equal(componentContents.length, 2);
328 | });
329 | it("should create correct name of files/folders", () => {
330 | const nodeProcess = spawnSync(
331 | "node",
332 | [rg, "c", "rfcredux", fileNames.component.name, "--ext", "jsx"],
333 | {
334 | cwd: tempDir,
335 | }
336 | );
337 | const tempContents = support.getDirContents(tempDir);
338 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
339 | const componentContents = support.getDirContents(
340 | `${tempDir}/${fileNames.component.pascalName}`
341 | );
342 | expect(componentContents).to.deep.equalInAnyOrder([
343 | fileNames.component.jsx,
344 | fileNames.css.normal,
345 | ]);
346 | });
347 | });
348 | // ========================================
349 | describe(`rg c rfcredux ${fileNames.component.name} --ext tsx`, () => {
350 | afterEach(() => {
351 | support.removeFolder(tempDir, fileNames.component.pascalName);
352 | });
353 | it("should create correct number of files/folders", () => {
354 | const nodeProcess = spawnSync(
355 | "node",
356 | [rg, "c", "rfcredux", fileNames.component.name, "--ext", "tsx"],
357 | {
358 | cwd: tempDir,
359 | }
360 | );
361 | const tempContents = support.getDirContents(tempDir);
362 | assert.equal(tempContents.length, 1);
363 | const componentContents = support.getDirContents(
364 | `${tempDir}/${fileNames.component.pascalName}`
365 | );
366 | assert.equal(componentContents.length, 2);
367 | });
368 | it("should create correct name of files/folders", () => {
369 | const nodeProcess = spawnSync(
370 | "node",
371 | [rg, "c", "rfcredux", fileNames.component.name, "--ext", "tsx"],
372 | {
373 | cwd: tempDir,
374 | }
375 | );
376 | const tempContents = support.getDirContents(tempDir);
377 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
378 | const componentContents = support.getDirContents(
379 | `${tempDir}/${fileNames.component.pascalName}`
380 | );
381 | expect(componentContents).to.deep.equalInAnyOrder([
382 | fileNames.component.tsx,
383 | fileNames.css.normal,
384 | ]);
385 | });
386 | });
387 | after("remove temp folder", () => {
388 | support.removeFolder("test", "rfcredux");
389 | });
390 | });
391 |
--------------------------------------------------------------------------------
/test/tests/rfcreduxp.js:
--------------------------------------------------------------------------------
1 | const support = require("../support/utils");
2 | const utils = require("../../lib/utils");
3 | const rg = "../../bin/react-generator.js";
4 | const { spawnSync } = require("child_process");
5 | const chai = require("chai");
6 | const { assert, expect } = chai;
7 | const should = chai.should();
8 | const { fileNames } = require("../support/constants");
9 |
10 | // Chai plugins
11 | const deepEqualInAnyOrder = require("deep-equal-in-any-order");
12 |
13 | chai.use(deepEqualInAnyOrder);
14 |
15 | const tempDir = "test/rfcreduxp";
16 |
17 | describe("component command", () => {
18 | before("create temp folder", () => {
19 | utils.createFolder("test", "rfcreduxp");
20 | });
21 | // ========================================
22 | // ========================================
23 | describe(`rg c rfcreduxp ${fileNames.component.name}`, () => {
24 | afterEach(() => {
25 | support.removeFolder(tempDir, fileNames.component.pascalName);
26 | });
27 | // ======================================
28 | it("should create correct number of files/folders", () => {
29 | const nodeProcess = spawnSync(
30 | "node",
31 | [rg, "c", "rfcreduxp", fileNames.component.name],
32 | {
33 | cwd: tempDir,
34 | }
35 | );
36 | const tempContents = support.getDirContents(tempDir);
37 | assert.equal(tempContents.length, 1);
38 | const componentContents = support.getDirContents(
39 | `${tempDir}/${fileNames.component.pascalName}`
40 | );
41 | assert.equal(componentContents.length, 2);
42 | });
43 | it("should create correct name of files/folders", () => {
44 | const nodeProcess = spawnSync(
45 | "node",
46 | [rg, "c", "rfcreduxp", fileNames.component.name],
47 | {
48 | cwd: tempDir,
49 | }
50 | );
51 | const tempContents = support.getDirContents(tempDir);
52 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
53 | const componentContents = support.getDirContents(
54 | `${tempDir}/${fileNames.component.pascalName}`
55 | );
56 | expect(componentContents).to.deep.equalInAnyOrder([
57 | fileNames.component.js,
58 | fileNames.css.normal,
59 | ]);
60 | });
61 | });
62 | // ========================================
63 | describe(`rg c rfcreduxp ${fileNames.component.name} --cssType modular`, () => {
64 | afterEach(() => {
65 | support.removeFolder(tempDir, fileNames.component.pascalName);
66 | });
67 | it("should create correct number of files/folders", () => {
68 | const nodeProcess = spawnSync(
69 | "node",
70 | [
71 | rg,
72 | "c",
73 | "rfcreduxp",
74 | fileNames.component.name,
75 | "--cssType",
76 | "modular",
77 | ],
78 | {
79 | cwd: tempDir,
80 | }
81 | );
82 | const tempContents = support.getDirContents(tempDir);
83 | assert.equal(tempContents.length, 1);
84 | const componentContents = support.getDirContents(
85 | `${tempDir}/${fileNames.component.pascalName}`
86 | );
87 | assert.equal(componentContents.length, 2);
88 | });
89 | it("should create correct name of files/folders", () => {
90 | const nodeProcess = spawnSync(
91 | "node",
92 | [
93 | rg,
94 | "c",
95 | "rfcreduxp",
96 | fileNames.component.name,
97 | "--cssType",
98 | "modular",
99 | ],
100 | {
101 | cwd: tempDir,
102 | }
103 | );
104 | const tempContents = support.getDirContents(tempDir);
105 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
106 | const componentContents = support.getDirContents(
107 | `${tempDir}/${fileNames.component.pascalName}`
108 | );
109 | expect(componentContents).to.deep.equalInAnyOrder([
110 | fileNames.component.js,
111 | fileNames.css.modular,
112 | ]);
113 | });
114 | });
115 | // ========================================
116 | describe(`rg c rfcreduxp ${fileNames.component.name} --test`, () => {
117 | afterEach(() => {
118 | support.removeFolder(tempDir, fileNames.component.pascalName);
119 | });
120 | it("should create correct number of files/folders", () => {
121 | const nodeProcess = spawnSync(
122 | "node",
123 | [rg, "c", "rfcreduxp", fileNames.component.name, "--test"],
124 | {
125 | cwd: tempDir,
126 | }
127 | );
128 | const tempContents = support.getDirContents(tempDir);
129 | assert.equal(tempContents.length, 1);
130 | const componentContents = support.getDirContents(
131 | `${tempDir}/${fileNames.component.pascalName}`
132 | );
133 | assert.equal(componentContents.length, 3);
134 | });
135 | it("should create correct name of files/folders", () => {
136 | const nodeProcess = spawnSync(
137 | "node",
138 | [rg, "c", "rfcreduxp", fileNames.component.name, "--test"],
139 | {
140 | cwd: tempDir,
141 | }
142 | );
143 | const tempContents = support.getDirContents(tempDir);
144 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
145 | const componentContents = support.getDirContents(
146 | `${tempDir}/${fileNames.component.pascalName}`
147 | );
148 | expect(componentContents).to.deep.equalInAnyOrder([
149 | fileNames.component.js,
150 | fileNames.css.normal,
151 | fileNames.test.js,
152 | ]);
153 | });
154 | });
155 | // ========================================
156 | describe(`rg c rfcreduxp ${fileNames.component.name} --test --testExt test-tsx`, () => {
157 | afterEach(() => {
158 | support.removeFolder(tempDir, fileNames.component.pascalName);
159 | });
160 | it("should create correct number of files/folders", () => {
161 | const nodeProcess = spawnSync(
162 | "node",
163 | [
164 | rg,
165 | "c",
166 | "rfcreduxp",
167 | fileNames.component.name,
168 | "--test",
169 | "--testExt",
170 | "test-tsx",
171 | ],
172 | {
173 | cwd: tempDir,
174 | }
175 | );
176 | const tempContents = support.getDirContents(tempDir);
177 | assert.equal(tempContents.length, 1);
178 | const componentContents = support.getDirContents(
179 | `${tempDir}/${fileNames.component.pascalName}`
180 | );
181 | assert.equal(componentContents.length, 3);
182 | });
183 | it("should create correct name of files/folders", () => {
184 | const nodeProcess = spawnSync(
185 | "node",
186 | [
187 | rg,
188 | "c",
189 | "rfcreduxp",
190 | fileNames.component.name,
191 | "--test",
192 | "--testExt",
193 | "test-tsx",
194 | ],
195 | {
196 | cwd: tempDir,
197 | }
198 | );
199 | const tempContents = support.getDirContents(tempDir);
200 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
201 | const componentContents = support.getDirContents(
202 | `${tempDir}/${fileNames.component.pascalName}`
203 | );
204 | expect(componentContents).to.deep.equalInAnyOrder([
205 | fileNames.component.js,
206 | fileNames.css.normal,
207 | fileNames.test.tsx,
208 | ]);
209 | });
210 | });
211 | // ========================================
212 | describe(`rg c rfcreduxp ${fileNames.component.name} --test --testExt spec-js`, () => {
213 | afterEach(() => {
214 | support.removeFolder(tempDir, fileNames.component.pascalName);
215 | });
216 | it("should create correct number of files/folders", () => {
217 | const nodeProcess = spawnSync(
218 | "node",
219 | [
220 | rg,
221 | "c",
222 | "rfcreduxp",
223 | fileNames.component.name,
224 | "--test",
225 | "--testExt",
226 | "spec-js",
227 | ],
228 | {
229 | cwd: tempDir,
230 | }
231 | );
232 | const tempContents = support.getDirContents(tempDir);
233 | assert.equal(tempContents.length, 1);
234 | const componentContents = support.getDirContents(
235 | `${tempDir}/${fileNames.component.pascalName}`
236 | );
237 | assert.equal(componentContents.length, 3);
238 | });
239 | it("should create correct name of files/folders", () => {
240 | const nodeProcess = spawnSync(
241 | "node",
242 | [
243 | rg,
244 | "c",
245 | "rfcreduxp",
246 | fileNames.component.name,
247 | "--test",
248 | "--testExt",
249 | "spec-js",
250 | ],
251 | {
252 | cwd: tempDir,
253 | }
254 | );
255 | const tempContents = support.getDirContents(tempDir);
256 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
257 | const componentContents = support.getDirContents(
258 | `${tempDir}/${fileNames.component.pascalName}`
259 | );
260 | expect(componentContents).to.deep.equalInAnyOrder([
261 | fileNames.component.js,
262 | fileNames.css.normal,
263 | fileNames.test.specJs,
264 | ]);
265 | });
266 | });
267 | // ========================================
268 | describe(`rg c rfcreduxp ${fileNames.component.name} --test --testExt spec-tsx`, () => {
269 | afterEach(() => {
270 | support.removeFolder(tempDir, fileNames.component.pascalName);
271 | });
272 | it("should create correct number of files/folders", () => {
273 | const nodeProcess = spawnSync(
274 | "node",
275 | [
276 | rg,
277 | "c",
278 | "rfcreduxp",
279 | fileNames.component.name,
280 | "--test",
281 | "--testExt",
282 | "spec-tsx",
283 | ],
284 | {
285 | cwd: tempDir,
286 | }
287 | );
288 | const tempContents = support.getDirContents(tempDir);
289 | assert.equal(tempContents.length, 1);
290 | const componentContents = support.getDirContents(
291 | `${tempDir}/${fileNames.component.pascalName}`
292 | );
293 | assert.equal(componentContents.length, 3);
294 | });
295 | it("should create correct name of files/folders", () => {
296 | const nodeProcess = spawnSync(
297 | "node",
298 | [
299 | rg,
300 | "c",
301 | "rfcreduxp",
302 | fileNames.component.name,
303 | "--test",
304 | "--testExt",
305 | "spec-tsx",
306 | ],
307 | {
308 | cwd: tempDir,
309 | }
310 | );
311 | const tempContents = support.getDirContents(tempDir);
312 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
313 | const componentContents = support.getDirContents(
314 | `${tempDir}/${fileNames.component.pascalName}`
315 | );
316 | expect(componentContents).to.deep.equalInAnyOrder([
317 | fileNames.component.js,
318 | fileNames.css.normal,
319 | fileNames.test.specTsx,
320 | ]);
321 | });
322 | });
323 | // ========================================
324 | describe(`rg c rfcreduxp ${fileNames.component.name} --ext jsx`, () => {
325 | afterEach(() => {
326 | support.removeFolder(tempDir, fileNames.component.pascalName);
327 | });
328 | it("should create correct number of files/folders", () => {
329 | const nodeProcess = spawnSync(
330 | "node",
331 | [rg, "c", "rfcreduxp", fileNames.component.name, "--ext", "jsx"],
332 | {
333 | cwd: tempDir,
334 | }
335 | );
336 | const tempContents = support.getDirContents(tempDir);
337 | assert.equal(tempContents.length, 1);
338 | const componentContents = support.getDirContents(
339 | `${tempDir}/${fileNames.component.pascalName}`
340 | );
341 | assert.equal(componentContents.length, 2);
342 | });
343 | it("should create correct name of files/folders", () => {
344 | const nodeProcess = spawnSync(
345 | "node",
346 | [rg, "c", "rfcreduxp", fileNames.component.name, "--ext", "jsx"],
347 | {
348 | cwd: tempDir,
349 | }
350 | );
351 | const tempContents = support.getDirContents(tempDir);
352 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
353 | const componentContents = support.getDirContents(
354 | `${tempDir}/${fileNames.component.pascalName}`
355 | );
356 | expect(componentContents).to.deep.equalInAnyOrder([
357 | fileNames.component.jsx,
358 | fileNames.css.normal,
359 | ]);
360 | });
361 | });
362 | // ========================================
363 | describe(`rg c rfcreduxp ${fileNames.component.name} --ext tsx`, () => {
364 | afterEach(() => {
365 | support.removeFolder(tempDir, fileNames.component.pascalName);
366 | });
367 | it("should create correct number of files/folders", () => {
368 | const nodeProcess = spawnSync(
369 | "node",
370 | [rg, "c", "rfcreduxp", fileNames.component.name, "--ext", "tsx"],
371 | {
372 | cwd: tempDir,
373 | }
374 | );
375 | const tempContents = support.getDirContents(tempDir);
376 | assert.equal(tempContents.length, 1);
377 | const componentContents = support.getDirContents(
378 | `${tempDir}/${fileNames.component.pascalName}`
379 | );
380 | assert.equal(componentContents.length, 2);
381 | });
382 | it("should create correct name of files/folders", () => {
383 | const nodeProcess = spawnSync(
384 | "node",
385 | [rg, "c", "rfcreduxp", fileNames.component.name, "--ext", "tsx"],
386 | {
387 | cwd: tempDir,
388 | }
389 | );
390 | const tempContents = support.getDirContents(tempDir);
391 | assert.deepEqual(tempContents, [fileNames.component.pascalName]);
392 | const componentContents = support.getDirContents(
393 | `${tempDir}/${fileNames.component.pascalName}`
394 | );
395 | expect(componentContents).to.deep.equalInAnyOrder([
396 | fileNames.component.tsx,
397 | fileNames.css.normal,
398 | ]);
399 | });
400 | });
401 | after("remove temp folder", () => {
402 | support.removeFolder("test", "rfcreduxp");
403 | });
404 | });
405 |
--------------------------------------------------------------------------------