feat(update): refactored updates to work as a single command
This commit is contained in:
+2
-6
@@ -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);
|
||||||
|
|||||||
@@ -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
|
|
||||||
.command('update-base')
|
|
||||||
.description('Sincroniza os diretórios gerenciados do diretório de plataforma Vitruvio com o repositório base-claude')
|
|
||||||
.action(function () {
|
|
||||||
var platformDir;
|
var platformDir;
|
||||||
try {
|
try {
|
||||||
platformDir = getPlatformDir();
|
platformDir = getPlatformDir();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Erro: ' + e.message);
|
throw new Error(e.message);
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(' Diretório de plataforma: ' + platformDir);
|
console.log(' Diretório de plataforma: ' + platformDir);
|
||||||
console.log(' Buscando repositório base-claude...');
|
console.log(' Buscando repositório base-claude...');
|
||||||
|
|
||||||
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 clonar o repositório base-claude.');
|
|
||||||
console.error(e.message);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fse.ensureDirSync(platformDir);
|
fse.ensureDirSync(platformDir);
|
||||||
|
|
||||||
var results = [];
|
|
||||||
|
|
||||||
MANAGED_DIRS.forEach(function (dirName) {
|
MANAGED_DIRS.forEach(function (dirName) {
|
||||||
var src = path.join(tmpDir, dirName);
|
var src = path.join(tmpDir, dirName);
|
||||||
var dest = path.join(platformDir, dirName);
|
var dest = path.join(platformDir, dirName);
|
||||||
|
|
||||||
if (!fs.existsSync(src)) {
|
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;
|
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);
|
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 {
|
} finally {
|
||||||
cleanupTemp(tmpDir);
|
cleanupTemp(tmpDir);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { register: register };
|
module.exports = { run: run };
|
||||||
|
|||||||
@@ -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
|
|
||||||
.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...');
|
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.removeSync(INSTALL_DIR);
|
|
||||||
}
|
|
||||||
fse.copySync(tmpDir, INSTALL_DIR);
|
fse.copySync(tmpDir, INSTALL_DIR);
|
||||||
} finally {
|
} finally {
|
||||||
cleanupTemp(tmpDir);
|
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 };
|
||||||
|
|||||||
@@ -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,29 +19,20 @@ 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 () {
|
function run() {
|
||||||
var repoDir = process.cwd();
|
var repoDir = process.cwd();
|
||||||
|
|
||||||
if (!fs.existsSync(path.join(repoDir, 'vitruvio.json'))) {
|
if (!isVitruvioRepo(repoDir)) {
|
||||||
console.error('Erro: nenhum vitruvio.json encontrado no diretório atual.');
|
throw new Error('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...');
|
console.log(' Buscando template mais recente...');
|
||||||
|
|
||||||
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 clonar o repositório template.');
|
|
||||||
console.error(e.message);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var updated = [];
|
var updated = [];
|
||||||
@@ -62,7 +52,6 @@ function register(program) {
|
|||||||
updated.push(relPath);
|
updated.push(relPath);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('');
|
|
||||||
if (updated.length > 0) {
|
if (updated.length > 0) {
|
||||||
console.log(' Arquivos atualizados (' + updated.length + '):');
|
console.log(' Arquivos atualizados (' + updated.length + '):');
|
||||||
updated.forEach(function (f) { console.log(' ' + f); });
|
updated.forEach(function (f) { console.log(' ' + f); });
|
||||||
@@ -71,12 +60,9 @@ function register(program) {
|
|||||||
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); });
|
skipped.forEach(function (f) { console.log(' ' + f); });
|
||||||
}
|
}
|
||||||
console.log('');
|
|
||||||
console.log('Atualização concluída.');
|
|
||||||
} finally {
|
} finally {
|
||||||
cleanupTemp(tmpDir);
|
cleanupTemp(tmpDir);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { register: register };
|
module.exports = { run: run, isVitruvioRepo: isVitruvioRepo };
|
||||||
|
|||||||
@@ -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 };
|
||||||
Reference in New Issue
Block a user