@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,123 @@
1
+ import { defineCommand } from "citty";
2
+ import path from "node:path";
3
+ import consola from "consola";
4
+ import { readFile, readdir, stat, writeFile } from "node:fs/promises";
5
+ import { fromDTCG, generateStyleframeCode } from "@styleframe/figma";
6
+ //#region src/commands/figma/import.ts
7
+ var import_default = defineCommand({
8
+ meta: {
9
+ name: "import",
10
+ description: "Generate Styleframe code from Figma-compatible DTCG per-mode files"
11
+ },
12
+ args: {
13
+ input: {
14
+ type: "string",
15
+ description: "Input .tokens.json file or directory of per-mode files",
16
+ required: true,
17
+ alias: ["i"],
18
+ valueHint: "path"
19
+ },
20
+ output: {
21
+ type: "string",
22
+ description: "Output Styleframe TypeScript file path",
23
+ default: "tokens.styleframe.ts",
24
+ alias: ["o"],
25
+ valueHint: "path"
26
+ },
27
+ composables: {
28
+ type: "boolean",
29
+ description: "Use @styleframe/theme composables (useColor, useSpacing, etc.)",
30
+ default: true
31
+ },
32
+ rem: {
33
+ type: "boolean",
34
+ description: "Use rem units for dimensions instead of px",
35
+ default: false
36
+ },
37
+ baseFontSize: {
38
+ type: "string",
39
+ description: "Base font size for rem conversion (in pixels)",
40
+ default: "16"
41
+ },
42
+ instanceName: {
43
+ type: "string",
44
+ description: "Name for the Styleframe instance variable",
45
+ default: "s"
46
+ }
47
+ },
48
+ async run({ args }) {
49
+ const inputPath = path.resolve(args.input);
50
+ const outputPath = path.resolve(args.output);
51
+ const baseFontSize = Number.parseInt(args.baseFontSize, 10) || 16;
52
+ consola.info(`Reading from "${path.relative(process.cwd(), inputPath)}"...`);
53
+ let data;
54
+ try {
55
+ if ((await stat(inputPath)).isDirectory()) {
56
+ const tokenFiles = (await readdir(inputPath)).filter((f) => f.endsWith(".tokens.json")).sort();
57
+ if (tokenFiles.length === 0) {
58
+ consola.error(`No .tokens.json files found in "${path.relative(process.cwd(), inputPath)}"`);
59
+ process.exit(1);
60
+ }
61
+ consola.info(`Found ${tokenFiles.length} mode file(s): ${tokenFiles.join(", ")}`);
62
+ const modeFormats = [];
63
+ for (const file of tokenFiles) {
64
+ const content = await readFile(path.join(inputPath, file), "utf-8");
65
+ const rawDoc = JSON.parse(content);
66
+ const modeData = fromDTCG(rawDoc, { defaultModeName: extractModeName(rawDoc, file) });
67
+ modeFormats.push(modeData);
68
+ }
69
+ data = mergeModeFormats(modeFormats);
70
+ } else {
71
+ const content = await readFile(inputPath, "utf-8");
72
+ data = fromDTCG(JSON.parse(content));
73
+ }
74
+ } catch (error) {
75
+ consola.error(`Failed to read or parse input: ${error instanceof Error ? error.message : error}`);
76
+ process.exit(1);
77
+ }
78
+ consola.info(`Generating Styleframe code for ${data.variables.length} variables...`);
79
+ const result = generateStyleframeCode(data, {
80
+ useComposables: args.composables,
81
+ useRem: args.rem,
82
+ baseFontSize,
83
+ instanceName: args.instanceName
84
+ });
85
+ consola.info(`Writing to "${path.relative(process.cwd(), outputPath)}"...`);
86
+ await writeFile(outputPath, result.code);
87
+ consola.success("Generated Styleframe code with:");
88
+ consola.info(` - ${result.variables.length} variables`);
89
+ consola.info(` - ${result.themes.length} theme(s)`);
90
+ if (args.composables && result.imports.length > 1) consola.info(` - Using composables: ${result.imports.slice(1).join(", ")}`);
91
+ consola.info(`\nOutput: ${path.relative(process.cwd(), outputPath)}`);
92
+ }
93
+ });
94
+ function extractModeName(doc, filename) {
95
+ const ext = doc.$extensions;
96
+ if (ext && typeof ext["com.figma.modeName"] === "string") return ext["com.figma.modeName"];
97
+ const sfExt = ext?.["dev.styleframe"];
98
+ if (sfExt && typeof sfExt.modeName === "string") return sfExt.modeName;
99
+ return filename.replace(/\.tokens\.json$/, "");
100
+ }
101
+ function mergeModeFormats(formats) {
102
+ if (formats.length === 1) return formats[0];
103
+ const allModes = [];
104
+ const variableMap = /* @__PURE__ */ new Map();
105
+ for (const format of formats) {
106
+ for (const mode of format.modes) if (!allModes.includes(mode)) allModes.push(mode);
107
+ for (const v of format.variables) {
108
+ const existing = variableMap.get(v.name);
109
+ if (existing) Object.assign(existing.values, v.values);
110
+ else variableMap.set(v.name, {
111
+ ...v,
112
+ values: { ...v.values }
113
+ });
114
+ }
115
+ }
116
+ return {
117
+ collection: formats[0].collection,
118
+ modes: allModes,
119
+ variables: [...variableMap.values()]
120
+ };
121
+ }
122
+ //#endregion
123
+ export { import_default as default };
@@ -0,0 +1,114 @@
1
+ import { defineCommand } from "citty";
2
+ import path from "node:path";
3
+ import consola from "consola";
4
+ import { readFile, stat, writeFile } from "node:fs/promises";
5
+ import { fromDTCG, fromDTCGResolver, generateStyleframeCode } from "@styleframe/figma";
6
+ //#region src/commands/dtcg/import.ts
7
+ var import_default = defineCommand({
8
+ meta: {
9
+ name: "import",
10
+ description: "Generate Styleframe code from DTCG format JSON"
11
+ },
12
+ args: {
13
+ input: {
14
+ type: "string",
15
+ description: "Input DTCG JSON file or directory containing tokens.json",
16
+ required: true,
17
+ alias: ["i"],
18
+ valueHint: "path"
19
+ },
20
+ output: {
21
+ type: "string",
22
+ description: "Output Styleframe TypeScript file path",
23
+ default: "tokens.styleframe.ts",
24
+ alias: ["o"],
25
+ valueHint: "path"
26
+ },
27
+ composables: {
28
+ type: "boolean",
29
+ description: "Use @styleframe/theme composables (useColor, useSpacing, etc.)",
30
+ default: true
31
+ },
32
+ rem: {
33
+ type: "boolean",
34
+ description: "Use rem units for dimensions instead of px",
35
+ default: false
36
+ },
37
+ baseFontSize: {
38
+ type: "string",
39
+ description: "Base font size for rem conversion (in pixels)",
40
+ default: "16"
41
+ },
42
+ instanceName: {
43
+ type: "string",
44
+ description: "Name for the Styleframe instance variable",
45
+ default: "s"
46
+ }
47
+ },
48
+ async run({ args }) {
49
+ const inputPath = path.resolve(args.input);
50
+ const outputPath = path.resolve(args.output);
51
+ const baseFontSize = Number.parseInt(args.baseFontSize, 10) || 16;
52
+ consola.info(`Reading from "${path.relative(process.cwd(), inputPath)}"...`);
53
+ let data;
54
+ try {
55
+ if ((await stat(inputPath)).isDirectory()) data = await readFromDirectory(inputPath);
56
+ else data = await readFromFile(inputPath);
57
+ } catch (error) {
58
+ consola.error(`Failed to read or parse input: ${error instanceof Error ? error.message : error}`);
59
+ process.exit(1);
60
+ }
61
+ consola.info(`Generating Styleframe code for ${data.variables.length} variables...`);
62
+ const result = generateStyleframeCode(data, {
63
+ useComposables: args.composables,
64
+ useRem: args.rem,
65
+ baseFontSize,
66
+ instanceName: args.instanceName
67
+ });
68
+ consola.info(`Writing to "${path.relative(process.cwd(), outputPath)}"...`);
69
+ await writeFile(outputPath, result.code);
70
+ consola.success(`Generated Styleframe code with:`);
71
+ consola.info(` - ${result.variables.length} variables`);
72
+ consola.info(` - ${result.themes.length} theme(s)`);
73
+ if (args.composables && result.imports.length > 1) consola.info(` - Using composables: ${result.imports.slice(1).join(", ")}`);
74
+ consola.info(`\nOutput: ${path.relative(process.cwd(), outputPath)}`);
75
+ }
76
+ });
77
+ async function readFromDirectory(dirPath) {
78
+ const content = await readFile(path.join(dirPath, "tokens.json"), "utf-8");
79
+ const tokensDoc = JSON.parse(content);
80
+ const resolverPath = path.join(dirPath, "tokens.resolver.json");
81
+ const resolverDoc = await tryReadJson(resolverPath);
82
+ if (resolverDoc) {
83
+ consola.info(`Found resolver: "${path.relative(process.cwd(), resolverPath)}"`);
84
+ return fromDTCGResolver(resolverDoc, { fileLoader: async (ref) => {
85
+ if (ref === "tokens.json") return tokensDoc;
86
+ throw new Error(`Resolver references "${ref}" but only "tokens.json" was found`);
87
+ } });
88
+ }
89
+ return fromDTCG(tokensDoc);
90
+ }
91
+ async function readFromFile(filePath) {
92
+ const content = await readFile(filePath, "utf-8");
93
+ const tokensDoc = JSON.parse(content);
94
+ const resolverPath = filePath.replace(/\.json$/, ".resolver.json");
95
+ const resolverDoc = await tryReadJson(resolverPath);
96
+ if (resolverDoc) {
97
+ consola.info(`Auto-detected resolver: "${path.relative(process.cwd(), resolverPath)}"`);
98
+ return fromDTCGResolver(resolverDoc, { fileLoader: async (ref) => {
99
+ if (ref === path.basename(filePath)) return tokensDoc;
100
+ throw new Error(`Resolver references "${ref}" but only "${path.basename(filePath)}" was provided`);
101
+ } });
102
+ }
103
+ return fromDTCG(tokensDoc);
104
+ }
105
+ async function tryReadJson(filePath) {
106
+ try {
107
+ const content = await readFile(filePath, "utf-8");
108
+ return JSON.parse(content);
109
+ } catch {
110
+ return;
111
+ }
112
+ }
113
+ //#endregion
114
+ export { import_default as default };
@@ -0,0 +1,117 @@
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/dtcg/import.ts
10
+ var import_default = (0, citty.defineCommand)({
11
+ meta: {
12
+ name: "import",
13
+ description: "Generate Styleframe code from DTCG format JSON"
14
+ },
15
+ args: {
16
+ input: {
17
+ type: "string",
18
+ description: "Input DTCG JSON file or directory containing tokens.json",
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()) data = await readFromDirectory(inputPath);
59
+ else data = await readFromFile(inputPath);
60
+ } catch (error) {
61
+ consola.default.error(`Failed to read or parse input: ${error instanceof Error ? error.message : error}`);
62
+ process.exit(1);
63
+ }
64
+ consola.default.info(`Generating Styleframe code for ${data.variables.length} variables...`);
65
+ const result = (0, _styleframe_figma.generateStyleframeCode)(data, {
66
+ useComposables: args.composables,
67
+ useRem: args.rem,
68
+ baseFontSize,
69
+ instanceName: args.instanceName
70
+ });
71
+ consola.default.info(`Writing to "${node_path.default.relative(process.cwd(), outputPath)}"...`);
72
+ await (0, node_fs_promises.writeFile)(outputPath, result.code);
73
+ consola.default.success(`Generated Styleframe code with:`);
74
+ consola.default.info(` - ${result.variables.length} variables`);
75
+ consola.default.info(` - ${result.themes.length} theme(s)`);
76
+ if (args.composables && result.imports.length > 1) consola.default.info(` - Using composables: ${result.imports.slice(1).join(", ")}`);
77
+ consola.default.info(`\nOutput: ${node_path.default.relative(process.cwd(), outputPath)}`);
78
+ }
79
+ });
80
+ async function readFromDirectory(dirPath) {
81
+ const content = await (0, node_fs_promises.readFile)(node_path.default.join(dirPath, "tokens.json"), "utf-8");
82
+ const tokensDoc = JSON.parse(content);
83
+ const resolverPath = node_path.default.join(dirPath, "tokens.resolver.json");
84
+ const resolverDoc = await tryReadJson(resolverPath);
85
+ if (resolverDoc) {
86
+ consola.default.info(`Found resolver: "${node_path.default.relative(process.cwd(), resolverPath)}"`);
87
+ return (0, _styleframe_figma.fromDTCGResolver)(resolverDoc, { fileLoader: async (ref) => {
88
+ if (ref === "tokens.json") return tokensDoc;
89
+ throw new Error(`Resolver references "${ref}" but only "tokens.json" was found`);
90
+ } });
91
+ }
92
+ return (0, _styleframe_figma.fromDTCG)(tokensDoc);
93
+ }
94
+ async function readFromFile(filePath) {
95
+ const content = await (0, node_fs_promises.readFile)(filePath, "utf-8");
96
+ const tokensDoc = JSON.parse(content);
97
+ const resolverPath = filePath.replace(/\.json$/, ".resolver.json");
98
+ const resolverDoc = await tryReadJson(resolverPath);
99
+ if (resolverDoc) {
100
+ consola.default.info(`Auto-detected resolver: "${node_path.default.relative(process.cwd(), resolverPath)}"`);
101
+ return (0, _styleframe_figma.fromDTCGResolver)(resolverDoc, { fileLoader: async (ref) => {
102
+ if (ref === node_path.default.basename(filePath)) return tokensDoc;
103
+ throw new Error(`Resolver references "${ref}" but only "${node_path.default.basename(filePath)}" was provided`);
104
+ } });
105
+ }
106
+ return (0, _styleframe_figma.fromDTCG)(tokensDoc);
107
+ }
108
+ async function tryReadJson(filePath) {
109
+ try {
110
+ const content = await (0, node_fs_promises.readFile)(filePath, "utf-8");
111
+ return JSON.parse(content);
112
+ } catch {
113
+ return;
114
+ }
115
+ }
116
+ //#endregion
117
+ exports.default = import_default;