atendeticket 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 AtendeTicket
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
File without changes
package/index.js ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ import chalk from "chalk";
3
+ import { showMainMenu } from "./src/menu.js";
4
+
5
+ // ================================
6
+ // ✅ VERIFICA SE ESTÁ COMO ROOT
7
+ // ================================
8
+ if (process.getuid && process.getuid() !== 0) {
9
+ console.log(
10
+ chalk.red.bold("\n❌ Erro: Permissão negada!\n") +
11
+ chalk.yellow("Execute o instalador como root:\n") +
12
+ chalk.cyan("sudo atendeticket\n")
13
+ );
14
+ process.exit(1);
15
+ }
16
+
17
+ // ================================
18
+ // ✅ LIMPA TELA
19
+ // ================================
20
+ console.clear();
21
+
22
+ // ================================
23
+ // ✅ BANNER PROFISSIONAL
24
+ // ================================
25
+ console.log(
26
+ chalk.green.bold(`
27
+ ███████╗ █████╗ ████████╗███████╗███╗ ██╗██████╗ ███████╗
28
+ ██╔════╝██╔══██╗╚══██╔══╝██╔════╝████╗ ██║██╔══██╗██╔════╝
29
+ █████╗ ███████║ ██║ █████╗ ██╔██╗ ██║██║ ██║█████╗
30
+ ██╔══╝ ██╔══██║ ██║ ██╔══╝ ██║╚██╗██║██║ ██║██╔══╝
31
+ ██║ ██║ ██║ ██║ ███████╗██║ ╚████║██████╔╝███████╗
32
+ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚═════╝ ╚══════╝
33
+ `
34
+ )
35
+ );
36
+
37
+ console.log(
38
+ chalk.white.bold(" 🚀 ATENDETICKET INSTALLER - v1.0.0\n")
39
+ );
40
+
41
+ // ================================
42
+ // ✅ INICIA O MENU PRINCIPAL
43
+ // ================================
44
+ try {
45
+ await showMainMenu();
46
+ } catch (err) {
47
+ console.log(chalk.red("\n❌ Erro fatal no instalador:\n"));
48
+ console.error(err);
49
+ process.exit(1);
50
+ }
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "atendeticket",
3
+ "version": "1.0.0",
4
+ "description": "🐬 Este é o instalador do AtendeTicket",
5
+ "bin": {
6
+ "atendeticket": "./index.js"
7
+ },
8
+ "type": "module",
9
+ "dependencies": {
10
+ "inquirer": "^9.0.0",
11
+ "chalk": "^5.0.0",
12
+ "ora": "^6.0.0"
13
+ }
14
+ }
@@ -0,0 +1,48 @@
1
+ import inquirer from "inquirer";
2
+
3
+ import { checkRoot } from "./installer/01-checkRoot.js";
4
+ import { installSystemDeps } from "./installer/02-systemDeps.js";
5
+ import { installNode } from "./installer/03-nodejs.js";
6
+ import { installPM2 } from "./installer/04-pm2.js";
7
+ import { installNginx } from "./installer/05-nginx.js";
8
+ import { installCertbot } from "./installer/06-certbot.js";
9
+ import { cloneRepos } from "./installer/07-cloneRepos.js";
10
+ import { setupBackend } from "./installer/08-backend.js";
11
+ import { setupFrontend } from "./installer/09-frontend.js";
12
+ import { createEnv } from "./installer/10-env.js";
13
+ import { startPM2 } from "./installer/11-pm2Start.js";
14
+ import { setupProxy } from "./installer/12-nginxProxy.js";
15
+ import { setupSSL } from "./installer/13-ssl.js";
16
+ import { finalReport } from "./installer/14-finalReport.js";
17
+
18
+ export async function installAtendeTicket() {
19
+ checkRoot();
20
+
21
+ const answers = await inquirer.prompt([
22
+ { name: "domain", message: "Domínio:" },
23
+ { name: "backendPort", message: "Porta do backend:", default: "3000" },
24
+ { name: "repoBackend", message: "Repo BACKEND:" },
25
+ { name: "repoFrontend", message: "Repo FRONTEND:" }
26
+ ]);
27
+
28
+ installSystemDeps();
29
+ installNode();
30
+ installPM2();
31
+ installNginx();
32
+ installCertbot();
33
+
34
+ cloneRepos({
35
+ backend: answers.repoBackend,
36
+ frontend: answers.repoFrontend
37
+ });
38
+
39
+ setupBackend();
40
+ setupFrontend();
41
+ createEnv({ backendPort: answers.backendPort });
42
+
43
+ startPM2();
44
+ setupProxy({ domain: answers.domain, backendPort: answers.backendPort });
45
+ setupSSL(answers.domain);
46
+
47
+ finalReport(answers.domain);
48
+ }
@@ -0,0 +1,5 @@
1
+ import fs from "fs";
2
+
3
+ export function log(message) {
4
+ fs.appendFileSync("/var/log/atendeticket-install.log", message + "\n");
5
+ }
@@ -0,0 +1,3 @@
1
+ export function rollback(step) {
2
+ console.log(`⚠️ Rollback iniciado no passo: ${step}`);
3
+ }
@@ -0,0 +1,6 @@
1
+ import { execSync } from "child_process";
2
+
3
+ export function run(cmd) {
4
+ console.log(`\n🔧 ${cmd}\n`);
5
+ execSync(cmd, { stdio: "inherit" });
6
+ }
@@ -0,0 +1,6 @@
1
+ export function checkRoot() {
2
+ if (process.getuid() !== 0) {
3
+ console.log("❌ Execute como root: sudo atendeticket");
4
+ process.exit(1);
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ import { run } from "../core/run.js";
2
+
3
+ export function installSystemDeps() {
4
+ run("apt update -y");
5
+ run("apt install -y curl git build-essential ufw");
6
+ }
@@ -0,0 +1,6 @@
1
+ import { run } from "../core/run.js";
2
+
3
+ export function installNode() {
4
+ run("curl -fsSL https://deb.nodesource.com/setup_20.x | bash -");
5
+ run("apt install -y nodejs");
6
+ }
@@ -0,0 +1,7 @@
1
+ import { run } from "../core/run.js";
2
+
3
+ export function installPM2() {
4
+ run("npm install -g pm2");
5
+ run("pm2 startup");
6
+ run("pm2 save");
7
+ }
@@ -0,0 +1,7 @@
1
+ import { run } from "../core/run.js";
2
+
3
+ export function installNginx() {
4
+ run("apt install -y nginx");
5
+ run("systemctl enable nginx");
6
+ run("systemctl start nginx");
7
+ }
@@ -0,0 +1,5 @@
1
+ import { run } from "../core/run.js";
2
+
3
+ export function installCertbot() {
4
+ run("apt install -y certbot python3-certbot-nginx");
5
+ }
@@ -0,0 +1,7 @@
1
+ import { run } from "../core/run.js";
2
+
3
+ export function cloneRepos({ backend, frontend }) {
4
+ run("mkdir -p /var/www/atendeticket");
5
+ run(`git clone ${backend} /var/www/atendeticket/backend`);
6
+ run(`git clone ${frontend} /var/www/atendeticket/frontend`);
7
+ }
@@ -0,0 +1,5 @@
1
+ import { run } from "../core/run.js";
2
+
3
+ export function setupBackend() {
4
+ run("cd /var/www/atendeticket/backend && npm install");
5
+ }
@@ -0,0 +1,6 @@
1
+ import { run } from "../core/run.js";
2
+
3
+ export function setupFrontend() {
4
+ run("cd /var/www/atendeticket/frontend && npm install");
5
+ run("cd /var/www/atendeticket/frontend && npm run build");
6
+ }
@@ -0,0 +1,6 @@
1
+ import fs from "fs";
2
+
3
+ export function createEnv({ backendPort }) {
4
+ const content = `PORT=${backendPort}`;
5
+ fs.writeFileSync("/var/www/atendeticket/backend/.env", content);
6
+ }
@@ -0,0 +1,6 @@
1
+ import { run } from "../core/run.js";
2
+
3
+ export function startPM2() {
4
+ run("cd /var/www/atendeticket/backend && pm2 start ecosystem.config.js --name atendeticket");
5
+ run("pm2 save");
6
+ }
@@ -0,0 +1,29 @@
1
+ import { run } from "../core/run.js";
2
+ import fs from "fs";
3
+
4
+ export function setupProxy({ domain, backendPort }) {
5
+ const conf = `
6
+ server {
7
+ listen 80;
8
+ server_name ${domain};
9
+
10
+ location / {
11
+ root /var/www/atendeticket/frontend/dist;
12
+ index index.html;
13
+ try_files $uri $uri/ /index.html;
14
+ }
15
+
16
+ location /api {
17
+ proxy_pass http://localhost:${backendPort};
18
+ proxy_set_header Host $host;
19
+ proxy_set_header X-Real-IP $remote_addr;
20
+ }
21
+ }
22
+ `;
23
+
24
+ fs.writeFileSync("/etc/nginx/sites-available/atendeticket", conf);
25
+
26
+ run("ln -sf /etc/nginx/sites-available/atendeticket /etc/nginx/sites-enabled/");
27
+ run("nginx -t");
28
+ run("systemctl reload nginx");
29
+ }
@@ -0,0 +1,5 @@
1
+ import { run } from "../core/run.js";
2
+
3
+ export function setupSSL(domain) {
4
+ run(`certbot --nginx -d ${domain} --non-interactive --agree-tos -m admin@${domain}`);
5
+ }
@@ -0,0 +1,9 @@
1
+ export function finalReport(domain) {
2
+ console.log(`
3
+ ====================================
4
+ ✅ ATENDETICKET INSTALADO COM SUCESSO
5
+ 🌐 https://${domain}
6
+ 📁 /var/www/atendeticket
7
+ ====================================
8
+ `);
9
+ }
package/src/menu.js ADDED
@@ -0,0 +1,46 @@
1
+ import inquirer from "inquirer";
2
+ import chalk from "chalk";
3
+
4
+ import { installAtendeTicket } from "./appInstaller.js";
5
+
6
+ export async function showMainMenu() {
7
+ const { option } = await inquirer.prompt([
8
+ {
9
+ type: "list",
10
+ name: "option",
11
+ message: "O que deseja fazer?",
12
+ choices: [
13
+ { name: "🚀 Instalar AtendeTicket Completo", value: "app" },
14
+ { name: "🛠 Instalar dependências do sistema", value: "system" },
15
+ { name: "⚡ Configurar PM2", value: "pm2" },
16
+ { name: "🌐 Configurar NGINX", value: "nginx" },
17
+ { name: "❌ Sair", value: "exit" }
18
+ ]
19
+ }
20
+ ]);
21
+
22
+ switch (option) {
23
+ case "app":
24
+ await installAtendeTicket();
25
+ break;
26
+
27
+ case "system":
28
+ console.log(chalk.yellow("Instalação de sistema ainda não ligada ao menu."));
29
+ break;
30
+
31
+ case "pm2":
32
+ console.log(chalk.yellow("Configuração do PM2 ainda não ligada ao menu."));
33
+ break;
34
+
35
+ case "nginx":
36
+ console.log(chalk.yellow("Configuração do NGINX ainda não ligada ao menu."));
37
+ break;
38
+
39
+ case "exit":
40
+ console.log(chalk.red("Saindo do instalador..."));
41
+ process.exit(0);
42
+ }
43
+
44
+ // Volta para o menu após qualquer ação
45
+ await showMainMenu();
46
+ }