@expressots/cli 4.0.0-preview.2 → 4.0.0-preview.3

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 (63) hide show
  1. package/bin/cicd/cli.d.ts +1 -1
  2. package/bin/cicd/cli.js +3 -1
  3. package/bin/cicd/form.js +5 -4
  4. package/bin/cli.d.ts +1 -5
  5. package/bin/cli.js +56 -6
  6. package/bin/commands/project.commands.js +233 -26
  7. package/bin/containerize/cli.d.ts +1 -1
  8. package/bin/containerize/cli.js +1 -1
  9. package/bin/containerize/form.js +49 -51
  10. package/bin/containerize/generators/ci-generator.js +16 -12
  11. package/bin/containerize/generators/docker-compose-generator.js +3 -2
  12. package/bin/containerize/generators/dockerfile-generator.js +50 -28
  13. package/bin/containerize/generators/kubernetes-generator.js +5 -4
  14. package/bin/costs/cli.d.ts +1 -1
  15. package/bin/costs/cli.js +4 -2
  16. package/bin/dev/cli.d.ts +1 -1
  17. package/bin/dev/cli.js +3 -1
  18. package/bin/generate/cli.d.ts +1 -1
  19. package/bin/generate/templates/nonopinionated/config.tpl +12 -12
  20. package/bin/generate/templates/nonopinionated/event.tpl +10 -10
  21. package/bin/generate/templates/nonopinionated/guard.tpl +18 -18
  22. package/bin/generate/templates/nonopinionated/handler.tpl +12 -12
  23. package/bin/generate/templates/nonopinionated/interceptor.tpl +27 -27
  24. package/bin/generate/templates/opinionated/config.tpl +47 -47
  25. package/bin/generate/templates/opinionated/event.tpl +15 -15
  26. package/bin/generate/templates/opinionated/guard.tpl +41 -41
  27. package/bin/generate/templates/opinionated/handler.tpl +23 -23
  28. package/bin/generate/templates/opinionated/interceptor.tpl +50 -50
  29. package/bin/generate/utils/command-utils.d.ts +13 -2
  30. package/bin/generate/utils/command-utils.js +50 -17
  31. package/bin/generate/utils/opinionated-cmd.js +19 -12
  32. package/bin/help/cli.d.ts +1 -1
  33. package/bin/help/command-help-registry.d.ts +23 -0
  34. package/bin/help/command-help-registry.js +303 -0
  35. package/bin/help/command-help.d.ts +36 -0
  36. package/bin/help/command-help.js +56 -0
  37. package/bin/help/form.js +127 -30
  38. package/bin/help/main-help.d.ts +8 -0
  39. package/bin/help/main-help.js +126 -0
  40. package/bin/help/render.d.ts +32 -0
  41. package/bin/help/render.js +46 -0
  42. package/bin/info/cli.d.ts +1 -1
  43. package/bin/info/form.d.ts +1 -1
  44. package/bin/info/form.js +11 -11
  45. package/bin/migrate/cli.d.ts +1 -1
  46. package/bin/migrate/cli.js +3 -1
  47. package/bin/migrate/form.js +4 -3
  48. package/bin/new/cli.d.ts +5 -1
  49. package/bin/new/cli.js +62 -14
  50. package/bin/new/form.d.ts +3 -1
  51. package/bin/new/form.js +338 -23
  52. package/bin/profile/cli.d.ts +1 -1
  53. package/bin/profile/cli.js +3 -1
  54. package/bin/profile/form.js +5 -4
  55. package/bin/providers/create/form.js +53 -4
  56. package/bin/studio/cli.js +9 -3
  57. package/bin/templates/cli.js +7 -5
  58. package/bin/utils/add-module-to-container.d.ts +14 -3
  59. package/bin/utils/add-module-to-container.js +330 -111
  60. package/bin/utils/cli-ui.d.ts +20 -1
  61. package/bin/utils/cli-ui.js +41 -3
  62. package/bin/utils/update-tsconfig-paths.js +73 -33
  63. package/package.json +22 -13
@@ -51,30 +51,73 @@ function generatePathAlias(folderName) {
51
51
  }
52
52
  exports.generatePathAlias = generatePathAlias;
53
53
  /**
54
- * Parse JSONC (JSON with Comments) by stripping comments and trailing commas
54
+ * Parse JSONC (JSON with Comments) by stripping comments and trailing commas.
55
+ *
56
+ * Implemented as a small character scanner so we are correctly string-aware:
57
+ * comment-delimiter sequences (slash-star and star-slash) inside a JSON
58
+ * string literal — e.g. the very common "src" double-star slash "*.ts"
59
+ * include glob — must NOT be treated as comments. The previous regex-based
60
+ * stripper silently corrupted such globs into `src*.ts`, which then got
61
+ * persisted to disk by the structured rewriter.
62
+ *
55
63
  * Handles:
56
- * - Single-line comments (//)
57
- * - Multi-line comments
58
- * - Trailing commas (common in tsconfig.json)
64
+ * - Line comments (`//` to end of line)
65
+ * - Block comments (may span lines, may also be empty)
66
+ * - Trailing commas before `}` / `]`
67
+ * - JSON string escapes (`\"`, `\\`, etc.)
59
68
  *
60
69
  * @param content - The JSONC content
61
70
  * @returns Cleaned JSON string that can be parsed by JSON.parse
62
71
  */
