atendeticket 2.1.21 → 2.1.24

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/core/exec.js CHANGED
@@ -1,18 +1,21 @@
1
1
  const { spawn } = require('cross-spawn');
2
- const { info, error } = require('./logger');
2
+ const { writeToFile } = require('./logger');
3
+ const ora = require('ora');
3
4
 
4
5
  /**
5
6
  * Executes a system command.
6
7
  * @param {string} cmd
7
8
  * @param {string[]} args
8
- * @param {object} options - spawn options + { input: string }
9
+ * @param {object} options - spawn options + { input: string, message: string }
9
10
  */
10
11
  function runCommand(cmd, args = [], options = {}) {
11
- const { input, ...spawnOptions } = options;
12
+ const { input, message, ...spawnOptions } = options;
13
+ const spinner = ora(message || `Executando ${cmd}...`).start();
14
+
12
15
  return new Promise((resolve, reject) => {
13
- const child = spawn(cmd, args, {
14
- stdio: input ? ['pipe', 'inherit', 'inherit'] : 'inherit',
15
- ...spawnOptions
16
+ const child = spawn(cmd, args, {
17
+ stdio: input ? ['pipe', 'pipe', 'pipe'] : ['ignore', 'pipe', 'pipe'],
18
+ ...spawnOptions
16
19
  });
17
20
 
18
21
  if (input && child.stdin) {
@@ -20,12 +23,32 @@ function runCommand(cmd, args = [], options = {}) {
20
23
  child.stdin.end();
21
24
  }
22
25
 
26
+ let output = '';
27
+
28
+ child.stdout.on('data', (data) => {
29
+ const str = data.toString();
30
+ output += str;
31
+ writeToFile(`[STDOUT] ${str}`);
32
+ });
33
+
34
+ child.stderr.on('data', (data) => {
35
+ const str = data.toString();
36
+ output += str;
37
+ writeToFile(`[STDERR] ${str}`);
38
+ });
39
+
23
40
  child.on('close', code => {
24
- if (code === 0) resolve();
25
- else reject(new Error(`${cmd} ${args.join(' ')} falhou com código ${code}`));
41
+ if (code === 0) {
42
+ spinner.succeed();
43
+ resolve();
44
+ } else {
45
+ spinner.fail();
46
+ reject(new Error(`${cmd} ${args.join(' ')} falhou com código ${code}`));
47
+ }
26
48
  });
27
49
 
28
50
  child.on('error', err => {
51
+ spinner.fail();
29
52
  reject(err);
30
53
  });
31
54
  });
package/core/logger.js CHANGED
@@ -1,15 +1,27 @@
1
1
  const chalk = require('chalk');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const logFile = path.join(process.cwd(), 'install.log');
6
+
7
+ function writeToFile(msg) {
8
+ const timestamp = new Date().toISOString();
9
+ fs.appendFileSync(logFile, `[${timestamp}] ${msg}\n`);
10
+ }
2
11
 
3
12
  function info(msg) {
4
13
  console.log(chalk.cyan('[INFO]'), msg);
14
+ writeToFile(`[INFO] ${msg}`);
5
15
  }
6
16
 
7
17
  function success(msg) {
8
18
  console.log(chalk.green('[SUCCESS]'), msg);
19
+ writeToFile(`[SUCCESS] ${msg}`);
9
20
  }
10
21
 
11
22
  function error(msg) {
12
23
  console.error(chalk.red('[ERROR]'), msg);
24
+ writeToFile(`[ERROR] ${msg}`);
13
25
  }
14
26
 
15
- module.exports = { info, success, error };
27
+ module.exports = { info, success, error, writeToFile };
@@ -3,9 +3,20 @@ const { info, success } = require('../../core/logger');
3
3
 
4
4
  async function installDocker() {
5
5
  info('Instalando Docker...');
6
- await runCommand('sudo', ['apt', 'install', '-y', 'docker.io']);
6
+
7
+ // Tenta remover versões pré-instaladas ou conflitantes (opcional, mas recomendado)
8
+ try {
9
+ await runCommand('sudo', ['apt-get', 'remove', '-y', 'docker', 'docker-engine', 'docker.io', 'containerd', 'runc']);
10
+ } catch (err) {
11
+ // Ignora erros se não houver o que remover
12
+ }
13
+
14
+ // Instala usando o script oficial
15
+ await runCommand('bash', ['-c', 'curl -fsSL https://get.docker.com | sh']);
16
+
7
17
  await runCommand('sudo', ['systemctl', 'enable', '--now', 'docker']);
8
- success('Docker instalado!');
18
+
19
+ success('Docker instalado com sucesso!');
9
20
  }
10
21
 
11
22
  module.exports = { installDocker };
@@ -3,22 +3,20 @@ const { info, success } = require('../../core/logger');
3
3
 
4
4
  async function installNode() {
5
5
  info('Instalando Node.js 22.x...');
6
- // Usamos bash -c para suportar o pipe (|) no spawn
7
- await runCommand('bash', ['-c', 'curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -']);
8
- await runCommand('sudo', ['apt-get', 'install', '-y', 'nodejs']);
6
+ await runCommand('bash', ['-c', 'curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -'], { message: 'Configurando repositório NodeSource...' });
7
+ await runCommand('sudo', ['apt-get', 'install', '-y', 'nodejs'], { message: 'Instalando Node.js...' });
9
8
 
10
9
  info('Atualizando npm...');
11
- await runCommand('sudo', ['npm', 'install', '-g', 'npm@latest']);
10
+ await runCommand('sudo', ['npm', 'install', '-g', 'npm@latest'], { message: 'Atualizando npm para a versão mais recente...' });
12
11
 
13
12
  info('Instalando PostgreSQL...');
14
- await runCommand('sudo', ['sh', '-c', 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list']);
15
- // Usamos bash -c para o pipe do wget para apt-key
16
- await runCommand('bash', ['-c', 'wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -']);
17
- await runCommand('sudo', ['apt-get', 'update', '-y']);
18
- await runCommand('sudo', ['apt-get', '-y', 'install', 'postgresql']);
13
+ await runCommand('sudo', ['sh', '-c', 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'], { message: 'Adicionando repositório PostgreSQL...' });
14
+ await runCommand('bash', ['-c', 'wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -'], { message: 'Adicionando chave GPG do PostgreSQL...' });
15
+ await runCommand('sudo', ['apt-get', 'update', '-y'], { message: 'Atualizando lista de pacotes...' });
16
+ await runCommand('sudo', ['apt-get', '-y', 'install', 'postgresql'], { message: 'Instalando PostgreSQL...' });
19
17
 
20
18
  info('Configurando timezone para America/Sao_Paulo...');
21
- await runCommand('sudo', ['timedatectl', 'set-timezone', 'America/Sao_Paulo']);
19
+ await runCommand('sudo', ['timedatectl', 'set-timezone', 'America/Sao_Paulo'], { message: 'Configurando timezone...' });
22
20
 
23
21
  success('Node.js e PostgreSQL instalados!');
24
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atendeticket",
3
- "version": "2.1.21",
3
+ "version": "2.1.24",
4
4
  "description": "Instalador CLI para AtendeTicket",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,6 +13,7 @@
13
13
  "dependencies": {
14
14
  "chalk": "^4.1.2",
15
15
  "cross-spawn": "^7.0.6",
16
- "inquirer": "^8.2.6"
16
+ "inquirer": "^8.2.6",
17
+ "ora": "^5.4.1"
17
18
  }
18
19
  }