@pavlos-samaras/react-cli 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -34
- package/dist/bin/ct.js +4 -73
- package/dist/bin/ct.js.map +1 -1
- package/dist/commands/generate.d.ts +12 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +88 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/new.d.ts +3 -0
- package/dist/commands/new.d.ts.map +1 -0
- package/dist/commands/new.js +53 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/constants/ct.config.d.ts +9 -0
- package/dist/constants/ct.config.d.ts.map +1 -0
- package/dist/constants/ct.config.js +9 -0
- package/dist/constants/ct.config.js.map +1 -0
- package/dist/utils/console.d.ts +4 -0
- package/dist/utils/console.d.ts.map +1 -0
- package/dist/utils/console.js +5 -0
- package/dist/utils/console.js.map +1 -0
- package/dist/utils/generate/component.d.ts +11 -0
- package/dist/utils/generate/component.d.ts.map +1 -0
- package/dist/utils/generate/component.js +44 -0
- package/dist/utils/generate/component.js.map +1 -0
- package/dist/utils/generate/hook.d.ts +6 -0
- package/dist/utils/generate/hook.d.ts.map +1 -0
- package/dist/utils/generate/hook.js +12 -0
- package/dist/utils/generate/hook.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# React CLI
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A command-line tool to scaffold React projects, components, and hooks.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -8,56 +8,69 @@ A simple command-line tool for generating React components and hooks.
|
|
|
8
8
|
npm install -g @pavlos-samaras/react-cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Create a React project
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
ct
|
|
14
|
+
ct new my-app
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
This runs the Vite project creator in a new `my-app/` directory and writes a
|
|
18
|
+
`ct.config.json` file with the CLI defaults. Vite's prompts let you choose the
|
|
19
|
+
framework and template. Dependencies are not installed automatically; install
|
|
20
|
+
them before starting the project:
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
```bash
|
|
23
|
+
cd my-app
|
|
24
|
+
npm install
|
|
25
|
+
npm run dev
|
|
26
|
+
```
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
| ----------- | --------------------------------------------------------------------------------------- |
|
|
23
|
-
| `component` | A folder with the component, a CSS/SCSS module, a hook and a test file |
|
|
24
|
-
| `hook` | A single hook file. The name must start with `use` followed by a capital (e.g. `useAuth`) |
|
|
28
|
+
## Generate code
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
```bash
|
|
31
|
+
ct generate <type> <name> [options]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`g` is an alias for `generate`.
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
| ------------------------- | ------------------------------------------------------------------------ |
|
|
30
|
-
| `-d, --dir <dir>` | Target folder inside `src/` (or inside the feature). Default depends on the type: `components` or `hooks` |
|
|
31
|
-
| `-f, --feature <feature>` | Put the output under `src/features/<feature>/` |
|
|
32
|
-
| `--ts` | Use TypeScript without prompting |
|
|
33
|
-
| `-y, --yes` | Use the defaults (TypeScript, SCSS) and skip all prompts |
|
|
36
|
+
### Types
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
| Type | Name format | Generated files |
|
|
39
|
+
| --- | --- | --- |
|
|
40
|
+
| `component` | PascalCase (for example, `Button`) | A component, CSS/SCSS module, hook, and test file in a component folder |
|
|
41
|
+
| `hook` | `use` followed by PascalCase (for example, `useAuth`) | A hook file in its own folder |
|
|
37
42
|
|
|
38
|
-
###
|
|
43
|
+
### Options
|
|
39
44
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
| `
|
|
45
|
-
| `
|
|
46
|
-
| `ct g hook useAuth -f auth` | `src/features/auth/hooks/useAuth.ts` |
|
|
45
|
+
| Option | Description |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| `-f, --feature <feature>` | Generate under `src/features/<feature>/` |
|
|
48
|
+
| `-s, --style <style>` | Component stylesheet format: `css` or `scss`. If omitted, the CLI prompts you. |
|
|
49
|
+
| `--ts` | Generate TypeScript files. Otherwise, TypeScript is selected automatically when the project has a `tsconfig.json`. |
|
|
50
|
+
| `--force` | Skip the check that requires the current directory to be detected as a React project. |
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
For example:
|
|
49
53
|
|
|
50
54
|
```bash
|
|
51
|
-
#
|
|
52
|
-
ct g component Button
|
|
55
|
+
# Create a component; choose the stylesheet format when prompted
|
|
56
|
+
ct g component Button
|
|
53
57
|
|
|
54
|
-
# TypeScript component
|
|
55
|
-
ct g component LoginForm --feature auth --ts
|
|
58
|
+
# Create a TypeScript component with a SCSS module
|
|
59
|
+
ct g component LoginForm --feature auth --style scss --ts
|
|
56
60
|
|
|
57
|
-
#
|
|
58
|
-
ct g hook useSession -f auth
|
|
61
|
+
# Create a hook in a feature folder
|
|
62
|
+
ct g hook useSession -f auth
|
|
59
63
|
```
|
|
60
64
|
|
|
65
|
+
### Output locations
|
|
66
|
+
|
|
67
|
+
| Command | Output |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `ct g component Button` | `src/components/Button/` |
|
|
70
|
+
| `ct g component Button -f auth` | `src/features/auth/components/Button/` |
|
|
71
|
+
| `ct g hook useAuth` | `src/hooks/useAuth/useAuth.js` (or `.ts` when TypeScript is enabled) |
|
|
72
|
+
| `ct g hook useAuth -f auth` | `src/features/auth/hooks/useAuth/useAuth.js` (or `.ts` when TypeScript is enabled) |
|
|
73
|
+
|
|
61
74
|
## Development
|
|
62
75
|
|
|
63
76
|
Run the CLI directly from the TypeScript source:
|
|
@@ -66,7 +79,7 @@ Run the CLI directly from the TypeScript source:
|
|
|
66
79
|
npm run dev -- generate component Button
|
|
67
80
|
```
|
|
68
81
|
|
|
69
|
-
|
|
82
|
+
Build and link the local CLI globally:
|
|
70
83
|
|
|
71
84
|
```bash
|
|
72
85
|
npm install
|
package/dist/bin/ct.js
CHANGED
|
@@ -1,82 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import chalk from "chalk";
|
|
5
2
|
import { createRequire } from "module";
|
|
6
3
|
import { Command } from "commander";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { DEFAULT_DIRS, TYPES } from "../constants/generator.js";
|
|
10
|
-
import { generateHook } from "../utils/generateHook.js";
|
|
11
|
-
import { isReactProject } from "../utils/validators.js";
|
|
12
|
-
import { loadConfig } from "../utils/loadConfig.js";
|
|
4
|
+
import { registerGenerateCommand } from "../commands/generate.js";
|
|
5
|
+
import { registerNewCommand } from "../commands/new.js";
|
|
13
6
|
const require = createRequire(import.meta.url);
|
|
14
7
|
const { version } = require("../../package.json");
|
|
15
8
|
const program = new Command();
|
|
16
9
|
program.name("ct").description("My React CLI").version(version);
|
|
17
|
-
program
|
|
18
|
-
|
|
19
|
-
.alias("g")
|
|
20
|
-
.description("Generate a <type>, e.g. ct g component Button")
|
|
21
|
-
.option("-d, --dir <dir>", "target folder")
|
|
22
|
-
.option("-f, --feature <feature>", "put <type> under a feature")
|
|
23
|
-
.option("--ts", "use Typescript")
|
|
24
|
-
.option("--force", "skip safety checks and overwrite")
|
|
25
|
-
.action((type, name, options) => {
|
|
26
|
-
if (!isReactProject() && !options.force) {
|
|
27
|
-
console.log(chalk.yellow("This doesn't look like a React project (no react in package.json)."));
|
|
28
|
-
console.log(chalk.gray("Run ct from your project root, or use --force."));
|
|
29
|
-
process.exitCode = 1;
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const config = loadConfig() ?? {};
|
|
33
|
-
if (!TYPES.includes(type)) {
|
|
34
|
-
console.log(chalk.red(`Unknown type: ${type}`));
|
|
35
|
-
process.exitCode = 1;
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (type === "component") {
|
|
39
|
-
const dir = options.dir ?? config.dir?.component ?? "components";
|
|
40
|
-
const pathToComponent = options.feature
|
|
41
|
-
? `src/features/${options.feature}/${dir}`
|
|
42
|
-
: `src/${dir}`;
|
|
43
|
-
const folder = path.join(process.cwd(), pathToComponent, name);
|
|
44
|
-
if (fs.existsSync(folder) && !options.force) {
|
|
45
|
-
console.log(chalk.yellow(`${name} already exists. Use --force to overwrite it.`));
|
|
46
|
-
process.exitCode = 1;
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
applySpinner({ name, folder }, async () => {
|
|
50
|
-
fs.mkdirSync(folder, { recursive: true });
|
|
51
|
-
const { JSX, stylesheet, hook, test } = await generateComponent(folder, name, options, config);
|
|
52
|
-
fs.writeFileSync(JSX.pathToFile, JSX.content);
|
|
53
|
-
fs.writeFileSync(stylesheet.pathToFile, stylesheet.content);
|
|
54
|
-
fs.writeFileSync(hook.pathToFile, hook.content);
|
|
55
|
-
fs.writeFileSync(test.pathToFile, test.content);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
if (type === "hook") {
|
|
59
|
-
if (!/^use[A-Z]\w+$/.test(name)) {
|
|
60
|
-
console.log(chalk.red("Hook must start with 'use' followed by a capital letter"));
|
|
61
|
-
process.exitCode = 1;
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const dir = options.dir ?? config.dir?.hook ?? "hooks";
|
|
65
|
-
const pathToHook = options.feature
|
|
66
|
-
? `src/features/${options.feature}/${dir}`
|
|
67
|
-
: `src/shared/${dir}`;
|
|
68
|
-
const folder = path.join(process.cwd(), pathToHook);
|
|
69
|
-
if (fs.existsSync(folder) && !options.force) {
|
|
70
|
-
console.log(chalk.yellow(`${name} already exists. Use --force to overwrite it.`));
|
|
71
|
-
process.exitCode = 1;
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
applySpinner({ name, folder }, async () => {
|
|
75
|
-
fs.mkdirSync(folder, { recursive: true });
|
|
76
|
-
const hook = await generateHook(folder, name, options, config);
|
|
77
|
-
fs.writeFileSync(hook.pathToFile, hook.content);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
});
|
|
10
|
+
registerGenerateCommand(program);
|
|
11
|
+
registerNewCommand(program);
|
|
81
12
|
program.parse();
|
|
82
13
|
//# sourceMappingURL=ct.js.map
|
package/dist/bin/ct.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ct.js","sourceRoot":"","sources":["../../src/bin/ct.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ct.js","sourceRoot":"","sources":["../../src/bin/ct.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAwB,CAAC;AAEzE,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhE,uBAAuB,CAAC,OAAO,CAAC,CAAC;AACjC,kBAAkB,CAAC,OAAO,CAAC,CAAC;AAE5B,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
declare const STYLES: readonly ["css", "scss"];
|
|
3
|
+
export type Style = (typeof STYLES)[number];
|
|
4
|
+
export interface Options {
|
|
5
|
+
feature?: string;
|
|
6
|
+
style?: Style;
|
|
7
|
+
ts?: boolean;
|
|
8
|
+
force?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const registerGenerateCommand: (program: Command) => void;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC,QAAA,MAAM,MAAM,YAAI,KAAK,EAAE,MAAM,CAAU,CAAC;AAGxC,MAAM,MAAM,KAAK,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAC5C,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAkBD,eAAO,MAAM,uBAAuB,YAAa,OAAO,SA0EvD,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { error, info, warning } from "../utils/console.js";
|
|
5
|
+
import { generateComponent, } from "../utils/generate/component.js";
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
import { isReactProject } from "../utils/validators.js";
|
|
8
|
+
import { generateHook } from "../utils/generate/hook.js";
|
|
9
|
+
const TYPES = ["component", "hook"];
|
|
10
|
+
const STYLES = ["css", "scss"];
|
|
11
|
+
// Utilities
|
|
12
|
+
const createDir = (pathToFolder) => {
|
|
13
|
+
const folder = path.join(process.cwd(), pathToFolder);
|
|
14
|
+
if (fs.existsSync(folder))
|
|
15
|
+
return;
|
|
16
|
+
fs.mkdirSync(folder, { recursive: true });
|
|
17
|
+
return folder;
|
|
18
|
+
};
|
|
19
|
+
const createComponentFiles = (component) => {
|
|
20
|
+
const { JSX, stylesheet, hook, test } = component;
|
|
21
|
+
fs.writeFileSync(JSX.path, JSX.content);
|
|
22
|
+
fs.writeFileSync(stylesheet.path, stylesheet.content);
|
|
23
|
+
fs.writeFileSync(hook.path, hook.content);
|
|
24
|
+
fs.writeFileSync(test.path, test.content);
|
|
25
|
+
};
|
|
26
|
+
export const registerGenerateCommand = (program) => {
|
|
27
|
+
program
|
|
28
|
+
.command("generate <type> <name>")
|
|
29
|
+
.alias("g")
|
|
30
|
+
.description("generate the given <type> content")
|
|
31
|
+
.option("-f, --feature <feature>", "generate the given <type> inside a feature", (value) => value.replace(/=/, ""))
|
|
32
|
+
.option("-s, --style <style>", "use the specified stylesheet style", (value) => value.replace(/=/, ""))
|
|
33
|
+
.option("--ts", "Use typescript")
|
|
34
|
+
.option("--force", "skip safety checks and overwrite")
|
|
35
|
+
.action(async (type, name, options) => {
|
|
36
|
+
if (!isReactProject() && !options.force) {
|
|
37
|
+
error("This is not a React project\ncreate one or use 'ct new <name>'");
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (!TYPES.includes(type)) {
|
|
42
|
+
error(`Invalid type: ${type}`);
|
|
43
|
+
process.exitCode = 1;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (options.style && !STYLES.includes(options.style)) {
|
|
47
|
+
error(`Invalid style: ${options.style}`);
|
|
48
|
+
process.exitCode = 1;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const rootDir = options.feature
|
|
52
|
+
? `src/features/${options.feature}`
|
|
53
|
+
: "src";
|
|
54
|
+
if (type === "component") {
|
|
55
|
+
if (!/^[A-Z][a-zA-Z]*$/.test(name)) {
|
|
56
|
+
warning(`Invalid component name ${name}`);
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const folder = createDir(`${rootDir}/components/${name}`);
|
|
61
|
+
if (!folder) {
|
|
62
|
+
warning(`Folder ${name} already exists!`);
|
|
63
|
+
process.exitCode = 1;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const component = await generateComponent(folder, name, options);
|
|
67
|
+
createComponentFiles(component);
|
|
68
|
+
info(`${name} created at ${chalk.gray(folder)}`);
|
|
69
|
+
}
|
|
70
|
+
if (type === "hook") {
|
|
71
|
+
if (!/^use[A-Z][a-zA-Z]*$/.test(name)) {
|
|
72
|
+
warning(`Invalid hook name ${name}`);
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const folder = createDir(`${rootDir}/hooks/${name}`);
|
|
77
|
+
if (!folder) {
|
|
78
|
+
warning(`Folder ${name} already exists!`);
|
|
79
|
+
process.exitCode = 1;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const hook = await generateHook(folder, name, options);
|
|
83
|
+
fs.writeFileSync(hook.path, hook.content);
|
|
84
|
+
info(`${name} created at ${chalk.gray(folder)}`);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EACL,iBAAiB,GAElB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC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YAC1C,IAAI,CAAC,GAAG,IAAI,eAAe,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new.d.ts","sourceRoot":"","sources":["../../src/commands/new.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,eAAO,MAAM,kBAAkB,YAAa,OAAO,SAiElD,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { spawnSync } from "child_process";
|
|
5
|
+
import { DEFAULT_CONFIG } from "../constants/ct.config.js";
|
|
6
|
+
export const registerNewCommand = (program) => {
|
|
7
|
+
program
|
|
8
|
+
.command("new <name>")
|
|
9
|
+
.description("Create a new React project with Vite")
|
|
10
|
+
.action((name) => {
|
|
11
|
+
if (!/^[a-z0-9][a-z0-9-_]*$/i.test(name)) {
|
|
12
|
+
console.log(chalk.red(`Invalid name ${name}`));
|
|
13
|
+
process.exitCode = 1;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const target = path.join(process.cwd(), name);
|
|
17
|
+
if (fs.existsSync(target)) {
|
|
18
|
+
console.log(chalk.yellow(`Folder ${name} already exists!`));
|
|
19
|
+
process.exitCode = 1;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const result = spawnSync(`npm create vite@latest ${name} -- --no-install`, {
|
|
23
|
+
stdio: "inherit",
|
|
24
|
+
shell: true,
|
|
25
|
+
});
|
|
26
|
+
const vitePassed = result.status === 0;
|
|
27
|
+
if (!vitePassed && !fs.existsSync(target)) {
|
|
28
|
+
console.log(chalk.red("Vite failed before creating the project."));
|
|
29
|
+
process.exitCode = 1;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
fs.writeFileSync(path.join(target, "ct.config.json"), JSON.stringify(DEFAULT_CONFIG, null, 2));
|
|
33
|
+
if (!vitePassed) {
|
|
34
|
+
console.log(chalk.yellow("Install failed (dependency conflict). Retrying with --legacy-peer-deps..."));
|
|
35
|
+
const retry = spawnSync("npm install --legacy-peer-deps", {
|
|
36
|
+
cwd: target,
|
|
37
|
+
stdio: "inherit",
|
|
38
|
+
shell: true,
|
|
39
|
+
});
|
|
40
|
+
if (retry.status !== 0) {
|
|
41
|
+
console.log(chalk.red("Install failed again. Finish it manually:"));
|
|
42
|
+
console.log(chalk.green(`cd ${name}`));
|
|
43
|
+
console.log(chalk.green("npm install --legacy-peer-deps"));
|
|
44
|
+
process.exitCode = 1;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
console.log(`\nDone! Next steps:\n`);
|
|
49
|
+
console.log(chalk.green(`cd ${name}`));
|
|
50
|
+
console.log(chalk.green("npm run dev"));
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=new.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new.js","sourceRoot":"","sources":["../../src/commands/new.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACrD,OAAO;SACJ,OAAO,CAAC,YAAY,CAAC;SACrB,WAAW,CAAC,sCAAsC,CAAC;SACnD,MAAM,CAAC,CAAC,IAAY,EAAE,EAAE;QACvB,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC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AAE,MAAM;gBACX,KAAK,EAAE,SAAS;gBAChB,KAAK,EAAE,IAAI;aACZ,CAAC,CAAC;YAEH,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC,CAAC;gBACpE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;gBACvC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC,CAAC;gBAC3D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;gBACrB,OAAO;YACT,CAAC;QACH,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QACrC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ct.config.d.ts","sourceRoot":"","sources":["../../src/constants/ct.config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc;IACzB,GAAG;QACD,SAAS;QACT,IAAI;;IAEN,UAAU;IACV,UAAU;CACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ct.config.js","sourceRoot":"","sources":["../../src/constants/ct.config.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,GAAG,EAAE;QACH,SAAS,EAAE,YAAY;QACvB,IAAI,EAAE,OAAO;KACd;IACD,UAAU,EAAE,KAAK;IACjB,UAAU,EAAE,KAAK;CAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/utils/console.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,KAAK,SAAU,MAAM,SAAiC,CAAC;AACpE,eAAO,MAAM,OAAO,SAAU,MAAM,SAAoC,CAAC;AACzE,eAAO,MAAM,IAAI,SAAU,MAAM,SAAmC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/utils/console.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACpE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AACzE,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Options } from "../../commands/generate.js";
|
|
2
|
+
type ComponentFile = "JSX" | "stylesheet" | "hook" | "test";
|
|
3
|
+
export type Component = {
|
|
4
|
+
[K in ComponentFile]: {
|
|
5
|
+
path: string;
|
|
6
|
+
content: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const generateComponent: (folder: string, name: string, options: Options) => Promise<Component>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/utils/generate/component.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE1D,KAAK,aAAa,GAAG,KAAK,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC;AAE5D,MAAM,MAAM,SAAS,GAAG;KACrB,CAAC,IAAI,aAAa,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;CACxD,CAAC;AAiBF,eAAO,MAAM,iBAAiB,WACpB,MAAM,QACR,MAAM,WACH,OAAO,KACf,OAAO,CAAC,SAAS,CAuBnB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import buildComponentTemplate from "../../templates/component.js";
|
|
4
|
+
import buildStylesheetTemplate from "../../templates/stylesheet.js";
|
|
5
|
+
import buildHookTemplate from "../../templates/hook.js";
|
|
6
|
+
import { isTypescriptUsed } from "../validators.js";
|
|
7
|
+
// Utilities
|
|
8
|
+
const askForStyle = async () => {
|
|
9
|
+
const answer = await prompts({
|
|
10
|
+
type: "select",
|
|
11
|
+
name: "style",
|
|
12
|
+
message: "What stylesheet to use?",
|
|
13
|
+
choices: [
|
|
14
|
+
{ title: "CSS", value: "css" },
|
|
15
|
+
{ title: "SCSS", value: "scss" },
|
|
16
|
+
],
|
|
17
|
+
initial: 1,
|
|
18
|
+
});
|
|
19
|
+
return answer.style ?? "css";
|
|
20
|
+
};
|
|
21
|
+
export const generateComponent = async (folder, name, options) => {
|
|
22
|
+
const stylesheetExt = options.style ?? (await askForStyle());
|
|
23
|
+
const useTs = options.ts ?? isTypescriptUsed();
|
|
24
|
+
const langExt = useTs ? "ts" : "js";
|
|
25
|
+
return {
|
|
26
|
+
JSX: {
|
|
27
|
+
path: path.join(folder, `${name}.${langExt}x`),
|
|
28
|
+
content: buildComponentTemplate(name, stylesheetExt, langExt),
|
|
29
|
+
},
|
|
30
|
+
stylesheet: {
|
|
31
|
+
path: path.join(folder, `${name}.module.${stylesheetExt}`),
|
|
32
|
+
content: buildStylesheetTemplate(name),
|
|
33
|
+
},
|
|
34
|
+
hook: {
|
|
35
|
+
path: path.join(folder, `use${name}.${langExt}`),
|
|
36
|
+
content: buildHookTemplate(name),
|
|
37
|
+
},
|
|
38
|
+
test: {
|
|
39
|
+
path: path.join(folder, `${name}.test.${langExt}`),
|
|
40
|
+
content: "",
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../src/utils/generate/component.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,sBAAsB,MAAM,8BAA8B,CAAC;AAClE,OAAO,uBAAuB,MAAM,+BAA+B,CAAC;AACpE,OAAO,iBAAiB,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AASpD,YAAY;AACZ,MAAM,WAAW,GAAG,KAAK,IAAqB,EAAE;IAC9C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;QAC3B,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,yBAAyB;QAClC,OAAO,EAAE;YACP,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;YAC9B,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;SACjC;QACD,OAAO,EAAE,CAAC;KACX,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,MAAc,EACd,IAAY,EACZ,OAAgB,EACI,EAAE;IACtB,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,MAAM,WAAW,EAAE,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,EAAE,IAAI,gBAAgB,EAAE,CAAC;IAC/C,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAEpC,OAAO;QACL,GAAG,EAAE;YACH,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,OAAO,GAAG,CAAC;YAC9C,OAAO,EAAE,sBAAsB,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,CAAC;SAC9D;QACD,UAAU,EAAE;YACV,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,WAAW,aAAa,EAAE,CAAC;YAC1D,OAAO,EAAE,uBAAuB,CAAC,IAAI,CAAC;SACvC;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;YAChD,OAAO,EAAE,iBAAiB,CAAC,IAAI,CAAC;SACjC;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,SAAS,OAAO,EAAE,CAAC;YAClD,OAAO,EAAE,EAAE;SACZ;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../../src/utils/generate/hook.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE1D,eAAO,MAAM,YAAY,WACf,MAAM,QACR,MAAM,WACH,OAAO;;;EASjB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { isTypescriptUsed } from "../validators.js";
|
|
3
|
+
import buildHookTemplate from "../../templates/hook.js";
|
|
4
|
+
export const generateHook = async (folder, name, options) => {
|
|
5
|
+
const useTs = options.ts ?? isTypescriptUsed();
|
|
6
|
+
const langExt = useTs ? "ts" : "js";
|
|
7
|
+
return {
|
|
8
|
+
path: path.join(folder, `${name}.${langExt}`),
|
|
9
|
+
content: buildHookTemplate(name),
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../../src/utils/generate/hook.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,iBAAiB,MAAM,yBAAyB,CAAC;AAGxD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,MAAc,EACd,IAAY,EACZ,OAAgB,EAChB,EAAE;IACF,MAAM,KAAK,GAAG,OAAO,CAAC,EAAE,IAAI,gBAAgB,EAAE,CAAC;IAC/C,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAEpC,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC;QAC7C,OAAO,EAAE,iBAAiB,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC"}
|