@nectarcrm/ccx 0.5.0 → 0.5.2
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/bin/ccx.js +21 -5
- package/package.json +1 -1
package/bin/ccx.js
CHANGED
|
@@ -511,13 +511,21 @@ async function autoUpdate() {
|
|
|
511
511
|
const prefix = globalPrefix()
|
|
512
512
|
if (!prefix) return save({ error: 'ccx não foi instalado com npm install -g' })
|
|
513
513
|
try {
|
|
514
|
-
const
|
|
515
|
-
|
|
514
|
+
const args = ['install', '-g', '--prefix', prefix, `${PKG}@${latest}`]
|
|
515
|
+
const opts = { stdio: ['ignore', 'ignore', 'pipe'], timeout: 180_000 }
|
|
516
|
+
// O npm que vem com o Node, rodado pelo próprio Node: sem cmd.exe, então espaço no caminho
|
|
517
|
+
// (C:\Program Files\nodejs, C:\Users\Nome Sobrenome) não quebra o comando
|
|
518
|
+
const cli = [join(dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js'), join(dirname(dirname(process.execPath)), 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js')].find(existsSync)
|
|
519
|
+
if (cli) execFileSync(process.execPath, [cli, ...args], opts)
|
|
520
|
+
else if (WIN) execFileSync('npm.cmd', args.map(a => `"${a}"`), { ...opts, shell: true })
|
|
521
|
+
else execFileSync('npm', args, opts)
|
|
516
522
|
log(`ccx atualizado: ${mine} → ${latest}`)
|
|
517
523
|
save({})
|
|
518
524
|
}
|
|
519
525
|
catch (e) {
|
|
520
|
-
|
|
526
|
+
// O motivo de verdade vem no fim do stderr do npm (ex.: EACCES, EPERM, ENOTFOUND)
|
|
527
|
+
const why = String(e.stderr ?? '').split(/\r?\n/).map(l => l.replace(/^npm (error|ERR!) ?/, '').trim()).filter(Boolean)
|
|
528
|
+
const msg = why.find(l => /^(code )?E[A-Z]+/.test(l)) ?? why.at(-1) ?? e.message.split('\n')[0]
|
|
521
529
|
log(`não consegui atualizar o ccx pra ${latest}: ${msg}`)
|
|
522
530
|
save({ error: msg })
|
|
523
531
|
}
|
|
@@ -787,8 +795,16 @@ if (cmd === 'doctor') await doctor()
|
|
|
787
795
|
|
|
788
796
|
if (cmd === 'login') await login(rest[0] ?? readJson(APP, null)?.url ?? DEFAULT_URL)
|
|
789
797
|
|
|
790
|
-
|
|
791
|
-
|
|
798
|
+
let app = readJson(APP, null)
|
|
799
|
+
let key = app && secretGet()
|
|
800
|
+
// `ccx` sozinho num terminal sem login: faz o login e segue pra escolha da conta.
|
|
801
|
+
// Os outros comandos (e scripts, sem terminal) só avisam: nunca abrem o navegador sem a pessoa pedir.
|
|
802
|
+
if ((!app || !key) && !cmd && process.stdin.isTTY) {
|
|
803
|
+
console.error('Este computador ainda não está conectado. Vamos fazer o login.\n')
|
|
804
|
+
await login(app?.url ?? DEFAULT_URL)
|
|
805
|
+
app = readJson(APP, null)
|
|
806
|
+
key = app && secretGet()
|
|
807
|
+
}
|
|
792
808
|
if (!app || !key) die('Este computador ainda não está conectado. Rode: ccx login')
|
|
793
809
|
|
|
794
810
|
if (cmd === 'logout') {
|