@devquest/cli 1.0.0 → 1.0.2

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.
@@ -12,13 +12,13 @@ const path_1 = __importDefault(require("path"));
12
12
  const os_1 = __importDefault(require("os"));
13
13
  const child_process_1 = require("child_process");
14
14
  const chalk_1 = __importDefault(require("chalk"));
15
+ const env_1 = require("../utils/env");
15
16
  const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.devquest');
16
17
  const CONFIG_FILE = path_1.default.join(CONFIG_DIR, 'config.json');
17
18
  exports.authCommand = new commander_1.Command('auth')
18
19
  .description('Autenticação via navegador no CLI')
19
20
  .action(async () => {
20
21
  const PORT = 3838;
21
- const DASHBOARD_URL = process.env.DEVQUEST_URL || 'http://localhost:3000';
22
22
  console.log(chalk_1.default.blue('⏳ Iniciando autenticação...'));
23
23
  console.log(chalk_1.default.gray(`Abriremos o seu navegador em breve para aprovação.`));
24
24
  const server = http_1.default.createServer((req, res) => {
@@ -33,6 +33,7 @@ exports.authCommand = new commander_1.Command('auth')
33
33
  const url = new URL(req.url || '/', `http://localhost:${PORT}`);
34
34
  if (url.pathname === '/callback') {
35
35
  const token = url.searchParams.get('token');
36
+ const redirectUrl = url.searchParams.get('redirect');
36
37
  if (token) {
37
38
  try {
38
39
  if (!fs_1.default.existsSync(CONFIG_DIR)) {
@@ -41,13 +42,21 @@ exports.authCommand = new commander_1.Command('auth')
41
42
  const config = fs_1.default.existsSync(CONFIG_FILE) ? JSON.parse(fs_1.default.readFileSync(CONFIG_FILE, 'utf-8')) : {};
42
43
  config.token = token;
43
44
  fs_1.default.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
44
- res.writeHead(200, { 'Content-Type': 'application/json' });
45
- res.end(JSON.stringify({ success: true }));
45
+ if (redirectUrl) {
46
+ res.writeHead(302, { 'Location': redirectUrl });
47
+ res.end();
48
+ }
49
+ else {
50
+ res.writeHead(200, { 'Content-Type': 'application/json' });
51
+ res.end(JSON.stringify({ success: true }));
52
+ }
46
53
  console.log(chalk_1.default.green('\n✅ Autenticado com sucesso! Seu token foi guardado localmente protegido.'));
47
54
  console.log(chalk_1.default.yellow('Agora você pode clonar e submeter desafios!'));
48
55
  console.log(chalk_1.default.gray('Use: devquest clone <id-do-curso>'));
49
- server.close();
50
- process.exit(0);
56
+ setTimeout(() => {
57
+ server.close();
58
+ process.exit(0);
59
+ }, 100);
51
60
  }
52
61
  catch (err) {
53
62
  console.error('\nErro ao salvar token de forma segura:', err);
@@ -69,7 +78,7 @@ exports.authCommand = new commander_1.Command('auth')
69
78
  });
70
79
  server.listen(PORT, () => {
71
80
  const cliAuthPath = encodeURIComponent(`/dashboard/cli-auth?port=${PORT}`);
72
- const authUrl = `${DASHBOARD_URL}/login?callbackUrl=${cliAuthPath}`;
81
+ const authUrl = `${env_1.DASHBOARD_URL}/login?callbackUrl=${cliAuthPath}`;
73
82
  (0, child_process_1.exec)(`open "${authUrl}"`, (err) => {
74
83
  if (err) {
75
84
  console.log(chalk_1.default.yellow(`Não foi possível abrir o navegador automaticamente.`));
@@ -11,7 +11,7 @@ const path_1 = __importDefault(require("path"));
11
11
  const chalk_1 = __importDefault(require("chalk"));
12
12
  const axios_1 = __importDefault(require("axios"));
13
13
  const auth_1 = require("./auth");
14
- const API_BASE = process.env.DEVQUEST_API_URL || 'http://localhost:8787';
14
+ const env_1 = require("../utils/env");
15
15
  exports.cloneCommand = new commander_1.Command('clone')
16
16
  .argument('<id>', 'ID do desafio (ex: build-your-own-redis)')
17
17
  .description('Clona o repositório boilerplate personalizado configurando o remoto')
@@ -25,7 +25,7 @@ exports.cloneCommand = new commander_1.Command('clone')
25
25
  try {
26
26
  // 1. Requisitar a URL do repositório para este usuário/desafio do Backend
27
27
  // Isso criaria um "provisionamento" do repositório no backend
28
- const response = await axios_1.default.post(`${API_BASE}/challenges/${id}/clone`, {}, {
28
+ const response = await axios_1.default.post(`${env_1.API_BASE}/challenges/${id}/clone`, {}, {
29
29
  headers: { Authorization: `Bearer ${token}` }
30
30
  });
31
31
  const { cloneUrl, targetDir } = response.data;
@@ -11,8 +11,7 @@ const path_1 = __importDefault(require("path"));
11
11
  const fs_1 = __importDefault(require("fs"));
12
12
  const axios_1 = __importDefault(require("axios"));
13
13
  const auth_1 = require("./auth");
14
- const API_BASE = process.env.DEVQUEST_API_URL || 'http://localhost:8787';
15
- const SSE_BASE = process.env.DEVQUEST_SSE_URL || 'http://localhost:8787/challenges/sse';
14
+ const env_1 = require("../utils/env");
16
15
  exports.submitCommand = new commander_1.Command('submit')
17
16
  .description('Envia seu código para os testes automatizados da plataforma')
18
17
  .action(async () => {
@@ -38,7 +37,7 @@ exports.submitCommand = new commander_1.Command('submit')
38
37
  }
39
38
  let stageOrder = 1;
40
39
  try {
41
- const progRes = await axios_1.default.get(`${API_BASE}/challenges/${challengeId}/progress`, {
40
+ const progRes = await axios_1.default.get(`${env_1.API_BASE}/challenges/${challengeId}/progress`, {
42
41
  headers: { Authorization: `Bearer ${token}` }
43
42
  });
44
43
  if (progRes.data.stageOrder) {
@@ -91,7 +90,7 @@ exports.submitCommand = new commander_1.Command('submit')
91
90
  }
92
91
  });
93
92
  async function startStreamingLogs(token, challengeDir, challengeId, stageOrder) {
94
- const url = `${SSE_BASE}?token=${encodeURIComponent(token)}&challengeId=${encodeURIComponent(challengeId)}&stageOrder=${stageOrder}`;
93
+ const url = `${env_1.SSE_BASE}?token=${encodeURIComponent(token)}&challengeId=${encodeURIComponent(challengeId)}&stageOrder=${stageOrder}`;
95
94
  console.log(chalk_1.default.cyan('📡 Conectando à Sandbox segurizada (MicroVM Firecracker)...'));
96
95
  try {
97
96
  const response = await fetch(url);
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SSE_BASE = exports.API_BASE = exports.DASHBOARD_URL = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const isDev = fs_1.default.existsSync(path_1.default.join(__dirname, '..', 'src')) || fs_1.default.existsSync(path_1.default.join(__dirname, '..', '..', 'src'));
10
+ exports.DASHBOARD_URL = isDev ? 'http://localhost:3000' : 'https://devquest-web.vercel.app';
11
+ exports.API_BASE = isDev ? 'http://localhost:8787' : 'https://api.devkalmon.workers.dev';
12
+ exports.SSE_BASE = isDev ? 'http://localhost:8787/challenges/sse' : 'https://api.devkalmon.workers.dev/challenges/sse';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devquest/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "DevQuest CLI - Construa seu próprio Redis, Docker, Git e mais",
5
5
  "main": "dist/index.js",
6
6
  "bin": {