@interactivethings/scripts 2.0.2 → 2.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.
- package/dist/cli.js +21 -12
- package/dist/cloudflare/cli.js +90 -0
- package/dist/cloudflare/cloudflare.js +44 -0
- package/dist/cloudflare/deployments.js +14 -0
- package/dist/config.js +12 -6
- package/dist/figma/cli.js +7 -5
- package/dist/figma/cli.test.js +8 -7
- package/dist/init/cli.js +9 -6
- package/dist/shared/cli.js +13 -0
- package/dist/shared/deployment-service.js +2 -0
- package/dist/shared/wait-deployment.js +29 -0
- package/dist/tokens-studio/cli.js +5 -3
- package/dist/tokens-studio/cli.test.js +8 -4
- package/dist/vercel/cli.js +7 -5
- package/dist/vercel/cli.test.js +9 -5
- package/dist/vercel/deployments.js +9 -36
- package/dist/vercel/vercel.js +31 -0
- package/package.json +5 -7
- package/dist/__tests__/figma-cli.test.js +0 -189
- package/dist/__tests__/tokens-studio-cli.test.js +0 -197
- package/dist/__tests__/vercel-cli.test.js +0 -86
- package/dist/cli.d.ts +0 -2
- package/dist/config.d.ts +0 -78
- package/dist/figma/api.d.ts +0 -71
- package/dist/figma/cli.d.ts +0 -20
- package/dist/figma/optimizeImage.js +0 -53
- package/dist/figma/utils.d.ts +0 -10
- package/dist/index.d.ts +0 -8
- package/dist/init/cli.d.ts +0 -3
- package/dist/mui-tokens-studio.js +0 -177
- package/dist/plugins/figma/index.js +0 -653
- package/dist/plugins/tokens-studio/utils.js +0 -155
- package/dist/tokens-studio/cli.d.ts +0 -8
- package/dist/tokens-studio/index.d.ts +0 -14
- package/dist/tokens-studio/mui.js +0 -212
- package/dist/tokens-studio/tailwind.js +0 -211
- package/dist/tokens-studio/utils.d.ts +0 -49
- package/dist/types.d.ts +0 -1
- package/dist/vercel/cli.d.ts +0 -4
- package/dist/vercel/waitForDeploymentReady.js +0 -43
- package/dist/wait-for-vercel-deploy.js +0 -79
|
@@ -1,41 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.waitForDeploymentReady = waitForDeploymentReady;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const response = await fetch(`https://vercel.com/api/v6/deployments?limit=20&projectId=${projectId}&state=READY,ERROR,BUILDING,QUEUED&teamId=${teamId}`, {
|
|
7
|
-
headers: {
|
|
8
|
-
Authorization: `Bearer ${accessToken}`,
|
|
9
|
-
},
|
|
10
|
-
}).then((x) => x.json());
|
|
11
|
-
const deployments = response.deployments.filter((deployment) => deployment.meta.githubCommitSha === commitSha);
|
|
12
|
-
return deployments;
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
console.error("Error:", error);
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const sleep = (duration) => new Promise((resolve) => setTimeout(resolve, duration));
|
|
4
|
+
const wait_deployment_1 = require("../shared/wait-deployment");
|
|
5
|
+
const vercel_1 = require("./vercel");
|
|
20
6
|
async function waitForDeploymentReady({ team, project, commitSha, interval, timeout, accessToken, }) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
throw new Error("Deployment errored");
|
|
29
|
-
}
|
|
30
|
-
console.log(`Deployment not yet ready (state: ${deployments[0].state}), waiting ${interval}ms for deployment with commit ${commitSha}`);
|
|
31
|
-
await sleep(Math.min(end - Date.now(), interval));
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
console.log(`Deployment for commit ${commitSha} is READY`);
|
|
35
|
-
return deployments[0];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (Date.now() > end) {
|
|
39
|
-
throw new Error("Timeout for waitForDeploymentReady");
|
|
40
|
-
}
|
|
7
|
+
const service = new vercel_1.VercelDeploymentService(team, project, accessToken);
|
|
8
|
+
return await (0, wait_deployment_1.waitForDeploymentReady)({
|
|
9
|
+
commitSha,
|
|
10
|
+
interval,
|
|
11
|
+
timeout,
|
|
12
|
+
deploymentService: service,
|
|
13
|
+
});
|
|
41
14
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VercelDeploymentService = void 0;
|
|
4
|
+
const getDeploymentState = (deployment) => {
|
|
5
|
+
return deployment.state;
|
|
6
|
+
};
|
|
7
|
+
const getDeploymentUrl = (deployment) => {
|
|
8
|
+
return `https://${deployment.url}`;
|
|
9
|
+
};
|
|
10
|
+
class VercelDeploymentService {
|
|
11
|
+
constructor(teamId, projectId, accessToken) {
|
|
12
|
+
this.teamId = teamId;
|
|
13
|
+
this.projectId = projectId;
|
|
14
|
+
this.accessToken = accessToken;
|
|
15
|
+
}
|
|
16
|
+
async fetchForCommit(commitSha) {
|
|
17
|
+
const response = await fetch(`https://vercel.com/api/v6/deployments?limit=20&projectId=${this.projectId}&state=READY,ERROR,BUILDING,QUEUED&teamId=${this.teamId}`, {
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
.then((x) => x.json())
|
|
23
|
+
.then((x) => x);
|
|
24
|
+
const deployments = response.deployments.filter((deployment) => deployment.meta.githubCommitSha === commitSha);
|
|
25
|
+
return deployments.map((d) => ({
|
|
26
|
+
state: getDeploymentState(d),
|
|
27
|
+
url: getDeploymentUrl(d),
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.VercelDeploymentService = VercelDeploymentService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interactivethings/scripts",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -28,9 +28,7 @@
|
|
|
28
28
|
"start": "bun ./dist/cli.js"
|
|
29
29
|
},
|
|
30
30
|
"bin": {
|
|
31
|
-
"ixt": "dist/cli.js"
|
|
32
|
-
"wait-for-vercel-deploy": "dist/wait-for-vercel-deploy.js",
|
|
33
|
-
"mui-tokens-studio": "dist/mui-tokens-studio.js"
|
|
31
|
+
"ixt": "dist/cli.js"
|
|
34
32
|
},
|
|
35
33
|
"files": [
|
|
36
34
|
"dist",
|
|
@@ -42,13 +40,13 @@
|
|
|
42
40
|
"@semantic-release/changelog": "^6.0.3",
|
|
43
41
|
"@semantic-release/git": "^10.0.1",
|
|
44
42
|
"@semantic-release/github": "^11.0.6",
|
|
45
|
-
"@types/argparse": "^2.0.
|
|
43
|
+
"@types/argparse": "^2.0.17",
|
|
46
44
|
"@types/jscodeshift": "^0.11.10",
|
|
47
45
|
"argparse": "^2.0.1",
|
|
48
46
|
"jiti": "^2.6.1",
|
|
49
47
|
"ora": "^9.0.0",
|
|
50
48
|
"prompts": "^2.4.2",
|
|
51
|
-
"remeda": "^
|
|
49
|
+
"remeda": "^2.32.0",
|
|
52
50
|
"zod": "^4.1.11"
|
|
53
51
|
},
|
|
54
52
|
"devDependencies": {
|
|
@@ -57,7 +55,7 @@
|
|
|
57
55
|
"jscodeshift": "^0.15.1",
|
|
58
56
|
"oxlint": "^1.19.0",
|
|
59
57
|
"typescript": "^5.9.3",
|
|
60
|
-
"vitest": "^
|
|
58
|
+
"vitest": "^3.2.4"
|
|
61
59
|
},
|
|
62
60
|
"peerDependencies": {
|
|
63
61
|
"@next/env": "^15.5.4"
|
|
@@ -1,189 +0,0 @@
|
|
|
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("../figma/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("../figma/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.describe)("download subcommand", () => {
|
|
96
|
-
(0, vitest_1.it)("should successfully download assets", async () => {
|
|
97
|
-
const mockImages = [
|
|
98
|
-
{
|
|
99
|
-
name: "test-image",
|
|
100
|
-
format: "png",
|
|
101
|
-
data: Buffer.from("test-data"),
|
|
102
|
-
},
|
|
103
|
-
];
|
|
104
|
-
mockAPI.images.fetch.mockResolvedValue(mockImages);
|
|
105
|
-
vitest_1.vi.mocked(fs.mkdir).mockResolvedValue(undefined);
|
|
106
|
-
vitest_1.vi.mocked(fs.writeFile).mockResolvedValue(undefined);
|
|
107
|
-
vitest_1.vi.mocked(images_1.optimizeImage).mockResolvedValue(undefined);
|
|
108
|
-
const consoleSpy = vitest_1.vi
|
|
109
|
-
.spyOn(console, "log")
|
|
110
|
-
.mockImplementation(() => { });
|
|
111
|
-
const args = {
|
|
112
|
-
subcommand: "download",
|
|
113
|
-
name: "test-assets",
|
|
114
|
-
config: undefined,
|
|
115
|
-
token: undefined,
|
|
116
|
-
};
|
|
117
|
-
await (0, cli_1.run)(args);
|
|
118
|
-
(0, vitest_1.expect)(config_1.loadConfig).toHaveBeenCalledWith(undefined);
|
|
119
|
-
(0, vitest_1.expect)(api_1.createAPI).toHaveBeenCalledWith("test-token");
|
|
120
|
-
(0, vitest_1.expect)(mockAPI.images.fetch).toHaveBeenCalled();
|
|
121
|
-
(0, vitest_1.expect)(fs.mkdir).toHaveBeenCalledWith(path_1.default.dirname("./test-output/test-image.png"), { recursive: true });
|
|
122
|
-
(0, vitest_1.expect)(fs.writeFile).toHaveBeenCalledWith("./test-output/test-image.png", Buffer.from("test-data"));
|
|
123
|
-
(0, vitest_1.expect)(images_1.optimizeImage).toHaveBeenCalledWith("./test-output/test-image.png");
|
|
124
|
-
consoleSpy.mockRestore();
|
|
125
|
-
});
|
|
126
|
-
(0, vitest_1.it)("should throw error when no assets are configured", async () => {
|
|
127
|
-
vitest_1.vi.mocked(config_1.mergeConfigWithArgs).mockReturnValue({
|
|
128
|
-
token: "test-token",
|
|
129
|
-
assets: [],
|
|
130
|
-
});
|
|
131
|
-
const args = {
|
|
132
|
-
subcommand: "download",
|
|
133
|
-
name: "test-assets",
|
|
134
|
-
config: undefined,
|
|
135
|
-
token: undefined,
|
|
136
|
-
};
|
|
137
|
-
await (0, vitest_1.expect)((0, cli_1.run)(args)).rejects.toThrow("No figma assets configured");
|
|
138
|
-
});
|
|
139
|
-
(0, vitest_1.it)("should throw error when asset is not found", async () => {
|
|
140
|
-
vitest_1.vi.mocked(config_1.mergeConfigWithArgs).mockReturnValue({
|
|
141
|
-
token: "test-token",
|
|
142
|
-
assets: [
|
|
143
|
-
{
|
|
144
|
-
name: "other-assets",
|
|
145
|
-
url: "https://www.figma.com/design/test-file-id/Test?node-id=123-456",
|
|
146
|
-
output: "./test-output",
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
});
|
|
150
|
-
const args = {
|
|
151
|
-
subcommand: "download",
|
|
152
|
-
name: "test-assets",
|
|
153
|
-
config: undefined,
|
|
154
|
-
token: undefined,
|
|
155
|
-
};
|
|
156
|
-
await (0, vitest_1.expect)((0, cli_1.run)(args)).rejects.toThrow('No asset configuration found for name "test-assets"');
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
(0, vitest_1.describe)("get subcommand", () => {
|
|
160
|
-
(0, vitest_1.it)("should successfully get node data", async () => {
|
|
161
|
-
const mockNodeData = { nodes: { "test-node": { id: "test-node" } } };
|
|
162
|
-
mockAPI.nodes.fetch.mockResolvedValue(mockNodeData);
|
|
163
|
-
const consoleSpy = vitest_1.vi
|
|
164
|
-
.spyOn(console, "log")
|
|
165
|
-
.mockImplementation(() => { });
|
|
166
|
-
const args = {
|
|
167
|
-
subcommand: "get",
|
|
168
|
-
url: "https://www.figma.com/design/test-file-id/Test?node-id=123-456",
|
|
169
|
-
config: undefined,
|
|
170
|
-
token: undefined,
|
|
171
|
-
};
|
|
172
|
-
await (0, cli_1.run)(args);
|
|
173
|
-
(0, vitest_1.expect)(mockAPI.nodes.fetch).toHaveBeenCalled();
|
|
174
|
-
(0, vitest_1.expect)(consoleSpy).toHaveBeenCalledWith(JSON.stringify(mockNodeData, null, 2));
|
|
175
|
-
consoleSpy.mockRestore();
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
(0, vitest_1.it)("should validate required configuration", async () => {
|
|
179
|
-
const args = {
|
|
180
|
-
subcommand: "download",
|
|
181
|
-
name: "test-assets",
|
|
182
|
-
config: undefined,
|
|
183
|
-
token: undefined,
|
|
184
|
-
};
|
|
185
|
-
await (0, cli_1.run)(args);
|
|
186
|
-
(0, vitest_1.expect)(config_1.validateRequiredConfig).toHaveBeenCalledWith(vitest_1.expect.objectContaining({ token: "test-token" }), ["token"]);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
});
|
|
@@ -1,197 +0,0 @@
|
|
|
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
|
-
const vitest_1 = require("vitest");
|
|
27
|
-
const argparse_1 = require("argparse");
|
|
28
|
-
const cli_1 = require("../tokens-studio/cli");
|
|
29
|
-
const fs = __importStar(require("fs"));
|
|
30
|
-
const path = __importStar(require("path"));
|
|
31
|
-
// Mock dependencies
|
|
32
|
-
vitest_1.vi.mock("../config", () => ({
|
|
33
|
-
loadConfig: vitest_1.vi.fn(),
|
|
34
|
-
mergeConfigWithArgs: vitest_1.vi.fn(),
|
|
35
|
-
validateRequiredConfig: vitest_1.vi.fn(),
|
|
36
|
-
}));
|
|
37
|
-
vitest_1.vi.mock("../tokens-studio/utils", () => ({
|
|
38
|
-
deepMerge: vitest_1.vi.fn(),
|
|
39
|
-
}));
|
|
40
|
-
vitest_1.vi.mock("fs");
|
|
41
|
-
const config_1 = require("../config");
|
|
42
|
-
const utils_1 = require("../tokens-studio/utils");
|
|
43
|
-
(0, vitest_1.describe)("Tokens Studio CLI", () => {
|
|
44
|
-
let tempDir;
|
|
45
|
-
let transformerPath;
|
|
46
|
-
(0, vitest_1.beforeEach)(() => {
|
|
47
|
-
vitest_1.vi.clearAllMocks();
|
|
48
|
-
// Set up test paths
|
|
49
|
-
tempDir = "/tmp/test-dir";
|
|
50
|
-
transformerPath = path.join(tempDir, "test-transformer.js");
|
|
51
|
-
// Mock loadConfig
|
|
52
|
-
vitest_1.vi.mocked(config_1.loadConfig).mockResolvedValue({});
|
|
53
|
-
// Mock validateRequiredConfig to not throw
|
|
54
|
-
vitest_1.vi.mocked(config_1.validateRequiredConfig).mockImplementation(() => { });
|
|
55
|
-
// Mock deepMerge
|
|
56
|
-
vitest_1.vi.mocked(utils_1.deepMerge).mockImplementation((target, source) => {
|
|
57
|
-
Object.assign(target, source);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
(0, vitest_1.describe)("configParser", () => {
|
|
61
|
-
(0, vitest_1.it)("should configure the argument parser correctly", () => {
|
|
62
|
-
const parser = new argparse_1.ArgumentParser();
|
|
63
|
-
const addSubparsersSpy = vitest_1.vi.spyOn(parser, "add_subparsers");
|
|
64
|
-
(0, cli_1.configParser)(parser);
|
|
65
|
-
(0, vitest_1.expect)(addSubparsersSpy).toHaveBeenCalledWith({
|
|
66
|
-
title: "tokens-studio commands",
|
|
67
|
-
dest: "subcommand",
|
|
68
|
-
help: "Use 'ixt tokens-studio <subcommand> --help' for more information",
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
(0, vitest_1.describe)("run", () => {
|
|
73
|
-
(0, vitest_1.beforeEach)(() => {
|
|
74
|
-
// Mock mergeConfigWithArgs to return our test configuration
|
|
75
|
-
vitest_1.vi.mocked(config_1.mergeConfigWithArgs).mockReturnValue({
|
|
76
|
-
handler: transformerPath,
|
|
77
|
-
input: path.join(tempDir, "tokens"),
|
|
78
|
-
output: path.join(tempDir, "output.json"),
|
|
79
|
-
});
|
|
80
|
-
// Mock fs.existsSync to return true for our paths
|
|
81
|
-
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
82
|
-
// Mock fs.readFileSync for token files
|
|
83
|
-
vitest_1.vi.mocked(fs.readFileSync).mockImplementation((pathStr, _encoding) => {
|
|
84
|
-
const pathString = pathStr.toString();
|
|
85
|
-
if (pathString.includes("$metadata.json")) {
|
|
86
|
-
return JSON.stringify({ tokenSetOrder: ["base", "semantic"] });
|
|
87
|
-
}
|
|
88
|
-
if (pathString.includes("base.json")) {
|
|
89
|
-
return JSON.stringify({
|
|
90
|
-
colors: { primary: { value: "#007bff", type: "color" } },
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
if (pathString.includes("semantic.json")) {
|
|
94
|
-
return JSON.stringify({
|
|
95
|
-
colors: {
|
|
96
|
-
background: { value: "{colors.primary}", type: "color" },
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
return "";
|
|
101
|
-
});
|
|
102
|
-
// Mock fs.writeFileSync
|
|
103
|
-
vitest_1.vi.mocked(fs.writeFileSync).mockImplementation(() => { });
|
|
104
|
-
// Mock require to return a test transformer
|
|
105
|
-
const mockRequire = vitest_1.vi.fn().mockReturnValue({
|
|
106
|
-
transform: (input) => ({
|
|
107
|
-
transformedTokens: input.tokenData,
|
|
108
|
-
metadata: input.metadata,
|
|
109
|
-
processed: true,
|
|
110
|
-
}),
|
|
111
|
-
});
|
|
112
|
-
vitest_1.vi.stubGlobal("require", mockRequire);
|
|
113
|
-
});
|
|
114
|
-
(0, vitest_1.it)("should successfully transform tokens", async () => {
|
|
115
|
-
const consoleSpy = vitest_1.vi.spyOn(console, "log").mockImplementation(() => { });
|
|
116
|
-
const args = {
|
|
117
|
-
subcommand: "transform",
|
|
118
|
-
config: undefined,
|
|
119
|
-
handler: undefined,
|
|
120
|
-
input: undefined,
|
|
121
|
-
output: undefined,
|
|
122
|
-
};
|
|
123
|
-
await (0, cli_1.run)(args);
|
|
124
|
-
(0, vitest_1.expect)(config_1.loadConfig).toHaveBeenCalledWith(undefined);
|
|
125
|
-
(0, vitest_1.expect)(config_1.validateRequiredConfig).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
126
|
-
handler: transformerPath,
|
|
127
|
-
output: path.join(tempDir, "output.json"),
|
|
128
|
-
}), ["handler", "output"]);
|
|
129
|
-
(0, vitest_1.expect)(fs.writeFileSync).toHaveBeenCalledWith(path.join(tempDir, "output.json"), vitest_1.expect.stringContaining('"processed": true'));
|
|
130
|
-
(0, vitest_1.expect)(consoleSpy).toHaveBeenCalledWith(`✅ Transformation complete! Output written to: ${path.join(tempDir, "output.json")}`);
|
|
131
|
-
consoleSpy.mockRestore();
|
|
132
|
-
});
|
|
133
|
-
(0, vitest_1.it)("should throw error when handler file does not exist", async () => {
|
|
134
|
-
vitest_1.vi.mocked(fs.existsSync).mockReturnValue(false);
|
|
135
|
-
const args = {
|
|
136
|
-
subcommand: "transform",
|
|
137
|
-
config: undefined,
|
|
138
|
-
handler: undefined,
|
|
139
|
-
input: undefined,
|
|
140
|
-
output: undefined,
|
|
141
|
-
};
|
|
142
|
-
await (0, vitest_1.expect)((0, cli_1.run)(args)).rejects.toThrow("Handler file not found");
|
|
143
|
-
});
|
|
144
|
-
(0, vitest_1.it)("should throw error when input directory does not exist", async () => {
|
|
145
|
-
vitest_1.vi.mocked(fs.existsSync).mockImplementation((pathStr) => {
|
|
146
|
-
const pathString = pathStr.toString();
|
|
147
|
-
return pathString === transformerPath; // only transformer exists
|
|
148
|
-
});
|
|
149
|
-
const args = {
|
|
150
|
-
subcommand: "transform",
|
|
151
|
-
config: undefined,
|
|
152
|
-
handler: undefined,
|
|
153
|
-
input: undefined,
|
|
154
|
-
output: undefined,
|
|
155
|
-
};
|
|
156
|
-
await (0, vitest_1.expect)((0, cli_1.run)(args)).rejects.toThrow("Input directory not found");
|
|
157
|
-
});
|
|
158
|
-
(0, vitest_1.it)("should throw error when transformer does not export transform function", async () => {
|
|
159
|
-
// Override the require mock for this test
|
|
160
|
-
const mockRequire = vitest_1.vi.fn().mockReturnValue({
|
|
161
|
-
someOtherFunction: () => { },
|
|
162
|
-
});
|
|
163
|
-
vitest_1.vi.stubGlobal("require", mockRequire);
|
|
164
|
-
const args = {
|
|
165
|
-
subcommand: "transform",
|
|
166
|
-
config: undefined,
|
|
167
|
-
handler: undefined,
|
|
168
|
-
input: undefined,
|
|
169
|
-
output: undefined,
|
|
170
|
-
};
|
|
171
|
-
await (0, vitest_1.expect)((0, cli_1.run)(args)).rejects.toThrow("Handler file must export a 'transform' function");
|
|
172
|
-
});
|
|
173
|
-
(0, vitest_1.it)("should use default input directory when not specified", async () => {
|
|
174
|
-
vitest_1.vi.mocked(config_1.mergeConfigWithArgs).mockReturnValue({
|
|
175
|
-
handler: transformerPath,
|
|
176
|
-
input: undefined,
|
|
177
|
-
output: "./output.json",
|
|
178
|
-
});
|
|
179
|
-
// Mock existsSync to handle the default path
|
|
180
|
-
vitest_1.vi.mocked(fs.existsSync).mockImplementation((pathStr) => {
|
|
181
|
-
const pathString = pathStr.toString();
|
|
182
|
-
return pathString === transformerPath || pathString.includes("tokens"); // Should resolve to './tokens'
|
|
183
|
-
});
|
|
184
|
-
const consoleSpy = vitest_1.vi.spyOn(console, "log").mockImplementation(() => { });
|
|
185
|
-
const args = {
|
|
186
|
-
subcommand: "transform",
|
|
187
|
-
config: undefined,
|
|
188
|
-
handler: undefined,
|
|
189
|
-
input: undefined,
|
|
190
|
-
output: undefined,
|
|
191
|
-
};
|
|
192
|
-
await (0, cli_1.run)(args);
|
|
193
|
-
(0, vitest_1.expect)(consoleSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining("✅ Transformation complete!"));
|
|
194
|
-
consoleSpy.mockRestore();
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const argparse_1 = require("argparse");
|
|
5
|
-
const cli_1 = require("../vercel/cli");
|
|
6
|
-
// Mock the waitForDeploymentReady function
|
|
7
|
-
vitest_1.vi.mock("@interactivethings/scripts/vercel/deployments", () => ({
|
|
8
|
-
waitForDeploymentReady: vitest_1.vi.fn(),
|
|
9
|
-
}));
|
|
10
|
-
const deployments_1 = require("@interactivethings/scripts/vercel/deployments");
|
|
11
|
-
(0, vitest_1.describe)("Vercel CLI", () => {
|
|
12
|
-
(0, vitest_1.beforeEach)(() => {
|
|
13
|
-
vitest_1.vi.clearAllMocks();
|
|
14
|
-
// Mock environment variable
|
|
15
|
-
process.env.VERCEL_TOKEN = "test-token";
|
|
16
|
-
});
|
|
17
|
-
(0, vitest_1.describe)("configParser", () => {
|
|
18
|
-
(0, vitest_1.it)("should configure the argument parser correctly", () => {
|
|
19
|
-
const parser = new argparse_1.ArgumentParser();
|
|
20
|
-
const addSubparsersSpy = vitest_1.vi.spyOn(parser, "add_subparsers");
|
|
21
|
-
(0, cli_1.configParser)(parser);
|
|
22
|
-
(0, vitest_1.expect)(addSubparsersSpy).toHaveBeenCalledWith({
|
|
23
|
-
title: "Vercel commands",
|
|
24
|
-
dest: "subcommand",
|
|
25
|
-
help: "Use 'ixt vercel <command> --help' for more information",
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
(0, vitest_1.describe)("run", () => {
|
|
30
|
-
(0, vitest_1.it)("should successfully wait for deployment with valid args", async () => {
|
|
31
|
-
const mockDeployment = {
|
|
32
|
-
url: "test-deployment.vercel.app",
|
|
33
|
-
state: "READY",
|
|
34
|
-
meta: {
|
|
35
|
-
githubCommitSha: "test-commit-sha",
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
vitest_1.vi.mocked(deployments_1.waitForDeploymentReady).mockResolvedValue(mockDeployment);
|
|
39
|
-
const consoleSpy = vitest_1.vi.spyOn(console, "log").mockImplementation(() => { });
|
|
40
|
-
const args = {
|
|
41
|
-
subcommand: "wait-deployment",
|
|
42
|
-
commit: "test-commit-sha",
|
|
43
|
-
interval: 5000,
|
|
44
|
-
timeout: 600000,
|
|
45
|
-
team: "test-team",
|
|
46
|
-
project: "test-project",
|
|
47
|
-
};
|
|
48
|
-
await (0, cli_1.run)(args);
|
|
49
|
-
(0, vitest_1.expect)(deployments_1.waitForDeploymentReady).toHaveBeenCalledWith({
|
|
50
|
-
commitSha: "test-commit-sha",
|
|
51
|
-
interval: 5000,
|
|
52
|
-
timeout: 600000,
|
|
53
|
-
team: "test-team",
|
|
54
|
-
project: "test-project",
|
|
55
|
-
accessToken: "test-token",
|
|
56
|
-
});
|
|
57
|
-
(0, vitest_1.expect)(consoleSpy).toHaveBeenCalledWith("DEPLOYMENT_URL=https://test-deployment.vercel.app");
|
|
58
|
-
consoleSpy.mockRestore();
|
|
59
|
-
});
|
|
60
|
-
(0, vitest_1.it)("should throw error when deployment is not found", async () => {
|
|
61
|
-
vitest_1.vi.mocked(deployments_1.waitForDeploymentReady).mockResolvedValue(undefined);
|
|
62
|
-
const args = {
|
|
63
|
-
subcommand: "wait-deployment",
|
|
64
|
-
commit: "test-commit-sha",
|
|
65
|
-
interval: 5000,
|
|
66
|
-
timeout: 600000,
|
|
67
|
-
team: "test-team",
|
|
68
|
-
project: "test-project",
|
|
69
|
-
};
|
|
70
|
-
await (0, vitest_1.expect)((0, cli_1.run)(args)).rejects.toThrow("Could not retrieve deployment");
|
|
71
|
-
});
|
|
72
|
-
(0, vitest_1.it)("should throw error when waitForDeploymentReady fails", async () => {
|
|
73
|
-
const error = new Error("Network error");
|
|
74
|
-
vitest_1.vi.mocked(deployments_1.waitForDeploymentReady).mockRejectedValue(error);
|
|
75
|
-
const args = {
|
|
76
|
-
subcommand: "wait-deployment",
|
|
77
|
-
commit: "test-commit-sha",
|
|
78
|
-
interval: 5000,
|
|
79
|
-
timeout: 600000,
|
|
80
|
-
team: "test-team",
|
|
81
|
-
project: "test-project",
|
|
82
|
-
};
|
|
83
|
-
await (0, vitest_1.expect)((0, cli_1.run)(args)).rejects.toThrow("Network error");
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
package/dist/cli.d.ts
DELETED