@nimbuslab/cli 0.14.0 → 0.16.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.
@@ -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
- return data.dependencies?.[PACKAGE_NAME]?.version || "unknown"
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
- const flag = args[0]
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("Versões disponíveis"))
114
+ p.intro(pc.cyan("Versoes disponiveis"))
51
115
 
52
116
  const spinner = p.spinner()
53
- spinner.start("Buscando versões...")
117
+ spinner.start("Buscando versoes...")
54
118
 
55
119
  const versions = await getAvailableVersions()
56
- spinner.stop("Versões encontradas")
120
+ spinner.stop("Versoes encontradas")
57
121
 
58
122
  if (versions.length === 0) {
59
- p.log.error("Não foi possível buscar as versões")
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("Últimas 10 versões:"))
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} versões`))
76
- console.log(pc.dim(`Instalar versão específica: nimbus update <versão>`))
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
- // Verificar versão atual
89
- spinner.start("Verificando versão atual...")
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(`Versão atual: ${currentVersion}`)
165
+ spinner.stop(`Versao atual: ${currentVersion === "unknown" ? "nao instalado" : currentVersion}`)
92
166
 
93
- // Verificar versão alvo
167
+ // Verificar versao alvo
168
+ let latestVersion: string | null = null
94
169
  if (!isSpecificVersion) {
95
- spinner.start("Verificando última versão...")
96
- const latest = await getLatestVersion()
97
- spinner.stop(`Última versão: ${latest || "desconhecida"}`)
170
+ spinner.start("Verificando ultima versao no npm...")
171
+ latestVersion = await getLatestVersion()
172
+ spinner.stop(`Ultima versao: ${latestVersion || "desconhecida"}`)
98
173
 
99
- if (latest && latest === currentVersion) {
100
- p.log.success("Você está na última versão!")
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: `Atualizar para ${versionText}?`,
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("Atualização cancelada")
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
- : PACKAGE_NAME
124
-
125
- // Usar npm para instalação global (mais estável que bun)
126
- execSync(`npm install -g ${packageSpec}`, {
127
- stdio: "pipe",
128
- encoding: "utf-8",
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("Atualização concluída!")
221
+ spinner.stop("Atualizacao concluida!")
132
222
 
133
- // Verificar nova versão
223
+ // Verificar nova versao
134
224
  const newVersion = getCurrentVersion()
135
225
 
136
- p.log.success(`${PACKAGE_NAME} atualizado: ${currentVersion} ${newVersion}`)
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 atualização")
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
- console.log(pc.cyan(` npm install -g ${PACKAGE_NAME}${isSpecificVersion ? `@${targetVersion}` : ""}`))
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 última versão
130
- update 0.11.0 Instalar versão específica
131
- update --list Listar versões disponíveis
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