@mondaydotcomorg/z2h-cli 0.15.0 → 0.15.2-feat-eitantsh-z2h-admin-panel-package-388aad6
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/dist/commands/build.d.ts +0 -1
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +0 -3
- package/dist/commands/clean.d.ts +1 -4
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +1 -4
- package/dist/commands/create-workspace.d.ts +1 -4
- package/dist/commands/create-workspace.d.ts.map +1 -1
- package/dist/commands/create-workspace.js +1 -4
- package/dist/commands/create.d.ts +0 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +0 -3
- package/dist/commands/delete.d.ts +0 -1
- package/dist/commands/delete.d.ts.map +1 -1
- package/dist/commands/delete.js +1 -4
- package/dist/commands/deploy.d.ts +0 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +4 -7
- package/dist/commands/dev.d.ts +0 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +0 -3
- package/dist/commands/doctor.d.ts +1 -4
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +2 -5
- package/dist/commands/edit.d.ts +1 -4
- package/dist/commands/edit.d.ts.map +1 -1
- package/dist/commands/edit.js +1 -4
- package/dist/commands/generate-z2h-token.d.ts +0 -1
- package/dist/commands/generate-z2h-token.d.ts.map +1 -1
- package/dist/commands/generate-z2h-token.js +0 -3
- package/dist/commands/grant.d.ts +1 -5
- package/dist/commands/grant.d.ts.map +1 -1
- package/dist/commands/grant.js +1 -10
- package/dist/commands/migrate.d.ts +0 -1
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +106 -4
- package/dist/commands/tag.d.ts +0 -1
- package/dist/commands/tag.d.ts.map +1 -1
- package/dist/commands/tag.js +1 -4
- package/dist/esm/commands/build.d.ts +0 -1
- package/dist/esm/commands/build.d.ts.map +1 -1
- package/dist/esm/commands/build.mjs +1 -4
- package/dist/esm/commands/clean.d.ts +1 -4
- package/dist/esm/commands/clean.d.ts.map +1 -1
- package/dist/esm/commands/clean.mjs +2 -5
- package/dist/esm/commands/create-workspace.d.ts +1 -4
- package/dist/esm/commands/create-workspace.d.ts.map +1 -1
- package/dist/esm/commands/create-workspace.mjs +2 -5
- package/dist/esm/commands/create.d.ts +0 -1
- package/dist/esm/commands/create.d.ts.map +1 -1
- package/dist/esm/commands/create.mjs +1 -4
- package/dist/esm/commands/delete.d.ts +0 -1
- package/dist/esm/commands/delete.d.ts.map +1 -1
- package/dist/esm/commands/delete.mjs +2 -5
- package/dist/esm/commands/deploy.d.ts +0 -1
- package/dist/esm/commands/deploy.d.ts.map +1 -1
- package/dist/esm/commands/deploy.mjs +5 -8
- package/dist/esm/commands/dev.d.ts +0 -1
- package/dist/esm/commands/dev.d.ts.map +1 -1
- package/dist/esm/commands/dev.mjs +1 -4
- package/dist/esm/commands/doctor.d.ts +1 -4
- package/dist/esm/commands/doctor.d.ts.map +1 -1
- package/dist/esm/commands/doctor.mjs +3 -6
- package/dist/esm/commands/edit.d.ts +1 -4
- package/dist/esm/commands/edit.d.ts.map +1 -1
- package/dist/esm/commands/edit.mjs +2 -5
- package/dist/esm/commands/generate-z2h-token.d.ts +0 -1
- package/dist/esm/commands/generate-z2h-token.d.ts.map +1 -1
- package/dist/esm/commands/generate-z2h-token.mjs +1 -4
- package/dist/esm/commands/grant.d.ts +1 -5
- package/dist/esm/commands/grant.d.ts.map +1 -1
- package/dist/esm/commands/grant.mjs +2 -11
- package/dist/esm/commands/migrate.d.ts +0 -1
- package/dist/esm/commands/migrate.d.ts.map +1 -1
- package/dist/esm/commands/migrate.mjs +101 -5
- package/dist/esm/commands/tag.d.ts +0 -1
- package/dist/esm/commands/tag.d.ts.map +1 -1
- package/dist/esm/commands/tag.mjs +2 -5
- package/dist/esm/index.mjs +20 -29
- package/dist/esm/util/tracker.d.ts.map +1 -1
- package/dist/esm/util/tracker.mjs +4 -1
- package/dist/esm/util/workspace.d.ts +3 -0
- package/dist/esm/util/workspace.d.ts.map +1 -1
- package/dist/esm/util/workspace.mjs +64 -2
- package/dist/index.js +19 -28
- package/dist/util/tracker.d.ts.map +1 -1
- package/dist/util/tracker.js +4 -1
- package/dist/util/workspace.d.ts +3 -0
- package/dist/util/workspace.d.ts.map +1 -1
- package/dist/util/workspace.js +65 -0
- package/package.json +1 -1
- package/src/commands/__tests__/doctor.test.ts +12 -5
- package/src/commands/build.ts +1 -6
- package/src/commands/clean.ts +2 -9
- package/src/commands/create-workspace.ts +2 -10
- package/src/commands/create.ts +1 -6
- package/src/commands/delete.ts +2 -7
- package/src/commands/deploy.ts +5 -10
- package/src/commands/dev.ts +1 -6
- package/src/commands/doctor.ts +3 -11
- package/src/commands/edit.ts +2 -10
- package/src/commands/generate-z2h-token.ts +1 -6
- package/src/commands/grant.ts +2 -16
- package/src/commands/migrate.ts +139 -6
- package/src/commands/tag.ts +2 -7
- package/src/index.ts +29 -41
- package/src/util/tracker.ts +6 -1
- package/src/util/workspace.ts +75 -1
- package/dist/esm/migrations/auto-migrate.d.ts +0 -2
- package/dist/esm/migrations/auto-migrate.d.ts.map +0 -1
- package/dist/esm/migrations/auto-migrate.mjs +0 -169
- package/dist/migrations/auto-migrate.d.ts +0 -2
- package/dist/migrations/auto-migrate.d.ts.map +0 -1
- package/dist/migrations/auto-migrate.js +0 -177
- package/src/migrations/auto-migrate.ts +0 -217
package/src/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { migrateCommand } from './commands/migrate';
|
|
|
17
17
|
import { tagCommand } from './commands/tag';
|
|
18
18
|
import { editCommand } from './commands/edit';
|
|
19
19
|
import { doctorCommand } from './commands/doctor';
|
|
20
|
-
import { errorLog, fail, getOutputMode } from './util/logger';
|
|
20
|
+
import { errorLog, fail, getOutputMode, setOutputMode } from './util/logger';
|
|
21
21
|
import { trackDuration } from './util/tracker';
|
|
22
22
|
import { getCwdAppName } from './util/app-name';
|
|
23
23
|
|
|
@@ -69,15 +69,20 @@ async function main(): Promise<void> {
|
|
|
69
69
|
' 2 system error (yarn install or trident build failed)',
|
|
70
70
|
].join('\n')
|
|
71
71
|
)
|
|
72
|
-
.version(version)
|
|
72
|
+
.version(version)
|
|
73
|
+
.option('--json', 'emit structured JSON on stdout')
|
|
74
|
+
.hook('preAction', (_thisCommand, actionCommand) => {
|
|
75
|
+
if (actionCommand.optsWithGlobals<{ json?: boolean }>().json) {
|
|
76
|
+
setOutputMode('json');
|
|
77
|
+
}
|
|
78
|
+
});
|
|
73
79
|
|
|
74
80
|
program
|
|
75
81
|
.command('build')
|
|
76
82
|
.description('Build the consumer into its .zth/ shadow and copy artifacts to ./build/')
|
|
77
|
-
.
|
|
78
|
-
.action(async (opts: { json?: boolean }) => {
|
|
83
|
+
.action(async () => {
|
|
79
84
|
try {
|
|
80
|
-
await trackDuration('z2h_app_build_success', () => buildCommand(
|
|
85
|
+
await trackDuration('z2h_app_build_success', () => buildCommand(), { app_name: getCwdAppName() });
|
|
81
86
|
} catch (err) {
|
|
82
87
|
await fail(`build failed: ${(err as Error).message}`, { command: 'build' }, 2);
|
|
83
88
|
}
|
|
@@ -87,8 +92,7 @@ async function main(): Promise<void> {
|
|
|
87
92
|
.command('dev')
|
|
88
93
|
.description('Start the Trident dev server against .zth/ with native Vite HMR')
|
|
89
94
|
.option('--open', 'open the browser automatically when the dev server is ready')
|
|
90
|
-
.
|
|
91
|
-
.action(async (opts: { open?: boolean; json?: boolean }) => {
|
|
95
|
+
.action(async (opts: { open?: boolean }) => {
|
|
92
96
|
try {
|
|
93
97
|
await devCommand(opts);
|
|
94
98
|
} catch (err) {
|
|
@@ -99,10 +103,9 @@ async function main(): Promise<void> {
|
|
|
99
103
|
program
|
|
100
104
|
.command('clean')
|
|
101
105
|
.description('Delete <consumer>/.zth/ and <consumer>/build/')
|
|
102
|
-
.
|
|
103
|
-
.action(async (opts: { json?: boolean }) => {
|
|
106
|
+
.action(async () => {
|
|
104
107
|
try {
|
|
105
|
-
await cleanCommand(
|
|
108
|
+
await cleanCommand();
|
|
106
109
|
} catch (err) {
|
|
107
110
|
await fail(`clean failed: ${(err as Error).message}`, { command: 'clean' }, 2);
|
|
108
111
|
}
|
|
@@ -112,7 +115,6 @@ async function main(): Promise<void> {
|
|
|
112
115
|
.command('deploy')
|
|
113
116
|
.description('Build, upload to S3, and register the app with the Z2H backend')
|
|
114
117
|
.option('--dry-run', 'print what would happen without uploading anything')
|
|
115
|
-
.option('--json', 'emit structured JSON on stdout')
|
|
116
118
|
.option(
|
|
117
119
|
'--remote <type>',
|
|
118
120
|
'First deploy only: source control remote to initialise — s3 (shared storage) or github (your repo). Error if the app already has a git remote.'
|
|
@@ -121,7 +123,7 @@ async function main(): Promise<void> {
|
|
|
121
123
|
'--repo-url <url>',
|
|
122
124
|
'First deploy only: GitHub repo URL — required when --remote=github. Error if the app already has a git remote.'
|
|
123
125
|
)
|
|
124
|
-
.action(async (opts: { dryRun?: boolean;
|
|
126
|
+
.action(async (opts: { dryRun?: boolean; remote?: string; repoUrl?: string }) => {
|
|
125
127
|
try {
|
|
126
128
|
await trackDuration(
|
|
127
129
|
'z2h_app_deploy_success',
|
|
@@ -139,8 +141,7 @@ async function main(): Promise<void> {
|
|
|
139
141
|
.command('tag [app-name]')
|
|
140
142
|
.description("Set an app's category tags — app type & team (interactive unless --tag or --json is given)")
|
|
141
143
|
.option('--tag <tag>', 'set a tag (repeatable); full-replaces the tag set non-interactively', collectTag, [])
|
|
142
|
-
.
|
|
143
|
-
.action(async (appName: string | undefined, opts: { tag?: string[]; json?: boolean }) => {
|
|
144
|
+
.action(async (appName: string | undefined, opts: { tag?: string[] }) => {
|
|
144
145
|
try {
|
|
145
146
|
await trackDuration('z2h_app_tag_success', () => tagCommand(appName, opts), {
|
|
146
147
|
app_name: appName ?? getCwdAppName(),
|
|
@@ -153,10 +154,9 @@ async function main(): Promise<void> {
|
|
|
153
154
|
program
|
|
154
155
|
.command('create-workspace')
|
|
155
156
|
.description(`Bootstrap the ${getWorkspaceHome()}/ yarn workspace (one-time setup)`)
|
|
156
|
-
.
|
|
157
|
-
.action(async (opts: { json?: boolean }) => {
|
|
157
|
+
.action(async () => {
|
|
158
158
|
try {
|
|
159
|
-
await createWorkspaceCommand(
|
|
159
|
+
await createWorkspaceCommand();
|
|
160
160
|
} catch (err) {
|
|
161
161
|
await fail(`create-workspace failed: ${(err as Error).message}`, { command: 'create-workspace' }, 1);
|
|
162
162
|
}
|
|
@@ -169,8 +169,7 @@ async function main(): Promise<void> {
|
|
|
169
169
|
)
|
|
170
170
|
.option('--no-browser', "don't auto-open the browser; print the URL and prompt for manual paste")
|
|
171
171
|
.option('--url <url>', 'Override the token page URL (e.g. for staging)')
|
|
172
|
-
.
|
|
173
|
-
.action(async (opts: { noBrowser?: boolean; url?: string; json?: boolean }) => {
|
|
172
|
+
.action(async (opts: { noBrowser?: boolean; url?: string }) => {
|
|
174
173
|
try {
|
|
175
174
|
await generateZ2HTokenCommand(opts);
|
|
176
175
|
} catch (err) {
|
|
@@ -185,12 +184,8 @@ async function main(): Promise<void> {
|
|
|
185
184
|
.option('--html-file <path>', 'Path to an HTML file to embed (implies --template html-embed)')
|
|
186
185
|
.option('--remote <type>', 'Source control remote: s3 (shared storage) or github (your repo)')
|
|
187
186
|
.option('--repo-url <url>', 'GitHub repo URL — required when --remote=github')
|
|
188
|
-
.option('--json', 'emit structured JSON on stdout')
|
|
189
187
|
.action(
|
|
190
|
-
async (
|
|
191
|
-
appName: string,
|
|
192
|
-
opts: { template?: string; htmlFile?: string; remote?: string; repoUrl?: string; json?: boolean }
|
|
193
|
-
) => {
|
|
188
|
+
async (appName: string, opts: { template?: string; htmlFile?: string; remote?: string; repoUrl?: string }) => {
|
|
194
189
|
try {
|
|
195
190
|
await trackDuration('z2h_app_created', () => createCommand(appName, opts as CreateOptions), {
|
|
196
191
|
app_name: appName,
|
|
@@ -206,10 +201,9 @@ async function main(): Promise<void> {
|
|
|
206
201
|
program
|
|
207
202
|
.command('edit <app-name>')
|
|
208
203
|
.description(`Pull the latest version of an app into ${getWorkspaceHome()}/<app-name>, cloning it first if needed`)
|
|
209
|
-
.
|
|
210
|
-
.action(async (appName: string, opts: { json?: boolean }) => {
|
|
204
|
+
.action(async (appName: string) => {
|
|
211
205
|
try {
|
|
212
|
-
await trackDuration('z2h_app_edit_pulled', () => editCommand(appName
|
|
206
|
+
await trackDuration('z2h_app_edit_pulled', () => editCommand(appName), {
|
|
213
207
|
app_name: appName,
|
|
214
208
|
});
|
|
215
209
|
} catch (err) {
|
|
@@ -222,8 +216,7 @@ async function main(): Promise<void> {
|
|
|
222
216
|
.description('Grant access to the current app (email, --public, or both)')
|
|
223
217
|
.option('--public', 'make the app visible to all monday.com employees')
|
|
224
218
|
.option('--level <level>', 'access level for user grants: owner, editor, or viewer (default: viewer)')
|
|
225
|
-
.
|
|
226
|
-
.action(async (email: string | undefined, opts: { public?: boolean; level?: string; json?: boolean }) => {
|
|
219
|
+
.action(async (email: string | undefined, opts: { public?: boolean; level?: string }) => {
|
|
227
220
|
try {
|
|
228
221
|
await grantCommand(email, opts as Parameters<typeof grantCommand>[1]);
|
|
229
222
|
} catch (err) {
|
|
@@ -235,8 +228,7 @@ async function main(): Promise<void> {
|
|
|
235
228
|
.command('revoke [email]')
|
|
236
229
|
.description('Revoke access to the current app (email or --public; owners/admins only)')
|
|
237
230
|
.option('--public', 'remove the public grant, making the app visible to owners/admins only')
|
|
238
|
-
.
|
|
239
|
-
.action(async (email: string | undefined, opts: { public?: boolean; json?: boolean }) => {
|
|
231
|
+
.action(async (email: string | undefined, opts: { public?: boolean }) => {
|
|
240
232
|
try {
|
|
241
233
|
await revokeCommand(email, opts as Parameters<typeof revokeCommand>[1]);
|
|
242
234
|
} catch (err) {
|
|
@@ -247,10 +239,9 @@ async function main(): Promise<void> {
|
|
|
247
239
|
program
|
|
248
240
|
.command('transfer-owner [email]')
|
|
249
241
|
.description('Transfer ownership of the current app to another monday.com user')
|
|
250
|
-
.
|
|
251
|
-
.action(async (email: string | undefined, opts: { json?: boolean }) => {
|
|
242
|
+
.action(async (email: string | undefined) => {
|
|
252
243
|
try {
|
|
253
|
-
await transferOwnerCommand(email
|
|
244
|
+
await transferOwnerCommand(email);
|
|
254
245
|
} catch (err) {
|
|
255
246
|
await fail(`transfer-owner failed: ${(err as Error).message}`, { command: 'transfer-owner' }, 1);
|
|
256
247
|
}
|
|
@@ -260,8 +251,7 @@ async function main(): Promise<void> {
|
|
|
260
251
|
.command('delete')
|
|
261
252
|
.description('Permanently delete the current app and take it offline (owners/admins only)')
|
|
262
253
|
.option('--yes', 'skip the confirmation prompt (required for --json / non-interactive)')
|
|
263
|
-
.
|
|
264
|
-
.action(async (opts: { yes?: boolean; json?: boolean }) => {
|
|
254
|
+
.action(async (opts: { yes?: boolean }) => {
|
|
265
255
|
try {
|
|
266
256
|
await trackDuration('z2h_app_delete_success', () => deleteCommand(opts), {
|
|
267
257
|
app_name: getCwdAppName(),
|
|
@@ -275,8 +265,7 @@ async function main(): Promise<void> {
|
|
|
275
265
|
.command('migrate')
|
|
276
266
|
.description('Run pending workspace migrations')
|
|
277
267
|
.option('--dry-run', 'show pending migrations without applying any changes')
|
|
278
|
-
.
|
|
279
|
-
.action(async (opts: { dryRun?: boolean; json?: boolean }) => {
|
|
268
|
+
.action(async (opts: { dryRun?: boolean }) => {
|
|
280
269
|
try {
|
|
281
270
|
await migrateCommand(version, opts);
|
|
282
271
|
} catch (err) {
|
|
@@ -287,10 +276,9 @@ async function main(): Promise<void> {
|
|
|
287
276
|
program
|
|
288
277
|
.command('doctor')
|
|
289
278
|
.description('Check that all Z2H tools, auth, workspace, and plugins are correctly set up')
|
|
290
|
-
.
|
|
291
|
-
.action(async (opts: { json?: boolean }) => {
|
|
279
|
+
.action(async () => {
|
|
292
280
|
try {
|
|
293
|
-
await doctorCommand(
|
|
281
|
+
await doctorCommand();
|
|
294
282
|
} catch (err) {
|
|
295
283
|
await fail(`doctor failed: ${(err as Error).message}`, { command: 'doctor' }, 1);
|
|
296
284
|
}
|
package/src/util/tracker.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
|
|
3
3
|
const DOORMAN_URL = 'https://track-int.bigbrain.me/prod/event';
|
|
4
|
+
const DOORMAN_URL_STAGING = 'https://track-int.bigbrainstaging.me/stage/event';
|
|
4
5
|
|
|
5
6
|
const username = os.userInfo().username;
|
|
6
7
|
|
|
8
|
+
const isStaging = process.env.NODE_ENV === 'staging';
|
|
9
|
+
|
|
7
10
|
export async function trackEvent(name: string, data: Record<string, unknown>): Promise<void> {
|
|
8
|
-
|
|
11
|
+
const doormanUrl = isStaging ? DOORMAN_URL_STAGING : DOORMAN_URL;
|
|
12
|
+
|
|
13
|
+
await fetch(doormanUrl, {
|
|
9
14
|
method: 'POST',
|
|
10
15
|
headers: { 'Content-Type': 'application/json' },
|
|
11
16
|
body: JSON.stringify({ name, source: 'z2h-cli', data: { user_name: username, ...data } }),
|
package/src/util/workspace.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import os from 'node:os';
|
|
3
|
-
import {
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { pathExists, readJson, writeFile, writeJson } from 'fs-extra';
|
|
5
|
+
import { execa } from 'execa';
|
|
6
|
+
import { info, warn } from './logger';
|
|
4
7
|
|
|
5
8
|
export const WORKSPACE_DIR_NAME = 'zth-projects';
|
|
6
9
|
export const WORKSPACE_MARKER_FIELD = 'z2hWorkspace';
|
|
@@ -50,3 +53,74 @@ export async function assertWorkspace(): Promise<string> {
|
|
|
50
53
|
`(or set Z2H_WORKSPACE_HOME if you keep the workspace elsewhere).`
|
|
51
54
|
);
|
|
52
55
|
}
|
|
56
|
+
|
|
57
|
+
export async function runYarnInstall(workspaceHome: string, context: string): Promise<boolean> {
|
|
58
|
+
info(`${context} — running yarn install...`);
|
|
59
|
+
try {
|
|
60
|
+
await execa('yarn', ['install'], { cwd: workspaceHome, stdio: 'pipe' });
|
|
61
|
+
return true;
|
|
62
|
+
} catch (err) {
|
|
63
|
+
const stderr = (err as { stderr?: string }).stderr || (err as Error).message;
|
|
64
|
+
warn(`yarn install failed: ${stderr}`);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function getLatestTrientMonorepoVersion(): Promise<string> {
|
|
70
|
+
try {
|
|
71
|
+
const { stdout } = await execa('npm', ['view', '@mondaydotcomorg/trident-monorepo', 'version']);
|
|
72
|
+
return `^${stdout.trim()}`;
|
|
73
|
+
} catch {
|
|
74
|
+
return '*';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function isNxAvailable(workspaceHome: string): boolean {
|
|
79
|
+
try {
|
|
80
|
+
const wsRequire = createRequire(path.join(workspaceHome, 'package.json'));
|
|
81
|
+
wsRequire.resolve('nx/src/generators/tree');
|
|
82
|
+
return true;
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const NX_JSON_CONTENT = '{\n "extends": "@mondaydotcomorg/trident-monorepo/presets/nx.json"\n}\n';
|
|
89
|
+
|
|
90
|
+
export async function ensureWorkspaceNx(workspaceHome: string): Promise<boolean> {
|
|
91
|
+
const nxJsonPath = path.join(workspaceHome, 'nx.json');
|
|
92
|
+
const pkgPath = path.join(workspaceHome, 'package.json');
|
|
93
|
+
|
|
94
|
+
if (!(await pathExists(nxJsonPath))) {
|
|
95
|
+
await writeFile(nxJsonPath, NX_JSON_CONTENT);
|
|
96
|
+
info('added nx.json to workspace');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const pkg = (await readJson(pkgPath)) as {
|
|
100
|
+
devDependencies?: Record<string, string>;
|
|
101
|
+
scripts?: Record<string, string>;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
if (!pkg.devDependencies?.['@mondaydotcomorg/trident-monorepo']) {
|
|
105
|
+
pkg.devDependencies = pkg.devDependencies ?? {};
|
|
106
|
+
pkg.devDependencies['@mondaydotcomorg/trident-monorepo'] = await getLatestTrientMonorepoVersion();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!pkg.scripts?.nx) {
|
|
110
|
+
pkg.scripts = pkg.scripts ?? {};
|
|
111
|
+
pkg.scripts.nx = 'nx';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
await writeJson(pkgPath, pkg, { spaces: 2 });
|
|
115
|
+
|
|
116
|
+
// Only install if NX isn't already importable from the workspace
|
|
117
|
+
if (!isNxAvailable(workspaceHome)) {
|
|
118
|
+
const ok = await runYarnInstall(workspaceHome, 'NX not found, installing');
|
|
119
|
+
if (!ok) {
|
|
120
|
+
warn('workspace migrations require NX. Fix the install error and run "z2h-cli migrate" to retry.');
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-migrate.d.ts","sourceRoot":"","sources":["../../../src/migrations/auto-migrate.ts"],"names":[],"mappings":"AAsHA,wBAAsB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAkGnF"}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { pathExists, readJson, writeJson, writeFile } from 'fs-extra';
|
|
5
|
-
import { execa } from 'execa';
|
|
6
|
-
import semver from 'semver';
|
|
7
|
-
import { warn, info, errorLog } from '../util/logger.mjs';
|
|
8
|
-
import { getWorkspaceHome, isZ2hWorkspace } from '../util/workspace.mjs';
|
|
9
|
-
|
|
10
|
-
const STATE_FILE = '.z2h-migrations-state.json';
|
|
11
|
-
const NX_JSON_CONTENT = '{\n "extends": "@mondaydotcomorg/trident-monorepo/presets/nx.json"\n}\n';
|
|
12
|
-
// ─── Helpers ───
|
|
13
|
-
async function readState(workspaceHome) {
|
|
14
|
-
const statePath = path.join(workspaceHome, STATE_FILE);
|
|
15
|
-
if (!(await pathExists(statePath))) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
return (await readJson(statePath));
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async function writeState(workspaceHome, state) {
|
|
26
|
-
const statePath = path.join(workspaceHome, STATE_FILE);
|
|
27
|
-
await writeJson(statePath, state, { spaces: 2 });
|
|
28
|
-
}
|
|
29
|
-
async function yarnInstall(workspaceHome, context) {
|
|
30
|
-
info(`${context} — running yarn install...`);
|
|
31
|
-
try {
|
|
32
|
-
await execa('yarn', ['install'], { cwd: workspaceHome, stdio: 'pipe' });
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
const stderr = err.stderr || err.message;
|
|
37
|
-
warn(`yarn install failed: ${stderr}`);
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async function getLatestTrientMonorepoVersion() {
|
|
42
|
-
try {
|
|
43
|
-
const { stdout } = await execa('npm', ['view', '@mondaydotcomorg/trident-monorepo', 'version']);
|
|
44
|
-
return `^${stdout.trim()}`;
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return '*';
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// ─── Workspace bootstrap ───
|
|
51
|
-
function isNxAvailable(workspaceHome) {
|
|
52
|
-
try {
|
|
53
|
-
const wsRequire = createRequire(path.join(workspaceHome, 'package.json'));
|
|
54
|
-
wsRequire.resolve('nx/src/generators/tree');
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async function ensureWorkspaceNx(workspaceHome) {
|
|
62
|
-
const nxJsonPath = path.join(workspaceHome, 'nx.json');
|
|
63
|
-
const pkgPath = path.join(workspaceHome, 'package.json');
|
|
64
|
-
if (!(await pathExists(nxJsonPath))) {
|
|
65
|
-
await writeFile(nxJsonPath, NX_JSON_CONTENT);
|
|
66
|
-
info('added nx.json to workspace');
|
|
67
|
-
}
|
|
68
|
-
const pkg = (await readJson(pkgPath));
|
|
69
|
-
if (!pkg.devDependencies?.['@mondaydotcomorg/trident-monorepo']) {
|
|
70
|
-
pkg.devDependencies = pkg.devDependencies ?? {};
|
|
71
|
-
pkg.devDependencies['@mondaydotcomorg/trident-monorepo'] = await getLatestTrientMonorepoVersion();
|
|
72
|
-
}
|
|
73
|
-
if (!pkg.scripts?.nx) {
|
|
74
|
-
pkg.scripts = pkg.scripts ?? {};
|
|
75
|
-
pkg.scripts.nx = 'nx';
|
|
76
|
-
}
|
|
77
|
-
await writeJson(pkgPath, pkg, { spaces: 2 });
|
|
78
|
-
// Only install if NX isn't already importable from the workspace
|
|
79
|
-
if (!isNxAvailable(workspaceHome)) {
|
|
80
|
-
const ok = await yarnInstall(workspaceHome, 'NX not found, installing');
|
|
81
|
-
if (!ok) {
|
|
82
|
-
warn('workspace migrations require NX. Fix the install error and run "z2h-cli migrate" to retry.');
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
// ─── Main ───
|
|
89
|
-
async function autoMigrate(cliVersion, dryRun = false) {
|
|
90
|
-
const workspaceHome = getWorkspaceHome();
|
|
91
|
-
if (!(await isZ2hWorkspace(workspaceHome))) {
|
|
92
|
-
warn('no Z2H workspace found');
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const state = await readState(workspaceHome);
|
|
96
|
-
const lastVersion = state?.lastMigratedVersion ?? '0.0.0';
|
|
97
|
-
if (!semver.gt(cliVersion, lastVersion)) {
|
|
98
|
-
info('workspace is up to date — no migrations pending');
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
info(`migrating workspace from v${lastVersion} → v${cliVersion}...`);
|
|
102
|
-
// migrations.json is at the package root — two dirs up from dist/migrations/
|
|
103
|
-
const thisDir = path.dirname(fileURLToPath(import.meta.url));
|
|
104
|
-
const migrationsJsonPath = path.resolve(thisDir, '..', '..', 'migrations.json');
|
|
105
|
-
if (!(await pathExists(migrationsJsonPath))) {
|
|
106
|
-
warn('migrations.json not found — skipping migrations');
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const migrationsJson = (await readJson(migrationsJsonPath));
|
|
110
|
-
// Filter to pending migrations (version > lastVersion AND <= cliVersion).
|
|
111
|
-
// CONVENTION: a migration's `version` field must equal the CLI release it
|
|
112
|
-
// ships with (not the feature branch version). This ensures the `gt` check
|
|
113
|
-
// always catches a migration on the exact upgrade that introduces it.
|
|
114
|
-
const pending = Object.entries(migrationsJson.migrations)
|
|
115
|
-
.filter(([, entry]) => semver.gt(entry.version, lastVersion) && semver.lte(entry.version, cliVersion))
|
|
116
|
-
.sort(([, a], [, b]) => semver.compare(a.version, b.version));
|
|
117
|
-
if (dryRun) {
|
|
118
|
-
info(`${pending.length} pending migration(s) (dry-run — no changes will be applied):`);
|
|
119
|
-
for (const [, entry] of pending) {
|
|
120
|
-
info(` - ${entry.description} (v${entry.version})`);
|
|
121
|
-
}
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (pending.length === 0) {
|
|
125
|
-
await writeState(workspaceHome, { lastMigratedVersion: cliVersion });
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const nxReady = await ensureWorkspaceNx(workspaceHome);
|
|
129
|
-
if (!nxReady) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
info(`applying ${pending.length} workspace migration(s)...`);
|
|
133
|
-
// Resolve NX from the workspace's node_modules (not from CLI's own deps)
|
|
134
|
-
const wsRequire = createRequire(path.join(workspaceHome, 'package.json'));
|
|
135
|
-
const { FsTree, flushChanges } = wsRequire('nx/src/generators/tree');
|
|
136
|
-
let needsInstall = false;
|
|
137
|
-
for (const [name, entry] of pending) {
|
|
138
|
-
const tree = new FsTree(workspaceHome, false);
|
|
139
|
-
try {
|
|
140
|
-
const factoryPath = path.resolve(path.dirname(migrationsJsonPath), entry.migrate);
|
|
141
|
-
const mod = require(factoryPath);
|
|
142
|
-
const fn = mod.default || mod;
|
|
143
|
-
fn(tree);
|
|
144
|
-
const changes = tree.listChanges();
|
|
145
|
-
if (changes.length > 0) {
|
|
146
|
-
if (changes.some(c => c.path.endsWith('package.json'))) {
|
|
147
|
-
needsInstall = true;
|
|
148
|
-
}
|
|
149
|
-
flushChanges(workspaceHome, changes);
|
|
150
|
-
info(` ✓ ${entry.description}`);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
info(` ○ ${entry.description} (no changes needed)`);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
catch (err) {
|
|
157
|
-
const errorMessage = `migration "${name}" failed: ${err.message}`;
|
|
158
|
-
errorLog(`${errorMessage}\nSkipping remaining migrations — run "z2h-cli migrate" to retry.`);
|
|
159
|
-
throw new Error(errorMessage);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (needsInstall) {
|
|
163
|
-
await yarnInstall(workspaceHome, 'package.json changed');
|
|
164
|
-
}
|
|
165
|
-
await writeState(workspaceHome, { lastMigratedVersion: cliVersion });
|
|
166
|
-
info('workspace migrations complete.');
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export { autoMigrate };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-migrate.d.ts","sourceRoot":"","sources":["../../src/migrations/auto-migrate.ts"],"names":[],"mappings":"AAsHA,wBAAsB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAkGnF"}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
3
|
-
const node_module = require('node:module');
|
|
4
|
-
const path = require('node:path');
|
|
5
|
-
const node_url = require('node:url');
|
|
6
|
-
const fs = require('fs-extra');
|
|
7
|
-
const execa = require('execa');
|
|
8
|
-
const semver = require('semver');
|
|
9
|
-
const util_logger = require('../util/logger.js');
|
|
10
|
-
const util_workspace = require('../util/workspace.js');
|
|
11
|
-
|
|
12
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
13
|
-
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
14
|
-
|
|
15
|
-
const path__default = /*#__PURE__*/_interopDefault(path);
|
|
16
|
-
const semver__default = /*#__PURE__*/_interopDefault(semver);
|
|
17
|
-
|
|
18
|
-
const STATE_FILE = '.z2h-migrations-state.json';
|
|
19
|
-
const NX_JSON_CONTENT = '{\n "extends": "@mondaydotcomorg/trident-monorepo/presets/nx.json"\n}\n';
|
|
20
|
-
// ─── Helpers ───
|
|
21
|
-
async function readState(workspaceHome) {
|
|
22
|
-
const statePath = path__default.default.join(workspaceHome, STATE_FILE);
|
|
23
|
-
if (!(await fs.pathExists(statePath))) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
return (await fs.readJson(statePath));
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async function writeState(workspaceHome, state) {
|
|
34
|
-
const statePath = path__default.default.join(workspaceHome, STATE_FILE);
|
|
35
|
-
await fs.writeJson(statePath, state, { spaces: 2 });
|
|
36
|
-
}
|
|
37
|
-
async function yarnInstall(workspaceHome, context) {
|
|
38
|
-
util_logger.info(`${context} — running yarn install...`);
|
|
39
|
-
try {
|
|
40
|
-
await execa.execa('yarn', ['install'], { cwd: workspaceHome, stdio: 'pipe' });
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
catch (err) {
|
|
44
|
-
const stderr = err.stderr || err.message;
|
|
45
|
-
util_logger.warn(`yarn install failed: ${stderr}`);
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async function getLatestTrientMonorepoVersion() {
|
|
50
|
-
try {
|
|
51
|
-
const { stdout } = await execa.execa('npm', ['view', '@mondaydotcomorg/trident-monorepo', 'version']);
|
|
52
|
-
return `^${stdout.trim()}`;
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
return '*';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// ─── Workspace bootstrap ───
|
|
59
|
-
function isNxAvailable(workspaceHome) {
|
|
60
|
-
try {
|
|
61
|
-
const wsRequire = node_module.createRequire(path__default.default.join(workspaceHome, 'package.json'));
|
|
62
|
-
wsRequire.resolve('nx/src/generators/tree');
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async function ensureWorkspaceNx(workspaceHome) {
|
|
70
|
-
const nxJsonPath = path__default.default.join(workspaceHome, 'nx.json');
|
|
71
|
-
const pkgPath = path__default.default.join(workspaceHome, 'package.json');
|
|
72
|
-
if (!(await fs.pathExists(nxJsonPath))) {
|
|
73
|
-
await fs.writeFile(nxJsonPath, NX_JSON_CONTENT);
|
|
74
|
-
util_logger.info('added nx.json to workspace');
|
|
75
|
-
}
|
|
76
|
-
const pkg = (await fs.readJson(pkgPath));
|
|
77
|
-
if (!pkg.devDependencies?.['@mondaydotcomorg/trident-monorepo']) {
|
|
78
|
-
pkg.devDependencies = pkg.devDependencies ?? {};
|
|
79
|
-
pkg.devDependencies['@mondaydotcomorg/trident-monorepo'] = await getLatestTrientMonorepoVersion();
|
|
80
|
-
}
|
|
81
|
-
if (!pkg.scripts?.nx) {
|
|
82
|
-
pkg.scripts = pkg.scripts ?? {};
|
|
83
|
-
pkg.scripts.nx = 'nx';
|
|
84
|
-
}
|
|
85
|
-
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
86
|
-
// Only install if NX isn't already importable from the workspace
|
|
87
|
-
if (!isNxAvailable(workspaceHome)) {
|
|
88
|
-
const ok = await yarnInstall(workspaceHome, 'NX not found, installing');
|
|
89
|
-
if (!ok) {
|
|
90
|
-
util_logger.warn('workspace migrations require NX. Fix the install error and run "z2h-cli migrate" to retry.');
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
// ─── Main ───
|
|
97
|
-
async function autoMigrate(cliVersion, dryRun = false) {
|
|
98
|
-
const workspaceHome = util_workspace.getWorkspaceHome();
|
|
99
|
-
if (!(await util_workspace.isZ2hWorkspace(workspaceHome))) {
|
|
100
|
-
util_logger.warn('no Z2H workspace found');
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const state = await readState(workspaceHome);
|
|
104
|
-
const lastVersion = state?.lastMigratedVersion ?? '0.0.0';
|
|
105
|
-
if (!semver__default.default.gt(cliVersion, lastVersion)) {
|
|
106
|
-
util_logger.info('workspace is up to date — no migrations pending');
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
util_logger.info(`migrating workspace from v${lastVersion} → v${cliVersion}...`);
|
|
110
|
-
// migrations.json is at the package root — two dirs up from dist/migrations/
|
|
111
|
-
const thisDir = path__default.default.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('migrations/auto-migrate.js', document.baseURI).href))));
|
|
112
|
-
const migrationsJsonPath = path__default.default.resolve(thisDir, '..', '..', 'migrations.json');
|
|
113
|
-
if (!(await fs.pathExists(migrationsJsonPath))) {
|
|
114
|
-
util_logger.warn('migrations.json not found — skipping migrations');
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
const migrationsJson = (await fs.readJson(migrationsJsonPath));
|
|
118
|
-
// Filter to pending migrations (version > lastVersion AND <= cliVersion).
|
|
119
|
-
// CONVENTION: a migration's `version` field must equal the CLI release it
|
|
120
|
-
// ships with (not the feature branch version). This ensures the `gt` check
|
|
121
|
-
// always catches a migration on the exact upgrade that introduces it.
|
|
122
|
-
const pending = Object.entries(migrationsJson.migrations)
|
|
123
|
-
.filter(([, entry]) => semver__default.default.gt(entry.version, lastVersion) && semver__default.default.lte(entry.version, cliVersion))
|
|
124
|
-
.sort(([, a], [, b]) => semver__default.default.compare(a.version, b.version));
|
|
125
|
-
if (dryRun) {
|
|
126
|
-
util_logger.info(`${pending.length} pending migration(s) (dry-run — no changes will be applied):`);
|
|
127
|
-
for (const [, entry] of pending) {
|
|
128
|
-
util_logger.info(` - ${entry.description} (v${entry.version})`);
|
|
129
|
-
}
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if (pending.length === 0) {
|
|
133
|
-
await writeState(workspaceHome, { lastMigratedVersion: cliVersion });
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
const nxReady = await ensureWorkspaceNx(workspaceHome);
|
|
137
|
-
if (!nxReady) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
util_logger.info(`applying ${pending.length} workspace migration(s)...`);
|
|
141
|
-
// Resolve NX from the workspace's node_modules (not from CLI's own deps)
|
|
142
|
-
const wsRequire = node_module.createRequire(path__default.default.join(workspaceHome, 'package.json'));
|
|
143
|
-
const { FsTree, flushChanges } = wsRequire('nx/src/generators/tree');
|
|
144
|
-
let needsInstall = false;
|
|
145
|
-
for (const [name, entry] of pending) {
|
|
146
|
-
const tree = new FsTree(workspaceHome, false);
|
|
147
|
-
try {
|
|
148
|
-
const factoryPath = path__default.default.resolve(path__default.default.dirname(migrationsJsonPath), entry.migrate);
|
|
149
|
-
const mod = require(factoryPath);
|
|
150
|
-
const fn = mod.default || mod;
|
|
151
|
-
fn(tree);
|
|
152
|
-
const changes = tree.listChanges();
|
|
153
|
-
if (changes.length > 0) {
|
|
154
|
-
if (changes.some(c => c.path.endsWith('package.json'))) {
|
|
155
|
-
needsInstall = true;
|
|
156
|
-
}
|
|
157
|
-
flushChanges(workspaceHome, changes);
|
|
158
|
-
util_logger.info(` ✓ ${entry.description}`);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
util_logger.info(` ○ ${entry.description} (no changes needed)`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
catch (err) {
|
|
165
|
-
const errorMessage = `migration "${name}" failed: ${err.message}`;
|
|
166
|
-
util_logger.errorLog(`${errorMessage}\nSkipping remaining migrations — run "z2h-cli migrate" to retry.`);
|
|
167
|
-
throw new Error(errorMessage);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (needsInstall) {
|
|
171
|
-
await yarnInstall(workspaceHome, 'package.json changed');
|
|
172
|
-
}
|
|
173
|
-
await writeState(workspaceHome, { lastMigratedVersion: cliVersion });
|
|
174
|
-
util_logger.info('workspace migrations complete.');
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
exports.autoMigrate = autoMigrate;
|