72 lines
1.9 KiB
JavaScript
72 lines
1.9 KiB
JavaScript
import fs from "fs";
|
|
import path from "path";
|
|
import readline from "readline";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const envPath = path.join(__dirname, ".env");
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout,
|
|
});
|
|
|
|
function question(query) {
|
|
return new Promise((resolve) => {
|
|
rl.question(query, resolve);
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
console.clear();
|
|
console.log("*** Setup Composer Builder ***\n");
|
|
console.log("Uzupełnij dane do konfiguracji API\n");
|
|
|
|
console.log("[INFO] Jak znaleźć dane:");
|
|
console.log("1. Zaloguj się do https://composer.idosell.com");
|
|
console.log("2. Otwórz DevTools (F12)");
|
|
console.log("3. Application → Cookies");
|
|
console.log("4. Skopiuj wartość cookie'a: monit_token\n");
|
|
|
|
const authToken = await question("[INPUT] AUTH_TOKEN (monit_token): ");
|
|
|
|
if (!authToken || authToken.trim().length < 10) {
|
|
console.log("\n[ERROR] Token jest zbyt krótki!");
|
|
process.exit(1);
|
|
}
|
|
|
|
const templateId = await question(
|
|
"[INPUT] TEMPLATE_ID (z URL: compositions/xxx.12345 → 12345): ",
|
|
);
|
|
|
|
if (!templateId || templateId.trim().length < 2) {
|
|
console.log("\n[ERROR] Template ID jest wymagany!");
|
|
process.exit(1);
|
|
}
|
|
|
|
const apiUrl =
|
|
(await question(
|
|
"[INPUT] API_URL (domyślnie: https://composer.idosell.com/api): ",
|
|
)) || "https://composer.idosell.com/api";
|
|
|
|
// Generuj .env
|
|
const envContent = `# Composer Builder Configuration
|
|
# Wygenerowano automatycznie
|
|
|
|
AUTH_TOKEN=${authToken.trim()}
|
|
TEMPLATE_ID=${templateId.trim()}
|
|
API_URL=${apiUrl.trim()}
|
|
`;
|
|
|
|
fs.writeFileSync(envPath, envContent);
|
|
|
|
console.log("\n[OK] Konfiguracja zapisana w .env");
|
|
console.log(`[INFO] Plik: ${envPath}\n`);
|
|
console.log("[NEXT] Możesz teraz uruchomić:");
|
|
console.log(" npm run template:pull\n");
|
|
|
|
rl.close();
|
|
}
|
|
|
|
main().catch(console.error);
|