63
72
  function stripJsonComments(content) {
64
- let result = content;
65
- // Remove multi-line comments first (they can span multiple lines)
66
- result = result.replace(/\/\*[\s\S]*?\*\//g, "");
67
- // Remove single-line comments (but not inside strings)
68
- // This regex looks for // that are not inside strings
69
- result = result.replace(/^(\s*)\/\/.*$/gm, "$1");
70
- // Also handle inline comments after values
71
- // Match: value, // comment or value // comment
72
- result = result.replace(/,\s*\/\/.*$/gm, ",");
73
- result = result.replace(/(["\d\w\]}\s])\s*\/\/.*$/gm, "$1");
74
- // Remove trailing commas before } or ]
75
- // This handles cases like: { "key": "value", }
76
- result = result.replace(/,(\s*[}\]])/g, "$1");
77
- return result;
73
+ let out = "";
74
+ let inString = false;
75
+ let escape = false;
76
+ for (let i = 0; i < content.length; i++) {
77
+ const ch = content[i];
78
+ const next = content[i + 1];
79
+ if (inString) {
80
+ out += ch;
81
+ if (escape) {
82
+ escape = false;
83
+ }
84
+ else if (ch === "\\") {
85
+ escape = true;
86
+ }
87
+ else if (ch === '"') {
88
+ inString = false;
89
+ }
90
+ continue;
91
+ }
92
+ if (ch === '"') {
93
+ inString = true;
94
+ out += ch;
95
+ continue;
96
+ }
97
+ if (ch === "/" && next === "/") {
98
+ // Line comment — skip until newline (newline is preserved).
99
+ i += 2;
100
+ while (i < content.length && content[i] !== "\n")
101
+ i++;
102
+ i--; // Loop will increment past this position.
103
+ continue;
104
+ }
105
+ if (ch === "/" && next === "*") {
106
+ // Block comment — skip until closing */. Replace with a single
107
+ // space so adjacent tokens don't fuse (e.g. `a/*x*/b` -> `a b`).
108
+ i += 2;
109
+ while (i < content.length &&
110
+ !(content[i] === "*" && content[i + 1] === "/")) {
111
+ i++;
112
+ }
113
+ i++; // Consume the closing '*' (loop increments past '/').
114
+ out += " ";
115
+ continue;
116
+ }
117
+ out += ch;
118
+ }
119
+ // Strip trailing commas before `}` / `]` (legal in JSONC, not in JSON).
120
+ return out.replace(/,(\s*[}\]])/g, "$1");
78
121
  }
79
122
  /**
80
123
  * Try to parse JSONC content, first stripping comments then parsing
@@ -122,15 +165,13 @@ function addPathAliasTextBased(content, aliasKey, aliasValue) {
122
165
  // Find compilerOptions to add paths object
123
166
  const compilerOptionsMatch = content.match(/"compilerOptions"\s*:\s*\{/);
124
167
  if (compilerOptionsMatch && compilerOptionsMatch.index !== undefined) {
125
- // Check if baseUrl exists
126
- const hasBaseUrl = /"baseUrl"\s*:/.test(content);
127
- // Find the end of compilerOptions opening brace
168
+ // Find the end of compilerOptions opening brace.
169
+ // We don't inject `baseUrl` here on purpose — `paths` resolve
170
+ // relative to the tsconfig file when `baseUrl` is absent (TS 5+),
171
+ // which matches the v4 template convention.
128
172
  const insertPos = compilerOptionsMatch.index + compilerOptionsMatch[0].length;
129
- let insertion = "\n";
130
- if (!hasBaseUrl) {
131
- insertion += '\t\t"baseUrl": ".",\n';
132
- }
133
- insertion += `\t\t"paths": {\n\t\t\t"${aliasKey}": ${JSON.stringify(aliasValue)}\n\t\t},`;
173
+ const insertion = "\n" +
174
+ `\t\t"paths": {\n\t\t\t"${aliasKey}": ${JSON.stringify(aliasValue)}\n\t\t},`;
134
175
  return (content.slice(0, insertPos) + insertion + content.slice(insertPos));
135
176
  }
136
177
  // Can't find compilerOptions, give up
@@ -170,13 +211,12 @@ async function updateTsconfigPaths(folderName, sourceRoot = "src") {
170
211
  config.compilerOptions = {};
171
212
  }
172
213
  const compilerOptions = config.compilerOptions;
173
- // Ensure baseUrl is set (required for paths to work)
174
- if (!compilerOptions.baseUrl) {
175
- compilerOptions.baseUrl = ".";
176
- }
177
- // Determine the correct path value based on baseUrl
178
- // If baseUrl is "./src" or "src", paths should be relative to src
179
- // If baseUrl is ".", paths should include the full path from root
214
+ // Determine the correct path value based on baseUrl. When
215
+ // `baseUrl` is absent (the TS 7-friendly default the v4
216
+ // templates ship) `paths` resolve relative to the tsconfig
217
+ // file itself — same effective behaviour as `baseUrl: "."`.
218
+ // We deliberately do NOT inject `baseUrl` here; doing so
219
+ // would silently undo the template's intentional removal.
180
220
  const baseUrl = compilerOptions.baseUrl || ".";
181
221
  const isBaseUrlSrc = baseUrl === `./${sourceRoot}` || baseUrl === sourceRoot;
182
222
  const aliasValue = isBaseUrlSrc
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/cli",
3
- "version": "4.0.0-preview.2",
3
+ "version": "4.0.0-preview.3",
4
4
  "description": "Expressots CLI - modern, fast, lightweight nodejs web framework (@cli)",
5
5
  "author": "Richard Zampieri",
6
6
  "license": "MIT",
@@ -41,32 +41,35 @@
41
41
  "clean": "node scripts/rm.js bin",
42
42
  "prepublish": "npm run build && npm pack",
43
43
  "format": "prettier --write \"./src/**/*.ts\" --cache",
