@devquest/cli 1.0.2 → 1.0.4
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/dist/commands/clone.js +50 -14
- package/dist/utils/env.js +5 -5
- package/package.json +1 -1
package/dist/commands/clone.js
CHANGED
|
@@ -23,31 +23,67 @@ exports.cloneCommand = new commander_1.Command('clone')
|
|
|
23
23
|
}
|
|
24
24
|
console.log(chalk_1.default.blue(`🚀 Iniciando o desafio: ${id}`));
|
|
25
25
|
try {
|
|
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
26
|
const response = await axios_1.default.post(`${env_1.API_BASE}/challenges/${id}/clone`, {}, {
|
|
29
27
|
headers: { Authorization: `Bearer ${token}` }
|
|
30
28
|
});
|
|
31
29
|
const { cloneUrl, targetDir } = response.data;
|
|
32
|
-
const
|
|
30
|
+
const targetFolderName = targetDir || id;
|
|
31
|
+
const destPath = path_1.default.resolve(process.cwd(), targetFolderName);
|
|
33
32
|
if (fs_1.default.existsSync(destPath)) {
|
|
34
33
|
console.log(chalk_1.default.red(`O diretório ${destPath} já existe.`));
|
|
35
34
|
process.exit(1);
|
|
36
35
|
}
|
|
37
36
|
let finalUrl = cloneUrl;
|
|
38
|
-
//
|
|
39
|
-
if (cloneUrl.startsWith('file
|
|
40
|
-
const repoRoot = path_1.default.resolve(__dirname, '../../../..');
|
|
41
|
-
|
|
37
|
+
// Se estiver local (IS_DEV) e o link for file://, resolvemos para o caminho local do monorepo
|
|
38
|
+
if (env_1.IS_DEV && cloneUrl.startsWith('file://')) {
|
|
39
|
+
const repoRoot = path_1.default.resolve(__dirname, '../../../..');
|
|
40
|
+
const templateName = cloneUrl.replace('file://../../templates/', '');
|
|
41
|
+
const localPath = path_1.default.join(repoRoot, 'templates', templateName);
|
|
42
|
+
if (fs_1.default.existsSync(localPath)) {
|
|
43
|
+
finalUrl = `file://${localPath}`;
|
|
44
|
+
console.log(chalk_1.default.cyan(`🏠 Ambiente de desenvolvimento detectado. Usando template local.`));
|
|
45
|
+
const git = (0, simple_git_1.default)();
|
|
46
|
+
await git.clone(finalUrl, destPath);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// Fallback para o repositório central de templates
|
|
50
|
+
finalUrl = `https://github.com/KalmonJ/devquest-templates.git`;
|
|
51
|
+
}
|
|
42
52
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
//
|
|
48
|
-
|
|
53
|
+
// Em produção, sempre usamos o repositório central devquest-templates
|
|
54
|
+
else {
|
|
55
|
+
finalUrl = `https://github.com/KalmonJ/devquest-templates.git`;
|
|
56
|
+
}
|
|
57
|
+
// Se o URL final for o repositório central, precisamos extrair a pasta específica
|
|
58
|
+
if (finalUrl.includes('devquest-templates.git')) {
|
|
59
|
+
console.log(chalk_1.default.gray(`Clonando template de devquest-templates...`));
|
|
60
|
+
const tempDir = path_1.default.join(process.cwd(), `.devquest-temp-${id}`);
|
|
61
|
+
const git = (0, simple_git_1.default)();
|
|
62
|
+
await git.clone(finalUrl, tempDir, ['--depth', '1']);
|
|
63
|
+
const templateSourcePath = path_1.default.join(tempDir, id);
|
|
64
|
+
if (!fs_1.default.existsSync(templateSourcePath)) {
|
|
65
|
+
// Cleanup antes do erro
|
|
66
|
+
fs_1.default.rmSync(tempDir, { recursive: true, force: true });
|
|
67
|
+
throw new Error(`Template '${id}' não encontrado no repositório de templates.`);
|
|
68
|
+
}
|
|
69
|
+
// Move a pasta do template para o destino final
|
|
70
|
+
// No Node < 16.7.0 fs.cpSync não existe, mas como o usuário usa node v24, podemos usar
|
|
71
|
+
fs_1.default.cpSync(templateSourcePath, destPath, { recursive: true });
|
|
72
|
+
// Remove a pasta temporária
|
|
73
|
+
fs_1.default.rmSync(tempDir, { recursive: true, force: true });
|
|
74
|
+
// Inicializa um novo repo git se o usuário quiser (opcional, mas bom pra começar limpo)
|
|
75
|
+
const newGit = (0, simple_git_1.default)(destPath);
|
|
76
|
+
await newGit.init();
|
|
77
|
+
console.log(chalk_1.default.cyan(`🌐 Template extraído com sucesso do repositório central.`));
|
|
78
|
+
}
|
|
79
|
+
else if (!env_1.IS_DEV || !cloneUrl.startsWith('file://')) {
|
|
80
|
+
// Fallback genérico para clone direto (caso o URL seja outro)
|
|
81
|
+
const git = (0, simple_git_1.default)();
|
|
82
|
+
await git.clone(finalUrl, destPath);
|
|
83
|
+
}
|
|
84
|
+
console.log(chalk_1.default.green(`✅ Desafio clonado com sucesso em ./${targetFolderName}`));
|
|
49
85
|
console.log(chalk_1.default.yellow(`\nPróximos passos:`));
|
|
50
|
-
console.log(` cd ${
|
|
86
|
+
console.log(` cd ${targetFolderName}`);
|
|
51
87
|
console.log(` Leia o README.md e comece a desenvolver.`);
|
|
52
88
|
console.log(` Para submeter: devquest submit`);
|
|
53
89
|
}
|
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
|
-
|
|
10
|
-
exports.DASHBOARD_URL =
|
|
11
|
-
exports.API_BASE =
|
|
12
|
-
exports.SSE_BASE =
|
|
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';
|