@interactivethings/scripts 0.0.9 → 2.0.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 (49) hide show
  1. package/README.md +210 -12
  2. package/codemods/__testfixtures__/sx-to-use-styles.input.js +50 -0
  3. package/codemods/__testfixtures__/sx-to-use-styles.output.js +59 -0
  4. package/codemods/__tests__/defineTest.ts +9 -0
  5. package/codemods/__tests__/sx-to-use-styles.test.js +3 -0
  6. package/codemods/sx-to-use-styles.js +162 -0
  7. package/dist/__tests__/figma-cli.test.js +189 -0
  8. package/dist/__tests__/tokens-studio-cli.test.js +197 -0
  9. package/dist/__tests__/vercel-cli.test.js +86 -0
  10. package/dist/cli.d.ts +2 -0
  11. package/dist/cli.js +94 -0
  12. package/dist/config.d.ts +78 -0
  13. package/dist/config.js +157 -0
  14. package/dist/figma/api.d.ts +71 -0
  15. package/dist/figma/api.js +175 -0
  16. package/dist/figma/cli.d.ts +20 -0
  17. package/dist/figma/cli.js +153 -0
  18. package/dist/figma/cli.test.js +187 -0
  19. package/dist/figma/images.js +53 -0
  20. package/dist/figma/optimizeImage.js +53 -0
  21. package/dist/figma/utils.d.ts +10 -0
  22. package/dist/figma/utils.js +26 -0
  23. package/dist/index.d.ts +8 -0
  24. package/dist/index.js +43 -0
  25. package/dist/init/cli.d.ts +3 -0
  26. package/dist/init/cli.js +312 -0
  27. package/dist/mui-tokens-studio.js +0 -0
  28. package/dist/plugins/figma/index.js +653 -0
  29. package/dist/plugins/tokens-studio/utils.js +155 -0
  30. package/dist/tokens-studio/__tests__/fixtures/invalid-transformer.js +12 -0
  31. package/dist/tokens-studio/__tests__/fixtures/test-transformer.js +18 -0
  32. package/dist/tokens-studio/cli.d.ts +8 -0
  33. package/dist/tokens-studio/cli.js +119 -0
  34. package/dist/tokens-studio/cli.test.js +150 -0
  35. package/dist/tokens-studio/index.d.ts +14 -0
  36. package/dist/tokens-studio/index.js +46 -0
  37. package/dist/tokens-studio/mui.js +212 -0
  38. package/dist/tokens-studio/require.js +17 -0
  39. package/dist/tokens-studio/tailwind.js +211 -0
  40. package/dist/tokens-studio/types.js +2 -0
  41. package/dist/tokens-studio/utils.d.ts +49 -0
  42. package/dist/tokens-studio/utils.js +156 -0
  43. package/dist/types.d.ts +1 -0
  44. package/dist/vercel/cli.d.ts +4 -0
  45. package/dist/vercel/cli.js +70 -0
  46. package/dist/vercel/cli.test.js +86 -0
  47. package/dist/vercel/deployments.js +42 -0
  48. package/dist/vercel/waitForDeploymentReady.js +43 -0
  49. package/package.json +46 -6
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const vitest_1 = require("vitest");
30
+ const argparse_1 = require("argparse");
31
+ const cli_1 = require("./cli");
32
+ const fs = __importStar(require("fs/promises"));
33
+ const path_1 = __importDefault(require("path"));
34
+ // Mock the API and other dependencies
35
+ vitest_1.vi.mock("../figma/api", () => ({
36
+ createAPI: vitest_1.vi.fn(),
37
+ }));
38
+ vitest_1.vi.mock("@interactivethings/scripts/figma/images", () => ({
39
+ optimizeImage: vitest_1.vi.fn(),
40
+ }));
41
+ vitest_1.vi.mock("../config", () => ({
42
+ loadConfig: vitest_1.vi.fn(),
43
+ mergeConfigWithArgs: vitest_1.vi.fn(),
44
+ validateRequiredConfig: vitest_1.vi.fn(),
45
+ }));
46
+ vitest_1.vi.mock("fs/promises");
47
+ vitest_1.vi.mock("ora", () => ({
48
+ default: vitest_1.vi.fn(() => ({
49
+ start: vitest_1.vi.fn().mockReturnThis(),
50
+ stop: vitest_1.vi.fn().mockReturnThis(),
51
+ text: "",
52
+ render: vitest_1.vi.fn(),
53
+ })),
54
+ }));
55
+ const api_1 = require("./api");
56
+ const images_1 = require("@interactivethings/scripts/figma/images");
57
+ const config_1 = require("../config");
58
+ (0, vitest_1.describe)("Figma CLI", () => {
59
+ const mockAPI = {
60
+ images: {
61
+ fetch: vitest_1.vi.fn(),
62
+ },
63
+ nodes: {
64
+ fetch: vitest_1.vi.fn(),
65
+ },
66
+ };
67
+ (0, vitest_1.beforeEach)(() => {
68
+ vitest_1.vi.clearAllMocks();
69
+ vitest_1.vi.mocked(api_1.createAPI).mockReturnValue(mockAPI);
70
+ vitest_1.vi.mocked(config_1.loadConfig).mockResolvedValue({});
71
+ vitest_1.vi.mocked(config_1.mergeConfigWithArgs).mockReturnValue({
72
+ token: "test-token",
73
+ assets: [
74
+ {
75
+ name: "test-assets",
76
+ url: "https://www.figma.com/design/test-file-id/Test?node-id=123-456",
77
+ output: "test-output",
78
+ },
79
+ ],
80
+ });
81
+ vitest_1.vi.mocked(config_1.validateRequiredConfig).mockImplementation(() => { });
82
+ });
83
+ (0, vitest_1.describe)("configParser", () => {
84
+ (0, vitest_1.it)("should configure the argument parser correctly", () => {
85
+ const parser = new argparse_1.ArgumentParser();
86
+ const addSubparsersSpy = vitest_1.vi.spyOn(parser, "add_subparsers");
87
+ (0, cli_1.configParser)(parser);
88
+ (0, vitest_1.expect)(addSubparsersSpy).toHaveBeenCalledWith({
89
+ title: "commands",
90
+ dest: "subcommand",
91
+ });
92
+ });
93
+ });
94
+ (0, vitest_1.describe)("run", () => {
95
+ (0, vitest_1.beforeEach)(() => {
96
+ vitest_1.vi.spyOn(console, "log").mockImplementation(() => { });
97
+ });
98
+ (0, vitest_1.afterEach)(() => {
99
+ vitest_1.vi.mocked(console.log).mockRestore();
100
+ });
101
+ (0, vitest_1.describe)("download subcommand", () => {
102
+ (0, vitest_1.it)("should successfully download assets", async () => {
103
+ const mockImages = [
104
+ {
105
+ name: "test-image",
106
+ format: "png",
107
+ data: Buffer.from("test-data"),
108
+ },
109
+ ];
110
+ mockAPI.images.fetch.mockResolvedValue(mockImages);
111
+ vitest_1.vi.mocked(fs.mkdir).mockResolvedValue(undefined);
112
+ vitest_1.vi.mocked(fs.writeFile).mockResolvedValue(undefined);
113
+ vitest_1.vi.mocked(images_1.optimizeImage).mockResolvedValue(undefined);
114
+ const args = {
115
+ subcommand: "download",
116
+ name: "test-assets",
117
+ config: undefined,
118
+ token: undefined,
119
+ };
120
+ await (0, cli_1.run)(args);
121
+ (0, vitest_1.expect)(config_1.loadConfig).toHaveBeenCalledWith(undefined);
122
+ (0, vitest_1.expect)(api_1.createAPI).toHaveBeenCalledWith("test-token");
123
+ (0, vitest_1.expect)(mockAPI.images.fetch).toHaveBeenCalled();
124
+ (0, vitest_1.expect)(fs.mkdir).toHaveBeenCalledWith(path_1.default.dirname("test-output/test-image.png"), { recursive: true });
125
+ (0, vitest_1.expect)(fs.writeFile).toHaveBeenCalledWith("test-output/test-image.png", Buffer.from("test-data"));
126
+ (0, vitest_1.expect)(images_1.optimizeImage).toHaveBeenCalledWith("test-output/test-image.png");
127
+ });
128
+ (0, vitest_1.it)("should throw error when no assets are configured", async () => {
129
+ vitest_1.vi.mocked(config_1.mergeConfigWithArgs).mockReturnValue({
130
+ token: "test-token",
131
+ assets: [],
132
+ });
133
+ const args = {
134
+ subcommand: "download",
135
+ name: "test-assets",
136
+ config: undefined,
137
+ token: undefined,
138
+ };
139
+ await (0, vitest_1.expect)((0, cli_1.run)(args)).rejects.toThrow("No figma assets configured");
140
+ });
141
+ (0, vitest_1.it)("should throw error when asset is not found", async () => {
142
+ vitest_1.vi.mocked(config_1.mergeConfigWithArgs).mockReturnValue({
143
+ token: "test-token",
144
+ assets: [
145
+ {
146
+ name: "other-assets",
147
+ url: "https://www.figma.com/design/test-file-id/Test?node-id=123-456",
148
+ output: "./test-output",
149
+ },
150
+ ],
151
+ });
152
+ const args = {
153
+ subcommand: "download",
154
+ name: "test-assets",
155
+ config: undefined,
156
+ token: undefined,
157
+ };
158
+ await (0, vitest_1.expect)((0, cli_1.run)(args)).rejects.toThrow('No asset configuration found for name "test-assets"');
159
+ });
160
+ });
161
+ (0, vitest_1.describe)("get subcommand", () => {
162
+ (0, vitest_1.it)("should successfully get node data", async () => {
163
+ const mockNodeData = { nodes: { "test-node": { id: "test-node" } } };
164
+ mockAPI.nodes.fetch.mockResolvedValue(mockNodeData);
165
+ const args = {
166
+ subcommand: "get",
167
+ url: "https://www.figma.com/design/test-file-id/Test?node-id=123-456",
168
+ config: undefined,
169
+ token: undefined,
170
+ };
171
+ await (0, cli_1.run)(args);
172
+ (0, vitest_1.expect)(mockAPI.nodes.fetch).toHaveBeenCalled();
173
+ (0, vitest_1.expect)(vitest_1.vi.mocked(console.log)).toHaveBeenCalledWith(JSON.stringify(mockNodeData, null, 2));
174
+ });
175
+ });
176
+ (0, vitest_1.it)("should validate required configuration", async () => {
177
+ const args = {
178
+ subcommand: "download",
179
+ name: "test-assets",
180
+ config: undefined,
181
+ token: undefined,
182
+ };
183
+ await (0, cli_1.run)(args);
184
+ (0, vitest_1.expect)(config_1.validateRequiredConfig).toHaveBeenCalledWith(vitest_1.expect.objectContaining({ token: "test-token" }), ["token"]);
185
+ });
186
+ });
187
+ });
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.optimizeImage = void 0;
27
+ const child_process_1 = require("child_process");
28
+ const path = __importStar(require("path"));
29
+ const optimizeImage = async (filepath) => {
30
+ try {
31
+ const extension = path.extname(filepath).toLowerCase();
32
+ const binaryForExtensions = new Map([
33
+ [".png", "optipng"],
34
+ [".jpg", "jpegoptim"],
35
+ ]);
36
+ const binaryName = binaryForExtensions.get(extension);
37
+ if (!binaryName) {
38
+ // console.log(`No optimizer found for ${extension}, skipping optimization`);
39
+ return;
40
+ }
41
+ const binaryPath = (0, child_process_1.execSync)(`which ${binaryName}`).toString().trim();
42
+ if (!binaryPath) {
43
+ throw new Error(`Cannot find ${binaryName} in PATH. Please install it.`);
44
+ }
45
+ console.log(`Optimizing with ${filepath} with ${binaryName}`);
46
+ await (0, child_process_1.execSync)(`${binaryPath} "${filepath}"`);
47
+ console.log(`Image optimized successfully: ${filepath}`);
48
+ }
49
+ catch (error) {
50
+ console.error(`Error optimizing image ${filepath}: ${error instanceof Error ? error.message : error}`);
51
+ }
52
+ };
53
+ exports.optimizeImage = optimizeImage;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.optimizeImage = void 0;
27
+ const child_process_1 = require("child_process");
28
+ const path = __importStar(require("path"));
29
+ const optimizeImage = async (filepath) => {
30
+ try {
31
+ const extension = path.extname(filepath).toLowerCase();
32
+ const binaryForExtensions = new Map([
33
+ [".png", "optipng"],
34
+ [".jpg", "jpegoptim"],
35
+ ]);
36
+ const binaryName = binaryForExtensions.get(extension);
37
+ if (!binaryName) {
38
+ // console.log(`No optimizer found for ${extension}, skipping optimization`);
39
+ return;
40
+ }
41
+ const binaryPath = (0, child_process_1.execSync)(`which ${binaryName}`).toString().trim();
42
+ if (!binaryPath) {
43
+ throw new Error(`Cannot find ${binaryName} in PATH. Please install it.`);
44
+ }
45
+ console.log(`Optimizing with ${filepath} with ${binaryName}`);
46
+ await (0, child_process_1.execSync)(`${binaryPath} "${filepath}"`);
47
+ console.log(`Image optimized successfully: ${filepath}`);
48
+ }
49
+ catch (error) {
50
+ console.error(`Error optimizing image ${filepath}: ${error instanceof Error ? error.message : error}`);
51
+ }
52
+ };
53
+ exports.optimizeImage = optimizeImage;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Should parse a URL in the form https://www.figma.com/design/ElWWZIcOGFhiT06rzfIwRO/Design-System-%5BTPW-Mobile-App%5D?node-id=10404-19140&p=f&t=K5K37NzOSt1uwjsX-0
3
+ * and extracts the pageId and nodeId
4
+ * The page id is the part just after /design
5
+ */
6
+ export declare const parseFigmaURL: (urlString: string) => {
7
+ figmaFileId: string;
8
+ figmaPageId: string;
9
+ };
10
+ export declare const formatFigmaURL: (figmaFileId: string, figmaPageId: string) => string;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatFigmaURL = exports.parseFigmaURL = void 0;
4
+ /**
5
+ * Should parse a URL in the form https://www.figma.com/design/ElWWZIcOGFhiT06rzfIwRO/Design-System-%5BTPW-Mobile-App%5D?node-id=10404-19140&p=f&t=K5K37NzOSt1uwjsX-0
6
+ * and extracts the pageId and nodeId
7
+ * The page id is the part just after /design
8
+ */
9
+ const parseFigmaURL = (urlString) => {
10
+ var _a;
11
+ const url = new URL(urlString);
12
+ const figmaFileId = url.pathname.split("/")[2];
13
+ const figmaPageId = (_a = url.searchParams.get("node-id")) !== null && _a !== void 0 ? _a : "";
14
+ if (!figmaFileId || !figmaPageId) {
15
+ throw new Error(`Invalid Figma URL: ${urlString}`);
16
+ }
17
+ return {
18
+ figmaFileId,
19
+ figmaPageId,
20
+ };
21
+ };
22
+ exports.parseFigmaURL = parseFigmaURL;
23
+ const formatFigmaURL = (figmaFileId, figmaPageId) => {
24
+ return `https://www.figma.com/file/${figmaFileId}/?node-id=${figmaPageId}&mode=design`;
25
+ };
26
+ exports.formatFigmaURL = formatFigmaURL;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @interactivethings/scripts
3
+ *
4
+ * A collection of useful development tools by Interactive Things
5
+ */
6
+ export * from "./types";
7
+ export { defineConfig, type IxtConfig, type FigmaConfig, type TokensStudioConfig, } from "./config";
8
+ export * as tokensStudio from "./tokens-studio";
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /**
3
+ * @interactivethings/scripts
4
+ *
5
+ * A collection of useful development tools by Interactive Things
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
24
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
25
+ };
26
+ var __importStar = (this && this.__importStar) || function (mod) {
27
+ if (mod && mod.__esModule) return mod;
28
+ var result = {};
29
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
30
+ __setModuleDefault(result, mod);
31
+ return result;
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.tokensStudio = exports.defineConfig = void 0;
35
+ // Export commonly used types
36
+ __exportStar(require("./types"), exports);
37
+ // Export configuration system
38
+ var config_1 = require("./config");
39
+ Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return config_1.defineConfig; } });
40
+ // Export tokens-studio utilities (for programmatic usage)
41
+ exports.tokensStudio = __importStar(require("./tokens-studio"));
42
+ // Note: CLI functionality is available via the 'ixt' binary
43
+ // Individual modules can be imported via subpaths like '@interactivethings/scripts/tokens-studio'
@@ -0,0 +1,3 @@
1
+ import { ArgumentParser } from "argparse";
2
+ export declare function configParser(parser: ArgumentParser): void;
3
+ export declare function run(mainParser: ArgumentParser): Promise<void>;