@pavlos-samaras/react-cli 2.0.1 → 2.1.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.
Files changed (147) hide show
  1. package/dist/bin/ct.js +2 -2
  2. package/dist/bin/ct.js.map +1 -1
  3. package/dist/commands/generate/generate.constants.d.ts +5 -0
  4. package/dist/commands/generate/generate.constants.d.ts.map +1 -0
  5. package/dist/commands/generate/generate.constants.js +5 -0
  6. package/dist/commands/generate/generate.constants.js.map +1 -0
  7. package/dist/commands/generate/generate.d.ts +3 -0
  8. package/dist/commands/generate/generate.d.ts.map +1 -0
  9. package/dist/commands/generate/generate.js +34 -0
  10. package/dist/commands/generate/generate.js.map +1 -0
  11. package/dist/commands/generate/generate.types.d.ts +22 -0
  12. package/dist/commands/generate/generate.types.d.ts.map +1 -0
  13. package/dist/commands/generate/generate.types.js +2 -0
  14. package/dist/commands/generate/generate.types.js.map +1 -0
  15. package/dist/commands/generate/utils/general.d.ts +4 -0
  16. package/dist/commands/generate/utils/general.d.ts.map +1 -0
  17. package/dist/commands/generate/utils/general.js +23 -0
  18. package/dist/commands/generate/utils/general.js.map +1 -0
  19. package/dist/commands/generate/utils/generateComponent.d.ts +3 -0
  20. package/dist/commands/generate/utils/generateComponent.d.ts.map +1 -0
  21. package/dist/{utils/generate/component.js → commands/generate/utils/generateComponent.js} +10 -9
  22. package/dist/commands/generate/utils/generateComponent.js.map +1 -0
  23. package/dist/{utils/generate/hook.d.ts → commands/generate/utils/generateHook.d.ts} +2 -2
  24. package/dist/commands/generate/utils/generateHook.d.ts.map +1 -0
  25. package/dist/{utils/generate/hook.js → commands/generate/utils/generateHook.js} +6 -5
  26. package/dist/commands/generate/utils/generateHook.js.map +1 -0
  27. package/dist/commands/generate/utils/runGenerateComponent.d.ts +3 -0
  28. package/dist/commands/generate/utils/runGenerateComponent.d.ts.map +1 -0
  29. package/dist/commands/generate/utils/runGenerateComponent.js +25 -0
  30. package/dist/commands/generate/utils/runGenerateComponent.js.map +1 -0
  31. package/dist/commands/generate/utils/runGenerateHook.d.ts +3 -0
  32. package/dist/commands/generate/utils/runGenerateHook.d.ts.map +1 -0
  33. package/dist/commands/generate/utils/runGenerateHook.js +23 -0
  34. package/dist/commands/generate/utils/runGenerateHook.js.map +1 -0
  35. package/dist/commands/new/new.constants.d.ts +4 -0
  36. package/dist/commands/new/new.constants.d.ts.map +1 -0
  37. package/dist/commands/new/new.constants.js +4 -0
  38. package/dist/commands/new/new.constants.js.map +1 -0
  39. package/dist/commands/new/new.d.ts.map +1 -0
  40. package/dist/commands/new/new.js +39 -0
  41. package/dist/commands/new/new.js.map +1 -0
  42. package/dist/commands/new/new.types.d.ts +7 -0
  43. package/dist/commands/new/new.types.d.ts.map +1 -0
  44. package/dist/commands/new/new.types.js +2 -0
  45. package/dist/commands/new/new.types.js.map +1 -0
  46. package/dist/commands/new/utils/general.d.ts +3 -0
  47. package/dist/commands/new/utils/general.d.ts.map +1 -0
  48. package/dist/commands/new/utils/general.js +6 -0
  49. package/dist/commands/new/utils/general.js.map +1 -0
  50. package/dist/commands/new/utils/runCommand.d.ts +2 -0
  51. package/dist/commands/new/utils/runCommand.d.ts.map +1 -0
  52. package/dist/commands/new/utils/runCommand.js +7 -0
  53. package/dist/commands/new/utils/runCommand.js.map +1 -0
  54. package/dist/commands/new/utils/runCreateVite.d.ts +2 -0
  55. package/dist/commands/new/utils/runCreateVite.d.ts.map +1 -0
  56. package/dist/commands/new/utils/runCreateVite.js +32 -0
  57. package/dist/commands/new/utils/runCreateVite.js.map +1 -0
  58. package/dist/commands/new/utils/runCustomTemplate.d.ts +3 -0
  59. package/dist/commands/new/utils/runCustomTemplate.d.ts.map +1 -0
  60. package/dist/commands/new/utils/runCustomTemplate.js +25 -0
  61. package/dist/commands/new/utils/runCustomTemplate.js.map +1 -0
  62. package/dist/constants/config.constants.d.ts +3 -0
  63. package/dist/constants/config.constants.d.ts.map +1 -0
  64. package/dist/constants/config.constants.js +5 -0
  65. package/dist/constants/config.constants.js.map +1 -0
  66. package/dist/types/config.types.d.ts +11 -0
  67. package/dist/types/config.types.d.ts.map +1 -0
  68. package/dist/types/config.types.js +2 -0
  69. package/dist/types/config.types.js.map +1 -0
  70. package/dist/utils/general.d.ts +4 -0
  71. package/dist/utils/general.d.ts.map +1 -0
  72. package/dist/utils/general.js +3 -0
  73. package/dist/utils/general.js.map +1 -0
  74. package/dist/utils/loadConfig.d.ts +2 -5
  75. package/dist/utils/loadConfig.d.ts.map +1 -1
  76. package/dist/utils/loadConfig.js +19 -4
  77. package/dist/utils/loadConfig.js.map +1 -1
  78. package/package.json +3 -2
  79. package/templates/component.tpl +9 -0
  80. package/templates/hook.tpl +3 -0
  81. package/templates/react/README.md +12 -0
  82. package/templates/react/eslint.config.js +29 -0
  83. package/templates/react/index.html +13 -0
  84. package/templates/react/jsconfig.json +13 -0
  85. package/templates/react/package.json +30 -0
  86. package/templates/react/public/favicon.svg +1 -0
  87. package/templates/react/src/app/App.jsx +12 -0
  88. package/templates/react/src/app/providers.jsx +13 -0
  89. package/templates/react/src/app/routes.jsx +19 -0
  90. package/templates/react/src/config/queryClient.config.js +12 -0
  91. package/templates/react/src/lib/queryClient.jsx +6 -0
  92. package/templates/react/src/main.jsx +13 -0
  93. package/templates/react/src/pages/home/Home.jsx +11 -0
  94. package/templates/react/src/pages/home/Home.module.scss +0 -0
  95. package/templates/react/vite.config.js +18 -0
  96. package/templates/react-ts/README.md +75 -0
  97. package/templates/react-ts/eslint.config.js +22 -0
  98. package/templates/react-ts/index.html +13 -0
  99. package/templates/react-ts/package-lock.json +3221 -0
  100. package/templates/react-ts/package.json +33 -0
  101. package/templates/react-ts/public/favicon.svg +1 -0
  102. package/templates/react-ts/src/app/App.tsx +12 -0
  103. package/templates/react-ts/src/app/providers.tsx +16 -0
  104. package/templates/react-ts/src/app/routes.tsx +19 -0
  105. package/templates/react-ts/src/config/queryClient.config.ts +14 -0
  106. package/templates/react-ts/src/lib/queryClient.tsx +6 -0
  107. package/templates/react-ts/src/main.tsx +13 -0
  108. package/templates/react-ts/src/pages/home/Home.module.scss +0 -0
  109. package/templates/react-ts/src/pages/home/Home.tsx +11 -0
  110. package/templates/react-ts/tsconfig.app.json +29 -0
  111. package/templates/react-ts/tsconfig.json +7 -0
  112. package/templates/react-ts/tsconfig.node.json +23 -0
  113. package/templates/react-ts/vite.config.ts +18 -0
  114. package/templates/stylesheet.tpl +3 -0
  115. package/dist/commands/generate.d.ts +0 -12
  116. package/dist/commands/generate.d.ts.map +0 -1
  117. package/dist/commands/generate.js +0 -88
  118. package/dist/commands/generate.js.map +0 -1
  119. package/dist/commands/new.d.ts.map +0 -1
  120. package/dist/commands/new.js +0 -53
  121. package/dist/commands/new.js.map +0 -1
  122. package/dist/constants/ct.config.d.ts +0 -5
  123. package/dist/constants/ct.config.d.ts.map +0 -1
  124. package/dist/constants/ct.config.js +0 -5
  125. package/dist/constants/ct.config.js.map +0 -1
  126. package/dist/templates/component.d.ts +0 -3
  127. package/dist/templates/component.d.ts.map +0 -1
  128. package/dist/templates/component.js +0 -11
  129. package/dist/templates/component.js.map +0 -1
  130. package/dist/templates/hook.d.ts +0 -3
  131. package/dist/templates/hook.d.ts.map +0 -1
  132. package/dist/templates/hook.js +0 -5
  133. package/dist/templates/hook.js.map +0 -1
  134. package/dist/templates/stylesheet.d.ts +0 -3
  135. package/dist/templates/stylesheet.d.ts.map +0 -1
  136. package/dist/templates/stylesheet.js +0 -7
  137. package/dist/templates/stylesheet.js.map +0 -1
  138. package/dist/types/generator.d.ts +0 -7
  139. package/dist/types/generator.d.ts.map +0 -1
  140. package/dist/types/generator.js +0 -2
  141. package/dist/types/generator.js.map +0 -1
  142. package/dist/utils/generate/component.d.ts +0 -11
  143. package/dist/utils/generate/component.d.ts.map +0 -1
  144. package/dist/utils/generate/component.js.map +0 -1
  145. package/dist/utils/generate/hook.d.ts.map +0 -1
  146. package/dist/utils/generate/hook.js.map +0 -1
  147. /package/dist/commands/{new.d.ts → new/new.d.ts} +0 -0
