@mondaydotcomorg/z2h-cli 0.6.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.mjs +28 -12
- package/dist/esm/util/logger.d.ts +1 -1
- package/dist/esm/util/logger.d.ts.map +1 -1
- package/dist/esm/util/logger.mjs +2 -2
- package/dist/esm/util/tracker.d.ts +1 -1
- package/dist/esm/util/tracker.d.ts.map +1 -1
- package/dist/esm/util/tracker.mjs +5 -5
- package/dist/index.js +32 -11
- package/dist/util/logger.d.ts +1 -1
- package/dist/util/logger.d.ts.map +1 -1
- package/dist/util/logger.js +2 -2
- package/dist/util/tracker.d.ts +1 -1
- package/dist/util/tracker.d.ts.map +1 -1
- package/dist/util/tracker.js +5 -5
- package/package.json +1 -1
- package/src/index.ts +29 -12
- package/src/util/logger.ts +2 -2
- package/src/util/tracker.ts +5 -5
package/dist/esm/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
3
5
|
import { Command } from 'commander';
|
|
6
|
+
import { execa } from 'execa';
|
|
4
7
|
import { devCommand } from './commands/dev.mjs';
|
|
5
8
|
import { buildCommand } from './commands/build.mjs';
|
|
6
9
|
import { cleanCommand } from './commands/clean.mjs';
|
|
@@ -9,10 +12,19 @@ import { createWorkspaceCommand } from './commands/create-workspace.mjs';
|
|
|
9
12
|
import { createCommand } from './commands/create.mjs';
|
|
10
13
|
import { generateZ2HTokenCommand } from './commands/generate-z2h-token.mjs';
|
|
11
14
|
import { migrateCommand } from './commands/migrate.mjs';
|
|
12
|
-
import { errorLog,
|
|
15
|
+
import { fail, errorLog, getOutputMode } from './util/logger.mjs';
|
|
13
16
|
import { trackDuration } from './util/tracker.mjs';
|
|
14
17
|
|
|
15
18
|
const { version } = createRequire(import.meta.url)('../package.json');
|
|
19
|
+
const UPDATE_SCRIPT = path.join(os.homedir(), 'Development', 'bigbrain-z2h', 'z2h', 'setup', 'update.sh');
|
|
20
|
+
function selfUpdate() {
|
|
21
|
+
try {
|
|
22
|
+
execa('bash', [UPDATE_SCRIPT], { detached: true, stdio: 'ignore' }).unref();
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
errorLog(`Z2H auto-update failed to start: ${err.message}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
16
28
|
function getCwdAppName() {
|
|
17
29
|
try {
|
|
18
30
|
return JSON.parse(readFileSync('package.json', 'utf8')).name;
|
|
@@ -47,7 +59,7 @@ async function main() {
|
|
|
47
59
|
await trackDuration('z2h_app_build_success', () => buildCommand(opts), { app_name: getCwdAppName() });
|
|
48
60
|
}
|
|
49
61
|
catch (err) {
|
|
50
|
-
fail(`build failed: ${err.message}`, { command: 'build' }, 2);
|
|
62
|
+
await fail(`build failed: ${err.message}`, { command: 'build' }, 2);
|
|
51
63
|
}
|
|
52
64
|
});
|
|
53
65
|
program
|
|
@@ -59,7 +71,7 @@ async function main() {
|
|
|
59
71
|
await devCommand(opts);
|
|
60
72
|
}
|
|
61
73
|
catch (err) {
|
|
62
|
-
fail(`dev failed: ${err.message}`, { command: 'dev' }, 2);
|
|
74
|
+
await fail(`dev failed: ${err.message}`, { command: 'dev' }, 2);
|
|
63
75
|
}
|
|
64
76
|
});
|
|
65
77
|
program
|
|
@@ -71,7 +83,7 @@ async function main() {
|
|
|
71
83
|
await cleanCommand(opts);
|
|
72
84
|
}
|
|
73
85
|
catch (err) {
|
|
74
|
-
fail(`clean failed: ${err.message}`, { command: 'clean' }, 2);
|
|
86
|
+
await fail(`clean failed: ${err.message}`, { command: 'clean' }, 2);
|
|
75
87
|
}
|
|
76
88
|
});
|
|
77
89
|
program
|
|
@@ -86,7 +98,7 @@ async function main() {
|
|
|
86
98
|
});
|
|
87
99
|
}
|
|
88
100
|
catch (err) {
|
|
89
|
-
fail(`deploy failed: ${err.message}`, { command: 'deploy' }, 2);
|
|
101
|
+
await fail(`deploy failed: ${err.message}`, { command: 'deploy' }, 2);
|
|
90
102
|
}
|
|
91
103
|
});
|
|
92
104
|
program
|
|
@@ -98,7 +110,7 @@ async function main() {
|
|
|
98
110
|
await createWorkspaceCommand(opts);
|
|
99
111
|
}
|
|
100
112
|
catch (err) {
|
|
101
|
-
fail(`create-workspace failed: ${err.message}`, { command: 'create-workspace' }, 1);
|
|
113
|
+
await fail(`create-workspace failed: ${err.message}`, { command: 'create-workspace' }, 1);
|
|
102
114
|
}
|
|
103
115
|
});
|
|
104
116
|
program
|
|
@@ -112,7 +124,7 @@ async function main() {
|
|
|
112
124
|
await generateZ2HTokenCommand(opts);
|
|
113
125
|
}
|
|
114
126
|
catch (err) {
|
|
115
|
-
fail(`generate-z2h-token failed: ${err.message}`, { command: 'generate-z2h-token' }, 1);
|
|
127
|
+
await fail(`generate-z2h-token failed: ${err.message}`, { command: 'generate-z2h-token' }, 1);
|
|
116
128
|
}
|
|
117
129
|
});
|
|
118
130
|
program
|
|
@@ -129,7 +141,7 @@ async function main() {
|
|
|
129
141
|
});
|
|
130
142
|
}
|
|
131
143
|
catch (err) {
|
|
132
|
-
fail(`create failed: ${err.message}`, { command: 'create' }, 1);
|
|
144
|
+
await fail(`create failed: ${err.message}`, { command: 'create' }, 1);
|
|
133
145
|
}
|
|
134
146
|
});
|
|
135
147
|
program
|
|
@@ -142,16 +154,20 @@ async function main() {
|
|
|
142
154
|
await migrateCommand(version, opts);
|
|
143
155
|
}
|
|
144
156
|
catch (err) {
|
|
145
|
-
fail(`migrate failed: ${err.message}`, { command: 'migrate' }, 1);
|
|
157
|
+
await fail(`migrate failed: ${err.message}`, { command: 'migrate' }, 1);
|
|
146
158
|
}
|
|
147
159
|
});
|
|
148
160
|
await program.parseAsync(process.argv);
|
|
149
161
|
}
|
|
150
162
|
void main()
|
|
151
163
|
.then(() => {
|
|
164
|
+
// After the command succeeds, kick off update in the background.
|
|
165
|
+
// Human mode only — never surprise machine (--json) consumers.
|
|
166
|
+
if (getOutputMode() === 'human') {
|
|
167
|
+
selfUpdate();
|
|
168
|
+
}
|
|
152
169
|
process.exit(0);
|
|
153
170
|
})
|
|
154
|
-
.catch((err) => {
|
|
155
|
-
|
|
156
|
-
process.exit(1);
|
|
171
|
+
.catch(async (err) => {
|
|
172
|
+
await fail(`main failed: ${err.message}`, { command: 'cli-main' });
|
|
157
173
|
});
|
|
@@ -18,5 +18,5 @@ export declare function output(human: string, data: unknown): void;
|
|
|
18
18
|
* Emit a structured failure payload (JSON mode) or a red error line (human mode),
|
|
19
19
|
* then exit with the given code.
|
|
20
20
|
*/
|
|
21
|
-
export declare function fail(message: string, payload: Record<string, unknown>, exitCode?: number): never
|
|
21
|
+
export declare function fail(message: string, payload: Record<string, unknown>, exitCode?: number): Promise<never>;
|
|
22
22
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/util/logger.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,CAAC;AAI1C,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAEpD;AAED,wBAAgB,aAAa,IAAI,UAAU,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAItC;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAItC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI1C;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAMzD;AAED;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/util/logger.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,CAAC;AAI1C,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAEpD;AAED,wBAAgB,aAAa,IAAI,UAAU,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAItC;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAItC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI1C;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAMzD;AAED;;;GAGG;AACH,wBAAsB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,SAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAW1G"}
|
package/dist/esm/util/logger.mjs
CHANGED
|
@@ -44,7 +44,7 @@ function output(human, data) {
|
|
|
44
44
|
* Emit a structured failure payload (JSON mode) or a red error line (human mode),
|
|
45
45
|
* then exit with the given code.
|
|
46
46
|
*/
|
|
47
|
-
function fail(message, payload, exitCode = 1) {
|
|
47
|
+
async function fail(message, payload, exitCode = 1) {
|
|
48
48
|
if (mode === 'json') {
|
|
49
49
|
process.stdout.write(`${JSON.stringify({ ok: false, error: message, ...payload })}\n`);
|
|
50
50
|
}
|
|
@@ -54,7 +54,7 @@ function fail(message, payload, exitCode = 1) {
|
|
|
54
54
|
process.stderr.write(pc.dim(` → ${payload.suggestedCommand}\n`));
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
trackEvent('z2h_cli_error', { action: payload.command ?? 'unknown', error: message });
|
|
57
|
+
await trackEvent('z2h_cli_error', { action: payload.command ?? 'unknown', error: message });
|
|
58
58
|
process.exit(exitCode);
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function trackEvent(name: string, data: Record<string, unknown>): void
|
|
1
|
+
export declare function trackEvent(name: string, data: Record<string, unknown>): Promise<void>;
|
|
2
2
|
export declare function trackDuration<T>(eventName: string, fn: () => Promise<T>, data?: Record<string, unknown>): Promise<T>;
|
|
3
3
|
//# sourceMappingURL=tracker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../../src/util/tracker.ts"],"names":[],"mappings":"AAMA,
|
|
1
|
+
{"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../../src/util/tracker.ts"],"names":[],"mappings":"AAMA,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAO3F;AAED,wBAAsB,aAAa,CAAC,CAAC,EACnC,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC,CAKZ"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
|
|
3
|
-
const DOORMAN_URL = 'https://track.bigbrain.me/prod/event';
|
|
3
|
+
const DOORMAN_URL = 'https://track-int.bigbrain.me/prod/event';
|
|
4
4
|
const username = os.userInfo().username;
|
|
5
|
-
function trackEvent(name, data) {
|
|
6
|
-
|
|
5
|
+
async function trackEvent(name, data) {
|
|
6
|
+
await fetch(DOORMAN_URL, {
|
|
7
7
|
method: 'POST',
|
|
8
8
|
headers: { 'Content-Type': 'application/json' },
|
|
9
|
-
body: JSON.stringify({ name, source: 'z2h-cli', data: { username, ...data } }),
|
|
9
|
+
body: JSON.stringify({ name, source: 'z2h-cli', data: { user_name: username, ...data } }),
|
|
10
10
|
signal: AbortSignal.timeout(5000),
|
|
11
11
|
}).catch(() => { });
|
|
12
12
|
}
|
|
13
13
|
async function trackDuration(eventName, fn, data) {
|
|
14
14
|
const start = Date.now();
|
|
15
15
|
const result = await fn();
|
|
16
|
-
trackEvent(eventName, { ...data, duration_ms: Date.now() - start });
|
|
16
|
+
await trackEvent(eventName, { ...data, duration_ms: Date.now() - start });
|
|
17
17
|
return result;
|
|
18
18
|
}
|
|
19
19
|
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const node_module = require('node:module');
|
|
2
2
|
const fs = require('node:fs');
|
|
3
|
+
const os = require('node:os');
|
|
4
|
+
const path = require('node:path');
|
|
3
5
|
const commander = require('commander');
|
|
6
|
+
const execa = require('execa');
|
|
4
7
|
const commands_dev = require('./commands/dev.js');
|
|
5
8
|
const commands_build = require('./commands/build.js');
|
|
6
9
|
const commands_clean = require('./commands/clean.js');
|
|
@@ -13,7 +16,21 @@ const util_logger = require('./util/logger.js');
|
|
|
13
16
|
const util_tracker = require('./util/tracker.js');
|
|
14
17
|
|
|
15
18
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
19
|
+
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
20
|
+
|
|
21
|
+
const os__default = /*#__PURE__*/_interopDefault(os);
|
|
22
|
+
const path__default = /*#__PURE__*/_interopDefault(path);
|
|
23
|
+
|
|
16
24
|
const { version } = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)))('../package.json');
|
|
25
|
+
const UPDATE_SCRIPT = path__default.default.join(os__default.default.homedir(), 'Development', 'bigbrain-z2h', 'z2h', 'setup', 'update.sh');
|
|
26
|
+
function selfUpdate() {
|
|
27
|
+
try {
|
|
28
|
+
execa.execa('bash', [UPDATE_SCRIPT], { detached: true, stdio: 'ignore' }).unref();
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
util_logger.errorLog(`Z2H auto-update failed to start: ${err.message}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
17
34
|
function getCwdAppName() {
|
|
18
35
|
try {
|
|
19
36
|
return JSON.parse(fs.readFileSync('package.json', 'utf8')).name;
|
|
@@ -48,7 +65,7 @@ async function main() {
|
|
|
48
65
|
await util_tracker.trackDuration('z2h_app_build_success', () => commands_build.buildCommand(opts), { app_name: getCwdAppName() });
|
|
49
66
|
}
|
|
50
67
|
catch (err) {
|
|
51
|
-
util_logger.fail(`build failed: ${err.message}`, { command: 'build' }, 2);
|
|
68
|
+
await util_logger.fail(`build failed: ${err.message}`, { command: 'build' }, 2);
|
|
52
69
|
}
|
|
53
70
|
});
|
|
54
71
|
program
|
|
@@ -60,7 +77,7 @@ async function main() {
|
|
|
60
77
|
await commands_dev.devCommand(opts);
|
|
61
78
|
}
|
|
62
79
|
catch (err) {
|
|
63
|
-
util_logger.fail(`dev failed: ${err.message}`, { command: 'dev' }, 2);
|
|
80
|
+
await util_logger.fail(`dev failed: ${err.message}`, { command: 'dev' }, 2);
|
|
64
81
|
}
|
|
65
82
|
});
|
|
66
83
|
program
|
|
@@ -72,7 +89,7 @@ async function main() {
|
|
|
72
89
|
await commands_clean.cleanCommand(opts);
|
|
73
90
|
}
|
|
74
91
|
catch (err) {
|
|
75
|
-
util_logger.fail(`clean failed: ${err.message}`, { command: 'clean' }, 2);
|
|
92
|
+
await util_logger.fail(`clean failed: ${err.message}`, { command: 'clean' }, 2);
|
|
76
93
|
}
|
|
77
94
|
});
|
|
78
95
|
program
|
|
@@ -87,7 +104,7 @@ async function main() {
|
|
|
87
104
|
});
|
|
88
105
|
}
|
|
89
106
|
catch (err) {
|
|
90
|
-
util_logger.fail(`deploy failed: ${err.message}`, { command: 'deploy' }, 2);
|
|
107
|
+
await util_logger.fail(`deploy failed: ${err.message}`, { command: 'deploy' }, 2);
|
|
91
108
|
}
|
|
92
109
|
});
|
|
93
110
|
program
|
|
@@ -99,7 +116,7 @@ async function main() {
|
|
|
99
116
|
await commands_createWorkspace.createWorkspaceCommand(opts);
|
|
100
117
|
}
|
|
101
118
|
catch (err) {
|
|
102
|
-
util_logger.fail(`create-workspace failed: ${err.message}`, { command: 'create-workspace' }, 1);
|
|
119
|
+
await util_logger.fail(`create-workspace failed: ${err.message}`, { command: 'create-workspace' }, 1);
|
|
103
120
|
}
|
|
104
121
|
});
|
|
105
122
|
program
|
|
@@ -113,7 +130,7 @@ async function main() {
|
|
|
113
130
|
await commands_generateZ2hToken.generateZ2HTokenCommand(opts);
|
|
114
131
|
}
|
|
115
132
|
catch (err) {
|
|
116
|
-
util_logger.fail(`generate-z2h-token failed: ${err.message}`, { command: 'generate-z2h-token' }, 1);
|
|
133
|
+
await util_logger.fail(`generate-z2h-token failed: ${err.message}`, { command: 'generate-z2h-token' }, 1);
|
|
117
134
|
}
|
|
118
135
|
});
|
|
119
136
|
program
|
|
@@ -130,7 +147,7 @@ async function main() {
|
|
|
130
147
|
});
|
|
131
148
|
}
|
|
132
149
|
catch (err) {
|
|
133
|
-
util_logger.fail(`create failed: ${err.message}`, { command: 'create' }, 1);
|
|
150
|
+
await util_logger.fail(`create failed: ${err.message}`, { command: 'create' }, 1);
|
|
134
151
|
}
|
|
135
152
|
});
|
|
136
153
|
program
|
|
@@ -143,16 +160,20 @@ async function main() {
|
|
|
143
160
|
await commands_migrate.migrateCommand(version, opts);
|
|
144
161
|
}
|
|
145
162
|
catch (err) {
|
|
146
|
-
util_logger.fail(`migrate failed: ${err.message}`, { command: 'migrate' }, 1);
|
|
163
|
+
await util_logger.fail(`migrate failed: ${err.message}`, { command: 'migrate' }, 1);
|
|
147
164
|
}
|
|
148
165
|
});
|
|
149
166
|
await program.parseAsync(process.argv);
|
|
150
167
|
}
|
|
151
168
|
void main()
|
|
152
169
|
.then(() => {
|
|
170
|
+
// After the command succeeds, kick off update in the background.
|
|
171
|
+
// Human mode only — never surprise machine (--json) consumers.
|
|
172
|
+
if (util_logger.getOutputMode() === 'human') {
|
|
173
|
+
selfUpdate();
|
|
174
|
+
}
|
|
153
175
|
process.exit(0);
|
|
154
176
|
})
|
|
155
|
-
.catch((err) => {
|
|
156
|
-
util_logger.
|
|
157
|
-
process.exit(1);
|
|
177
|
+
.catch(async (err) => {
|
|
178
|
+
await util_logger.fail(`main failed: ${err.message}`, { command: 'cli-main' });
|
|
158
179
|
});
|
package/dist/util/logger.d.ts
CHANGED
|
@@ -18,5 +18,5 @@ export declare function output(human: string, data: unknown): void;
|
|
|
18
18
|
* Emit a structured failure payload (JSON mode) or a red error line (human mode),
|
|
19
19
|
* then exit with the given code.
|
|
20
20
|
*/
|
|
21
|
-
export declare function fail(message: string, payload: Record<string, unknown>, exitCode?: number): never
|
|
21
|
+
export declare function fail(message: string, payload: Record<string, unknown>, exitCode?: number): Promise<never>;
|
|
22
22
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,CAAC;AAI1C,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAEpD;AAED,wBAAgB,aAAa,IAAI,UAAU,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAItC;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAItC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI1C;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAMzD;AAED;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,CAAC;AAI1C,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAEpD;AAED,wBAAgB,aAAa,IAAI,UAAU,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAItC;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAItC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI1C;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAMzD;AAED;;;GAGG;AACH,wBAAsB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,SAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAW1G"}
|
package/dist/util/logger.js
CHANGED
|
@@ -50,7 +50,7 @@ function output(human, data) {
|
|
|
50
50
|
* Emit a structured failure payload (JSON mode) or a red error line (human mode),
|
|
51
51
|
* then exit with the given code.
|
|
52
52
|
*/
|
|
53
|
-
function fail(message, payload, exitCode = 1) {
|
|
53
|
+
async function fail(message, payload, exitCode = 1) {
|
|
54
54
|
if (mode === 'json') {
|
|
55
55
|
process.stdout.write(`${JSON.stringify({ ok: false, error: message, ...payload })}\n`);
|
|
56
56
|
}
|
|
@@ -60,7 +60,7 @@ function fail(message, payload, exitCode = 1) {
|
|
|
60
60
|
process.stderr.write(pc__default.default.dim(` → ${payload.suggestedCommand}\n`));
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
util_tracker.trackEvent('z2h_cli_error', { action: payload.command ?? 'unknown', error: message });
|
|
63
|
+
await util_tracker.trackEvent('z2h_cli_error', { action: payload.command ?? 'unknown', error: message });
|
|
64
64
|
process.exit(exitCode);
|
|
65
65
|
}
|
|
66
66
|
|
package/dist/util/tracker.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function trackEvent(name: string, data: Record<string, unknown>): void
|
|
1
|
+
export declare function trackEvent(name: string, data: Record<string, unknown>): Promise<void>;
|
|
2
2
|
export declare function trackDuration<T>(eventName: string, fn: () => Promise<T>, data?: Record<string, unknown>): Promise<T>;
|
|
3
3
|
//# sourceMappingURL=tracker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../src/util/tracker.ts"],"names":[],"mappings":"AAMA,
|
|
1
|
+
{"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../src/util/tracker.ts"],"names":[],"mappings":"AAMA,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAO3F;AAED,wBAAsB,aAAa,CAAC,CAAC,EACnC,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC,CAKZ"}
|
package/dist/util/tracker.js
CHANGED
|
@@ -6,20 +6,20 @@ const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
|
6
6
|
|
|
7
7
|
const os__default = /*#__PURE__*/_interopDefault(os);
|
|
8
8
|
|
|
9
|
-
const DOORMAN_URL = 'https://track.bigbrain.me/prod/event';
|
|
9
|
+
const DOORMAN_URL = 'https://track-int.bigbrain.me/prod/event';
|
|
10
10
|
const username = os__default.default.userInfo().username;
|
|
11
|
-
function trackEvent(name, data) {
|
|
12
|
-
|
|
11
|
+
async function trackEvent(name, data) {
|
|
12
|
+
await fetch(DOORMAN_URL, {
|
|
13
13
|
method: 'POST',
|
|
14
14
|
headers: { 'Content-Type': 'application/json' },
|
|
15
|
-
body: JSON.stringify({ name, source: 'z2h-cli', data: { username, ...data } }),
|
|
15
|
+
body: JSON.stringify({ name, source: 'z2h-cli', data: { user_name: username, ...data } }),
|
|
16
16
|
signal: AbortSignal.timeout(5000),
|
|
17
17
|
}).catch(() => { });
|
|
18
18
|
}
|
|
19
19
|
async function trackDuration(eventName, fn, data) {
|
|
20
20
|
const start = Date.now();
|
|
21
21
|
const result = await fn();
|
|
22
|
-
trackEvent(eventName, { ...data, duration_ms: Date.now() - start });
|
|
22
|
+
await trackEvent(eventName, { ...data, duration_ms: Date.now() - start });
|
|
23
23
|
return result;
|
|
24
24
|
}
|
|
25
25
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
3
5
|
import { Command } from 'commander';
|
|
6
|
+
import { execa } from 'execa';
|
|
4
7
|
import { devCommand } from './commands/dev';
|
|
5
8
|
import { buildCommand } from './commands/build';
|
|
6
9
|
import { cleanCommand } from './commands/clean';
|
|
@@ -9,11 +12,21 @@ import { createWorkspaceCommand } from './commands/create-workspace';
|
|
|
9
12
|
import { createCommand } from './commands/create';
|
|
10
13
|
import { generateZ2HTokenCommand } from './commands/generate-z2h-token';
|
|
11
14
|
import { migrateCommand } from './commands/migrate';
|
|
12
|
-
import { errorLog, fail } from './util/logger';
|
|
15
|
+
import { errorLog, fail, getOutputMode } from './util/logger';
|
|
13
16
|
import { trackDuration } from './util/tracker';
|
|
14
17
|
|
|
15
18
|
const { version } = createRequire(import.meta.url)('../package.json') as { version: string };
|
|
16
19
|
|
|
20
|
+
const UPDATE_SCRIPT = path.join(os.homedir(), 'Development', 'bigbrain-z2h', 'z2h', 'setup', 'update.sh');
|
|
21
|
+
|
|
22
|
+
function selfUpdate(): void {
|
|
23
|
+
try {
|
|
24
|
+
execa('bash', [UPDATE_SCRIPT], { detached: true, stdio: 'ignore' }).unref();
|
|
25
|
+
} catch (err) {
|
|
26
|
+
errorLog(`Z2H auto-update failed to start: ${(err as Error).message}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
function getCwdAppName(): string | undefined {
|
|
18
31
|
try {
|
|
19
32
|
return (JSON.parse(readFileSync('package.json', 'utf8')) as { name?: string }).name;
|
|
@@ -50,7 +63,7 @@ async function main(): Promise<void> {
|
|
|
50
63
|
try {
|
|
51
64
|
await trackDuration('z2h_app_build_success', () => buildCommand(opts), { app_name: getCwdAppName() });
|
|
52
65
|
} catch (err) {
|
|
53
|
-
fail(`build failed: ${(err as Error).message}`, { command: 'build' }, 2);
|
|
66
|
+
await fail(`build failed: ${(err as Error).message}`, { command: 'build' }, 2);
|
|
54
67
|
}
|
|
55
68
|
});
|
|
56
69
|
|
|
@@ -62,7 +75,7 @@ async function main(): Promise<void> {
|
|
|
62
75
|
try {
|
|
63
76
|
await devCommand(opts);
|
|
64
77
|
} catch (err) {
|
|
65
|
-
fail(`dev failed: ${(err as Error).message}`, { command: 'dev' }, 2);
|
|
78
|
+
await fail(`dev failed: ${(err as Error).message}`, { command: 'dev' }, 2);
|
|
66
79
|
}
|
|
67
80
|
});
|
|
68
81
|
|
|
@@ -74,7 +87,7 @@ async function main(): Promise<void> {
|
|
|
74
87
|
try {
|
|
75
88
|
await cleanCommand(opts);
|
|
76
89
|
} catch (err) {
|
|
77
|
-
fail(`clean failed: ${(err as Error).message}`, { command: 'clean' }, 2);
|
|
90
|
+
await fail(`clean failed: ${(err as Error).message}`, { command: 'clean' }, 2);
|
|
78
91
|
}
|
|
79
92
|
});
|
|
80
93
|
|
|
@@ -89,7 +102,7 @@ async function main(): Promise<void> {
|
|
|
89
102
|
app_name: getCwdAppName(),
|
|
90
103
|
});
|
|
91
104
|
} catch (err) {
|
|
92
|
-
fail(`deploy failed: ${(err as Error).message}`, { command: 'deploy' }, 2);
|
|
105
|
+
await fail(`deploy failed: ${(err as Error).message}`, { command: 'deploy' }, 2);
|
|
93
106
|
}
|
|
94
107
|
});
|
|
95
108
|
|
|
@@ -101,7 +114,7 @@ async function main(): Promise<void> {
|
|
|
101
114
|
try {
|
|
102
115
|
await createWorkspaceCommand(opts);
|
|
103
116
|
} catch (err) {
|
|
104
|
-
fail(`create-workspace failed: ${(err as Error).message}`, { command: 'create-workspace' }, 1);
|
|
117
|
+
await fail(`create-workspace failed: ${(err as Error).message}`, { command: 'create-workspace' }, 1);
|
|
105
118
|
}
|
|
106
119
|
});
|
|
107
120
|
|
|
@@ -117,7 +130,7 @@ async function main(): Promise<void> {
|
|
|
117
130
|
try {
|
|
118
131
|
await generateZ2HTokenCommand(opts);
|
|
119
132
|
} catch (err) {
|
|
120
|
-
fail(`generate-z2h-token failed: ${(err as Error).message}`, { command: 'generate-z2h-token' }, 1);
|
|
133
|
+
await fail(`generate-z2h-token failed: ${(err as Error).message}`, { command: 'generate-z2h-token' }, 1);
|
|
121
134
|
}
|
|
122
135
|
});
|
|
123
136
|
|
|
@@ -134,7 +147,7 @@ async function main(): Promise<void> {
|
|
|
134
147
|
template: opts.template ?? 'default',
|
|
135
148
|
});
|
|
136
149
|
} catch (err) {
|
|
137
|
-
fail(`create failed: ${(err as Error).message}`, { command: 'create' }, 1);
|
|
150
|
+
await fail(`create failed: ${(err as Error).message}`, { command: 'create' }, 1);
|
|
138
151
|
}
|
|
139
152
|
});
|
|
140
153
|
|
|
@@ -147,7 +160,7 @@ async function main(): Promise<void> {
|
|
|
147
160
|
try {
|
|
148
161
|
await migrateCommand(version, opts);
|
|
149
162
|
} catch (err) {
|
|
150
|
-
fail(`migrate failed: ${(err as Error).message}`, { command: 'migrate' }, 1);
|
|
163
|
+
await fail(`migrate failed: ${(err as Error).message}`, { command: 'migrate' }, 1);
|
|
151
164
|
}
|
|
152
165
|
});
|
|
153
166
|
|
|
@@ -156,9 +169,13 @@ async function main(): Promise<void> {
|
|
|
156
169
|
|
|
157
170
|
void main()
|
|
158
171
|
.then(() => {
|
|
172
|
+
// After the command succeeds, kick off update in the background.
|
|
173
|
+
// Human mode only — never surprise machine (--json) consumers.
|
|
174
|
+
if (getOutputMode() === 'human') {
|
|
175
|
+
selfUpdate();
|
|
176
|
+
}
|
|
159
177
|
process.exit(0);
|
|
160
178
|
})
|
|
161
|
-
.catch((err: unknown) => {
|
|
162
|
-
|
|
163
|
-
process.exit(1);
|
|
179
|
+
.catch(async (err: unknown) => {
|
|
180
|
+
await fail(`main failed: ${(err as Error).message}`, { command: 'cli-main' });
|
|
164
181
|
});
|
package/src/util/logger.ts
CHANGED
|
@@ -52,7 +52,7 @@ export function output(human: string, data: unknown): void {
|
|
|
52
52
|
* Emit a structured failure payload (JSON mode) or a red error line (human mode),
|
|
53
53
|
* then exit with the given code.
|
|
54
54
|
*/
|
|
55
|
-
export function fail(message: string, payload: Record<string, unknown>, exitCode = 1): never {
|
|
55
|
+
export async function fail(message: string, payload: Record<string, unknown>, exitCode = 1): Promise<never> {
|
|
56
56
|
if (mode === 'json') {
|
|
57
57
|
process.stdout.write(`${JSON.stringify({ ok: false, error: message, ...payload })}\n`);
|
|
58
58
|
} else {
|
|
@@ -61,6 +61,6 @@ export function fail(message: string, payload: Record<string, unknown>, exitCode
|
|
|
61
61
|
process.stderr.write(pc.dim(` → ${payload.suggestedCommand}\n`));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
trackEvent('z2h_cli_error', { action:
|
|
64
|
+
await trackEvent('z2h_cli_error', { action: payload.command ?? 'unknown', error: message });
|
|
65
65
|
process.exit(exitCode);
|
|
66
66
|
}
|
package/src/util/tracker.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
|
|
3
|
-
const DOORMAN_URL = 'https://track.bigbrain.me/prod/event';
|
|
3
|
+
const DOORMAN_URL = 'https://track-int.bigbrain.me/prod/event';
|
|
4
4
|
|
|
5
5
|
const username = os.userInfo().username;
|
|
6
6
|
|
|
7
|
-
export function trackEvent(name: string, data: Record<string, unknown>): void {
|
|
8
|
-
|
|
7
|
+
export async function trackEvent(name: string, data: Record<string, unknown>): Promise<void> {
|
|
8
|
+
await fetch(DOORMAN_URL, {
|
|
9
9
|
method: 'POST',
|
|
10
10
|
headers: { 'Content-Type': 'application/json' },
|
|
11
|
-
body: JSON.stringify({ name, source: 'z2h-cli', data: { username, ...data } }),
|
|
11
|
+
body: JSON.stringify({ name, source: 'z2h-cli', data: { user_name: username, ...data } }),
|
|
12
12
|
signal: AbortSignal.timeout(5000),
|
|
13
13
|
}).catch(() => {});
|
|
14
14
|
}
|
|
@@ -20,6 +20,6 @@ export async function trackDuration<T>(
|
|
|
20
20
|
): Promise<T> {
|
|
21
21
|
const start = Date.now();
|
|
22
22
|
const result = await fn();
|
|
23
|
-
trackEvent(eventName, { ...data, duration_ms: Date.now() - start });
|
|
23
|
+
await trackEvent(eventName, { ...data, duration_ms: Date.now() - start });
|
|
24
24
|
return result;
|
|
25
25
|
}
|