@devquest/cli 1.0.1 → 1.0.3

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.
@@ -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);
@@ -24,7 +24,6 @@ exports.cloneCommand = new commander_1.Command('clone')
24
24
  console.log(chalk_1.default.blue(`🚀 Iniciando o desafio: ${id}`));
25
25
  try {
26
26
  // 1. Requisitar a URL do repositório para este usuário/desafio do Backend
27
- // Isso criaria um "provisionamento" do repositório no backend
28
27
  const response = await axios_1.default.post(`${env_1.API_BASE}/challenges/${id}/clone`, {}, {
29
28
  headers: { Authorization: `Bearer ${token}` }
30
29
  });
@@ -35,16 +34,31 @@ exports.cloneCommand = new commander_1.Command('clone')
35
34
  process.exit(1);
36
35
  }
37
36
  let finalUrl = cloneUrl;
38
- // Trata casos locais (para dev) onde o banco retorna 'file://../../templates/xyz'
39
- if (cloneUrl.startsWith('file://../../templates/')) {
40
- const repoRoot = path_1.default.resolve(__dirname, '../../../..'); // de dist/commands -> root turborepo
41
- finalUrl = `file://${path_1.default.join(repoRoot, 'templates', targetDir || id)}`;
37
+ // Lógica dinâmica sugerida pelo usuário:
38
+ // Se estiver local (IS_DEV) e o link for file://, resolvemos para o caminho local do monorepo
39
+ if (env_1.IS_DEV && cloneUrl.startsWith('file://')) {
40
+ // Assume que estamos no monorepo e templates estão em ../../../../templates
41
+ const repoRoot = path_1.default.resolve(__dirname, '../../../..');
42
+ const templateName = cloneUrl.replace('file://../../templates/', '');
43
+ const localPath = path_1.default.join(repoRoot, 'templates', templateName);
44
+ if (fs_1.default.existsSync(localPath)) {
45
+ finalUrl = `file://${localPath}`;
46
+ console.log(chalk_1.default.cyan(`🏠 Ambiente de desenvolvimento detectado. Usando template local.`));
47
+ }
48
+ else {
49
+ // Se não achar local mesmo em dev, tenta o fallback remoto
50
+ finalUrl = `https://github.com/kalmonj/devquest-template-${id}.git`;
51
+ }
52
+ }
53
+ // Se não estiver em dev e for um link de arquivo (que veio do banco do monorepo),
54
+ // ou se o link do banco for inválido para produção
55
+ else if (!env_1.IS_DEV && cloneUrl.startsWith('file://')) {
56
+ finalUrl = `https://github.com/kalmonj/devquest-template-${id}.git`;
57
+ console.log(chalk_1.default.cyan(`🌐 CLI em produção. Usando repositório remoto oficial.`));
42
58
  }
43
59
  console.log(chalk_1.default.gray(`Clonando de ${finalUrl} para ${destPath}...`));
44
60
  const git = (0, simple_git_1.default)();
45
61
  await git.clone(finalUrl, destPath);
46
- // 2. O boilerplate baixado deverá ter o origin já devidamente setado
47
- // O remote será algo como http://git.plataforma.com/hash.git (servidor git interno)
48
62
  console.log(chalk_1.default.green(`✅ Desafio clonado com sucesso em ./${targetDir || id}`));
49
63
  console.log(chalk_1.default.yellow(`\nPróximos passos:`));
50
64
  console.log(` cd ${targetDir || id}`);
package/dist/utils/env.js CHANGED
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SSE_BASE = exports.API_BASE = exports.DASHBOARD_URL = void 0;
6
+ exports.SSE_BASE = exports.API_BASE = exports.DASHBOARD_URL = exports.IS_DEV = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
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';
9
+ exports.IS_DEV = fs_1.default.existsSync(path_1.default.join(__dirname, '..', 'src')) || fs_1.default.existsSync(path_1.default.join(__dirname, '..', '..', 'src'));
10
+ exports.DASHBOARD_URL = exports.IS_DEV ? 'http://localhost:3000' : 'https://devquest-web.vercel.app';
11
+ exports.API_BASE = exports.IS_DEV ? 'http://localhost:8787' : 'https://api.devkalmon.workers.dev';
12
+ exports.SSE_BASE = exports.IS_DEV ? '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.1",
3
+ "version": "1.0.3",
4
4
  "description": "DevQuest CLI - Construa seu próprio Redis, Docker, Git e mais",
5
5
  "main": "dist/index.js",
6
6
  "bin": {