@pavlos-samaras/react-cli 0.0.0-stage → 1.0.1

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 CHANGED
@@ -1,3 +1,37 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # React CLI
2
+
3
+ A simple command-line tool for generating React components.
4
+
5
+ ## Build and link
6
+
7
+ ```bash
8
+ npm install
9
+ npm run build
10
+ npm link
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Generate a component in `src/components/<Name>`:
16
+
17
+ ```bash
18
+ ct generate component Button
19
+ ```
20
+
21
+ You can also use the `g` shorthand, choose a different target directory, or
22
+ create a TypeScript file:
23
+
24
+ ```bash
25
+ ct g component Button --dir src/ui --ts
26
+ ```
27
+
28
+ Without `--ts`, the CLI asks whether to use TypeScript and creates either a
29
+ `.tsx` or `.jsx` file.
30
+
31
+ ## Development
32
+
33
+ Run the CLI directly from the TypeScript source:
34
+
35
+ ```bash
36
+ npm run dev -- generate component Button
37
+ ```
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=ct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ct.d.ts","sourceRoot":"","sources":["../../src/bin/ct.ts"],"names":[],"mappings":""}
package/dist/bin/ct.js ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import { createRequire } from "module";
5
+ import { Command } from "commander";
6
+ import { generateComponent } from "../utils/generateComponent.js";
7
+ const require = createRequire(import.meta.url);
8
+ const { version } = require("../../package.json");
9
+ const program = new Command();
10
+ const TYPES = ["component"];
11
+ program.name("ct").description("My React CLI").version(version);
12
+ program
13
+ .command("generate <type> <name>")
14
+ .alias("g")
15
+ .description("Generate a component, e.g. ct g component Button")
16
+ .option("-d, --dir <div>", "target folder", "components")
17
+ .option("-f, --feature <feature>", "put component under a feature")
18
+ .option("--ts", "create a .tsx file")
19
+ .action(async (type, name, options) => {
20
+ if (!TYPES.includes(type))
21
+ return console.log(`Unknown type: ${type}`);
22
+ if (type === "component") {
23
+ const pathToComponent = options.feature
24
+ ? `src/features/${options.feature}/${options.dir}`
25
+ : `src/${options.dir}`;
26
+ const folder = path.join(process.cwd(), pathToComponent, name);
27
+ fs.mkdirSync(folder, { recursive: true });
28
+ const { JSX, stylesheet, hook, test } = await generateComponent(name, options);
29
+ fs.writeFileSync(path.join(folder, JSX.file), JSX.content);
30
+ fs.writeFileSync(path.join(folder, stylesheet.file), stylesheet.content);
31
+ fs.writeFileSync(path.join(folder, hook.file), hook.content);
32
+ fs.writeFileSync(path.join(folder, test.file), test.content);
33
+ }
34
+ });
35
+ program.parse();
36
+ //# sourceMappingURL=ct.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ct.js","sourceRoot":"","sources":["../../src/bin/ct.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAGlE,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,MAAM,KAAK,GAAG,CAAC,WAAW,CAAC,CAAC;AAE5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhE,OAAO;KACJ,OAAO,CAAC,wBAAwB,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AI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7D,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const buildComponentTemplate: (name: string, stylesheetExt: string, componentExt: string) => string;
2
+ export default buildComponentTemplate;
3
+ //# sourceMappingURL=component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/templates/component.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,sBAAsB,SACpB,MAAM,iBACG,MAAM,gBACP,MAAM,WASrB,CAAC;eAEa,sBAAsB"}
@@ -0,0 +1,11 @@
1
+ const buildComponentTemplate = (name, stylesheetExt, componentExt) => {
2
+ return `import styles from "./${name}.module.${stylesheetExt}"
3
+ import { use${name} } from "./use${name}.${componentExt}"
4
+
5
+ export const ${name} = () => {
6
+ const hook = use${name}();
7
+ return <div className={styles.${name.toLowerCase()}></div>
8
+ }`;
9
+ };
10
+ export default buildComponentTemplate;
11
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/templates/component.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAG,CAC7B,IAAY,EACZ,aAAqB,EACrB,YAAoB,EACpB,EAAE;IACF,OAAO,yBAAyB,IAAI,WAAW,aAAa;cAChD,IAAI,iBAAiB,IAAI,IAAI,YAAY;;eAExC,IAAI;oBACC,IAAI;kCACU,IAAI,CAAC,WAAW,EAAE;EAClD,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const buildHookTemplate: (name: string) => string;
2
+ export default buildHookTemplate;
3
+ //# sourceMappingURL=hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/templates/hook.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,iBAAiB,SAAU,MAAM,WAEtC,CAAC;eAEa,iBAAiB"}
@@ -0,0 +1,5 @@
1
+ const buildHookTemplate = (name) => {
2
+ return `export const use${name} = () => {}`;
3
+ };
4
+ export default buildHookTemplate;
5
+ //# sourceMappingURL=hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.js","sourceRoot":"","sources":["../../src/templates/hook.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,EAAE;IACzC,OAAO,mBAAmB,IAAI,aAAa,CAAC;AAC9C,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const buildStylesheetTemplate: (name: string) => string;
2
+ export default buildStylesheetTemplate;
3
+ //# sourceMappingURL=stylesheet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stylesheet.d.ts","sourceRoot":"","sources":["../../src/templates/stylesheet.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,uBAAuB,SAAU,MAAM,WAI5C,CAAC;eAEa,uBAAuB"}
@@ -0,0 +1,7 @@
1
+ const buildStylesheetTemplate = (name) => {
2
+ return `.${name.toLowerCase()} {
3
+ // Styles go here
4
+ }`;
5
+ };
6
+ export default buildStylesheetTemplate;
7
+ //# sourceMappingURL=stylesheet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stylesheet.js","sourceRoot":"","sources":["../../src/templates/stylesheet.ts"],"names":[],"mappings":"AAAA,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAE,EAAE;IAC/C,OAAO,IAAI,IAAI,CAAC,WAAW,EAAE;;EAE7B,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export type ComponentOptions = {
2
+ dir: string;
3
+ feature?: string;
4
+ ts?: boolean;
5
+ };
6
+ //# sourceMappingURL=component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/types/component.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,OAAO,CAAC;CACd,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/types/component.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ import type { ComponentOptions } from "../types/component.js";
2
+ export declare const generateComponent: (name: string, options: ComponentOptions) => Promise<{
3
+ JSX: {
4
+ file: string;
5
+ content: string;
6
+ };
7
+ stylesheet: {
8
+ file: string;
9
+ content: string;
10
+ };
11
+ hook: {
12
+ file: string;
13
+ content: string;
14
+ };
15
+ test: {
16
+ file: string;
17
+ content: string;
18
+ };
19
+ }>;
20
+ //# sourceMappingURL=generateComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateComponent.d.ts","sourceRoot":"","sources":["../../src/utils/generateComponent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAI9D,eAAO,MAAM,iBAAiB,SACtB,MAAM,WACH,gBAAgB;;QAiCrB,IAAI;QACJ,OAAO;;;QAOP,IAAI;QACJ,OAAO;;;QAGP,IAAI;QACJ,OAAO;;;QAGP,IAAI;QACJ,OAAO;;EAGZ,CAAC"}
@@ -0,0 +1,50 @@
1
+ import prompts from "prompts";
2
+ import buildComponentTemplate from "../templates/component.js";
3
+ import buildStylesheetTemplate from "../templates/stylesheet.js";
4
+ import buildHookTemplate from "../templates/hook.js";
5
+ export const generateComponent = async (name, options) => {
6
+ let componentExt;
7
+ if (options.ts === undefined) {
8
+ const answer = await prompts({
9
+ type: "select",
10
+ name: "ts",
11
+ message: "Use TypeScript?",
12
+ choices: [
13
+ { title: "Yes", value: "tsx" },
14
+ { title: "No", value: "jsx" },
15
+ ],
16
+ initial: 0,
17
+ });
18
+ componentExt = answer.ts;
19
+ }
20
+ const stylesheetExt = await prompts({
21
+ type: "select",
22
+ name: "style",
23
+ message: "What stylesheet to use",
24
+ choices: [
25
+ { title: "CSS", value: "css" },
26
+ { title: "SCSS", value: "scss" },
27
+ ],
28
+ initial: 1,
29
+ });
30
+ const componentLanguage = componentExt?.replace("x", "");
31
+ return {
32
+ JSX: {
33
+ file: `${name}.${componentExt}`,
34
+ content: buildComponentTemplate(name, stylesheetExt.style, componentLanguage),
35
+ },
36
+ stylesheet: {
37
+ file: `${name}.module.${stylesheetExt.style}`,
38
+ content: buildStylesheetTemplate(name),
39
+ },
40
+ hook: {
41
+ file: `use${name}.${componentLanguage}`,
42
+ content: buildHookTemplate(name),
43
+ },
44
+ test: {
45
+ file: `${name}.test.${componentLanguage}`,
46
+ content: "",
47
+ },
48
+ };
49
+ };
50
+ //# sourceMappingURL=generateComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateComponent.js","sourceRoot":"","sources":["../../src/utils/generateComponent.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,sBAAsB,MAAM,2BAA2B,CAAC;AAE/D,OAAO,uBAAuB,MAAM,4BAA4B,CAAC;AACjE,OAAO,iBAAiB,MAAM,sBAAsB,CAAC;AAErD,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,IAAY,EACZ,OAAyB,EACzB,EAAE;IACF,IAAI,YAAY,CAAC;IAEjB,IAAI,OAAO,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;QAC7B,MAAM,M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;KACF,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
- {
2
- "name": "@pavlos-samaras/react-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@pavlos-samaras/react-cli",
3
+ "version": "1.0.1",
4
+ "author": "sammern-stack",
5
+ "description": "A CLI to generate React code",
6
+ "keywords": [
7
+ "react",
8
+ "cli",
9
+ "generator"
10
+ ],
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "bin": {
14
+ "ct": "./dist/bin/ct.js"
15
+ },
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "prepublishOnly": "npm run build",
19
+ "dev": "tsx src/bin/ct.ts",
20
+ "build:link": "npm run build && npm link"
21
+ },
22
+ "dependencies": {
23
+ "commander": "^15.0.0",
24
+ "prompts": "^2.4.2"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^26.6.6",
28
+ "@types/prompts": "^2.4.9",
29
+ "tsx": "^4.23.15",
30
+ "typescript": "^7.0.2"
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ]
35
+ }