feat(update): refactored updates to work as a single command

This commit is contained in:
jb
2026-04-17 15:00:51 -03:00
parent 992cb0e7dd
commit e3a6837052
5 changed files with 165 additions and 162 deletions
+2 -6
View File
@@ -5,11 +5,9 @@ var { Command } = require('commander');
var pkg = require('../package.json');
var initCmd = require('../src/commands/init');
var updateRepoCmd = require('../src/commands/update-repo');
var updateBaseCmd = require('../src/commands/update-base');
var updateCmd = require('../src/commands/update');
var docsCmd = require('../src/commands/docs');
var updateIdeCmd = require('../src/commands/update-ide');
var updateCliCmd = require('../src/commands/update-cli');
var program = new Command();
@@ -19,10 +17,8 @@ program
.version(pkg.version);
initCmd.register(program);
updateRepoCmd.register(program);
updateBaseCmd.register(program);
updateCmd.register(program);
docsCmd.register(program);
updateIdeCmd.register(program);
updateCliCmd.register(program);
program.parse(process.argv);
+9 -37
View File
@@ -9,68 +9,40 @@ var { getPlatformDir } = require('../utils/platform');
var SSH_URL = 'ssh://git@git.davinti.com.br:2222/davinTI/base-claude.git';
var HTTPS_URL = 'https://git.davinti.com.br/davinTI/base-claude.git';
// Directories inside the platform dir that are fully managed by this command.
// Each of these is replaced in its entirety — files removed from the source
// are also removed locally. Directories not in this list are never touched.
var MANAGED_DIRS = ['libs', 'docs', 'examples'];
function register(program) {
program
.command('update-base')
.description('Sincroniza os diretórios gerenciados do diretório de plataforma Vitruvio com o repositório base-claude')
.action(function () {
function run() {
var platformDir;
try {
platformDir = getPlatformDir();
} catch (e) {
console.error('Erro: ' + e.message);
process.exit(1);
throw new Error(e.message);
}
console.log('Diretório de plataforma: ' + platformDir);
console.log('Buscando repositório base-claude...');
console.log(' Diretório de plataforma: ' + platformDir);
console.log(' Buscando repositório base-claude...');
var tmpDir = null;
try {
tmpDir = cloneWithFallback(SSH_URL, HTTPS_URL);
} catch (e) {
console.error('Erro: não foi possível clonar o repositório base-claude.');
console.error(e.message);
process.exit(1);
}
var tmpDir = cloneWithFallback(SSH_URL, HTTPS_URL);
try {
fse.ensureDirSync(platformDir);
var results = [];
MANAGED_DIRS.forEach(function (dirName) {
var src = path.join(tmpDir, dirName);
var dest = path.join(platformDir, dirName);
if (!fs.existsSync(src)) {
results.push({ dir: dirName, status: 'não encontrado no repositório' });
console.log(' ' + dirName + '/ — não encontrado no repositório');
return;
}
// Full replacement: remove existing dir, copy fresh from source
if (fs.existsSync(dest)) {
fse.removeSync(dest);
}
if (fs.existsSync(dest)) fse.removeSync(dest);
fse.copySync(src, dest);
results.push({ dir: dirName, status: 'atualizado' });
console.log(' ' + dirName + '/ — atualizado');
});
console.log('');
results.forEach(function (r) {
console.log(' ' + r.dir + '/ — ' + r.status);
});
console.log('');
console.log('Atualização concluída.');
} finally {
cleanupTemp(tmpDir);
}
});
}
module.exports = { register: register };
module.exports = { run: run };
+8 -32
View File
@@ -12,48 +12,24 @@ var HTTPS_URL = 'https://git.davinti.com.br/davinTI/vitruvio-cli.git';
var INSTALL_DIR = path.join(os.homedir(), '.local', 'share', 'vitruvio-cli');
function register(program) {
program
.command('update-cli')
.description('Atualiza o Vitruvio CLI para a versão mais recente')
.action(function () {
console.log('Buscando versão mais recente do Vitruvio CLI...');
function run() {
console.log(' Buscando versão mais recente do Vitruvio CLI...');
var tmpDir = null;
try {
tmpDir = cloneWithFallback(SSH_URL, HTTPS_URL);
} catch (e) {
console.error('Erro: não foi possível baixar o repositório do CLI.');
console.error(e.message);
process.exit(1);
}
var tmpDir = cloneWithFallback(SSH_URL, HTTPS_URL);
try {
// Replace stable install dir with fresh clone
if (fs.existsSync(INSTALL_DIR)) {
fse.removeSync(INSTALL_DIR);
}
if (fs.existsSync(INSTALL_DIR)) fse.removeSync(INSTALL_DIR);
fse.copySync(tmpDir, INSTALL_DIR);
} finally {
cleanupTemp(tmpDir);
}
try {
console.log('Instalando dependências...');
console.log(' Instalando dependências...');
execSync('npm install', { cwd: INSTALL_DIR, stdio: 'inherit' });
console.log('Vinculando comando vitruvio...');
try { execSync('npm unlink -g vitruvio', { stdio: 'pipe' }); } catch (_) { }
console.log(' Vinculando comando vitruvio...');
try { execSync('npm unlink -g vitruvio', { stdio: 'pipe' }); } catch (_) {}
execSync('npm link', { cwd: INSTALL_DIR, stdio: 'inherit' });
console.log('');
console.log('Vitruvio CLI atualizado com sucesso.');
console.log('Origem: ' + INSTALL_DIR);
} catch (e) {
console.error('Erro ao instalar o CLI: ' + e.message);
process.exit(1);
}
});
}
module.exports = { register: register };
module.exports = { run: run };
+12 -26
View File
@@ -8,7 +8,6 @@ var { cloneWithFallback, cleanupTemp } = require('../utils/git');
var SSH_URL = 'ssh://git@git.davinti.com.br:2222/davinTI/projeto-base.git';
var HTTPS_URL = 'https://git.davinti.com.br/davinTI/projeto-base.git';
// CLAUDE.md files managed by the template — relative paths from repo root
var MANAGED_FILES = [
'CLAUDE.md',
'endpoints/CLAUDE.md',
@@ -20,29 +19,20 @@ var MANAGED_FILES = [
'scripts/CLAUDE.md'
];
function register(program) {
program
.command('update-repo')
.description('Atualiza os arquivos CLAUDE.md gerenciados neste repositório com a versão mais recente do template')
.action(function () {
function isVitruvioRepo(dir) {
return fs.existsSync(path.join(dir, 'vitruvio.json'));
}
function run() {
var repoDir = process.cwd();
if (!fs.existsSync(path.join(repoDir, 'vitruvio.json'))) {
console.error('Erro: nenhum vitruvio.json encontrado no diretório atual.');
console.error('Execute este comando dentro de um repositório Vitruvio.');
process.exit(1);
if (!isVitruvioRepo(repoDir)) {
throw new Error('nenhum vitruvio.json encontrado no diretório atual.');
}
console.log('Buscando template mais recente...');
console.log(' Buscando template mais recente...');
var tmpDir = null;
try {
tmpDir = cloneWithFallback(SSH_URL, HTTPS_URL);
} catch (e) {
console.error('Erro: não foi possível clonar o repositório template.');
console.error(e.message);
process.exit(1);
}
var tmpDir = cloneWithFallback(SSH_URL, HTTPS_URL);
try {
var updated = [];
@@ -62,21 +52,17 @@ function register(program) {
updated.push(relPath);
});
console.log('');
if (updated.length > 0) {
console.log('Arquivos atualizados (' + updated.length + '):');
console.log(' Arquivos atualizados (' + updated.length + '):');
updated.forEach(function (f) { console.log(' ' + f); });
}
if (skipped.length > 0) {
console.log('Não encontrados no template (' + skipped.length + '):');
console.log(' Não encontrados no template (' + skipped.length + '):');
skipped.forEach(function (f) { console.log(' ' + f); });
}
console.log('');
console.log('Atualização concluída.');
} finally {
cleanupTemp(tmpDir);
}
});
}
module.exports = { register: register };
module.exports = { run: run, isVitruvioRepo: isVitruvioRepo };
+73
View File
@@ -0,0 +1,73 @@
'use strict';
var updateBase = require('./update-base');
var updateRepo = require('./update-repo');
var updateCli = require('./update-cli');
var TARGETS = ['base', 'repo', 'cli'];
function runTarget(name) {
console.log('\n[' + name + ']');
if (name === 'base') updateBase.run();
else if (name === 'repo') updateRepo.run();
else if (name === 'cli') updateCli.run();
console.log(' Concluído.');
}
function register(program) {
program
.command('update [alvo]')
.description('Atualiza componentes do Vitruvio (alvo: base | repo | cli). Sem alvo, atualiza tudo.')
.action(function (alvo) {
if (alvo) {
var key = alvo.toLowerCase();
if (!TARGETS.includes(key)) {
console.error('Alvo inválido: "' + alvo + '". Use: base, repo ou cli.');
process.exit(1);
}
if (key === 'repo' && !updateRepo.isVitruvioRepo(process.cwd())) {
console.error('Erro: nenhum vitruvio.json encontrado no diretório atual.');
console.error('Execute este comando dentro de um repositório Vitruvio.');
process.exit(1);
}
try {
runTarget(key);
} catch (e) {
console.error('Erro: ' + e.message);
process.exit(1);
}
return;
}
// No target — update everything applicable
var errors = [];
var inRepo = updateRepo.isVitruvioRepo(process.cwd());
['base', 'cli'].forEach(function (name) {
try {
runTarget(name);
} catch (e) {
errors.push(name + ': ' + e.message);
}
});
if (inRepo) {
try {
runTarget('repo');
} catch (e) {
errors.push('repo: ' + e.message);
}
}
console.log('');
if (errors.length > 0) {
console.error('Atualização concluída com erros:');
errors.forEach(function (msg) { console.error(' ' + msg); });
process.exit(1);
} else {
console.log('Tudo atualizado com sucesso.');
}
});
}
module.exports = { register: register };