specifica-br 1.1.1 → 1.2.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.
@@ -3,9 +3,42 @@ import chalk from 'chalk';
3
3
  import { exec } from 'child_process';
4
4
  import { promisify } from 'util';
5
5
  import { platform } from 'os';
6
+ import { readFileSync } from 'fs';
7
+ import path from 'path';
8
+ import { fileURLToPath } from 'url';
6
9
  import { logService } from '../utils/log-service.js';
7
10
  import { updateNotifierMiddleware } from '../utils/update-notifier-middleware.js';
11
+ import latestVersion from 'latest-version';
12
+ import semver from 'semver';
8
13
  const execAsync = promisify(exec);
14
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
15
+ const PACKAGE_JSON_PATH = path.join(__dirname, '..', '..', 'package.json');
16
+ async function getCurrentVersion() {
17
+ try {
18
+ const packageJson = JSON.parse(readFileSync(PACKAGE_JSON_PATH, 'utf-8'));
19
+ return packageJson.version;
20
+ }
21
+ catch (error) {
22
+ throw new Error('Não foi possível ler a versão atual do package.json');
23
+ }
24
+ }
25
+ async function getLatestVersion(packageName) {
26
+ try {
27
+ const version = await latestVersion(packageName);
28
+ return version;
29
+ }
30
+ catch (error) {
31
+ const { stdout } = await execAsync(`npm view ${packageName} version`);
32
+ const version = stdout.trim();
33
+ return version;
34
+ }
35
+ }
36
+ async function isVersionOutdated(currentVersion, remoteVersion) {
37
+ if (!semver.valid(currentVersion) || !semver.valid(remoteVersion)) {
38
+ return false;
39
+ }
40
+ return semver.lt(currentVersion, remoteVersion);
41
+ }
9
42
  function isWindows() {
10
43
  return platform() === 'win32';
11
44
  }
@@ -19,22 +52,32 @@ async function checkNpmInstalled() {
19
52
  }
20
53
  }
21
54
  async function runUpgradeCommand() {
22
- console.log('');
23
- console.log(chalk.cyan('Verificando instalação do npm...'));
24
- console.log('');
25
55
  const npmInstalled = await checkNpmInstalled();
26
56
  if (!npmInstalled) {
27
- console.log('');
28
57
  console.log(chalk.red('✗ npm não encontrado.'));
29
58
  console.log(chalk.yellow('Instale Node.js e npm em: https://nodejs.org'));
30
- console.log('');
31
59
  process.exit(1);
32
60
  }
33
- console.log(chalk.green(' npm encontrado.'));
34
- console.log('');
35
- console.log(chalk.cyan('Atualizando specifica-br para a versão mais recente...'));
36
- console.log(chalk.gray('Executando: npm i -g specifica-br@latest'));
37
- console.log('');
61
+ console.log(chalk.cyan('Verificando se há atualizações disponíveis...'));
62
+ try {
63
+ const currentVersion = await getCurrentVersion();
64
+ const remoteVersion = await getLatestVersion('specifica-br');
65
+ const outdated = await isVersionOutdated(currentVersion, remoteVersion);
66
+ if (!outdated) {
67
+ console.log(chalk.green(`specifica-br atualização ignorada: a versão ${currentVersion} já está instalada`));
68
+ console.log('');
69
+ process.exit(0);
70
+ }
71
+ console.log(chalk.cyan('Atualizando specifica-br para a versão mais recente...'));
72
+ console.log(chalk.gray(`Versão atual: ${currentVersion} → ${remoteVersion}`));
73
+ console.log(chalk.gray('Executando: npm i -g specifica-br@latest'));
74
+ console.log('');
75
+ }
76
+ catch (error) {
77
+ console.log('');
78
+ console.log(chalk.yellow('Aviso: Não foi possível verificar a versão mais recente. Continuando com a atualização...'));
79
+ console.log('');
80
+ }
38
81
  try {
39
82
  const { stdout, stderr } = await execAsync('npm i -g specifica-br@latest', {
40
83
  maxBuffer: 1024 * 1024 * 10,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "specifica-br",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Ferramenta de automação para desenvolvimento guiado por especificações (Spec Driven Development - SDD) com IA. Otimizado para o ecossistema brasileiro.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",