@newtype-ai/nit 0.4.6 → 0.4.7
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/cli.js +28 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from "./chunk-535YI4CD.js";
|
|
19
19
|
|
|
20
20
|
// src/update-check.ts
|
|
21
|
+
import { execSync } from "child_process";
|
|
21
22
|
import { homedir } from "os";
|
|
22
23
|
import { join } from "path";
|
|
23
24
|
import { readFile, writeFile } from "fs/promises";
|
|
@@ -27,7 +28,7 @@ var FETCH_TIMEOUT_MS = 3e3;
|
|
|
27
28
|
var REGISTRY_URL = "https://registry.npmjs.org/@newtype-ai/nit/latest";
|
|
28
29
|
function getCurrentVersion() {
|
|
29
30
|
try {
|
|
30
|
-
return "0.4.
|
|
31
|
+
return "0.4.7";
|
|
31
32
|
} catch {
|
|
32
33
|
return "0.0.0";
|
|
33
34
|
}
|
|
@@ -81,6 +82,31 @@ async function checkForUpdate() {
|
|
|
81
82
|
clearTimeout(timeout);
|
|
82
83
|
}
|
|
83
84
|
}
|
|
85
|
+
async function autoUpdate() {
|
|
86
|
+
const update = await checkForUpdate().catch(() => null);
|
|
87
|
+
if (!update) return;
|
|
88
|
+
const { current, latest } = update;
|
|
89
|
+
process.stderr.write(`nit: updating ${current} \u2192 ${latest}...
|
|
90
|
+
`);
|
|
91
|
+
try {
|
|
92
|
+
execSync("npm install -g @newtype-ai/nit@latest", {
|
|
93
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
94
|
+
timeout: 3e4
|
|
95
|
+
});
|
|
96
|
+
} catch {
|
|
97
|
+
process.stderr.write(`nit: auto-update failed. Run manually: npm install -g @newtype-ai/nit
|
|
98
|
+
`);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const args = process.argv.slice(2).join(" ");
|
|
103
|
+
execSync(`nit ${args}`, { stdio: "inherit", timeout: 6e4 });
|
|
104
|
+
process.exit(0);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
const code = err.status ?? 1;
|
|
107
|
+
process.exit(code);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
84
110
|
|
|
85
111
|
// src/cli.ts
|
|
86
112
|
var bold = (s) => `\x1B[1m${s}\x1B[0m`;
|
|
@@ -89,6 +115,7 @@ var yellow = (s) => `\x1B[33m${s}\x1B[0m`;
|
|
|
89
115
|
var red = (s) => `\x1B[31m${s}\x1B[0m`;
|
|
90
116
|
var dim = (s) => `\x1B[2m${s}\x1B[0m`;
|
|
91
117
|
async function main() {
|
|
118
|
+
await autoUpdate();
|
|
92
119
|
const [, , command, ...args] = process.argv;
|
|
93
120
|
try {
|
|
94
121
|
switch (command) {
|
|
@@ -144,13 +171,6 @@ async function main() {
|
|
|
144
171
|
if (command === "--version" || command === "-v") {
|
|
145
172
|
console.log(`nit ${version}`);
|
|
146
173
|
}
|
|
147
|
-
const update = await checkForUpdate().catch(() => null);
|
|
148
|
-
if (update) {
|
|
149
|
-
console.error(yellow(`
|
|
150
|
-
Update available: ${update.current} \u2192 ${update.latest}`));
|
|
151
|
-
console.error(yellow(` Run: npm install -g @newtype-ai/nit
|
|
152
|
-
`));
|
|
153
|
-
}
|
|
154
174
|
}
|
|
155
175
|
async function cmdInit() {
|
|
156
176
|
const result = await init();
|