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 pkg = require('../package.json');
var initCmd = require('../src/commands/init'); var initCmd = require('../src/commands/init');
var updateRepoCmd = require('../src/commands/update-repo'); var updateCmd = require('../src/commands/update');
var updateBaseCmd = require('../src/commands/update-base');
var docsCmd = require('../src/commands/docs'); var docsCmd = require('../src/commands/docs');
var updateIdeCmd = require('../src/commands/update-ide'); var updateIdeCmd = require('../src/commands/update-ide');
var updateCliCmd = require('../src/commands/update-cli');
var program = new Command(); var program = new Command();
@@ -19,10 +17,8 @@ program
.version(pkg.version); .version(pkg.version);
initCmd.register(program); initCmd.register(program);
updateRepoCmd.register(program); updateCmd.register(program);
updateBaseCmd.register(program);
docsCmd.register(program); docsCmd.register(program);
updateIdeCmd.register(program); updateIdeCmd.register(program);
updateCliCmd.register(program);
program.parse(process.argv); program.parse(process.argv);
+30 -58
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 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'; 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']; var MANAGED_DIRS = ['libs', 'docs', 'examples'];
function register(program) { function run() {
program var platformDir;
.command('update-base') try {
.description('Sincroniza os diretórios gerenciados do diretório de plataforma Vitruvio com o repositório base-claude') platformDir = getPlatformDir();
.action(function () { } catch (e) {
var platformDir; throw new Error(e.message);
try { }
platformDir = getPlatformDir();
} catch (e) { console.log(' Diretório de plataforma: ' + platformDir);
console.error('Erro: ' + e.message); console.log(' Buscando repositório base-claude...');
process.exit(1);
var tmpDir = cloneWithFallback(SSH_URL, HTTPS_URL);
try {
fse.ensureDirSync(platformDir);
MANAGED_DIRS.forEach(function (dirName) {
var src = path.join(tmpDir, dirName);
var dest = path.join(platformDir, dirName);
if (!fs.existsSync(src)) {
console.log(' ' + dirName + '/ — não encontrado no repositório');
return;
} }
console.log('Diretório de plataforma: ' + platformDir); if (fs.existsSync(dest)) fse.removeSync(dest);
console.log('Buscando repositório base-claude...'); fse.copySync(src, dest);
console.log(' ' + dirName + '/ — atualizado');
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);
}
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' });
return;
}
// Full replacement: remove existing dir, copy fresh from source
if (fs.existsSync(dest)) {
fse.removeSync(dest);
}
fse.copySync(src, dest);
results.push({ dir: dirName, status: 'atualizado' });
});
console.log('');
results.forEach(function (r) {
console.log(' ' + r.dir + '/ — ' + r.status);
});
console.log('');
console.log('Atualização concluída.');
} finally {
cleanupTemp(tmpDir);
}
}); });
} finally {
cleanupTemp(tmpDir);
}
} }
module.exports = { register: register }; module.exports = { run: run };
+15 -39
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'); var INSTALL_DIR = path.join(os.homedir(), '.local', 'share', 'vitruvio-cli');
function register(program) { function run() {
program console.log(' Buscando versão mais recente do Vitruvio CLI...');
.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...');
var tmpDir = null; var tmpDir = cloneWithFallback(SSH_URL, HTTPS_URL);
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);
}
try { try {
// Replace stable install dir with fresh clone if (fs.existsSync(INSTALL_DIR)) fse.removeSync(INSTALL_DIR);
if (fs.existsSync(INSTALL_DIR)) { fse.copySync(tmpDir, INSTALL_DIR);
fse.removeSync(INSTALL_DIR); } finally {
} cleanupTemp(tmpDir);
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' });
execSync('npm install', { cwd: INSTALL_DIR, stdio: 'inherit' });
console.log('Vinculando comando vitruvio...'); console.log(' Vinculando comando vitruvio...');
try { execSync('npm unlink -g vitruvio', { stdio: 'pipe' }); } catch (_) { } try { execSync('npm unlink -g vitruvio', { stdio: 'pipe' }); } catch (_) {}
execSync('npm link', { cwd: INSTALL_DIR, stdio: 'inherit' }); 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 };
+45 -59
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 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'; 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 = [ var MANAGED_FILES = [
'CLAUDE.md', 'CLAUDE.md',
'endpoints/CLAUDE.md', 'endpoints/CLAUDE.md',
@@ -20,63 +19,50 @@ var MANAGED_FILES = [
'scripts/CLAUDE.md' 'scripts/CLAUDE.md'
]; ];
function register(program) { function isVitruvioRepo(dir) {
program return fs.existsSync(path.join(dir, 'vitruvio.json'));
.command('update-repo')
.description('Atualiza os arquivos CLAUDE.md gerenciados neste repositório com a versão mais recente do template')
.action(function () {
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);
}
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);
}
try {
var updated = [];
var skipped = [];
MANAGED_FILES.forEach(function (relPath) {
var src = path.join(tmpDir, relPath);
var dest = path.join(repoDir, relPath);
if (!fs.existsSync(src)) {
skipped.push(relPath);
return;
}
fse.ensureDirSync(path.dirname(dest));
fse.copySync(src, dest, { overwrite: true });
updated.push(relPath);
});
console.log('');
if (updated.length > 0) {
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 + '):');
skipped.forEach(function (f) { console.log(' ' + f); });
}
console.log('');
console.log('Atualização concluída.');
} finally {
cleanupTemp(tmpDir);
}
});
} }
module.exports = { register: register }; function run() {
var repoDir = process.cwd();
if (!isVitruvioRepo(repoDir)) {
throw new Error('nenhum vitruvio.json encontrado no diretório atual.');
}
console.log(' Buscando template mais recente...');
var tmpDir = cloneWithFallback(SSH_URL, HTTPS_URL);
try {
var updated = [];
var skipped = [];
MANAGED_FILES.forEach(function (relPath) {
var src = path.join(tmpDir, relPath);
var dest = path.join(repoDir, relPath);
if (!fs.existsSync(src)) {
skipped.push(relPath);
return;
}
fse.ensureDirSync(path.dirname(dest));
fse.copySync(src, dest, { overwrite: true });
updated.push(relPath);
});
if (updated.length > 0) {
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 + '):');
skipped.forEach(function (f) { console.log(' ' + f); });
}
} finally {
cleanupTemp(tmpDir);
}
}
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 };