cloudflare/kumo

Public

mirrored fromhttps://github.com/cloudflare/kumoAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
5260f1a5703bb69e6c7f7cf0ce8033a561cac8b5

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/kumo-figma/scripts/maybe-sync.ts

61lines · modecode

1import { existsSync, readFileSync } from "node:fs";
2import { dirname, resolve } from "node:path";
3import { fileURLToPath } from "node:url";
4import { spawnSync } from "node:child_process";
5
6const __dirname = dirname(fileURLToPath(import.meta.url));
7const ENV_PATH = resolve(__dirname, ".env");
8
9function loadDotEnvIfPresent() {
10 if (!existsSync(ENV_PATH)) return;
11
12 const envContent = readFileSync(ENV_PATH, "utf-8");
13 for (const line of envContent.split("\n")) {
14 const trimmed = line.trim();
15 if (trimmed.length === 0) continue;
16 if (trimmed.startsWith("#")) continue;
17
18 const [key, ...valueParts] = trimmed.split("=");
19 const value = valueParts.join("=").replace(/^["']|["']$/g, "");
20 if (!key || !value) continue;
21
22 if (!process.env[key]) {
23 process.env[key] = value;
24 }
25 }
26}
27
28function shouldSkipSync() {
29 const value = (process.env.KUMO_FIGMA_SKIP_SYNC || "").toLowerCase();
30 return value === "1" || value === "true" || value === "yes";
31}
32
33function main() {
34 if (shouldSkipSync()) {
35 console.log("Skipping figma:sync (KUMO_FIGMA_SKIP_SYNC=1)");
36 return;
37 }
38
39 // Support the common setup of putting FIGMA_TOKEN in scripts/.env
40 loadDotEnvIfPresent();
41
42 if (!process.env.FIGMA_TOKEN) {
43 console.log(
44 "Skipping figma:sync (no FIGMA_TOKEN). " +
45 "Create packages/kumo-figma/scripts/.env or export FIGMA_TOKEN to enable token sync.",
46 );
47 return;
48 }
49
50 console.log("Running figma:sync...");
51 const result = spawnSync("pnpm", ["run", "figma:sync"], {
52 stdio: "inherit",
53 env: process.env,
54 });
55
56 if (typeof result.status === "number" && result.status !== 0) {
57 process.exit(result.status);
58 }
59}
60
61main();
62