package/dist/bin/ct.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from "module";
3
3
  import { Command } from "commander";
4
- import { registerGenerateCommand } from "../commands/generate.js";
5
- import { registerNewCommand } from "../commands/new.js";
4
+ import { registerGenerateCommand } from "../commands/generate/generate.js";
5
+ import { registerNewCommand } from "../commands/new/new.js";
6
6
  const require = createRequire(import.meta.url);
7
7
  const { version } = require("../../package.json");
8
8
  const program = new Command();
@@ -1 +1 @@
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"}
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,kCAAkC,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,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,5 @@
1
+ export declare const TYPES: readonly ["component", "hook"];
2
+ export declare const STYLES: readonly ["css", "scss"];
3
+ export declare const VALID_COMPONENT_NAME: RegExp;
4
+ export declare const VALID_HOOK_NAME: RegExp;
5
+ //# sourceMappingURL=generate.constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.constants.d.ts","sourceRoot":"","sources":["../../../src/commands/generate/generate.constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,YAAI,WAAW,EAAE,MAAM,CAAU,CAAC;AACpD,eAAO,MAAM,MAAM,YAAI,KAAK,EAAE,MAAM,CAAU,CAAC;AAE/C,eAAO,MAAM,oBAAoB,QAAqB,CAAC;AACvD,eAAO,MAAM,eAAe,QAAwB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export const TYPES = ["component", "hook"];
2
+ export const STYLES = ["css", "scss"];
3
+ export const VALID_COMPONENT_NAME = /^[A-Z][a-zA-Z]*$/;
4
+ export const VALID_HOOK_NAME = /^use[A-Z][a-zA-Z]*$/;
5
+ //# sourceMappingURL=generate.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.constants.js","sourceRoot":"","sources":["../../../src/commands/generate/generate.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,WAAW,EAAE,MAAM,CAAU,CAAC;AACpD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,CAAU,CAAC;AAE/C,MAAM,CAAC,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,qBAAqB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ export declare const registerGenerateCommand: (program: Command) => void;
3
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/commands/generate/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,eAAO,MAAM,uBAAuB,YAAa,OAAO,SAqCvD,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Command } from "commander";
2
+ import { error } from "../../utils/console.js";
3
+ import { buildPreActionChecks } from "./utils/general.js";
4
+ import { runGenerateComponent } from "./utils/runGenerateComponent.js";
5
+ import { runGenerateHook } from "./utils/runGenerateHook.js";
6
+ export const registerGenerateCommand = (program) => {
7
+ program
8
+ .command("generate <type> <name>")
9
+ .alias("g")
10
+ .description("generate the given <type> content")
11
+ .option("-d, --dir <dir>", "target folder for the <type> folder", (value) => value.replace(/=/, ""))
12
+ .option("-f, --feature <feature>", "generate the given <type> inside a feature", (value) => value.replace(/=/, ""))
13
+ .option("-s, --style <style>", "use the specified stylesheet style", (value) => value.replace(/=/, ""))
14
+ .option("--ts", "Use typescript")
15
+ .option("--force", "skip safety checks and overwrite")
16
+ .action(async (type, name, options) => {
17
+ const checks = buildPreActionChecks(type, options);
18
+ for (const check of checks) {
19
+ if (check.condition) {
20
+ error(check.message);
21
+ process.exitCode = 1;
22
+ return;
23
+ }
24
+ }
25
+ const rootDir = options.feature
26
+ ? `src/features/${options.feature}`
27
+ : `src`;
28
+ if (type === "component")
29
+ runGenerateComponent(rootDir, name, options);
30
+ if (type === "hook")
31
+ runGenerateHook(rootDir, name, options);
32
+ });
33
+ };
34
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/commands/generate/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,OAAgB,EAAE,EAAE;IAC1D,OAAO;SACJ,OAAO,CAAC,wBAAwB,CAAC;SACjC,KAAK,CAAC,GAAG,CAAC;SACV,WAAW,CAAC,mCAAmC,CAAC;SAChD,MAAM,CAAC,iBAAiB,EAAE,qCAAqC,EAAE,CAAC,KAAK,EAAE,EAAE,CAC1E,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CACvB;SACA,MAAM,CACL,yBAAyB,EACzB,4CAA4C,EAC5C,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAClC;SACA,MAAM,CACL,qBAAqB,EACrB,oCAAoC,EACpC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAClC;SACA,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC;SAChC,MAAM,CAAC,SAAS,EAAE,kCAAkC,CAAC;SACrD,MAAM,CAAC,KAAK,EAAE,IAAU,EAAE,IAAY,EAAE,OAAgB,EAAE,EAAE;QAC3D,MAAM,MAAM,GAAG,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACnD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;gBACpB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACrB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;gBACrB,OAAO;YACT,CAAC;QACH,CAAC;QAED,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO;YAC7B,CAAC,CAAC,gBAAgB,OAAO,CAAC,OAAO,EAAE;YACnC,CAAC,CAAC,KAAK,CAAC;QAEV,IAAI,IAAI,KAAK,WAAW;YAAE,oBAAoB,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACvE,IAAI,IAAI,KAAK,MAAM;YAAE,eAAe,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { STYLES, TYPES } from "./generate.constants.js";
2
+ export type Check = {
3
+ condition: boolean | undefined;
4
+ message: string;
5
+ };
6
+ export type Type = (typeof TYPES)[number];
7
+ export type Style = (typeof STYLES)[number];
8
+ export interface Options {
9
+ dir?: string;
10
+ feature?: string;
11
+ style?: Style;
12
+ ts?: boolean;
13
+ force?: boolean;
14
+ }
15
+ export type ComponentFile = "JSX" | "stylesheet" | "hook" | "test";
16
+ export type Component = {
17
+ [K in ComponentFile]: {
18
+ path: string;
19
+ content: string;
20
+ };
21
+ };
22
+ //# sourceMappingURL=generate.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.types.d.ts","sourceRoot":"","sources":["../../../src/commands/generate/generate.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,MAAM,KAAK,GAAG;IAAE,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1C,MAAM,MAAM,KAAK,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5C,MAAM,WAAW,OAAO;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC;AAEnE,MAAM,MAAM,SAAS,GAAG;KACrB,CAAC,IAAI,aAAa,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;CACxD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=generate.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.types.js","sourceRoot":"","sources":["../../../src/commands/generate/generate.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { Check, Options, Type } from "../generate.types.js";
2
+ export declare const createDir: (pathToFolder: string) => string | undefined;
3
+ export declare const buildPreActionChecks: (type: Type, options: Options) => Check[];
4
+ //# sourceMappingURL=general.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../../../src/commands/generate/utils/general.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAIjE,eAAO,MAAM,SAAS,iBAAkB,MAAM,uBAK7C,CAAC;AAEF,eAAO,MAAM,oBAAoB,SAAU,IAAI,WAAW,OAAO,KAAG,KAAK,EAWxE,CAAC"}
@@ -0,0 +1,23 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import { isReactProject } from "../../../utils/validators.js";
4
+ import { STYLES, TYPES } from "../generate.constants.js";
5
+ export const createDir = (pathToFolder) => {
6
+ const folder = path.join(process.cwd(), pathToFolder);
7
+ if (fs.existsSync(folder))
8
+ return;
9
+ fs.mkdirSync(folder, { recursive: true });
10
+ return folder;
11
+ };
12
+ export const buildPreActionChecks = (type, options) => [
13
+ {
14
+ condition: !isReactProject() && !options.force,
15
+ message: "This is not a React project\ncreate one with 'ct new <name>' or use --force",
16
+ },
17
+ { condition: !TYPES.includes(type), message: `Invalid type: ${type}` },
18
+ {
19
+ condition: options.style && !STYLES.includes(options.style),
20
+ message: `Invalid style: ${options.style}`,
21
+ },
22
+ ];
23
+ //# sourceMappingURL=general.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"general.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/general.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,YAAoB,EAAE,EAAE;IAChD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;IACtD,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO;IAClC,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAU,EAAE,OAAgB,EAAW,EAAE,CAAC;IAC7E;QACE,SAAS,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;QAC9C,OAAO,EACL,6EAA6E;KAChF;IACD,EAAE,SAAS,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,iBAAiB,IAAI,EAAE,EAAE;IACtE;QACE,SAAS,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC;QAC3D,OAAO,EAAE,kBAAkB,OAAO,CAAC,KAAK,EAAE;KAC3C;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Component, Options } from "../generate.types.js";
2
+ export declare const generateComponent: (folder: string, name: string, options: Options) => Promise<Component>;
3
+ //# sourceMappingURL=generateComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateComponent.d.ts","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateComponent.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAiB/D,eAAO,MAAM,iBAAiB,WACpB,MAAM,QACR,MAAM,WACH,OAAO,KACf,OAAO,CAAC,SAAS,CA+BnB,CAAC"}
@@ -1,10 +1,8 @@
1
1
  import path from "path";
