@objectstack/cli 4.0.4 → 4.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 (269) hide show
  1. package/README.md +44 -25
  2. package/dist/commands/build.d.ts +5 -0
  3. package/dist/commands/build.d.ts.map +1 -0
  4. package/dist/commands/build.js +6 -0
  5. package/dist/commands/build.js.map +1 -0
  6. package/dist/commands/cloud/login.d.ts +16 -0
  7. package/dist/commands/cloud/login.d.ts.map +1 -0
  8. package/dist/commands/cloud/login.js +166 -0
  9. package/dist/commands/cloud/login.js.map +1 -0
  10. package/dist/commands/cloud/logout.d.ts +15 -0
  11. package/dist/commands/cloud/logout.d.ts.map +1 -0
  12. package/dist/commands/cloud/logout.js +51 -0
  13. package/dist/commands/cloud/logout.js.map +1 -0
  14. package/dist/commands/cloud/whoami.d.ts +15 -0
  15. package/dist/commands/cloud/whoami.d.ts.map +1 -0
  16. package/dist/commands/cloud/whoami.js +81 -0
  17. package/dist/commands/cloud/whoami.js.map +1 -0
  18. package/dist/commands/compile.d.ts +3 -0
  19. package/dist/commands/compile.d.ts.map +1 -1
  20. package/dist/commands/compile.js +128 -6
  21. package/dist/commands/compile.js.map +1 -1
  22. package/dist/commands/create.js +1 -1
  23. package/dist/commands/data/create.js +2 -2
  24. package/dist/commands/data/create.js.map +1 -1
  25. package/dist/commands/data/delete.js +2 -2
  26. package/dist/commands/data/delete.js.map +1 -1
  27. package/dist/commands/data/get.js +2 -2
  28. package/dist/commands/data/get.js.map +1 -1
  29. package/dist/commands/data/query.js +2 -2
  30. package/dist/commands/data/query.js.map +1 -1
  31. package/dist/commands/data/update.js +2 -2
  32. package/dist/commands/data/update.js.map +1 -1
  33. package/dist/commands/dev.d.ts +9 -0
  34. package/dist/commands/dev.d.ts.map +1 -1
  35. package/dist/commands/dev.js +116 -22
  36. package/dist/commands/dev.js.map +1 -1
  37. package/dist/commands/generate.js +9 -9
  38. package/dist/commands/generate.js.map +1 -1
  39. package/dist/commands/i18n/check.d.ts +18 -0
  40. package/dist/commands/i18n/check.d.ts.map +1 -0
  41. package/dist/commands/i18n/check.js +153 -0
  42. package/dist/commands/i18n/check.js.map +1 -0
  43. package/dist/commands/init.js +2 -2
  44. package/dist/commands/lint.d.ts +3 -0
  45. package/dist/commands/lint.d.ts.map +1 -1
  46. package/dist/commands/lint.js +24 -0
  47. package/dist/commands/lint.js.map +1 -1
  48. package/dist/commands/login.d.ts +17 -0
  49. package/dist/commands/login.d.ts.map +1 -0
  50. package/dist/commands/login.js +313 -0
  51. package/dist/commands/login.js.map +1 -0
  52. package/dist/commands/logout.d.ts.map +1 -0
  53. package/dist/commands/{auth/logout.js → logout.js} +14 -2
  54. package/dist/commands/logout.js.map +1 -0
  55. package/dist/commands/meta/delete.js +2 -2
  56. package/dist/commands/meta/delete.js.map +1 -1
  57. package/dist/commands/meta/get.js +2 -2
  58. package/dist/commands/meta/get.js.map +1 -1
  59. package/dist/commands/meta/list.js +2 -2
  60. package/dist/commands/meta/list.js.map +1 -1
  61. package/dist/commands/meta/register.js +2 -2
  62. package/dist/commands/meta/register.js.map +1 -1
  63. package/dist/commands/package/publish.d.ts +32 -0
  64. package/dist/commands/package/publish.d.ts.map +1 -0
  65. package/dist/commands/package/publish.js +324 -0
  66. package/dist/commands/package/publish.js.map +1 -0
  67. package/dist/commands/projects/bind.d.ts +30 -0
  68. package/dist/commands/projects/bind.d.ts.map +1 -0
  69. package/dist/commands/projects/bind.js +132 -0
  70. package/dist/commands/projects/bind.js.map +1 -0
  71. package/dist/commands/projects/create.d.ts +28 -0
  72. package/dist/commands/projects/create.d.ts.map +1 -0
  73. package/dist/commands/projects/create.js +120 -0
  74. package/dist/commands/projects/create.js.map +1 -0
  75. package/dist/commands/projects/list.d.ts +21 -0
  76. package/dist/commands/projects/list.d.ts.map +1 -0
  77. package/dist/commands/projects/list.js +79 -0
  78. package/dist/commands/projects/list.js.map +1 -0
  79. package/dist/commands/projects/projects.test.d.ts +2 -0
  80. package/dist/commands/projects/projects.test.d.ts.map +1 -0
  81. package/dist/commands/projects/projects.test.js +56 -0
  82. package/dist/commands/projects/projects.test.js.map +1 -0
  83. package/dist/commands/projects/show.d.ts +21 -0
  84. package/dist/commands/projects/show.d.ts.map +1 -0
  85. package/dist/commands/projects/show.js +72 -0
  86. package/dist/commands/projects/show.js.map +1 -0
  87. package/dist/commands/projects/switch.d.ts +24 -0
  88. package/dist/commands/projects/switch.d.ts.map +1 -0
  89. package/dist/commands/projects/switch.js +64 -0
  90. package/dist/commands/projects/switch.js.map +1 -0
  91. package/dist/commands/publish.d.ts +17 -0
  92. package/dist/commands/publish.d.ts.map +1 -0
  93. package/dist/commands/publish.js +135 -0
  94. package/dist/commands/publish.js.map +1 -0
  95. package/dist/commands/{auth/login.d.ts → register.d.ts} +3 -2
  96. package/dist/commands/register.d.ts.map +1 -0
  97. package/dist/commands/{auth/login.js → register.js} +44 -61
  98. package/dist/commands/register.js.map +1 -0
  99. package/dist/commands/rollback.d.ts +13 -0
  100. package/dist/commands/rollback.d.ts.map +1 -0
  101. package/dist/commands/rollback.js +77 -0
  102. package/dist/commands/rollback.js.map +1 -0
  103. package/dist/commands/serve.d.ts +22 -0
  104. package/dist/commands/serve.d.ts.map +1 -1
  105. package/dist/commands/serve.js +1173 -58
  106. package/dist/commands/serve.js.map +1 -1
  107. package/dist/commands/start.d.ts +18 -0
  108. package/dist/commands/start.d.ts.map +1 -0
  109. package/dist/commands/start.js +112 -0
  110. package/dist/commands/start.js.map +1 -0
  111. package/dist/commands/whoami.d.ts.map +1 -0
  112. package/dist/commands/{auth/whoami.js → whoami.js} +5 -5
  113. package/dist/commands/whoami.js.map +1 -0
  114. package/dist/index.d.ts +11 -4
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +14 -5
  117. package/dist/index.js.map +1 -1
  118. package/dist/utils/account.d.ts +31 -0
  119. package/dist/utils/account.d.ts.map +1 -0
  120. package/dist/utils/account.js +154 -0
  121. package/dist/utils/account.js.map +1 -0
  122. package/dist/utils/api-client.d.ts +10 -4
  123. package/dist/utils/api-client.d.ts.map +1 -1
  124. package/dist/utils/api-client.js +13 -7
  125. package/dist/utils/api-client.js.map +1 -1
  126. package/dist/utils/auth-config.d.ts +6 -0
  127. package/dist/utils/auth-config.d.ts.map +1 -1
  128. package/dist/utils/auth-config.js.map +1 -1
  129. package/dist/utils/auth-flows.d.ts +31 -0
  130. package/dist/utils/auth-flows.d.ts.map +1 -0
  131. package/dist/utils/auth-flows.js +151 -0
  132. package/dist/utils/auth-flows.js.map +1 -0
  133. package/dist/utils/build-runtime.d.ts +45 -0
  134. package/dist/utils/build-runtime.d.ts.map +1 -0
  135. package/dist/utils/build-runtime.js +154 -0
  136. package/dist/utils/build-runtime.js.map +1 -0
  137. package/dist/utils/cloud-config.d.ts +24 -0
  138. package/dist/utils/cloud-config.d.ts.map +1 -0
  139. package/dist/utils/cloud-config.js +75 -0
  140. package/dist/utils/cloud-config.js.map +1 -0
  141. package/dist/utils/config.d.ts.map +1 -1
  142. package/dist/utils/config.js +17 -2
  143. package/dist/utils/config.js.map +1 -1
  144. package/dist/utils/console.d.ts +33 -0
  145. package/dist/utils/console.d.ts.map +1 -0
  146. package/dist/utils/console.js +172 -0
  147. package/dist/utils/console.js.map +1 -0
  148. package/dist/utils/extract-hook-body.d.ts +13 -0
  149. package/dist/utils/extract-hook-body.d.ts.map +1 -0
  150. package/dist/utils/extract-hook-body.js +175 -0
  151. package/dist/utils/extract-hook-body.js.map +1 -0
  152. package/dist/utils/format.d.ts +8 -0
  153. package/dist/utils/format.d.ts.map +1 -1
  154. package/dist/utils/format.js +15 -2
  155. package/dist/utils/format.js.map +1 -1
  156. package/dist/utils/i18n-coverage.d.ts +61 -0
  157. package/dist/utils/i18n-coverage.d.ts.map +1 -0
  158. package/dist/utils/i18n-coverage.js +176 -0
  159. package/dist/utils/i18n-coverage.js.map +1 -0
  160. package/dist/utils/lower-callables.d.ts +17 -0
  161. package/dist/utils/lower-callables.d.ts.map +1 -0
  162. package/dist/utils/lower-callables.js +181 -0
  163. package/dist/utils/lower-callables.js.map +1 -0
  164. package/dist/utils/plugin-detection.d.ts +1 -0
  165. package/dist/utils/plugin-detection.d.ts.map +1 -1
  166. package/dist/utils/plugin-detection.js +41 -0
  167. package/dist/utils/plugin-detection.js.map +1 -1
  168. package/dist/utils/studio.d.ts +1 -0
  169. package/dist/utils/studio.d.ts.map +1 -1
  170. package/dist/utils/studio.js +24 -9
  171. package/dist/utils/studio.js.map +1 -1
  172. package/package.json +60 -22
  173. package/.turbo/turbo-build.log +0 -4
  174. package/CHANGELOG.md +0 -821
  175. package/bin/run-dev.js +0 -5
  176. package/dist/commands/auth/login.d.ts.map +0 -1
  177. package/dist/commands/auth/login.js.map +0 -1
  178. package/dist/commands/auth/logout.d.ts.map +0 -1
  179. package/dist/commands/auth/logout.js.map +0 -1
  180. package/dist/commands/auth/whoami.d.ts.map +0 -1
  181. package/dist/commands/auth/whoami.js.map +0 -1
  182. package/dist/commands/codemod/v2-to-v3.d.ts +0 -10
  183. package/dist/commands/codemod/v2-to-v3.d.ts.map +0 -1
  184. package/dist/commands/codemod/v2-to-v3.js +0 -145
  185. package/dist/commands/codemod/v2-to-v3.js.map +0 -1
  186. package/dist/commands/plugin/add.d.ts +0 -22
  187. package/dist/commands/plugin/add.d.ts.map +0 -1
  188. package/dist/commands/plugin/add.js +0 -93
  189. package/dist/commands/plugin/add.js.map +0 -1
  190. package/dist/commands/plugin/build.d.ts +0 -29
  191. package/dist/commands/plugin/build.d.ts.map +0 -1
  192. package/dist/commands/plugin/build.js +0 -170
  193. package/dist/commands/plugin/build.js.map +0 -1
  194. package/dist/commands/plugin/info.d.ts +0 -10
  195. package/dist/commands/plugin/info.d.ts.map +0 -1
  196. package/dist/commands/plugin/info.js +0 -65
  197. package/dist/commands/plugin/info.js.map +0 -1
  198. package/dist/commands/plugin/list.d.ts +0 -13
  199. package/dist/commands/plugin/list.d.ts.map +0 -1
  200. package/dist/commands/plugin/list.js +0 -78
  201. package/dist/commands/plugin/list.js.map +0 -1
  202. package/dist/commands/plugin/publish.d.ts +0 -27
  203. package/dist/commands/plugin/publish.d.ts.map +0 -1
  204. package/dist/commands/plugin/publish.js +0 -152
  205. package/dist/commands/plugin/publish.js.map +0 -1
  206. package/dist/commands/plugin/remove.d.ts +0 -20
  207. package/dist/commands/plugin/remove.d.ts.map +0 -1
  208. package/dist/commands/plugin/remove.js +0 -79
  209. package/dist/commands/plugin/remove.js.map +0 -1
  210. package/dist/commands/plugin/validate.d.ts +0 -23
  211. package/dist/commands/plugin/validate.d.ts.map +0 -1
  212. package/dist/commands/plugin/validate.js +0 -251
  213. package/dist/commands/plugin/validate.js.map +0 -1
  214. package/src/bin.ts +0 -13
  215. package/src/commands/auth/login.ts +0 -188
  216. package/src/commands/auth/logout.ts +0 -51
  217. package/src/commands/auth/whoami.ts +0 -85
  218. package/src/commands/codemod/v2-to-v3.ts +0 -171
  219. package/src/commands/compile.ts +0 -114
  220. package/src/commands/create.ts +0 -281
  221. package/src/commands/data/create.ts +0 -110
  222. package/src/commands/data/delete.ts +0 -84
  223. package/src/commands/data/get.ts +0 -84
  224. package/src/commands/data/query.ts +0 -127
  225. package/src/commands/data/update.ts +0 -114
  226. package/src/commands/dev.ts +0 -83
  227. package/src/commands/diff.ts +0 -294
  228. package/src/commands/doctor.ts +0 -572
  229. package/src/commands/explain.ts +0 -412
  230. package/src/commands/generate.ts +0 -924
  231. package/src/commands/info.ts +0 -124
  232. package/src/commands/init.ts +0 -327
  233. package/src/commands/lint.ts +0 -315
  234. package/src/commands/meta/delete.ts +0 -79
  235. package/src/commands/meta/get.ts +0 -73
  236. package/src/commands/meta/list.ts +0 -105
  237. package/src/commands/meta/register.ts +0 -97
  238. package/src/commands/plugin/add.ts +0 -112
  239. package/src/commands/plugin/build.ts +0 -193
  240. package/src/commands/plugin/info.ts +0 -79
  241. package/src/commands/plugin/list.ts +0 -93
  242. package/src/commands/plugin/publish.ts +0 -176
  243. package/src/commands/plugin/remove.ts +0 -97
  244. package/src/commands/plugin/validate.ts +0 -268
  245. package/src/commands/serve.ts +0 -411
  246. package/src/commands/studio.ts +0 -52
  247. package/src/commands/test.ts +0 -135
  248. package/src/commands/validate.ts +0 -143
  249. package/src/index.ts +0 -22
  250. package/src/utils/api-client.ts +0 -88
  251. package/src/utils/auth-config.ts +0 -107
  252. package/src/utils/config.ts +0 -80
  253. package/src/utils/format.ts +0 -267
  254. package/src/utils/output-formatter.ts +0 -91
  255. package/src/utils/plugin-detection.ts +0 -16
  256. package/src/utils/plugin-helpers.ts +0 -37
  257. package/src/utils/studio.ts +0 -350
  258. package/test/commands.test.ts +0 -128
  259. package/test/create.test.ts +0 -25
  260. package/test/plugin-commands.test.ts +0 -44
  261. package/test/plugin.test.ts +0 -169
  262. package/test/remote-api-commands.test.ts +0 -188
  263. package/test/remote-api-utils.test.ts +0 -196
  264. package/test/serve-host-config.test.ts +0 -77
  265. package/tsconfig.build.json +0 -20
  266. package/tsconfig.json +0 -25
  267. package/tsup.config.ts +0 -23
  268. /package/dist/commands/{auth/logout.d.ts → logout.d.ts} +0 -0
  269. /package/dist/commands/{auth/whoami.d.ts → whoami.d.ts} +0 -0
