@nimbuslab/cli 0.14.0 → 0.15.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.
- package/.github/workflows/publish.yml +25 -0
- package/dist/index.js +130 -35
- package/package.json +1 -1
- package/src/commands/lola.ts +33 -0
- package/src/commands/update.ts +133 -35
- package/src/index.ts +4 -3
|
@@ -16,27 +16,52 @@ jobs:
|
|
|
16
16
|
- name: Checkout
|
|
17
17
|
uses: actions/checkout@v4
|
|
18
18
|
|
|
19
|
+
- name: Check if version changed
|
|
20
|
+
id: version_check
|
|
21
|
+
run: |
|
|
22
|
+
LOCAL_VERSION=$(node -p "require('./package.json').version")
|
|
23
|
+
NPM_VERSION=$(npm view @nimbuslab/cli version 2>/dev/null || echo "0.0.0")
|
|
24
|
+
echo "local=$LOCAL_VERSION" >> $GITHUB_OUTPUT
|
|
25
|
+
echo "npm=$NPM_VERSION" >> $GITHUB_OUTPUT
|
|
26
|
+
if [ "$LOCAL_VERSION" = "$NPM_VERSION" ]; then
|
|
27
|
+
echo "changed=false" >> $GITHUB_OUTPUT
|
|
28
|
+
echo "Versao $LOCAL_VERSION ja existe no npm. Pulando publish."
|
|
29
|
+
else
|
|
30
|
+
echo "changed=true" >> $GITHUB_OUTPUT
|
|
31
|
+
echo "Nova versao detectada: $NPM_VERSION -> $LOCAL_VERSION"
|
|
32
|
+
fi
|
|
33
|
+
|
|
19
34
|
- name: Setup Bun
|
|
35
|
+
if: steps.version_check.outputs.changed == 'true'
|
|
20
36
|
uses: oven-sh/setup-bun@v2
|
|
21
37
|
with:
|
|
22
38
|
bun-version: latest
|
|
23
39
|
|
|
24
40
|
- name: Setup Node (for npm publish)
|
|
41
|
+
if: steps.version_check.outputs.changed == 'true'
|
|
25
42
|
uses: actions/setup-node@v4
|
|
26
43
|
with:
|
|
27
44
|
node-version: "24"
|
|
28
45
|
registry-url: "https://registry.npmjs.org"
|
|
29
46
|
|
|
30
47
|
- name: Install dependencies
|
|
48
|
+
if: steps.version_check.outputs.changed == 'true'
|
|
31
49
|
run: bun install
|
|
32
50
|
|
|
33
51
|
- name: Typecheck
|
|
52
|
+
if: steps.version_check.outputs.changed == 'true'
|
|
34
53
|
run: bun run typecheck
|
|
35
54
|
|
|
36
55
|
- name: Build
|
|
56
|
+
if: steps.version_check.outputs.changed == 'true'
|
|
37
57
|
run: bun run build
|
|
38
58
|
|
|
39
59
|
- name: Publish to npm
|
|
60
|
+
if: steps.version_check.outputs.changed == 'true'
|
|
40
61
|
run: npm publish --access public
|
|
41
62
|
env:
|
|
42
63
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
64
|
+
|
|
65
|
+
- name: Skip message
|
|
66
|
+
if: steps.version_check.outputs.changed == 'false'
|
|
67
|
+
run: echo "Publish pulado - versao ${{ steps.version_check.outputs.local }} ja existe no npm"
|
package/dist/index.js
CHANGED
|
@@ -150,7 +150,7 @@ var require_src = __commonJS((exports, module) => {
|
|
|
150
150
|
var require_package = __commonJS((exports, module) => {
|
|
151
151
|
module.exports = {
|
|
152
152
|
name: "@nimbuslab/cli",
|
|
153
|
-
version: "0.
|
|
153
|
+
version: "0.15.0",
|
|
154
154
|
description: "CLI para criar projetos nimbuslab",
|
|
155
155
|
type: "module",
|
|
156
156
|
bin: {
|
|
@@ -2382,84 +2382,149 @@ async function getLatestVersion() {
|
|
|
2382
2382
|
return null;
|
|
2383
2383
|
}
|
|
2384
2384
|
}
|
|
2385
|
+
function detectPackageManager2() {
|
|
2386
|
+
try {
|
|
2387
|
+
const bunResult = spawnSync("bun", ["pm", "ls", "-g"], {
|
|
2388
|
+
encoding: "utf-8",
|
|
2389
|
+
shell: true,
|
|
2390
|
+
timeout: 5000
|
|
2391
|
+
});
|
|
2392
|
+
if (bunResult.stdout && bunResult.stdout.includes(PACKAGE_NAME)) {
|
|
2393
|
+
return "bun";
|
|
2394
|
+
}
|
|
2395
|
+
} catch {}
|
|
2396
|
+
try {
|
|
2397
|
+
const npmResult = spawnSync("npm", ["ls", "-g", PACKAGE_NAME, "--json"], {
|
|
2398
|
+
encoding: "utf-8",
|
|
2399
|
+
shell: true,
|
|
2400
|
+
timeout: 5000
|
|
2401
|
+
});
|
|
2402
|
+
if (npmResult.stdout) {
|
|
2403
|
+
const data = JSON.parse(npmResult.stdout);
|
|
2404
|
+
if (data.dependencies?.[PACKAGE_NAME]) {
|
|
2405
|
+
return "npm";
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
} catch {}
|
|
2409
|
+
return "unknown";
|
|
2410
|
+
}
|
|
2385
2411
|
function getCurrentVersion() {
|
|
2412
|
+
try {
|
|
2413
|
+
const bunResult = spawnSync("bun", ["pm", "ls", "-g"], {
|
|
2414
|
+
encoding: "utf-8",
|
|
2415
|
+
shell: true,
|
|
2416
|
+
timeout: 5000
|
|
2417
|
+
});
|
|
2418
|
+
if (bunResult.stdout) {
|
|
2419
|
+
const match = bunResult.stdout.match(new RegExp(`${PACKAGE_NAME.replace("/", "\\/")}@([\\d.]+)`));
|
|
2420
|
+
if (match?.[1]) {
|
|
2421
|
+
return match[1];
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
} catch {}
|
|
2386
2425
|
try {
|
|
2387
2426
|
const result = spawnSync("npm", ["ls", "-g", PACKAGE_NAME, "--json"], {
|
|
2388
2427
|
encoding: "utf-8",
|
|
2389
|
-
shell: true
|
|
2428
|
+
shell: true,
|
|
2429
|
+
timeout: 5000
|
|
2390
2430
|
});
|
|
2391
2431
|
if (result.stdout) {
|
|
2392
2432
|
const data = JSON.parse(result.stdout);
|
|
2393
|
-
|
|
2433
|
+
if (data.dependencies?.[PACKAGE_NAME]?.version) {
|
|
2434
|
+
return data.dependencies[PACKAGE_NAME].version;
|
|
2435
|
+
}
|
|
2394
2436
|
}
|
|
2395
2437
|
} catch {}
|
|
2396
2438
|
return "unknown";
|
|
2397
2439
|
}
|
|
2398
2440
|
async function update(args) {
|
|
2399
|
-
const
|
|
2441
|
+
const forceFlag = args.includes("--force") || args.includes("-f");
|
|
2442
|
+
const filteredArgs = args.filter((a) => a !== "--force" && a !== "-f");
|
|
2443
|
+
const flag = filteredArgs[0];
|
|
2400
2444
|
if (flag === "--list" || flag === "-l") {
|
|
2401
|
-
Ie(import_picocolors6.default.cyan("
|
|
2445
|
+
Ie(import_picocolors6.default.cyan("Versoes disponiveis"));
|
|
2402
2446
|
const spinner2 = Y2();
|
|
2403
|
-
spinner2.start("Buscando
|
|
2447
|
+
spinner2.start("Buscando versoes...");
|
|
2404
2448
|
const versions = await getAvailableVersions();
|
|
2405
|
-
spinner2.stop("
|
|
2449
|
+
spinner2.stop("Versoes encontradas");
|
|
2406
2450
|
if (versions.length === 0) {
|
|
2407
|
-
M2.error("
|
|
2451
|
+
M2.error("Nao foi possivel buscar as versoes");
|
|
2408
2452
|
return;
|
|
2409
2453
|
}
|
|
2410
2454
|
const current = getCurrentVersion();
|
|
2455
|
+
const pm2 = detectPackageManager2();
|
|
2411
2456
|
console.log();
|
|
2412
|
-
console.log(import_picocolors6.default.bold("
|
|
2457
|
+
console.log(import_picocolors6.default.bold("Ultimas 10 versoes:"));
|
|
2413
2458
|
versions.slice(0, 10).forEach((v2, i) => {
|
|
2414
2459
|
const isCurrent = v2 === current;
|
|
2415
|
-
const prefix = isCurrent ? import_picocolors6.default.green("
|
|
2460
|
+
const prefix = isCurrent ? import_picocolors6.default.green("-> ") : " ";
|
|
2416
2461
|
const suffix = isCurrent ? import_picocolors6.default.dim(" (instalada)") : "";
|
|
2417
2462
|
const isLatest = i === 0 ? import_picocolors6.default.yellow(" (latest)") : "";
|
|
2418
2463
|
console.log(`${prefix}${v2}${suffix}${isLatest}`);
|
|
2419
2464
|
});
|
|
2420
2465
|
console.log();
|
|
2421
|
-
console.log(import_picocolors6.default.dim(`Total: ${versions.length}
|
|
2422
|
-
console.log(import_picocolors6.default.dim(`
|
|
2466
|
+
console.log(import_picocolors6.default.dim(`Total: ${versions.length} versoes`));
|
|
2467
|
+
console.log(import_picocolors6.default.dim(`Package manager detectado: ${pm2 === "unknown" ? "nenhum" : pm2}`));
|
|
2468
|
+
console.log(import_picocolors6.default.dim(`Instalar versao especifica: nimbus update <versao>`));
|
|
2469
|
+
console.log(import_picocolors6.default.dim(`Forcar reinstalacao: nimbus update --force`));
|
|
2423
2470
|
return;
|
|
2424
2471
|
}
|
|
2425
2472
|
const targetVersion = flag || "latest";
|
|
2426
|
-
const isSpecificVersion = flag && flag !== "latest";
|
|
2473
|
+
const isSpecificVersion = flag && flag !== "latest" && !flag.startsWith("-");
|
|
2427
2474
|
Ie(import_picocolors6.default.cyan(`Atualizando ${PACKAGE_NAME}`));
|
|
2428
2475
|
const spinner = Y2();
|
|
2429
|
-
spinner.start("
|
|
2476
|
+
spinner.start("Detectando package manager...");
|
|
2477
|
+
const detectedPm = detectPackageManager2();
|
|
2478
|
+
const pm = detectedPm === "unknown" ? "bun" : detectedPm;
|
|
2479
|
+
spinner.stop(`Package manager: ${pm}${detectedPm === "unknown" ? " (padrao)" : ""}`);
|
|
2480
|
+
spinner.start("Verificando versao atual...");
|
|
2430
2481
|
const currentVersion = getCurrentVersion();
|
|
2431
|
-
spinner.stop(`
|
|
2482
|
+
spinner.stop(`Versao atual: ${currentVersion === "unknown" ? "nao instalado" : currentVersion}`);
|
|
2483
|
+
let latestVersion = null;
|
|
2432
2484
|
if (!isSpecificVersion) {
|
|
2433
|
-
spinner.start("Verificando
|
|
2434
|
-
|
|
2435
|
-
spinner.stop(
|
|
2436
|
-
if (
|
|
2437
|
-
M2.success("
|
|
2485
|
+
spinner.start("Verificando ultima versao no npm...");
|
|
2486
|
+
latestVersion = await getLatestVersion();
|
|
2487
|
+
spinner.stop(`Ultima versao: ${latestVersion || "desconhecida"}`);
|
|
2488
|
+
if (!forceFlag && latestVersion && latestVersion === currentVersion) {
|
|
2489
|
+
M2.success("Voce ja esta na ultima versao!");
|
|
2490
|
+
console.log(import_picocolors6.default.dim(" Use --force para reinstalar"));
|
|
2438
2491
|
return;
|
|
2439
2492
|
}
|
|
2440
2493
|
}
|
|
2441
|
-
const versionText = isSpecificVersion ? targetVersion : "latest";
|
|
2494
|
+
const versionText = isSpecificVersion ? targetVersion : latestVersion || "latest";
|
|
2495
|
+
const actionText = forceFlag ? "Reinstalar" : "Atualizar";
|
|
2442
2496
|
const confirmUpdate = await ye({
|
|
2443
|
-
message:
|
|
2497
|
+
message: `${actionText} para ${versionText} usando ${pm}?`,
|
|
2444
2498
|
initialValue: true
|
|
2445
2499
|
});
|
|
2446
2500
|
if (pD(confirmUpdate) || !confirmUpdate) {
|
|
2447
|
-
xe("
|
|
2501
|
+
xe("Atualizacao cancelada");
|
|
2448
2502
|
return;
|
|
2449
2503
|
}
|
|
2450
2504
|
spinner.start("Atualizando...");
|
|
2451
2505
|
try {
|
|
2452
|
-
const packageSpec = isSpecificVersion ? `${PACKAGE_NAME}@${targetVersion}` : PACKAGE_NAME;
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2506
|
+
const packageSpec = isSpecificVersion ? `${PACKAGE_NAME}@${targetVersion}` : latestVersion ? `${PACKAGE_NAME}@${latestVersion}` : PACKAGE_NAME;
|
|
2507
|
+
if (pm === "bun") {
|
|
2508
|
+
if (forceFlag) {
|
|
2509
|
+
try {
|
|
2510
|
+
execSync(`bun remove -g ${PACKAGE_NAME}`, { stdio: "pipe", encoding: "utf-8" });
|
|
2511
|
+
} catch {}
|
|
2512
|
+
}
|
|
2513
|
+
execSync(`bun add -g ${packageSpec}`, { stdio: "pipe", encoding: "utf-8" });
|
|
2514
|
+
} else {
|
|
2515
|
+
const forceArg = forceFlag ? " --force" : "";
|
|
2516
|
+
execSync(`npm install -g ${packageSpec}${forceArg}`, { stdio: "pipe", encoding: "utf-8" });
|
|
2517
|
+
}
|
|
2518
|
+
spinner.stop("Atualizacao concluida!");
|
|
2458
2519
|
const newVersion = getCurrentVersion();
|
|
2459
|
-
|
|
2520
|
+
if (currentVersion === newVersion && !forceFlag) {
|
|
2521
|
+
M2.warn("Versao nao mudou. Tente com --force");
|
|
2522
|
+
} else {
|
|
2523
|
+
M2.success(`${PACKAGE_NAME} atualizado: ${currentVersion} -> ${newVersion}`);
|
|
2524
|
+
}
|
|
2460
2525
|
Se(import_picocolors6.default.green("Pronto!"));
|
|
2461
2526
|
} catch (error) {
|
|
2462
|
-
spinner.stop("Erro na
|
|
2527
|
+
spinner.stop("Erro na atualizacao");
|
|
2463
2528
|
const err = error;
|
|
2464
2529
|
M2.error("Falha ao atualizar");
|
|
2465
2530
|
if (err.stderr) {
|
|
@@ -2467,7 +2532,11 @@ async function update(args) {
|
|
|
2467
2532
|
}
|
|
2468
2533
|
console.log();
|
|
2469
2534
|
console.log(import_picocolors6.default.yellow("Tente manualmente:"));
|
|
2470
|
-
|
|
2535
|
+
if (pm === "bun") {
|
|
2536
|
+
console.log(import_picocolors6.default.cyan(` bun add -g ${PACKAGE_NAME}${isSpecificVersion ? `@${targetVersion}` : ""}`));
|
|
2537
|
+
} else {
|
|
2538
|
+
console.log(import_picocolors6.default.cyan(` npm install -g ${PACKAGE_NAME}${isSpecificVersion ? `@${targetVersion}` : ""}`));
|
|
2539
|
+
}
|
|
2471
2540
|
}
|
|
2472
2541
|
}
|
|
2473
2542
|
|
|
@@ -2536,11 +2605,36 @@ async function installLola() {
|
|
|
2536
2605
|
if (isUpdate) {
|
|
2537
2606
|
console.log(import_picocolors7.default.dim(` Lola ja instalada em ${LOLA_DIR}`));
|
|
2538
2607
|
console.log(import_picocolors7.default.cyan(" Atualizando..."));
|
|
2608
|
+
const statusCheck = Bun.spawnSync(["git", "status", "--porcelain"], {
|
|
2609
|
+
cwd: LOLA_DIR,
|
|
2610
|
+
stdout: "pipe"
|
|
2611
|
+
});
|
|
2612
|
+
const hasLocalChanges = statusCheck.stdout.toString().trim().length > 0;
|
|
2613
|
+
if (hasLocalChanges) {
|
|
2614
|
+
console.log(import_picocolors7.default.dim(" Salvando mudancas locais..."));
|
|
2615
|
+
Bun.spawnSync(["git", "stash", "--quiet"], {
|
|
2616
|
+
cwd: LOLA_DIR,
|
|
2617
|
+
stdout: "pipe",
|
|
2618
|
+
stderr: "pipe"
|
|
2619
|
+
});
|
|
2620
|
+
}
|
|
2539
2621
|
const result = Bun.spawnSync(["git", "pull", "--quiet"], {
|
|
2540
2622
|
cwd: LOLA_DIR,
|
|
2541
2623
|
stdout: "inherit",
|
|
2542
2624
|
stderr: "inherit"
|
|
2543
2625
|
});
|
|
2626
|
+
if (hasLocalChanges) {
|
|
2627
|
+
console.log(import_picocolors7.default.dim(" Restaurando mudancas locais..."));
|
|
2628
|
+
const stashPop = Bun.spawnSync(["git", "stash", "pop", "--quiet"], {
|
|
2629
|
+
cwd: LOLA_DIR,
|
|
2630
|
+
stdout: "pipe",
|
|
2631
|
+
stderr: "pipe"
|
|
2632
|
+
});
|
|
2633
|
+
if (stashPop.exitCode !== 0) {
|
|
2634
|
+
console.log(import_picocolors7.default.yellow(" Aviso: conflito ao restaurar mudancas locais"));
|
|
2635
|
+
console.log(import_picocolors7.default.dim(" Verifique ~/.lola e resolva manualmente: git stash pop"));
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2544
2638
|
if (result.exitCode !== 0) {
|
|
2545
2639
|
console.log(import_picocolors7.default.red(" Erro ao atualizar Lola"));
|
|
2546
2640
|
process.exit(1);
|
|
@@ -3176,9 +3270,10 @@ ${import_picocolors8.default.bold("Analyze & Upgrade:")}
|
|
|
3176
3270
|
upgrade tailwind Atualizar Tailwind CSS
|
|
3177
3271
|
|
|
3178
3272
|
${import_picocolors8.default.bold("Update (CLI):")}
|
|
3179
|
-
update Atualizar para
|
|
3180
|
-
update 0.11.0 Instalar
|
|
3181
|
-
update --list Listar
|
|
3273
|
+
update Atualizar para ultima versao
|
|
3274
|
+
update 0.11.0 Instalar versao especifica
|
|
3275
|
+
update --list Listar versoes disponiveis
|
|
3276
|
+
update --force Forcar reinstalacao (limpa cache)
|
|
3182
3277
|
|
|
3183
3278
|
${import_picocolors8.default.bold("Op\xE7\xF5es:")}
|
|
3184
3279
|
-y, --yes Aceitar padr\xF5es
|
package/package.json
CHANGED
package/src/commands/lola.ts
CHANGED
|
@@ -73,12 +73,45 @@ async function installLola(): Promise<void> {
|
|
|
73
73
|
console.log(pc.dim(` Lola ja instalada em ${LOLA_DIR}`))
|
|
74
74
|
console.log(pc.cyan(" Atualizando..."))
|
|
75
75
|
|
|
76
|
+
// Verificar se tem mudancas locais
|
|
77
|
+
const statusCheck = Bun.spawnSync(["git", "status", "--porcelain"], {
|
|
78
|
+
cwd: LOLA_DIR,
|
|
79
|
+
stdout: "pipe",
|
|
80
|
+
})
|
|
81
|
+
const hasLocalChanges = statusCheck.stdout.toString().trim().length > 0
|
|
82
|
+
|
|
83
|
+
// Stash se tiver mudancas locais
|
|
84
|
+
if (hasLocalChanges) {
|
|
85
|
+
console.log(pc.dim(" Salvando mudancas locais..."))
|
|
86
|
+
Bun.spawnSync(["git", "stash", "--quiet"], {
|
|
87
|
+
cwd: LOLA_DIR,
|
|
88
|
+
stdout: "pipe",
|
|
89
|
+
stderr: "pipe",
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Pull
|
|
76
94
|
const result = Bun.spawnSync(["git", "pull", "--quiet"], {
|
|
77
95
|
cwd: LOLA_DIR,
|
|
78
96
|
stdout: "inherit",
|
|
79
97
|
stderr: "inherit",
|
|
80
98
|
})
|
|
81
99
|
|
|
100
|
+
// Restaurar mudancas locais se tinha
|
|
101
|
+
if (hasLocalChanges) {
|
|
102
|
+
console.log(pc.dim(" Restaurando mudancas locais..."))
|
|
103
|
+
const stashPop = Bun.spawnSync(["git", "stash", "pop", "--quiet"], {
|
|
104
|
+
cwd: LOLA_DIR,
|
|
105
|
+
stdout: "pipe",
|
|
106
|
+
stderr: "pipe",
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
if (stashPop.exitCode !== 0) {
|
|
110
|
+
console.log(pc.yellow(" Aviso: conflito ao restaurar mudancas locais"))
|
|
111
|
+
console.log(pc.dim(" Verifique ~/.lola e resolva manualmente: git stash pop"))
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
82
115
|
if (result.exitCode !== 0) {
|
|
83
116
|
console.log(pc.red(" Erro ao atualizar Lola"))
|
|
84
117
|
process.exit(1)
|
package/src/commands/update.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { execSync, spawnSync } from "child_process"
|
|
|
4
4
|
|
|
5
5
|
const PACKAGE_NAME = "@nimbuslab/cli"
|
|
6
6
|
|
|
7
|
+
type PackageManager = "bun" | "npm" | "unknown"
|
|
8
|
+
|
|
7
9
|
async function getAvailableVersions(): Promise<string[]> {
|
|
8
10
|
try {
|
|
9
11
|
const res = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`)
|
|
@@ -26,91 +28,166 @@ async function getLatestVersion(): Promise<string | null> {
|
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
// Detecta qual package manager tem o pacote instalado globalmente
|
|
32
|
+
function detectPackageManager(): PackageManager {
|
|
33
|
+
// Tentar bun primeiro
|
|
34
|
+
try {
|
|
35
|
+
const bunResult = spawnSync("bun", ["pm", "ls", "-g"], {
|
|
36
|
+
encoding: "utf-8",
|
|
37
|
+
shell: true,
|
|
38
|
+
timeout: 5000,
|
|
39
|
+
})
|
|
40
|
+
if (bunResult.stdout && bunResult.stdout.includes(PACKAGE_NAME)) {
|
|
41
|
+
return "bun"
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
// ignore
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Tentar npm
|
|
48
|
+
try {
|
|
49
|
+
const npmResult = spawnSync("npm", ["ls", "-g", PACKAGE_NAME, "--json"], {
|
|
50
|
+
encoding: "utf-8",
|
|
51
|
+
shell: true,
|
|
52
|
+
timeout: 5000,
|
|
53
|
+
})
|
|
54
|
+
if (npmResult.stdout) {
|
|
55
|
+
const data = JSON.parse(npmResult.stdout)
|
|
56
|
+
if (data.dependencies?.[PACKAGE_NAME]) {
|
|
57
|
+
return "npm"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
// ignore
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return "unknown"
|
|
65
|
+
}
|
|
66
|
+
|
|
29
67
|
function getCurrentVersion(): string {
|
|
68
|
+
// Tentar bun primeiro
|
|
69
|
+
try {
|
|
70
|
+
const bunResult = spawnSync("bun", ["pm", "ls", "-g"], {
|
|
71
|
+
encoding: "utf-8",
|
|
72
|
+
shell: true,
|
|
73
|
+
timeout: 5000,
|
|
74
|
+
})
|
|
75
|
+
if (bunResult.stdout) {
|
|
76
|
+
// Formato: "@nimbuslab/cli@0.14.0"
|
|
77
|
+
const match = bunResult.stdout.match(new RegExp(`${PACKAGE_NAME.replace("/", "\\/")}@([\\d.]+)`))
|
|
78
|
+
if (match?.[1]) {
|
|
79
|
+
return match[1]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
// ignore
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Fallback para npm
|
|
30
87
|
try {
|
|
31
88
|
const result = spawnSync("npm", ["ls", "-g", PACKAGE_NAME, "--json"], {
|
|
32
89
|
encoding: "utf-8",
|
|
33
90
|
shell: true,
|
|
91
|
+
timeout: 5000,
|
|
34
92
|
})
|
|
35
93
|
if (result.stdout) {
|
|
36
94
|
const data = JSON.parse(result.stdout)
|
|
37
|
-
|
|
95
|
+
if (data.dependencies?.[PACKAGE_NAME]?.version) {
|
|
96
|
+
return data.dependencies[PACKAGE_NAME].version
|
|
97
|
+
}
|
|
38
98
|
}
|
|
39
99
|
} catch {
|
|
40
100
|
// ignore
|
|
41
101
|
}
|
|
102
|
+
|
|
42
103
|
return "unknown"
|
|
43
104
|
}
|
|
44
105
|
|
|
45
106
|
export async function update(args: string[]) {
|
|
46
|
-
|
|
107
|
+
// Parse flags
|
|
108
|
+
const forceFlag = args.includes("--force") || args.includes("-f")
|
|
109
|
+
const filteredArgs = args.filter(a => a !== "--force" && a !== "-f")
|
|
110
|
+
const flag = filteredArgs[0]
|
|
47
111
|
|
|
48
112
|
// nimbus update --list
|
|
49
113
|
if (flag === "--list" || flag === "-l") {
|
|
50
|
-
p.intro(pc.cyan("
|
|
114
|
+
p.intro(pc.cyan("Versoes disponiveis"))
|
|
51
115
|
|
|
52
116
|
const spinner = p.spinner()
|
|
53
|
-
spinner.start("Buscando
|
|
117
|
+
spinner.start("Buscando versoes...")
|
|
54
118
|
|
|
55
119
|
const versions = await getAvailableVersions()
|
|
56
|
-
spinner.stop("
|
|
120
|
+
spinner.stop("Versoes encontradas")
|
|
57
121
|
|
|
58
122
|
if (versions.length === 0) {
|
|
59
|
-
p.log.error("
|
|
123
|
+
p.log.error("Nao foi possivel buscar as versoes")
|
|
60
124
|
return
|
|
61
125
|
}
|
|
62
126
|
|
|
63
127
|
const current = getCurrentVersion()
|
|
128
|
+
const pm = detectPackageManager()
|
|
64
129
|
|
|
65
130
|
console.log()
|
|
66
|
-
console.log(pc.bold("
|
|
131
|
+
console.log(pc.bold("Ultimas 10 versoes:"))
|
|
67
132
|
versions.slice(0, 10).forEach((v, i) => {
|
|
68
133
|
const isCurrent = v === current
|
|
69
|
-
const prefix = isCurrent ? pc.green("
|
|
134
|
+
const prefix = isCurrent ? pc.green("-> ") : " "
|
|
70
135
|
const suffix = isCurrent ? pc.dim(" (instalada)") : ""
|
|
71
136
|
const isLatest = i === 0 ? pc.yellow(" (latest)") : ""
|
|
72
137
|
console.log(`${prefix}${v}${suffix}${isLatest}`)
|
|
73
138
|
})
|
|
74
139
|
console.log()
|
|
75
|
-
console.log(pc.dim(`Total: ${versions.length}
|
|
76
|
-
console.log(pc.dim(`
|
|
140
|
+
console.log(pc.dim(`Total: ${versions.length} versoes`))
|
|
141
|
+
console.log(pc.dim(`Package manager detectado: ${pm === "unknown" ? "nenhum" : pm}`))
|
|
142
|
+
console.log(pc.dim(`Instalar versao especifica: nimbus update <versao>`))
|
|
143
|
+
console.log(pc.dim(`Forcar reinstalacao: nimbus update --force`))
|
|
77
144
|
return
|
|
78
145
|
}
|
|
79
146
|
|
|
80
147
|
// nimbus update [version]
|
|
81
148
|
const targetVersion = flag || "latest"
|
|
82
|
-
const isSpecificVersion = flag && flag !== "latest"
|
|
149
|
+
const isSpecificVersion = flag && flag !== "latest" && !flag.startsWith("-")
|
|
83
150
|
|
|
84
151
|
p.intro(pc.cyan(`Atualizando ${PACKAGE_NAME}`))
|
|
85
152
|
|
|
86
153
|
const spinner = p.spinner()
|
|
87
154
|
|
|
88
|
-
//
|
|
89
|
-
spinner.start("
|
|
155
|
+
// Detectar package manager
|
|
156
|
+
spinner.start("Detectando package manager...")
|
|
157
|
+
const detectedPm = detectPackageManager()
|
|
158
|
+
// Usar bun como padrao se nenhum detectado
|
|
159
|
+
const pm = detectedPm === "unknown" ? "bun" : detectedPm
|
|
160
|
+
spinner.stop(`Package manager: ${pm}${detectedPm === "unknown" ? " (padrao)" : ""}`)
|
|
161
|
+
|
|
162
|
+
// Verificar versao atual
|
|
163
|
+
spinner.start("Verificando versao atual...")
|
|
90
164
|
const currentVersion = getCurrentVersion()
|
|
91
|
-
spinner.stop(`
|
|
165
|
+
spinner.stop(`Versao atual: ${currentVersion === "unknown" ? "nao instalado" : currentVersion}`)
|
|
92
166
|
|
|
93
|
-
// Verificar
|
|
167
|
+
// Verificar versao alvo
|
|
168
|
+
let latestVersion: string | null = null
|
|
94
169
|
if (!isSpecificVersion) {
|
|
95
|
-
spinner.start("Verificando
|
|
96
|
-
|
|
97
|
-
spinner.stop(
|
|
170
|
+
spinner.start("Verificando ultima versao no npm...")
|
|
171
|
+
latestVersion = await getLatestVersion()
|
|
172
|
+
spinner.stop(`Ultima versao: ${latestVersion || "desconhecida"}`)
|
|
98
173
|
|
|
99
|
-
if (
|
|
100
|
-
p.log.success("
|
|
174
|
+
if (!forceFlag && latestVersion && latestVersion === currentVersion) {
|
|
175
|
+
p.log.success("Voce ja esta na ultima versao!")
|
|
176
|
+
console.log(pc.dim(" Use --force para reinstalar"))
|
|
101
177
|
return
|
|
102
178
|
}
|
|
103
179
|
}
|
|
104
180
|
|
|
105
181
|
// Confirmar
|
|
106
|
-
const versionText = isSpecificVersion ? targetVersion : "latest"
|
|
182
|
+
const versionText = isSpecificVersion ? targetVersion : (latestVersion || "latest")
|
|
183
|
+
const actionText = forceFlag ? "Reinstalar" : "Atualizar"
|
|
107
184
|
const confirmUpdate = await p.confirm({
|
|
108
|
-
message:
|
|
185
|
+
message: `${actionText} para ${versionText} usando ${pm}?`,
|
|
109
186
|
initialValue: true,
|
|
110
187
|
})
|
|
111
188
|
|
|
112
189
|
if (p.isCancel(confirmUpdate) || !confirmUpdate) {
|
|
113
|
-
p.cancel("
|
|
190
|
+
p.cancel("Atualizacao cancelada")
|
|
114
191
|
return
|
|
115
192
|
}
|
|
116
193
|
|
|
@@ -120,23 +197,40 @@ export async function update(args: string[]) {
|
|
|
120
197
|
try {
|
|
121
198
|
const packageSpec = isSpecificVersion
|
|
122
199
|
? `${PACKAGE_NAME}@${targetVersion}`
|
|
123
|
-
:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
200
|
+
: latestVersion
|
|
201
|
+
? `${PACKAGE_NAME}@${latestVersion}`
|
|
202
|
+
: PACKAGE_NAME
|
|
203
|
+
|
|
204
|
+
// Usar o package manager detectado
|
|
205
|
+
if (pm === "bun") {
|
|
206
|
+
// Bun: remover primeiro se --force, depois instalar
|
|
207
|
+
if (forceFlag) {
|
|
208
|
+
try {
|
|
209
|
+
execSync(`bun remove -g ${PACKAGE_NAME}`, { stdio: "pipe", encoding: "utf-8" })
|
|
210
|
+
} catch {
|
|
211
|
+
// ignore - pode nao estar instalado
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
execSync(`bun add -g ${packageSpec}`, { stdio: "pipe", encoding: "utf-8" })
|
|
215
|
+
} else {
|
|
216
|
+
// npm: usar --force se solicitado
|
|
217
|
+
const forceArg = forceFlag ? " --force" : ""
|
|
218
|
+
execSync(`npm install -g ${packageSpec}${forceArg}`, { stdio: "pipe", encoding: "utf-8" })
|
|
219
|
+
}
|
|
130
220
|
|
|
131
|
-
spinner.stop("
|
|
221
|
+
spinner.stop("Atualizacao concluida!")
|
|
132
222
|
|
|
133
|
-
// Verificar nova
|
|
223
|
+
// Verificar nova versao
|
|
134
224
|
const newVersion = getCurrentVersion()
|
|
135
225
|
|
|
136
|
-
|
|
226
|
+
if (currentVersion === newVersion && !forceFlag) {
|
|
227
|
+
p.log.warn("Versao nao mudou. Tente com --force")
|
|
228
|
+
} else {
|
|
229
|
+
p.log.success(`${PACKAGE_NAME} atualizado: ${currentVersion} -> ${newVersion}`)
|
|
230
|
+
}
|
|
137
231
|
p.outro(pc.green("Pronto!"))
|
|
138
232
|
} catch (error) {
|
|
139
|
-
spinner.stop("Erro na
|
|
233
|
+
spinner.stop("Erro na atualizacao")
|
|
140
234
|
|
|
141
235
|
const err = error as Error & { stderr?: string }
|
|
142
236
|
p.log.error("Falha ao atualizar")
|
|
@@ -147,6 +241,10 @@ export async function update(args: string[]) {
|
|
|
147
241
|
|
|
148
242
|
console.log()
|
|
149
243
|
console.log(pc.yellow("Tente manualmente:"))
|
|
150
|
-
|
|
244
|
+
if (pm === "bun") {
|
|
245
|
+
console.log(pc.cyan(` bun add -g ${PACKAGE_NAME}${isSpecificVersion ? `@${targetVersion}` : ""}`))
|
|
246
|
+
} else {
|
|
247
|
+
console.log(pc.cyan(` npm install -g ${PACKAGE_NAME}${isSpecificVersion ? `@${targetVersion}` : ""}`))
|
|
248
|
+
}
|
|
151
249
|
}
|
|
152
250
|
}
|
package/src/index.ts
CHANGED
|
@@ -126,9 +126,10 @@ ${pc.bold("Analyze & Upgrade:")}
|
|
|
126
126
|
upgrade tailwind Atualizar Tailwind CSS
|
|
127
127
|
|
|
128
128
|
${pc.bold("Update (CLI):")}
|
|
129
|
-
update Atualizar para
|
|
130
|
-
update 0.11.0 Instalar
|
|
131
|
-
update --list Listar
|
|
129
|
+
update Atualizar para ultima versao
|
|
130
|
+
update 0.11.0 Instalar versao especifica
|
|
131
|
+
update --list Listar versoes disponiveis
|
|
132
|
+
update --force Forcar reinstalacao (limpa cache)
|
|
132
133
|
|
|
133
134
|
${pc.bold("Opções:")}
|
|
134
135
|
-y, --yes Aceitar padrões
|