@styleframe/cli 3.0.0 → 4.1.0

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/dist/build-CBdsifMN.js +47 -0
  3. package/dist/build-D7cinF0l.cjs +50 -0
  4. package/dist/build-dtcg-BpbjBRCf.js +429 -0
  5. package/dist/build-dtcg-vuGHy-Sl.cjs +434 -0
  6. package/dist/chunk-D6vf50IK.cjs +28 -0
  7. package/dist/commands/build.d.ts +22 -0
  8. package/dist/commands/build.d.ts.map +1 -0
  9. package/dist/commands/dtcg/build-dtcg.d.ts +36 -0
  10. package/dist/commands/dtcg/build-dtcg.d.ts.map +1 -0
  11. package/dist/commands/dtcg/build-dtcg.test.d.ts +2 -0
  12. package/dist/commands/dtcg/build-dtcg.test.d.ts.map +1 -0
  13. package/dist/commands/dtcg/evaluate.d.ts +30 -0
  14. package/dist/commands/dtcg/evaluate.d.ts.map +1 -0
  15. package/dist/commands/dtcg/evaluate.test.d.ts +2 -0
  16. package/dist/commands/dtcg/evaluate.test.d.ts.map +1 -0
  17. package/dist/commands/dtcg/export.d.ts +24 -0
  18. package/dist/commands/dtcg/export.d.ts.map +1 -0
  19. package/dist/commands/dtcg/import.d.ts +38 -0
  20. package/dist/commands/dtcg/import.d.ts.map +1 -0
  21. package/dist/commands/dtcg/index.d.ts +3 -0
  22. package/dist/commands/dtcg/index.d.ts.map +1 -0
  23. package/dist/commands/figma/export.d.ts +24 -0
  24. package/dist/commands/figma/export.d.ts.map +1 -0
  25. package/dist/commands/figma/import.d.ts +38 -0
  26. package/dist/commands/figma/import.d.ts.map +1 -0
  27. package/dist/commands/figma/index.d.ts +3 -0
  28. package/dist/commands/figma/index.d.ts.map +1 -0
  29. package/dist/commands/init/nuxt.d.ts +2 -0
  30. package/dist/commands/init/nuxt.d.ts.map +1 -0
  31. package/dist/commands/init/vite.d.ts +2 -0
  32. package/dist/commands/init/vite.d.ts.map +1 -0
  33. package/dist/commands/init.d.ts +26 -0
  34. package/dist/commands/init.d.ts.map +1 -0
  35. package/dist/constants.d.ts +8 -0
  36. package/dist/constants.d.ts.map +1 -0
  37. package/dist/dtcg-D1-iITOr.js +14 -0
  38. package/dist/dtcg-D84AfyzO.cjs +13 -0
  39. package/dist/export-CBdPGGEq.js +66 -0
  40. package/dist/export-DmPAU9Wh.cjs +69 -0
  41. package/dist/export-ONk9eKoZ.cjs +86 -0
  42. package/dist/export-suUS16eO.js +83 -0
  43. package/dist/figma-BvXoqRPU.cjs +13 -0
  44. package/dist/figma-D2RJh56T.js +14 -0
  45. package/dist/import-BQrcHNjK.cjs +126 -0
  46. package/dist/import-Bll_uBvJ.js +123 -0
  47. package/dist/import-MqLYxb8d.js +114 -0
  48. package/dist/import-ibQc_GXm.cjs +117 -0
  49. package/dist/index.cjs +21 -8669
  50. package/dist/index.d.ts +3 -4
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +16 -18
  53. package/dist/init-CAO0mA_w.js +262 -0
  54. package/dist/init-CaJoUVv2.cjs +265 -0
  55. package/dist/utils.d.ts +7 -0
  56. package/dist/utils.d.ts.map +1 -0
  57. package/package.json +14 -17
  58. package/dist/build-BFZSJ2Zh.js +0 -49
  59. package/dist/export-SH70kD-5.js +0 -139
  60. package/dist/import-CwuwczM7.js +0 -90
  61. package/dist/index-C3Gqfamh.js +0 -3689
  62. package/dist/index-DH3Hm47n.js +0 -14
  63. package/dist/index-DtEAy_us.js +0 -4475
  64. package/dist/init-DnrkQJYO.js +0 -234