@@ -1,572 +0,0 @@
1
- // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2
-
3
- import { Command, Flags } from '@oclif/core';
4
- import chalk from 'chalk';
5
- import { execSync } from 'child_process';
6
- import fs from 'fs';
7
- import path from 'path';
8
- import { normalizeStackInput } from '@objectstack/spec';
9
- import { printHeader, printSuccess, printWarning, printError, printStep, printInfo } from '../utils/format.js';
10
- import { loadConfig, configExists } from '../utils/config.js';
11
-
12
- interface HealthCheckResult {
13
- name: string;
14
- status: 'ok' | 'warning' | 'error';
15
- message: string;
16
- fix?: string;
17
- }
18
-
19
- // ─── Config-Aware Checks ────────────────────────────────────────────
20
-
21
- function detectCircularDependencies(objects: any[]): string[] {
22
- const issues: string[] = [];
23
- const graph = new Map<string, string[]>();
24
-
25
- for (const obj of objects) {
26
- const deps: string[] = [];
27
- if (obj.fields && typeof obj.fields === 'object') {
28
- for (const field of Object.values(obj.fields) as any[]) {
29
- if (field?.type === 'lookup' && field?.reference) {
30
- deps.push(field.reference);
31
- }
32
- }
33
- }
34
- graph.set(obj.name, deps);
35
- }
36
-
37
- // DFS cycle detection
38
- const visited = new Set<string>();
39
- const stack = new Set<string>();
40
-
41
- function dfs(node: string, path: string[]): boolean {
42
- if (stack.has(node)) {
43
- const cycleStart = path.indexOf(node);
44
- const cycle = path.slice(cycleStart).concat(node);
45
- issues.push(`Circular dependency: ${cycle.join(' → ')}`);
46
- return true;
47
- }
48
- if (visited.has(node)) return false;
49
-
50
- visited.add(node);
51
- stack.add(node);
52
-
53
- for (const dep of graph.get(node) || []) {
54
- if (graph.has(dep)) {
55
- dfs(dep, [...path, node]);
56
- }
57
- }
58
-
59
- stack.delete(node);
60
- return false;
61
- }
62
-
63
- for (const name of graph.keys()) {
64
- if (!visited.has(name)) {
65
- dfs(name, []);
66
- }
67
- }
68
-
69
- return issues;
70
- }
71
-
72
- function findOrphanViews(config: any): string[] {
73
- const objectNames = new Set<string>();
74
- if (Array.isArray(config.objects)) {
75
- for (const obj of config.objects) {
76
- if (obj.name) objectNames.add(obj.name);
77
- }
78
- }
79
-
80
- const orphans: string[] = [];
81
- if (Array.isArray(config.views)) {
82
- for (const view of config.views) {
83
- if (view.object && !objectNames.has(view.object)) {
84
- orphans.push(`View "${view.name || '?'}" references non-existent object "${view.object}"`);
85
- }
86
- }
87
- }
88
- return orphans;
89
- }
90
-
91
- function findUnusedObjects(config: any): string[] {
92
- const objectNames = new Set<string>();
93
- if (Array.isArray(config.objects)) {
94
- for (const obj of config.objects) {
95
- if (obj.name) objectNames.add(obj.name);
96
- }
97
- }
98
-
99
- const referencedObjects = new Set<string>();
100
-
101
- // Views reference objects
102
- if (Array.isArray(config.views)) {
103
- for (const view of config.views) {
104
- if (view.object) referencedObjects.add(view.object);
105
- }
106
- }
107
-
108
- // Flows may reference objects via trigger
109
- if (Array.isArray(config.flows)) {
110
- for (const flow of config.flows) {
111
- if (flow.trigger?.object) referencedObjects.add(flow.trigger.object);
112
- if (flow.object) referencedObjects.add(flow.object);
113
- }
114
- }
115
-
116
- // Apps may reference objects via navigation
117
- if (Array.isArray(config.apps)) {
118
- for (const app of config.apps) {
119
- if (Array.isArray(app.navigation)) {
120
- for (const nav of app.navigation) {
121
- if (nav.object) referencedObjects.add(nav.object);
122
- }
123
- }
124
- }
125
- }
126
-
127
- // Agents may reference objects
128
- if (Array.isArray(config.agents)) {
129
- for (const agent of config.agents) {
130
- if (Array.isArray(agent.objects)) {
131
- for (const o of agent.objects) referencedObjects.add(o);
132
- }
133
- }
134
- }
135
-
136
- // Lookup fields reference other objects
137
- if (Array.isArray(config.objects)) {
138
- for (const obj of config.objects) {
139
- if (obj.fields && typeof obj.fields === 'object') {
140
- for (const field of Object.values(obj.fields) as any[]) {
141
- if (field?.type === 'lookup' && field?.reference) {
142
- referencedObjects.add(field.reference);
143
- }
144
- }
145
- }
146
- }
147
- }
148
-
149
- const unused: string[] = [];
150
- for (const name of objectNames) {
151
- if (!referencedObjects.has(name)) {
152
- unused.push(`Object "${name}" is defined but not referenced by any view, flow, app, or agent`);
153
- }
154
- }
155
- return unused;
156
- }
157
-
158
- // ─── Filesystem Checks ──────────────────────────────────────────────
159
-
160
- function walkDir(dir: string, ext: string): string[] {
161
- const results: string[] = [];
162
- if (!fs.existsSync(dir)) return results;
163
-
164
- const entries = fs.readdirSync(dir, { withFileTypes: true });
165
- for (const entry of entries) {
166
- if (entry.name === 'node_modules') continue;
167
- const fullPath = path.join(dir, entry.name);
168
- if (entry.isDirectory()) {
169
- results.push(...walkDir(fullPath, ext));
170
- } else if (entry.name.endsWith(ext)) {
171
- results.push(fullPath);
172
- }
173
- }
174
- return results;
175
- }
176
-
177
- function findMissingTests(cwd: string): string[] {
178
- const specSrcDir = path.join(cwd, 'packages/spec/src');
179
- if (!fs.existsSync(specSrcDir)) return [];
180
-
181
- const missing: string[] = [];
182
- const zodFiles = walkDir(specSrcDir, '.zod.ts');
183
-
184
- for (const zodFile of zodFiles) {
185
- const testFile = zodFile.replace('.zod.ts', '.test.ts');
186
- if (!fs.existsSync(testFile)) {
187
- const relZod = path.relative(specSrcDir, zodFile);
188
- const relTest = path.relative(specSrcDir, testFile);
189
- missing.push(`Missing test: ${relTest} (for ${relZod})`);
190
- }
191
- }
192
- return missing;
193
- }
194
-
195
- function findDeprecatedUsages(cwd: string): string[] {
196
- const specSrcDir = path.join(cwd, 'packages/spec/src');
197
- if (!fs.existsSync(specSrcDir)) return [];
198
-
199
- const deprecated: string[] = [];
200
- const tsFiles = walkDir(specSrcDir, '.ts')
201
- .filter((f) => !f.endsWith('.test.ts'));
202
-
203
- for (const tsFile of tsFiles) {
204
- try {
205
- const content = fs.readFileSync(tsFile, 'utf-8');
206
- const lines = content.split('\n');
207
- const relPath = path.relative(specSrcDir, tsFile);
208
- for (let i = 0; i < lines.length; i++) {
209
- if (lines[i].includes('@deprecated')) {
210
- deprecated.push(`${relPath}:${i + 1} — @deprecated tag found`);
211
- }
212
- }
213
- } catch {
214
- // Skip unreadable files
215
- }
216
- }
217
- return deprecated;
218
- }
219
-
220
- // ─── Deprecated Pattern Detection ───────────────────────────────────
221
-
222
- const DEPRECATED_PATTERNS: Array<{
223
- pattern: RegExp;
224
- description: string;
225
- replacement: string;
226
- }> = [
227
- {
228
- pattern: /\bEnhancedObjectKernel\b/,
229
- description: 'EnhancedObjectKernel is deprecated in v3',
230
- replacement: 'Use ObjectKernel instead',
231
- },
232
- {
233
- pattern: /\bmax_length\b/,
234
- description: 'snake_case config key: max_length',
235
- replacement: 'Use maxLength (camelCase)',
236
- },
237
- {
238
- pattern: /\bdefault_value\b/,
239
- description: 'snake_case config key: default_value',
240
- replacement: 'Use defaultValue (camelCase)',
241
- },
242
- {
243
- pattern: /\bmin_length\b/,
244
- description: 'snake_case config key: min_length',
245
- replacement: 'Use minLength (camelCase)',
246
- },
247
- {
248
- pattern: /\breference_filters\b/,
249
- description: 'snake_case config key: reference_filters',
250
- replacement: 'Use referenceFilters (camelCase)',
251
- },
252
- {
253
- pattern: /\bunique_name\b/,
254
- description: 'snake_case config key: unique_name',
255
- replacement: 'Use uniqueName (camelCase)',
256
- },
257
- {
258
- pattern: /from\s+['"]@objectstack\/core\/enhanced['"]/,
259
- description: 'Import from deprecated @objectstack/core/enhanced path',
260
- replacement: "Use import from '@objectstack/core'",
261
- },
262
- {
263
- pattern: /from\s+['"]@objectstack\/spec\/dist\/[^'"]+['"]/,
264
- description: 'Import from deprecated @objectstack/spec/dist/ deep path',
265
- replacement: "Use import from '@objectstack/spec'",
266
- },
267
- ];
268
-
269
- function scanDeprecatedPatterns(dir: string): Array<{ file: string; line: number; description: string; replacement: string }> {
270
- const results: Array<{ file: string; line: number; description: string; replacement: string }> = [];
271
- if (!fs.existsSync(dir)) return results;
272
-
273
- const tsFiles = walkDir(dir, '.ts').filter(f => !f.endsWith('.test.ts'));
274
-
275
- for (const tsFile of tsFiles) {
276
- try {
277
- const content = fs.readFileSync(tsFile, 'utf-8');
278
- const lines = content.split('\n');
279
- const relPath = path.relative(process.cwd(), tsFile);
280
-
281
- for (let i = 0; i < lines.length; i++) {
282
- for (const dp of DEPRECATED_PATTERNS) {
283
- if (dp.pattern.test(lines[i])) {
284
- results.push({
285
- file: relPath,
286
- line: i + 1,
287
- description: dp.description,
288
- replacement: dp.replacement,
289
- });
290
- }
291
- }
292
- }
293
- } catch {
294
- // Skip unreadable files
295
- }
296
- }
297
- return results;
298
- }
299
-
300
- // ─── Command ────────────────────────────────────────────────────────
301
-
302
- export default class Doctor extends Command {
303
- static override description = 'Check development environment and configuration health';
304
-
305
- static override flags = {
306
- verbose: Flags.boolean({ char: 'v', description: 'Show detailed information' }),
307
- 'scan-deprecations': Flags.boolean({ description: 'Scan for deprecated ObjectStack patterns' }),
308
- };
309
-
310
- async run(): Promise<void> {
311
- const { flags } = await this.parse(Doctor);
312
-
313
- printHeader('Environment Health Check');
314
-
315
- const results: HealthCheckResult[] = [];
316
-
317
- // Check Node.js version
318
- try {
319
- const nodeVersion = process.version;
320
- const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]);
321
-
322
- if (majorVersion >= 18) {
323
- results.push({
324
- name: 'Node.js',
325
- status: 'ok',
326
- message: `Version ${nodeVersion}`,
327
- });
328
- } else {
329
- results.push({
330
- name: 'Node.js',
331
- status: 'error',
332
- message: `Version ${nodeVersion} (requires >= 18.0.0)`,
333
- fix: 'Upgrade Node.js: https://nodejs.org',
334
- });
335
- }
336
- } catch (error) {
337
- results.push({
338
- name: 'Node.js',
339
- status: 'error',
340
- message: 'Not found',
341
- fix: 'Install Node.js: https://nodejs.org',
342
- });
343
- }
344
-
345
- // Check pnpm
346
- try {
347
- const pnpmVersion = execSync('pnpm -v', { encoding: 'utf-8' }).trim();
348
- results.push({
349
- name: 'pnpm',
350
- status: 'ok',
351
- message: `Version ${pnpmVersion}`,
352
- });
353
- } catch (error) {
354
- results.push({
355
- name: 'pnpm',
356
- status: 'error',
357
- message: 'Not found',
358
- fix: 'Install pnpm: npm install -g pnpm@10.28.1',
359
- });
360
- }
361
-
362
- // Check TypeScript
363
- try {
364
- const tscVersion = execSync('tsc -v', { encoding: 'utf-8' }).trim();
365
- results.push({
366
- name: 'TypeScript',
367
- status: 'ok',
368
- message: tscVersion,
369
- });
370
- } catch (error) {
371
- results.push({
372
- name: 'TypeScript',
373
- status: 'warning',
374
- message: 'Not found in PATH',
375
- fix: 'Installed locally via pnpm',
376
- });
377
- }
378
-
379
- // Check if dependencies are installed
380
- const cwd = process.cwd();
381
- const nodeModulesPath = path.join(cwd, 'node_modules');
382
-
383
- if (fs.existsSync(nodeModulesPath)) {
384
- results.push({
385
- name: 'Dependencies',
386
- status: 'ok',
387
- message: 'Installed',
388
- });
389
- } else {
390
- results.push({
391
- name: 'Dependencies',
392
- status: 'error',
393
- message: 'Not installed',
394
- fix: 'Run: pnpm install',
395
- });
396
- }
397
-
398
- // Check if spec package is built
399
- const specDistPath = path.join(cwd, 'packages/spec/dist');
400
-
401
- if (fs.existsSync(specDistPath)) {
402
- results.push({
403
- name: '@objectstack/spec',
404
- status: 'ok',
405
- message: 'Built',
406
- });
407
- } else {
408
- results.push({
409
- name: '@objectstack/spec',
410
- status: 'warning',
411
- message: 'Not built',
412
- fix: 'Run: pnpm --filter @objectstack/spec build',
413
- });
414
- }
415
-
416
- // Check Git
417
- try {
418
- const gitVersion = execSync('git --version', { encoding: 'utf-8' }).trim();
419
- results.push({
420
- name: 'Git',
421
- status: 'ok',
422
- message: gitVersion,
423
- });
424
- } catch (error) {
425
- results.push({
426
- name: 'Git',
427
- status: 'warning',
428
- message: 'Not found',
429
- fix: 'Install Git for version control',
430
- });
431
- }
432
-
433
- // Display environment results
434
- let hasErrors = false;
435
- let hasWarnings = false;
436
-
437
- console.log('');
438
- results.forEach((result) => {
439
- const padded = result.name.padEnd(20);
440
- if (result.status === 'ok') {
441
- printSuccess(`${padded} ${result.message}`);
442
- } else if (result.status === 'warning') {
443
- printWarning(`${padded} ${result.message}`);
444
- } else {
445
- printError(`${padded} ${result.message}`);
446
- }
447
-
448
- if (result.fix && (flags.verbose || result.status === 'error')) {
449
- console.log(chalk.dim(` → ${result.fix}`));
450
- }
451
-
452
- if (result.status === 'error') hasErrors = true;
453
- if (result.status === 'warning') hasWarnings = true;
454
- });
455
-
456
- // ── Extended Checks ──────────────────────────────────────────────
457
-
458
- // Missing test files
459
- printStep('Checking for missing test files...');
460
- const missingTests = findMissingTests(cwd);
461
- if (missingTests.length > 0) {
462
- hasWarnings = true;
463
- for (const msg of missingTests) {
464
- printWarning(msg);
465
- }
466
- } else {
467
- printSuccess('Test coverage All *.zod.ts files have matching tests');
468
- }
469
-
470
- // Deprecated usage detection
471
- printStep('Scanning for @deprecated usage...');
472
- const deprecatedUsages = findDeprecatedUsages(cwd);
473
- if (deprecatedUsages.length > 0) {
474
- hasWarnings = true;
475
- for (const msg of deprecatedUsages) {
476
- printWarning(`Deprecated: ${msg}`);
477
- }
478
- } else {
479
- printSuccess('Deprecations No @deprecated tags found');
480
- }
481
-
482
- // Config-aware checks (only if config exists)
483
- if (configExists()) {
484
- printStep('Loading configuration for analysis...');
485
- try {
486
- const { config: rawConfig } = await loadConfig();
487
- const config: any = normalizeStackInput(rawConfig as Record<string, unknown>);
488
-
489
- // Circular dependency detection
490
- if (Array.isArray(config.objects) && config.objects.length > 0) {
491
- printStep('Checking for circular dependencies...');
492
- const cycles = detectCircularDependencies(config.objects);
493
- if (cycles.length > 0) {
494
- hasWarnings = true;
495
- for (const msg of cycles) {
496
- printWarning(msg);
497
- }
498
- } else {
499
- printSuccess('Dependencies No circular references detected');
500
- }
501
-
502
- // Unused objects
503
- printStep('Checking for unused objects...');
504
- const unused = findUnusedObjects(config);
505
- if (unused.length > 0) {
506
- hasWarnings = true;
507
- for (const msg of unused) {
508
- printWarning(msg);
509
- }
510
- } else {
511
- printSuccess('Object usage All objects are referenced');
512
- }
513
- }
514
-
515
- // Orphan views
516
- if (Array.isArray(config.views) && config.views.length > 0) {
517
- printStep('Checking for orphan views...');
518
- const orphans = findOrphanViews(config);
519
- if (orphans.length > 0) {
520
- hasWarnings = true;
521
- for (const msg of orphans) {
522
- printWarning(msg);
523
- }
524
- } else {
525
- printSuccess('View integrity All views reference valid objects');
526
- }
527
- }
528
- } catch {
529
- printWarning('Could not load config for analysis (config checks skipped)');
530
- hasWarnings = true;
531
- }
532
- }
533
-
534
- // ── Deprecation Pattern Scan ─────────────────────────────────────
535
- if (flags['scan-deprecations']) {
536
- printStep('Scanning for deprecated ObjectStack patterns...');
537
- const scanDir = path.join(cwd, 'src');
538
- const deprecations = scanDeprecatedPatterns(scanDir);
539
- if (deprecations.length > 0) {
540
- hasWarnings = true;
541
- for (const dep of deprecations) {
542
- printWarning(`${dep.file}:${dep.line} — ${dep.description}`);
543
- if (flags.verbose) {
544
- console.log(chalk.dim(` → ${dep.replacement}`));
545
- }
546
- }
547
- console.log('');
548
- printInfo(`Found ${deprecations.length} deprecated pattern(s). Run \`objectstack codemod v2-to-v3\` to auto-fix.`);
549
- } else {
550
- printSuccess('Deprecation scan No deprecated patterns found');
551
- }
552
- }
553
-
554
- console.log('');
555
-
556
- // Summary
557
- if (hasErrors) {
558
- console.log(chalk.red('❌ Some critical issues found. Please fix them before continuing.'));
559
- results
560
- .filter(r => r.status === 'error' && r.fix)
561
- .forEach(r => console.log(chalk.dim(` ${r.fix}`)));
562
- process.exit(1);
563
- } else if (hasWarnings) {
564
- console.log(chalk.yellow('⚠️ Environment is functional but has some warnings.'));
565
- console.log(chalk.dim(' Run with --verbose to see fix suggestions.'));
566
- } else {
567
- console.log(chalk.green('✅ Environment is healthy and ready for development!'));
568
- }
569
-
570
- console.log('');
571
- }
572
- }