2
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
- import { loadConfig } from "../loadConfig.js";
3
+ import { loadConfig } from "../../../utils/loadConfig.js";
4
+ import { isTypescriptUsed } from "../../../utils/validators.js";
5
+ import { getTemplate } from "../../../utils/general.js";
8
6
  // Utilities
9
7
  const askForStyle = async () => {
10
8
  const answer = await prompts({
@@ -27,15 +25,18 @@ export const generateComponent = async (folder, name, options) => {
27
25
  return {
28
26
  JSX: {
29
27
  path: path.join(folder, `${name}.${langExt}x`),
30
- content: buildComponentTemplate(name, stylesheetExt, langExt),
28
+ content: getTemplate("component")
29
+ .replace(/__NAME__/g, name)
30
+ .replace(/__CLASSNAME__/, name.toLowerCase())
31
+ .replace(/.scss/g, `.${stylesheetExt}`),
31
32
  },
32
33
  stylesheet: {
33
34
  path: path.join(folder, `${name}.module.${stylesheetExt}`),
34
- content: buildStylesheetTemplate(name),
35
+ content: getTemplate("stylesheet").replace(/__CLASSNAME__/, name.toLowerCase()),
35
36
  },
36
37
  hook: {
37
38
  path: path.join(folder, `use${name}.${langExt}`),
38
- content: buildHookTemplate(name),
39
+ content: getTemplate("hook").replace(/__NAME__/g, name),
39
40
  },
40
41
  test: {
41
42
  path: path.join(folder, `${name}.test.${langExt}`),
@@ -43,4 +44,4 @@ export const generateComponent = async (folder, name, options) => {
43
44
  },
44
45
  };
45
46
  };
46
- //# sourceMappingURL=component.js.map
47
+ //# sourceMappingURL=generateComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateComponent.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateComponent.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,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,MAAM,GAAG,UAAU,EAAE,IAAI,EAAE,CAAC;IAClC,MAAM,aAAa,GACjB,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,UAAU,IAAI,CAAC,MAAM,WAAW,EAAE,CAAC,CAAC;IAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,EAAE,IAAI,MAAM,CAAC,UAAU,IAAI,gBAAgB,EAAE,CAAC;IACpE,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,WAAW,CAAC,WAAW,CAAC;iBAC9B,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC;iBAC1B,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;iBAC5C,OAAO,CAAC,QAAQ,EAAE,IAAI,aAAa,EAAE,CAAC;SAC1C;QACD,UAAU,EAAE;YACV,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,WAAW,aAAa,EAAE,CAAC;YAC1D,OAAO,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC,OAAO,CACxC,eAAe,EACf,IAAI,CAAC,WAAW,EAAE,CACnB;SACF;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;YAChD,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC;SACxD;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"}
@@ -1,6 +1,6 @@
1
- import type { Options } from "../../commands/generate.js";
1
+ import type { Options } from "../generate.types.js";
2
2
  export declare const generateHook: (folder: string, name: string, options: Options) => Promise<{
3
3
  path: string;
4
4
  content: string;
5
5
  }>;
6
- //# sourceMappingURL=hook.d.ts.map
6
+ //# sourceMappingURL=generateHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateHook.d.ts","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateHook.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGpD,eAAO,MAAM,YAAY,WACf,MAAM,QACR,MAAM,WACH,OAAO;;;EAUjB,CAAC"}
@@ -1,14 +1,15 @@
1
1
  import path from "path";
2
- import { isTypescriptUsed } from "../validators.js";
3
- import buildHookTemplate from "../../templates/hook.js";
4
- import { loadConfig } from "../loadConfig.js";
2
+ import fs from "fs";
3
+ import { loadConfig } from "../../../utils/loadConfig.js";
4
+ import { isTypescriptUsed } from "../../../utils/validators.js";
5
+ import { getTemplate } from "../../../utils/general.js";
5
6
  export const generateHook = async (folder, name, options) => {
6
7
  const config = loadConfig() ?? {};
7
8
  const useTs = options.ts ?? config.typescript ?? isTypescriptUsed();
8
9
  const langExt = useTs ? "ts" : "js";
9
10
  return {
10
11
  path: path.join(folder, `${name}.${langExt}`),
11
- content: buildHookTemplate(name),
12
+ content: getTemplate("hook").replace(/__NAME__/g, name),
12
13
  };
13
14
  };
14
- //# sourceMappingURL=hook.js.map
15
+ //# sourceMappingURL=generateHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateHook.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/generateHook.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,MAAc,EACd,IAAY,EACZ,OAAgB,EAChB,EAAE;IACF,MAAM,MAAM,GAAG,UAAU,EAAE,IAAI,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,OAAO,CAAC,EAAE,IAAI,MAAM,CAAC,UAAU,IAAI,gBAAgB,EAAE,CAAC;IACpE,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,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC;KACxD,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Options } from "../generate.types.js";
2
+ export declare const runGenerateComponent: (rootDir: string, name: string, options: Options) => Promise<void>;
3
+ //# sourceMappingURL=runGenerateComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runGenerateComponent.d.ts","sourceRoot":"","sources":["../../../../src/commands/generate/utils/runGenerateComponent.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGpD,eAAO,MAAM,oBAAoB,YACtB,MAAM,QACT,MAAM,WACH,OAAO,kBAkBjB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import fs from "fs";
2
+ import chalk from "chalk";
3
+ import { info, warning } from "../../../utils/console.js";
4
+ import { createDir } from "./general.js";
5
+ import { generateComponent } from "./generateComponent.js";
6
+ import { VALID_COMPONENT_NAME } from "../generate.constants.js";
7
+ export const runGenerateComponent = async (rootDir, name, options) => {
8
+ if (!VALID_COMPONENT_NAME.test(name)) {
9
+ warning(`Invalid component name ${name}`);
10
+ process.exitCode = 1;
11
+ return;
12
+ }
13
+ const folder = createDir(`${rootDir}/${options.dir ?? "components"}/${name}`);
14
+ if (!folder) {
15
+ warning(`Folder ${name} already exists!`);
16
+ process.exitCode = 1;
17
+ return;
18
+ }
19
+ const component = await generateComponent(folder, name, options);
20
+ for (const file of Object.values(component)) {
21
+ fs.writeFileSync(file.path, file.content);
22
+ }
23
+ info(`${name} created at ${chalk.gray(folder)}`);
24
+ };
25
+ //# sourceMappingURL=runGenerateComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runGenerateComponent.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/runGenerateComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EACvC,OAAe,EACf,IAAY,EACZ,OAAgB,EAChB,EAAE;IACF,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,OAAO,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC;QAC1C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,OAAO,IAAI,OAAO,CAAC,GAAG,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC,CAAC;IAC9E,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,UAAU,IAAI,kBAAkB,CAAC,CAAC;QAC1C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACjE,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5C,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,CAAC,GAAG,IAAI,eAAe,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Options } from "../generate.types.js";
2
+ export declare const runGenerateHook: (rootDir: string, name: string, options: Options) => Promise<void>;
3
+ //# sourceMappingURL=runGenerateHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runGenerateHook.d.ts","sourceRoot":"","sources":["../../../../src/commands/generate/utils/runGenerateHook.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,eAAO,MAAM,eAAe,YACjB,MAAM,QACT,MAAM,WACH,OAAO,kBAgBjB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import fs from "fs";
2
+ import chalk from "chalk";
3
+ import { VALID_HOOK_NAME } from "../generate.constants.js";
4
+ import { info, warning } from "../../../utils/console.js";
5
+ import { createDir } from "./general.js";
6
+ import { generateHook } from "./generateHook.js";
7
+ export const runGenerateHook = async (rootDir, name, options) => {
8
+ if (!VALID_HOOK_NAME.test(name)) {
9
+ warning(`Invalid hook name ${name}`);
10
+ process.exitCode = 1;
11
+ return;
12
+ }
13
+ const folder = createDir(`${rootDir}/${options.dir ?? "hooks"}/${name}`);
14
+ if (!folder) {
15
+ warning(`Folder ${name} already exists!`);
16
+ process.exitCode = 1;
17
+ return;
18
+ }
19
+ const hook = await generateHook(folder, name, options);
20
+ fs.writeFileSync(hook.path, hook.content);
21
+ info(`${name} created at ${chalk.gray(folder)}`);
22
+ };
23
+ //# sourceMappingURL=runGenerateHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runGenerateHook.js","sourceRoot":"","sources":["../../../../src/commands/generate/utils/runGenerateHook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,OAAe,EACf,IAAY,EACZ,OAAgB,EAChB,EAAE;IACF,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,OAAO,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC;QACrC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,OAAO,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC,CAAC;IACzE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,UAAU,IAAI,kBAAkB,CAAC,CAAC;QAC1C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACvD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,IAAI,CAAC,GAAG,IAAI,eAAe,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const VALID_REACT_NAME: RegExp;
2
+ export declare const TEMPLATES: readonly ["react", "react-ts", "react-swc", "react-swc-ts"];
3
+ export declare const CUSTOM_TEMPLATES: readonly ["custom-js", "custom-ts"];
4
+ //# sourceMappingURL=new.constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new.constants.d.ts","sourceRoot":"","sources":["../../../src/commands/new/new.constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,QAA2B,CAAC;AACzD,eAAO,MAAM,SAAS,YAAI,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,CAAU,CAAC;AACrF,eAAO,MAAM,gBAAgB,YAAI,WAAW,EAAE,WAAW,CAAU,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const VALID_REACT_NAME = /^[a-z0-9][a-z0-9-_]*$/i;
2
+ export const TEMPLATES = ["react", "react-ts", "react-swc", "react-swc-ts"];
3
+ export const CUSTOM_TEMPLATES = ["custom-js", "custom-ts"];
4
+ //# sourceMappingURL=new.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new.constants.js","sourceRoot":"","sources":["../../../src/commands/new/new.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AACzD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,CAAU,CAAC;AACrF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,WAAW,CAAU,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new.d.ts","sourceRoot":"","sources":["../../../src/commands/new/new.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,eAAO,MAAM,kBAAkB,YAAa,OAAO,SAqClD,CAAC"}
@@ -0,0 +1,39 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import { error, info, warning } from "../../utils/console.js";
4
+ import { CUSTOM_TEMPLATES, TEMPLATES, VALID_REACT_NAME, } from "./new.constants.js";
5
+ import { runCustomTemplate } from "./utils/runCustomTemplate.js";
6
+ import { runCreateVite } from "./utils/runCreateVite.js";
7
+ import { isCustomTemplate, isInvalidTemplate } from "./utils/general.js";
8
+ export const registerNewCommand = (program) => {
9
+ program
10
+ .command("new <name>")
11
+ .description("Create a new React project with Vite")
12
+ .option("-t, --template <template>", "apply a react Vite template. Use (custom-ts or custom-js) for a custom src layout")
13
+ .action((name, options) => {
14
+ if (!VALID_REACT_NAME.test(name)) {
15
+ error(`Invalid name ${name}`);
16
+ process.exitCode = 1;
17
+ return;
18
+ }
19
+ if (isInvalidTemplate(options.template)) {
20
+ const templates = [...TEMPLATES, ...CUSTOM_TEMPLATES].join(", ");
21
+ error(`Invalid template ${options.template}`);
22
+ info(`You can choose between: ${templates}`);
23
+ process.exitCode = 1;
24
+ return;
25
+ }
26
+ const target = path.join(process.cwd(), name);
27
+ if (fs.existsSync(target)) {
28
+ warning(`Folder ${name} already exists!`);
29
+ process.exitCode = 1;
30
+ return;
31
+ }
32
+ runCreateVite(name, target, options.template);
33
+ fs.writeFileSync(path.join(target, "ct.config.json"), "{}");
34
+ if (isCustomTemplate(options.template)) {
35
+ runCustomTemplate(target, options);
36
+ }
37
+ });
38
+ };
39
+ //# sourceMappingURL=new.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new.js","sourceRoot":"","sources":["../../../src/commands/new/new.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAIzE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACrD,OAAO;SACJ,OAAO,CAAC,YAAY,CAAC;SACrB,WAAW,CAAC,sCAAsC,CAAC;SACnD,MAAM,CACL,2BAA2B,EAC3B,mFAAmF,CACpF;SACA,MAAM,CAAC,CAAC,IAAY,EAAE,OAAgB,EAAE,EAAE;QACzC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,KAAK,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;YAC9B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QAED,IAAI,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxC,MAAM,SAAS,GAAG,CAAC,GAAG,SAAS,EAAE,GAAG,gBAAgB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjE,KAAK,CAAC,oBAAoB,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC9C,IAAI,CAAC,2BAA2B,SAAS,EAAE,CAAC,CAAC;YAC7C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;QAC9C,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,UAAU,IAAI,kBAAkB,CAAC,CAAC;YAC1C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QAED,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAE9C,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5D,IAAI,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvC,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { CUSTOM_TEMPLATES, TEMPLATES } from "./new.constants.js";
2
+ export type Template = (typeof TEMPLATES)[number];
3
+ export type CustomTemplate = (typeof CUSTOM_TEMPLATES)[number];
4
+ export interface Options {
5
+ template?: Template | CustomTemplate;
6
+ }
7
+ //# sourceMappingURL=new.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new.types.d.ts","sourceRoot":"","sources":["../../../src/commands/new/new.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEtE,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAClD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,EAAE,QAAQ,GAAG,cAAc,CAAC;CACtC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=new.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new.types.js","sourceRoot":"","sources":["../../../src/commands/new/new.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export declare const isInvalidTemplate: (template?: string) => "" | boolean | undefined;
2
+ export declare const isCustomTemplate: (template?: string) => "" | boolean | undefined;
3
+ //# sourceMappingURL=general.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../../../src/commands/new/utils/general.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,iBAAiB,cAAe,MAAM,6BAGR,CAAC;AAE5C,eAAO,MAAM,gBAAgB,cAAe,MAAM,6BACiB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { CUSTOM_TEMPLATES, TEMPLATES } from "../new.constants.js";
2
+ export const isInvalidTemplate = (template) => template &&
3
+ !CUSTOM_TEMPLATES.includes(template) &&
4
+ !TEMPLATES.includes(template);
5
+ export const isCustomTemplate = (template) => template && CUSTOM_TEMPLATES.includes(template);
6
+ //# sourceMappingURL=general.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"general.js","sourceRoot":"","sources":["../../../../src/commands/new/utils/general.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGlE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAiB,EAAE,EAAE,CACrD,QAAQ;IACR,CAAC,gBAAgB,CAAC,QAAQ,CAAC,QAA0B,CAAC;IACtD,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAoB,CAAC,CAAC;AAE5C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAiB,EAAE,EAAE,CACpD,QAAQ,IAAI,gBAAgB,CAAC,QAAQ,CAAC,QAA0B,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const runCommand: (command: string, target?: string) => import("node:child_process").SpawnSyncReturns<NonSharedBuffer>;
2
+ //# sourceMappingURL=runCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCommand.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,YAAa,MAAM,WAAW,MAAM,mEAKvD,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { spawnSync } from "child_process";
2
+ export const runCommand = (command, target) => spawnSync(command, {
3
+ ...(target && { cwd: target }),
4
+ stdio: "inherit",
5
+ shell: true,
6
+ });
7
+ //# sourceMappingURL=runCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runCommand.js","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,MAAe,EAAE,EAAE,CAC7D,SAAS,CAAC,OAAO,EAAE;IACjB,GAAG,CAAC,MAAM,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;IAC9B,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,IAAI;CACZ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const runCreateVite: (name: string, target: string, template?: string) => void;
2
+ //# sourceMappingURL=runCreateVite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runCreateVite.d.ts","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCreateVite.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,aAAa,SAClB,MAAM,UACJ,MAAM,aACH,MAAM,SAmBlB,CAAC"}
@@ -0,0 +1,32 @@
1
+ import fs from "fs";
2
+ import { warning, error, info } from "../../../utils/console.js";
3
+ import { TEMPLATES } from "../new.constants.js";
4
+ import { runCommand } from "./runCommand.js";
5
+ // Utility
6
+ const retryInstallDependencies = (name, target) => {
7
+ warning("Install failed (dependency conflict). Retrying with --legacy-peer-deps...");
8
+ const retry = runCommand("npm install --legacy-peer-deps", target);
9
+ if (retry.status !== 0) {
10
+ error("Install failed again. Finish it manually:");
11
+ info(`cd ${name}\nnpm install --legacy-peer-deps`);
12
+ process.exitCode = 1;
13
+ return;
14
+ }
15
+ };
16
+ export const runCreateVite = (name, target, template) => {
17
+ const createViteCommand = template
18
+ ? TEMPLATES.includes(template)
19
+ ? `npm create vite@latest ${name} -- --template ${template} --no-interactive`
20
+ : `npm create vite@latest ${name} -- --template ${template.endsWith("-ts") ? "react-ts" : "react"} --no-interactive`
21
+ : `npm create vite@latest ${name}`;
22
+ const result = runCommand(createViteCommand);
23
+ const vitePassed = result.status === 0;
24
+ if (!vitePassed && !fs.existsSync(target)) {
25
+ error("Vite failed before creating the project.");
26
+ process.exitCode = 1;
27
+ return;
28
+ }
29
+ if (!vitePassed)
30
+ retryInstallDependencies(name, target);
31
+ };
32
+ //# sourceMappingURL=runCreateVite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runCreateVite.js","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCreateVite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,UAAU;AACV,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,MAAc,EAAE,EAAE;IAChE,OAAO,CACL,2EAA2E,CAC5E,CAAC;IAEF,MAAM,KAAK,GAAG,UAAU,CAAC,gCAAgC,EAAE,MAAM,CAAC,CAAC;IAEnE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,KAAK,CAAC,2CAA2C,CAAC,CAAC;QACnD,IAAI,CAAC,MAAM,IAAI,kCAAkC,CAAC,CAAC;QACnD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,IAAY,EACZ,MAAc,EACd,QAAiB,EACjB,EAAE;IACF,MAAM,iBAAiB,GAAG,QAAQ;QAChC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAoB,CAAC;YACxC,CAAC,CAAC,0BAA0B,IAAI,kBAAkB,QAAQ,mBAAmB;YAC7E,CAAC,CAAC,0BAA0B,IAAI,kBAAkB,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,mBAAmB;QACtH,CAAC,CAAC,0BAA0B,IAAI,EAAE,CAAC;IAErC,MAAM,MAAM,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAE7C,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC;IAEvC,IAAI,CAAC,UAAU,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1C,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAClD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IAED,IAAI,CAAC,UAAU;QAAE,wBAAwB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Options } from "../new.types.js";
2
+ export declare const runCustomTemplate: (target: string, options: Options) => void;
3
+ //# sourceMappingURL=runCustomTemplate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runCustomTemplate.d.ts","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCustomTemplate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAQ/C,eAAO,MAAM,iBAAiB,WAAY,MAAM,WAAW,OAAO,SAkBjE,CAAC"}
@@ -0,0 +1,25 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ // Utility
4
+ const removeDefaultFiles = (target, files) => {
5
+ for (const file in files)
6
+ fs.rmSync(path.join(target, file), { force: true });
7
+ fs.rmSync(path.join(target, "src/assets"), { recursive: true, force: true });
8
+ };
9
+ export const runCustomTemplate = (target, options) => {
10
+ if (!options.template)
11
+ return;
12
+ const isTs = options.template.endsWith("-ts");
13
+ const variant = isTs ? "react-ts" : "react";
14
+ const overlay = new URL(`../../../../templates/${variant}`, import.meta.url);
15
+ const ext = isTs ? "tsx" : "jsx";
16
+ const filesToRemove = [
17
+ `src/App.${ext}`,
18
+ "src/App.css",
19
+ "src/index.css",
20
+ ".oxlintrc.json",
21
+ ];
22
+ removeDefaultFiles(target, filesToRemove);
23
+ fs.cpSync(overlay, target, { recursive: true });
24
+ };
25
+ //# sourceMappingURL=runCustomTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runCustomTemplate.js","sourceRoot":"","sources":["../../../../src/commands/new/utils/runCustomTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAGpB,UAAU;AACV,MAAM,kBAAkB,GAAG,CAAC,MAAc,EAAE,KAAe,EAAE,EAAE;IAC7D,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9E,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC/E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAE,EAAE;IACpE,IAAI,CAAC,OAAO,CAAC,QAAQ;QAAE,OAAO;IAE9B,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE9C,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,yBAAyB,OAAO,EAAE,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7E,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IAEjC,MAAM,aAAa,GAAG;QACpB,WAAW,GAAG,EAAE;QAChB,aAAa;QACb,eAAe;QACf,gBAAgB;KACjB,CAAC;IACF,kBAAkB,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAE1C,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAClD,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ConfigPropertyTypes } from "../types/config.types.js";
2
+ export declare const CONFIG_PROPERTY_TYPES: ConfigPropertyTypes;
3
+ //# sourceMappingURL=config.constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.constants.d.ts","sourceRoot":"","sources":["../../src/constants/config.constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,eAAO,MAAM,qBAAqB,EAAE,mBAGnC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export const CONFIG_PROPERTY_TYPES = {
2
+ typescript: "boolean",
3
+ stylesheet: "string",
4
+ };
5
+ //# sourceMappingURL=config.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.constants.js","sourceRoot":"","sources":["../../src/constants/config.constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAwB;IACxD,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE,QAAQ;CACrB,CAAC"}
@@ -0,0 +1,11 @@
1
+ type AllowedTypes = "string" | "number" | "boolean" | "bigint" | "symbol" | "object" | "null";
2
+ export type Config = {
3
+ typescript?: boolean;
4
+ stylesheet?: string;
5
+ };
6
+ export type ConfigKeys = keyof Config;
7
+ export type ConfigPropertyTypes = {
8
+ [K in ConfigKeys]: AllowedTypes;
9
+ };
10
+ export {};
11
+ //# sourceMappingURL=config.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.types.d.ts","sourceRoot":"","sources":["../../src/types/config.types.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GACb,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,MAAM,CAAC;AAEX,MAAM,MAAM,MAAM,GAAG;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC;AACtC,MAAM,MAAM,mBAAmB,GAAG;KAAG,CAAC,IAAI,UAAU,GAAG,YAAY;CAAE,CAAC"}