@@ -0,0 +1,24 @@
1
+ declare const _default: import('citty').CommandDef<{
2
+ config: {
3
+ type: "string";
4
+ description: string;
5
+ default: string;
6
+ alias: string[];
7
+ valueHint: string;
8
+ };
9
+ output: {
10
+ type: "string";
11
+ description: string;
12
+ default: string;
13
+ alias: string[];
14
+ valueHint: string;
15
+ };
16
+ collection: {
17
+ type: "string";
18
+ description: string;
19
+ default: string;
20
+ alias: string[];
21
+ };
22
+ }>;
23
+ export default _default;
24
+ //# sourceMappingURL=export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../src/commands/figma/export.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AASA,wBAgGG"}
@@ -0,0 +1,38 @@
1
+ declare const _default: import('citty').CommandDef<{
2
+ input: {
3
+ type: "string";
4
+ description: string;
5
+ required: true;
6
+ alias: string[];
7
+ valueHint: string;
8
+ };
9
+ output: {
10
+ type: "string";
11
+ description: string;
12
+ default: string;
13
+ alias: string[];
14
+ valueHint: string;
15
+ };
16
+ composables: {
17
+ type: "boolean";
18
+ description: string;
19
+ default: true;
20
+ };
21
+ rem: {
22
+ type: "boolean";
23
+ description: string;
24
+ default: false;
25
+ };
26
+ baseFontSize: {
27
+ type: "string";
28
+ description: string;
29
+ default: string;
30
+ };
31
+ instanceName: {
32
+ type: "string";
33
+ description: string;
34
+ default: string;
35
+ };
36
+ }>;
37
+ export default _default;
38
+ //# sourceMappingURL=import.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../../src/commands/figma/import.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,wBA0HG"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import('citty').CommandDef<import('citty').ArgsDef>;
2
+ export default _default;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/figma/index.ts"],"names":[],"mappings":";AAEA,wBAUG"}
@@ -0,0 +1,2 @@
1
+ export declare function initializeNuxtFrameworkFile(cwd: string): Promise<void>;
2
+ //# sourceMappingURL=nuxt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../../../src/commands/init/nuxt.ts"],"names":[],"mappings":"AASA,wBAAsB,2BAA2B,CAAC,GAAG,EAAE,MAAM,iBAqB5D"}
@@ -0,0 +1,2 @@
1
+ export declare function initializeViteFrameworkFile(cwd: string): Promise<void>;
2
+ //# sourceMappingURL=vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../../src/commands/init/vite.ts"],"names":[],"mappings":"AASA,wBAAsB,2BAA2B,CAAC,GAAG,EAAE,MAAM,iBAyB5D"}
@@ -0,0 +1,26 @@
1
+ interface TsConfigOptions {
2
+ /**
3
+ * Whether to add a `compilerOptions.paths` entry mapping `virtual:styleframe`
4
+ * to `styleframe.d.ts`. Required for type-checkers that cannot resolve a
5
+ * bare-specifier ambient `declare module` (e.g. `vue-tsc` inside `.vue` SFCs).
6
+ * When false, both virtual modules resolve from the ambient `shims.d.ts`
7
+ * (picked up via the includes) with zero extra config.
8
+ */
9
+ paths: boolean;
10
+ }
11
+ export declare function initializeConfigFile(cwd: string): Promise<void>;
12
+ export declare function initializeTsConfig(cwd: string, options: TsConfigOptions): Promise<void>;
13
+ export declare function addPackageJsonDependencies(cwd: string): Promise<void>;
14
+ export declare function initializeFrameworkFile(cwd: string): Promise<void>;
15
+ declare const _default: import('citty').CommandDef<{
16
+ cwd: {
17
+ type: "string";
18
+ required: false;
19
+ default: string;
20
+ description: string;
21
+ alias: string[];
22
+ valueHint: string;
23
+ };
24
+ }>;
25
+ export default _default;
26
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AA+BA,UAAU,eAAe;IACxB;;;;;;OAMG;IACH,KAAK,EAAE,OAAO,CAAC;CACf;AA+CD,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,MAAM,iBAWrD;AAuBD,wBAAsB,kBAAkB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,eAAe,iBAyCxB;AAED,wBAAsB,0BAA0B,CAAC,GAAG,EAAE,MAAM,iBAsB3D;AAED,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,MAAM,iBAWxD;;;;;;;;;;;AAED,wBA2BG"}
@@ -0,0 +1,8 @@
1
+ export declare const HOMEPAGE_URL = "https://styleframe.dev";
2
+ export declare const DOCS_URL = "https://styleframe.dev/docs";
3
+ export declare const DOCS_INSTALLATION_VITE_URL = "https://styleframe.dev/docs/getting-started/installation/vite";
4
+ export declare const DOCS_MANUAL_INSTALLATION_VITE_URL = "https://styleframe.dev/docs/getting-started/installation/manual/vite";
5
+ export declare const DOCS_INSTALLATION_NUXT_URL = "https://styleframe.dev/docs/getting-started/installation/nuxt";
6
+ export declare const DOCS_MANUAL_INSTALLATION_NUXT_URL = "https://styleframe.dev/docs/getting-started/installation/manual/nuxt";
7
+ export declare const DOCS_INSTALLATION_CUSTOM_URL = "https://styleframe.dev/docs/getting-started/installation/custom";
8
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,2BAA2B,CAAC;AACrD,eAAO,MAAM,QAAQ,gCAAyB,CAAC;AAC/C,eAAO,MAAM,0BAA0B,kEAAkD,CAAC;AAC1F,eAAO,MAAM,iCAAiC,yEAAyD,CAAC;AACxG,eAAO,MAAM,0BAA0B,kEAAkD,CAAC;AAC1F,eAAO,MAAM,iCAAiC,yEAAyD,CAAC;AACxG,eAAO,MAAM,4BAA4B,oEAAoD,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { defineCommand } from "citty";
2
+ //#region src/commands/dtcg/index.ts
3
+ var dtcg_default = defineCommand({
4
+ meta: {
5
+ name: "dtcg",
6
+ description: "Export Styleframe variables to and import them from DTCG format"
7
+ },
8
+ subCommands: {
9
+ export: () => import("./export-CBdPGGEq.js").then((m) => m.default),
10
+ import: () => import("./import-MqLYxb8d.js").then((m) => m.default)
11
+ }
12
+ });
13
+ //#endregion
14
+ export { dtcg_default as default };
@@ -0,0 +1,13 @@
1
+ //#region src/commands/dtcg/index.ts
2
+ var dtcg_default = (0, require("citty").defineCommand)({
3
+ meta: {
4
+ name: "dtcg",
5
+ description: "Export Styleframe variables to and import them from DTCG format"
6
+ },
7
+ subCommands: {
8
+ export: () => Promise.resolve().then(() => require("./export-DmPAU9Wh.cjs")).then((m) => m.default),
9
+ import: () => Promise.resolve().then(() => require("./import-ibQc_GXm.cjs")).then((m) => m.default)
10
+ }
11
+ });
12
+ //#endregion
13
+ exports.default = dtcg_default;
@@ -0,0 +1,66 @@
1
+ import { t as buildDTCG } from "./build-dtcg-BpbjBRCf.js";
2
+ import { defineCommand } from "citty";
3
+ import path from "node:path";
4
+ import { loadConfiguration } from "@styleframe/loader";
5
+ import consola from "consola";
6
+ import { mkdir, writeFile } from "node:fs/promises";
7
+ //#region src/commands/dtcg/export.ts
8
+ var export_default = defineCommand({
9
+ meta: {
10
+ name: "export",
11
+ description: "Export Styleframe variables to spec-conformant DTCG JSON"
12
+ },
13
+ args: {
14
+ config: {
15
+ type: "string",
16
+ description: "Path to the Styleframe config file",
17
+ default: "styleframe.config.ts",
18
+ alias: ["c"],
19
+ valueHint: "path"
20
+ },
21
+ output: {
22
+ type: "string",
23
+ description: "Output directory for DTCG files",
24
+ default: ".",
25
+ alias: ["o"],
26
+ valueHint: "path"
27
+ },
28
+ collection: {
29
+ type: "string",
30
+ description: "Collection name embedded in the export",
31
+ default: "Design Tokens",
32
+ alias: ["n", "name"]
33
+ }
34
+ },
35
+ async run({ args }) {
36
+ const configPath = path.resolve(args.config);
37
+ const outputDir = path.resolve(args.output);
38
+ consola.info(`Loading configuration from "${path.relative(process.cwd(), configPath)}"...`);
39
+ const root = (await loadConfiguration({ entry: configPath })).root;
40
+ consola.info("Building DTCG document...");
41
+ const { tokens, resolver, diagnostics, emittedCount, fluidNormalisedCount, maxViewport } = buildDTCG(root, {
42
+ collectionName: args.collection,
43
+ tokensSourceRef: "tokens.json"
44
+ });
45
+ await mkdir(outputDir, { recursive: true });
46
+ const tokensPath = path.join(outputDir, "tokens.json");
47
+ await writeFile(tokensPath, `${JSON.stringify(tokens, null, 2)}\n`);
48
+ consola.info(`Wrote ${emittedCount} tokens to "${path.relative(process.cwd(), tokensPath)}"`);
49
+ if (fluidNormalisedCount > 0) consola.info(`Normalised ${fluidNormalisedCount} fluid token(s) using max viewport (${maxViewport}px).`);
50
+ if (resolver) {
51
+ const resolverPath = path.join(outputDir, "tokens.resolver.json");
52
+ await writeFile(resolverPath, `${JSON.stringify(resolver, null, 2)}\n`);
53
+ consola.info(`Wrote resolver to "${path.relative(process.cwd(), resolverPath)}"`);
54
+ }
55
+ const warnings = diagnostics.filter((d) => d.level === "warn");
56
+ if (warnings.length > 0) {
57
+ consola.warn(`${warnings.length} variable(s) needed special handling — see Styleframe ↔ DTCG round-trip notes`);
58
+ for (const w of warnings.slice(0, 10)) consola.info(` - ${w.name}: ${w.reason}`);
59
+ if (warnings.length > 10) consola.info(` ... and ${warnings.length - 10} more`);
60
+ consola.info("Tip: untyped tokens are usually CSS keywords (e.g. \"normal\", \"thin\", \"italic\") with no DTCG equivalent — they round-trip to Figma as STRING variables.");
61
+ }
62
+ consola.success(`Exported ${emittedCount} tokens in DTCG format to "${path.relative(process.cwd(), outputDir)}"`);
63
+ }
64
+ });
65
+ //#endregion
66
+ export { export_default as default };
@@ -0,0 +1,69 @@
1
+ const require_chunk = require("./chunk-D6vf50IK.cjs");
2
+ const require_build_dtcg = require("./build-dtcg-vuGHy-Sl.cjs");
3
+ let citty = require("citty");
4
+ let node_path = require("node:path");
5
+ node_path = require_chunk.__toESM(node_path, 1);
6
+ let _styleframe_loader = require("@styleframe/loader");
7
+ let consola = require("consola");
8
+ consola = require_chunk.__toESM(consola, 1);
9
+ let node_fs_promises = require("node:fs/promises");
10
+ //#region src/commands/dtcg/export.ts
11
+ var export_default = (0, citty.defineCommand)({
12
+ meta: {
13
+ name: "export",
14
+ description: "Export Styleframe variables to spec-conformant DTCG JSON"
15
+ },
16
+ args: {
17
+ config: {
18
+ type: "string",
19
+ description: "Path to the Styleframe config file",
20
+ default: "styleframe.config.ts",
21
+ alias: ["c"],
22
+ valueHint: "path"
23
+ },
24
+ output: {
25
+ type: "string",
26
+ description: "Output directory for DTCG files",
27
+ default: ".",
28
+ alias: ["o"],
29
+ valueHint: "path"
30
+ },
31
+ collection: {
32
+ type: "string",
33
+ description: "Collection name embedded in the export",
34
+ default: "Design Tokens",
35
+ alias: ["n", "name"]
36
+ }
37
+ },
38
+ async run({ args }) {
39
+ const configPath = node_path.default.resolve(args.config);
40
+ const outputDir = node_path.default.resolve(args.output);
41
+ consola.default.info(`Loading configuration from "${node_path.default.relative(process.cwd(), configPath)}"...`);
42
+ const root = (await (0, _styleframe_loader.loadConfiguration)({ entry: configPath })).root;
43
+ consola.default.info("Building DTCG document...");
44
+ const { tokens, resolver, diagnostics, emittedCount, fluidNormalisedCount, maxViewport } = require_build_dtcg.buildDTCG(root, {
45
+ collectionName: args.collection,
46
+ tokensSourceRef: "tokens.json"
47
+ });
48
+ await (0, node_fs_promises.mkdir)(outputDir, { recursive: true });
49
+ const tokensPath = node_path.default.join(outputDir, "tokens.json");
50
+ await (0, node_fs_promises.writeFile)(tokensPath, `${JSON.stringify(tokens, null, 2)}\n`);
51
+ consola.default.info(`Wrote ${emittedCount} tokens to "${node_path.default.relative(process.cwd(), tokensPath)}"`);
52
+ if (fluidNormalisedCount > 0) consola.default.info(`Normalised ${fluidNormalisedCount} fluid token(s) using max viewport (${maxViewport}px).`);
53
+ if (resolver) {
54
+ const resolverPath = node_path.default.join(outputDir, "tokens.resolver.json");
55
+ await (0, node_fs_promises.writeFile)(resolverPath, `${JSON.stringify(resolver, null, 2)}\n`);
56
+ consola.default.info(`Wrote resolver to "${node_path.default.relative(process.cwd(), resolverPath)}"`);
57
+ }
58
+ const warnings = diagnostics.filter((d) => d.level === "warn");
59
+ if (warnings.length > 0) {
60
+ consola.default.warn(`${warnings.length} variable(s) needed special handling — see Styleframe ↔ DTCG round-trip notes`);
61
+ for (const w of warnings.slice(0, 10)) consola.default.info(` - ${w.name}: ${w.reason}`);
62
+ if (warnings.length > 10) consola.default.info(` ... and ${warnings.length - 10} more`);
63
+ consola.default.info("Tip: untyped tokens are usually CSS keywords (e.g. \"normal\", \"thin\", \"italic\") with no DTCG equivalent — they round-trip to Figma as STRING variables.");
64
+ }
65
+ consola.default.success(`Exported ${emittedCount} tokens in DTCG format to "${node_path.default.relative(process.cwd(), outputDir)}"`);
66
+ }
67
+ });
68
+ //#endregion
69
+ exports.default = export_default;
@@ -0,0 +1,86 @@
1
+ const require_chunk = require("./chunk-D6vf50IK.cjs");
2
+ const require_build_dtcg = require("./build-dtcg-vuGHy-Sl.cjs");
3
+ let citty = require("citty");
4
+ let node_path = require("node:path");
5
+ node_path = require_chunk.__toESM(node_path, 1);
6
+ let _styleframe_loader = require("@styleframe/loader");
7
+ let consola = require("consola");
8
+ consola = require_chunk.__toESM(consola, 1);
9
+ let node_fs_promises = require("node:fs/promises");
10
+ let _styleframe_figma = require("@styleframe/figma");
11
+ //#region src/commands/figma/export.ts
12
+ var export_default = (0, citty.defineCommand)({
13
+ meta: {
14
+ name: "export",
15
+ description: "Export Styleframe variables to Figma-compatible DTCG format (per-mode files)"
16
+ },
17
+ args: {
18
+ config: {
19
+ type: "string",
20
+ description: "Path to the Styleframe config file",
21
+ default: "styleframe.config.ts",
22
+ alias: ["c"],
23
+ valueHint: "path"
24
+ },
25
+ output: {
26
+ type: "string",
27
+ description: "Output directory for per-mode .tokens.json files",
28
+ default: ".",
29
+ alias: ["o"],
30
+ valueHint: "path"
31
+ },
32
+ collection: {
33
+ type: "string",
34
+ description: "Collection name embedded in the export",
35
+ default: "Design Tokens",
36
+ alias: ["n", "name"]
37
+ }
38
+ },
39
+ async run({ args }) {
40
+ const configPath = node_path.default.resolve(args.config);
41
+ const outputDir = node_path.default.resolve(args.output);
42
+ consola.default.info(`Loading configuration from "${node_path.default.relative(process.cwd(), configPath)}"...`);
43
+ const root = (await (0, _styleframe_loader.loadConfiguration)({ entry: configPath })).root;
44
+ consola.default.info("Building DTCG document...");
45
+ const { tokens, resolver, diagnostics: buildDiags, emittedCount, fluidNormalisedCount, maxViewport } = require_build_dtcg.buildDTCG(root, { collectionName: args.collection });
46
+ consola.default.info("Flattening to Figma-compatible format...");
47
+ const { modes, diagnostics: flattenDiags } = await (0, _styleframe_figma.flattenToFigmaDTCG)(tokens, resolver);
48
+ await (0, node_fs_promises.mkdir)(outputDir, { recursive: true });
49
+ for (const [modeName, modeDoc] of Object.entries(modes)) {
50
+ const filename = `${modeName}.tokens.json`;
51
+ const filePath = node_path.default.join(outputDir, filename);
52
+ await (0, node_fs_promises.writeFile)(filePath, `${JSON.stringify(modeDoc, null, 2)}\n`);
53
+ const tokenCount = countTokens(modeDoc);
54
+ consola.default.info(`Wrote "${node_path.default.relative(process.cwd(), filePath)}" (${tokenCount} tokens)`);
55
+ }
56
+ if (fluidNormalisedCount > 0) consola.default.info(`Normalised ${fluidNormalisedCount} fluid token(s) using max viewport (${maxViewport}px).`);
57
+ const allDiags = [...buildDiags.filter((d) => d.level === "warn"), ...flattenDiags];
58
+ if (allDiags.length > 0) {
59
+ consola.default.warn(`${allDiags.length} token(s) needed special handling`);
60
+ for (const d of allDiags.slice(0, 10)) {
61
+ const name = "name" in d ? d.name : d.path;
62
+ const reason = "reason" in d ? d.reason : "";
63
+ consola.default.info(` - ${name}: ${reason}`);
64
+ }
65
+ if (allDiags.length > 10) consola.default.info(` ... and ${allDiags.length - 10} more`);
66
+ }
67
+ consola.default.success(`Exported ${emittedCount} tokens as ${Object.keys(modes).length} Figma-compatible mode file(s) to "${node_path.default.relative(process.cwd(), outputDir)}"`);
68
+ }
69
+ });
70
+ function countTokens(doc) {
71
+ let count = 0;
72
+ for (const [key, value] of Object.entries(doc)) {
73
+ if (key === "$root") {
74
+ if (typeof value === "object" && value !== null && !Array.isArray(value) && "$value" in value) count++;
75
+ continue;
76
+ }
77
+ if (key.startsWith("$")) continue;
78
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
79
+ if ("$value" in value) count++;
80
+ count += countTokens(value);
81
+ }
82
+ }
83
+ return count;
84
+ }
85
+ //#endregion
86
+ exports.default = export_default;
@@ -0,0 +1,83 @@
1
+ import { t as buildDTCG } from "./build-dtcg-BpbjBRCf.js";
2
+ import { defineCommand } from "citty";
3
+ import path from "node:path";
4
+ import { loadConfiguration } from "@styleframe/loader";
5
+ import consola from "consola";
6
+ import { mkdir, writeFile } from "node:fs/promises";
7
+ import { flattenToFigmaDTCG } from "@styleframe/figma";
8
+ //#region src/commands/figma/export.ts
9
+ var export_default = defineCommand({
10
+ meta: {
11
+ name: "export",
12
+ description: "Export Styleframe variables to Figma-compatible DTCG format (per-mode files)"
13
+ },
14
+ args: {
15
+ config: {
16
+ type: "string",
17
+ description: "Path to the Styleframe config file",
18
+ default: "styleframe.config.ts",
19
+ alias: ["c"],
20
+ valueHint: "path"
21
+ },
22
+ output: {
23
+ type: "string",
24
+ description: "Output directory for per-mode .tokens.json files",
25
+ default: ".",
26
+ alias: ["o"],
27
+ valueHint: "path"
28
+ },
29
+ collection: {
30
+ type: "string",
31
+ description: "Collection name embedded in the export",
32
+ default: "Design Tokens",
33
+ alias: ["n", "name"]
34
+ }
35
+ },
36
+ async run({ args }) {
37
+ const configPath = path.resolve(args.config);
38
+ const outputDir = path.resolve(args.output);
39
+ consola.info(`Loading configuration from "${path.relative(process.cwd(), configPath)}"...`);
40
+ const root = (await loadConfiguration({ entry: configPath })).root;
41
+ consola.info("Building DTCG document...");
42
+ const { tokens, resolver, diagnostics: buildDiags, emittedCount, fluidNormalisedCount, maxViewport } = buildDTCG(root, { collectionName: args.collection });
43
+ consola.info("Flattening to Figma-compatible format...");
44
+ const { modes, diagnostics: flattenDiags } = await flattenToFigmaDTCG(tokens, resolver);
45
+ await mkdir(outputDir, { recursive: true });
46
+ for (const [modeName, modeDoc] of Object.entries(modes)) {
47
+ const filename = `${modeName}.tokens.json`;
48
+ const filePath = path.join(outputDir, filename);
49
+ await writeFile(filePath, `${JSON.stringify(modeDoc, null, 2)}\n`);
50
+ const tokenCount = countTokens(modeDoc);
51
+ consola.info(`Wrote "${path.relative(process.cwd(), filePath)}" (${tokenCount} tokens)`);
52
+ }
53
+ if (fluidNormalisedCount > 0) consola.info(`Normalised ${fluidNormalisedCount} fluid token(s) using max viewport (${maxViewport}px).`);
54
+ const allDiags = [...buildDiags.filter((d) => d.level === "warn"), ...flattenDiags];
55
+ if (allDiags.length > 0) {
56
+ consola.warn(`${allDiags.length} token(s) needed special handling`);
57
+ for (const d of allDiags.slice(0, 10)) {
58
+ const name = "name" in d ? d.name : d.path;
59
+ const reason = "reason" in d ? d.reason : "";
60
+ consola.info(` - ${name}: ${reason}`);
61
+ }
62
+ if (allDiags.length > 10) consola.info(` ... and ${allDiags.length - 10} more`);
63
+ }
64
+ consola.success(`Exported ${emittedCount} tokens as ${Object.keys(modes).length} Figma-compatible mode file(s) to "${path.relative(process.cwd(), outputDir)}"`);
65
+ }
66
+ });
67
+ function countTokens(doc) {
68
+ let count = 0;
69
+ for (const [key, value] of Object.entries(doc)) {
70
+ if (key === "$root") {
71
+ if (typeof value === "object" && value !== null && !Array.isArray(value) && "$value" in value) count++;
72
+ continue;
73
+ }
74
+ if (key.startsWith("$")) continue;
75
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
76
+ if ("$value" in value) count++;
77
+ count += countTokens(value);
78
+ }
79
+ }
80
+ return count;
81
+ }
82
+ //#endregion
83
+ export { export_default as default };
@@ -0,0 +1,13 @@
1
+ //#region src/commands/figma/index.ts
2
+ var figma_default = (0, require("citty").defineCommand)({
3
+ meta: {
4
+ name: "figma",
5
+ description: "Export and import Figma-compatible DTCG format (per-mode files)"
6
+ },
7
+ subCommands: {
8
+ export: () => Promise.resolve().then(() => require("./export-ONk9eKoZ.cjs")).then((m) => m.default),
9
+ import: () => Promise.resolve().then(() => require("./import-BQrcHNjK.cjs")).then((m) => m.default)
10
+ }
11
+ });
12
+ //#endregion
13
+ exports.default = figma_default;
@@ -0,0 +1,14 @@
1
+ import { defineCommand } from "citty";
2
+ //#region src/commands/figma/index.ts
3
+ var figma_default = defineCommand({
4
+ meta: {
5
+ name: "figma",
6
+ description: "Export and import Figma-compatible DTCG format (per-mode files)"
7
+ },
8
+ subCommands: {
9
+ export: () => import("./export-suUS16eO.js").then((m) => m.default),
10
+ import: () => import("./import-Bll_uBvJ.js").then((m) => m.default)
11
+ }
12
+ });
13
+ //#endregion
14
+ export { figma_default as default };
@@ -0,0 +1,126 @@
1
+ const require_chunk = require("./chunk-D6vf50IK.cjs");
2
+ let citty = require("citty");
3
+ let node_path = require("node:path");
4
+ node_path = require_chunk.__toESM(node_path, 1);
5
+ let consola = require("consola");
6
+ consola = require_chunk.__toESM(consola, 1);
7
+ let node_fs_promises = require("node:fs/promises");
8
+ let _styleframe_figma = require("@styleframe/figma");
9
+ //#region src/commands/figma/import.ts
10
+ var import_default = (0, citty.defineCommand)({
11
+ meta: {
12
+ name: "import",
13
+ description: "Generate Styleframe code from Figma-compatible DTCG per-mode files"
14
+ },
15
+ args: {
16
+ input: {
17
+ type: "string",
18
+ description: "Input .tokens.json file or directory of per-mode files",
19
+ required: true,
20
+ alias: ["i"],
21
+ valueHint: "path"
22
+ },
23
+ output: {
24
+ type: "string",
25
+ description: "Output Styleframe TypeScript file path",
26
+ default: "tokens.styleframe.ts",
27
+ alias: ["o"],
28
+ valueHint: "path"
29
+ },
30
+ composables: {
31
+ type: "boolean",
32
+ description: "Use @styleframe/theme composables (useColor, useSpacing, etc.)",
33
+ default: true
34
+ },
35
+ rem: {
36
+ type: "boolean",
37
+ description: "Use rem units for dimensions instead of px",
38
+ default: false
39
+ },
40
+ baseFontSize: {
41
+ type: "string",
42
+ description: "Base font size for rem conversion (in pixels)",
43
+ default: "16"
44
+ },
45
+ instanceName: {
46
+ type: "string",
47
+ description: "Name for the Styleframe instance variable",
48
+ default: "s"
49
+ }
50
+ },
51
+ async run({ args }) {
52
+ const inputPath = node_path.default.resolve(args.input);
53
+ const outputPath = node_path.default.resolve(args.output);
54
+ const baseFontSize = Number.parseInt(args.baseFontSize, 10) || 16;
55
+ consola.default.info(`Reading from "${node_path.default.relative(process.cwd(), inputPath)}"...`);
56
+ let data;
57
+ try {
58
+ if ((await (0, node_fs_promises.stat)(inputPath)).isDirectory()) {
59
+ const tokenFiles = (await (0, node_fs_promises.readdir)(inputPath)).filter((f) => f.endsWith(".tokens.json")).sort();
60
+ if (tokenFiles.length === 0) {
61
+ consola.default.error(`No .tokens.json files found in "${node_path.default.relative(process.cwd(), inputPath)}"`);
62
+ process.exit(1);
63
+ }
64
+ consola.default.info(`Found ${tokenFiles.length} mode file(s): ${tokenFiles.join(", ")}`);
65
+ const modeFormats = [];
66
+ for (const file of tokenFiles) {
67
+ const content = await (0, node_fs_promises.readFile)(node_path.default.join(inputPath, file), "utf-8");
68
+ const rawDoc = JSON.parse(content);
69
+ const modeData = (0, _styleframe_figma.fromDTCG)(rawDoc, { defaultModeName: extractModeName(rawDoc, file) });
70
+ modeFormats.push(modeData);
71
+ }
72
+ data = mergeModeFormats(modeFormats);
73
+ } else {
74
+ const content = await (0, node_fs_promises.readFile)(inputPath, "utf-8");
75
+ data = (0, _styleframe_figma.fromDTCG)(JSON.parse(content));
76
+ }
77
+ } catch (error) {
78
+ consola.default.error(`Failed to read or parse input: ${error instanceof Error ? error.message : error}`);
79
+ process.exit(1);
80
+ }
81
+ consola.default.info(`Generating Styleframe code for ${data.variables.length} variables...`);
82
+ const result = (0, _styleframe_figma.generateStyleframeCode)(data, {
83
+ useComposables: args.composables,
84
+ useRem: args.rem,
85
+ baseFontSize,
86
+ instanceName: args.instanceName
87
+ });
88
+ consola.default.info(`Writing to "${node_path.default.relative(process.cwd(), outputPath)}"...`);
89
+ await (0, node_fs_promises.writeFile)(outputPath, result.code);
90
+ consola.default.success("Generated Styleframe code with:");
91
+ consola.default.info(` - ${result.variables.length} variables`);
92
+ consola.default.info(` - ${result.themes.length} theme(s)`);
93
+ if (args.composables && result.imports.length > 1) consola.default.info(` - Using composables: ${result.imports.slice(1).join(", ")}`);
94
+ consola.default.info(`\nOutput: ${node_path.default.relative(process.cwd(), outputPath)}`);
95
+ }
96
+ });
97
+ function extractModeName(doc, filename) {
98
+ const ext = doc.$extensions;
99
+ if (ext && typeof ext["com.figma.modeName"] === "string") return ext["com.figma.modeName"];
100
+ const sfExt = ext?.["dev.styleframe"];
101
+ if (sfExt && typeof sfExt.modeName === "string") return sfExt.modeName;
102
+ return filename.replace(/\.tokens\.json$/, "");
103
+ }
104
+ function mergeModeFormats(formats) {
105
+ if (formats.length === 1) return formats[0];
106
+ const allModes = [];
107
+ const variableMap = /* @__PURE__ */ new Map();
108
+ for (const format of formats) {
109
+ for (const mode of format.modes) if (!allModes.includes(mode)) allModes.push(mode);
110
+ for (const v of format.variables) {
111
+ const existing = variableMap.get(v.name);
112
+ if (existing) Object.assign(existing.values, v.values);
113
+ else variableMap.set(v.name, {
114
+ ...v,
115
+ values: { ...v.values }
116
+ });
117
+ }
118
+ }
119
+ return {
120
+ collection: formats[0].collection,
121
+ modes: allModes,
122
+ variables: [...variableMap.values()]
123
+ };
124
+ }
125
+ //#endregion
126
+ exports.default = import_default;