UNPKG

@embeddable.com/sdk-core

Version:

Core Embeddable SDK module responsible for web-components bundling and publishing.

108 lines (92 loc) 2.64 kB
import { build, buildPackage, defineConfig, dev, login, push, } from "../lib/index.esm.js"; import { spawn } from "child_process"; import path from "path"; import fs from "fs"; const COMMANDS_MAP = { build, login, push, dev, defineConfig, buildPackage, }; export async function main() { const command = process.argv[2]; const runScript = COMMANDS_MAP[command]; const args = process.argv.slice(2); const skipTypeCheck = args.includes("--force"); if (!runScript) { process.exit(1); } if (command === "build") { await runTypeScriptCheck(skipTypeCheck); } await runScript(); } async function outputWarning(message) { console.warn(`\x1b[33m⚠️ WARNING: ${message}\x1b[0m`); } async function runTypeScriptCheck(skipTypeCheck = false) { const skipTypeCheckWarning = "You can skip type checking by running with the --force flag, if you know what you are doing."; return new Promise((resolve) => { const customerProjectDir = process.cwd(); const tsconfigPath = path.join(customerProjectDir, "tsconfig.json"); if (skipTypeCheck) { outputWarning("Type checking skipped."); } if (!fs.existsSync(tsconfigPath) || skipTypeCheck) { resolve(); return; } const isWindows = process.platform === "win32"; const tscBinary = isWindows ? "tsc.cmd" : "tsc"; const tscPath = path.join( customerProjectDir, "node_modules", ".bin", tscBinary, ); if (!fs.existsSync(tscPath) && !skipTypeCheck) { outputWarning( "TypeScript compiler not found. Please ensure 'typescript' is installed in your project dependencies.", ); outputWarning(skipTypeCheckWarning); process.exit(1); } try { const tsc = spawn(tscPath, ["--noEmit", "--pretty"], { cwd: customerProjectDir, stdio: "inherit", env: { ...process.env, FORCE_COLOR: "true" }, shell: isWindows, // Use shell on Windows windowsVerbatimArguments: isWindows, // Preserve argument quoting on Windows }); tsc.on("error", (err) => { outputWarning(`Failed to start TypeScript compiler: ${err.message}`); outputWarning(skipTypeCheckWarning); process.exit(1); }); tsc.on("exit", (code) => { if (code !== 0) { outputWarning(skipTypeCheckWarning); process.exit(1); } else { resolve(); } }); } catch (err) { outputWarning(`Failed to start TypeScript compiler: ${err.message}`); outputWarning(skipTypeCheckWarning); process.exit(1); } }); } main();