44
- "lint": "eslint \"./src/**/*.ts\"",
45
- "lint:fix": "eslint \"./src/**/*.ts\" --fix",
44
+ "lint": "eslint \"./src/**/*.ts\" --cache --cache-location node_modules/.cache/eslint/",
45
+ "lint:fix": "eslint \"./src/**/*.ts\" --fix --cache --cache-location node_modules/.cache/eslint/",
46
46
  "release": "release-it",
47
+ "release:prepare": "node scripts/release/prepare-publish.mjs",
48
+ "release:restore": "node scripts/release/restore-package-json.mjs",
49
+ "release:publish": "npm run build && npm run release:prepare && npm publish --tag next --access public && npm run release:restore",
47
50
  "test": "jest",
48
51
  "coverage": "jest --coverage",
49
52
  "test:watch": "jest --watch"
50
53
  },
51
54
  "dependencies": {
55
+ "@expressots/shared": "^4.0.0-preview.3",
56
+ "chalk": "4.1.2",
52
57
  "cli-progress": "3.12.0",
53
- "cli-table3": "0.6.5",
54
58
  "cross-spawn": "7.0.6",
55
59
  "degit": "2.8.4",
56
60
  "glob": "13.0.6",
57
- "inquirer": "8.2.6",
58
- "mustache": "4.2.0",
59
- "ora": "5.4.1",
61
+ "inquirer": "^8.2.7",
62
+ "mustache": "4.2.0",
63
+ "ora": "5.4.1",
60
64
  "semver": "7.6.3",
61
65
  "ts-node": "10.9.2",
62
66
  "yargs": "17.7.2"
63
67
  },
64
68
  "devDependencies": {
65
- "@codecov/vite-plugin": "0.0.1-beta.9",
69
+ "@codecov/vite-plugin": "^2.0.1",
66
70
  "@commitlint/cli": "19.2.1",
67
71
  "@commitlint/config-conventional": "19.1.0",
68
- "@expressots/shared": "file:../shared/expressots-shared-4.0.0-preview.1.tgz",
69
- "@release-it/conventional-changelog": "7.0.2",
72
+ "@release-it/conventional-changelog": "^11.0.0",
70
73
  "@types/cli-progress": "3.11.0",
71
74
  "@types/cross-spawn": "6.0.6",
72
75
  "@types/degit": "2.8.3",
@@ -77,20 +80,26 @@
77
80
  "@types/yargs": "17.0.22",
78
81
  "@typescript-eslint/eslint-plugin": "7.6.0",
79
82
  "@typescript-eslint/parser": "7.6.0",
80
- "chalk": "4.1.2",
81
83
  "eslint": "8.57.0",
82
84
  "eslint-config-prettier": "9.1.0",
83
85
  "husky": "9.0.11",
84
86
  "jest": "^29.7.0",
87
+ "lint-staged": "^15.2.10",
85
88
  "prettier": "3.2.5",
86
89
  "reflect-metadata": "0.2.2",
87
- "release-it": "16.3.0",
90
+ "release-it": "^20.0.1",
88
91
  "shx": "0.3.4",
89
92
  "ts-jest": "^29.2.5",
90
93
  "tsx": "^4.19.2",
91
94
  "typescript": "5.2.2"
92
95
  },
93
- "release-it": {
96
+ "lint-staged": {
97
+ "src/**/*.ts": [
98
+ "eslint --cache --cache-location node_modules/.cache/eslint/ --fix",
99
+ "prettier --write --cache"
100
+ ]
101
+ },
102
+ "release-it": {
94
103
  "git": {
95
104
  "commitMessage": "chore: release ${version}"
96
105
  },