@interactivethings/scripts 0.0.8 → 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.
- package/README.md +210 -12
- package/codemods/__testfixtures__/sx-to-use-styles.input.js +50 -0
- package/codemods/__testfixtures__/sx-to-use-styles.output.js +59 -0
- package/codemods/__tests__/defineTest.ts +9 -0
- package/codemods/__tests__/sx-to-use-styles.test.js +3 -0
- package/codemods/sx-to-use-styles.js +162 -0
- package/dist/__tests__/figma-cli.test.js +189 -0
- package/dist/__tests__/tokens-studio-cli.test.js +197 -0
- package/dist/__tests__/vercel-cli.test.js +86 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +94 -0
- package/dist/config.d.ts +78 -0
- package/dist/config.js +157 -0
- package/dist/figma/api.d.ts +71 -0
- package/dist/figma/api.js +175 -0
- package/dist/figma/cli.d.ts +20 -0
- package/dist/figma/cli.js +153 -0
- package/dist/figma/cli.test.js +187 -0
- package/dist/figma/images.js +53 -0
- package/dist/figma/optimizeImage.js +53 -0
- package/dist/figma/utils.d.ts +10 -0
- package/dist/figma/utils.js +26 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +43 -0
- package/dist/init/cli.d.ts +3 -0
- package/dist/init/cli.js +312 -0
- package/dist/mui-tokens-studio.js +1 -0
- package/dist/plugins/figma/index.js +653 -0
- package/dist/plugins/tokens-studio/utils.js +155 -0
- package/dist/tokens-studio/__tests__/fixtures/invalid-transformer.js +12 -0
- package/dist/tokens-studio/__tests__/fixtures/test-transformer.js +18 -0
- package/dist/tokens-studio/cli.d.ts +8 -0
- package/dist/tokens-studio/cli.js +119 -0
- package/dist/tokens-studio/cli.test.js +150 -0
- package/dist/tokens-studio/index.d.ts +14 -0
- package/dist/tokens-studio/index.js +46 -0
- package/dist/tokens-studio/mui.js +212 -0
- package/dist/tokens-studio/require.js +17 -0
- package/dist/tokens-studio/tailwind.js +211 -0
- package/dist/tokens-studio/types.js +2 -0
- package/dist/tokens-studio/utils.d.ts +49 -0
- package/dist/tokens-studio/utils.js +156 -0
- package/dist/types.d.ts +1 -0
- package/dist/vercel/cli.d.ts +4 -0
- package/dist/vercel/cli.js +70 -0
- package/dist/vercel/cli.test.js +86 -0
- package/dist/vercel/deployments.js +42 -0
- package/dist/vercel/waitForDeploymentReady.js +43 -0
- package/package.json +46 -6
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.run = exports.configParser = void 0;
|
|
5
|
+
const deployments_1 = require("./deployments");
|
|
6
|
+
const argparse_1 = require("argparse");
|
|
7
|
+
const configParser = (parser) => {
|
|
8
|
+
const commands = parser.add_subparsers({
|
|
9
|
+
title: "Vercel commands",
|
|
10
|
+
dest: "subcommand",
|
|
11
|
+
help: "Use 'ixt vercel <command> --help' for more information",
|
|
12
|
+
});
|
|
13
|
+
// wait-deployment subcommand
|
|
14
|
+
const waitDeploymentParser = commands.add_parser("wait-deployment", {
|
|
15
|
+
help: "Wait for a Vercel deployment to complete",
|
|
16
|
+
});
|
|
17
|
+
waitDeploymentParser.add_argument("commit", {
|
|
18
|
+
help: "Commit that started the deployment",
|
|
19
|
+
});
|
|
20
|
+
waitDeploymentParser.add_argument("--interval", {
|
|
21
|
+
default: 5000,
|
|
22
|
+
type: Number,
|
|
23
|
+
});
|
|
24
|
+
waitDeploymentParser.add_argument("--project", {
|
|
25
|
+
required: true,
|
|
26
|
+
});
|
|
27
|
+
waitDeploymentParser.add_argument("--team", {
|
|
28
|
+
required: true,
|
|
29
|
+
});
|
|
30
|
+
waitDeploymentParser.add_argument("--timeout", {
|
|
31
|
+
default: 10 * 60 * 1000,
|
|
32
|
+
type: Number,
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.configParser = configParser;
|
|
36
|
+
const run = async (args) => {
|
|
37
|
+
const accessToken = process.env.VERCEL_TOKEN;
|
|
38
|
+
switch (args.subcommand) {
|
|
39
|
+
case "wait-deployment":
|
|
40
|
+
const deployment = await (0, deployments_1.waitForDeploymentReady)({
|
|
41
|
+
commitSha: args.commit,
|
|
42
|
+
interval: args.interval,
|
|
43
|
+
timeout: args.timeout,
|
|
44
|
+
team: args.team,
|
|
45
|
+
project: args.project,
|
|
46
|
+
accessToken: accessToken,
|
|
47
|
+
});
|
|
48
|
+
if (!deployment) {
|
|
49
|
+
throw new Error("Could not retrieve deployment");
|
|
50
|
+
}
|
|
51
|
+
console.log(`DEPLOYMENT_URL=https://${deployment.url}`);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports.run = run;
|
|
56
|
+
async function main() {
|
|
57
|
+
const parser = new argparse_1.ArgumentParser({
|
|
58
|
+
description: "Vercel deployment utilities",
|
|
59
|
+
});
|
|
60
|
+
const args = parser.parse_args();
|
|
61
|
+
(0, exports.configParser)(parser);
|
|
62
|
+
await (0, exports.run)(args);
|
|
63
|
+
}
|
|
64
|
+
// Only run main if this file is being executed directly
|
|
65
|
+
if (require.main === module) {
|
|
66
|
+
main().catch((e) => {
|
|
67
|
+
console.error(e);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
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("./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
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForDeploymentReady = void 0;
|
|
4
|
+
async function fetchDeploymentForCommit(commitSha, teamId, projectId, accessToken) {
|
|
5
|
+
try {
|
|
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));
|
|
20
|
+
async function waitForDeploymentReady({ team, project, commitSha, interval, timeout, accessToken, }) {
|
|
21
|
+
const start = Date.now();
|
|
22
|
+
const end = start + timeout;
|
|
23
|
+
while (Date.now() < end) {
|
|
24
|
+
const deployments = await fetchDeploymentForCommit(commitSha, team, project, accessToken);
|
|
25
|
+
if (deployments.length === 0 || deployments[0].state !== "READY") {
|
|
26
|
+
const state = deployments[0].state;
|
|
27
|
+
if (state === "ERROR") {
|
|
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
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.waitForDeploymentReady = waitForDeploymentReady;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForDeploymentReady = void 0;
|
|
4
|
+
const cli_1 = require("@interactivethings/scripts/vercel/cli");
|
|
5
|
+
async function fetchDeploymentForCommit(commitSha, teamId, projectId) {
|
|
6
|
+
try {
|
|
7
|
+
const response = await fetch(`https://vercel.com/api/v6/deployments?limit=20&projectId=${projectId}&state=READY,ERROR,BUILDING,QUEUED&teamId=${teamId}`, {
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: `Bearer ${cli_1.accessToken}`,
|
|
10
|
+
},
|
|
11
|
+
}).then((x) => x.json());
|
|
12
|
+
const deployments = response.deployments.filter((deployment) => deployment.meta.githubCommitSha === commitSha);
|
|
13
|
+
return deployments;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.error("Error:", error);
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const sleep = (duration) => new Promise((resolve) => setTimeout(resolve, duration));
|
|
21
|
+
async function waitForDeploymentReady({ team, project, commitSha, interval, timeout, }) {
|
|
22
|
+
const start = Date.now();
|
|
23
|
+
const end = start + timeout;
|
|
24
|
+
while (Date.now() < end) {
|
|
25
|
+
const deployments = await fetchDeploymentForCommit(commitSha, team, project);
|
|
26
|
+
if (deployments.length === 0 || deployments[0].state !== "READY") {
|
|
27
|
+
const state = deployments[0].state;
|
|
28
|
+
if (state === "ERROR") {
|
|
29
|
+
throw new Error("Deployment errored");
|
|
30
|
+
}
|
|
31
|
+
console.log(`Deployment not yet ready (state: ${deployments[0].state}), waiting ${interval}ms for deployment with commit ${commitSha}`);
|
|
32
|
+
await sleep(Math.min(end - Date.now(), interval));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.log(`Deployment for commit ${commitSha} is READY`);
|
|
36
|
+
return deployments[0];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (Date.now() > end) {
|
|
40
|
+
throw new Error("Timeout for waitForDeploymentReady");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.waitForDeploymentReady = waitForDeploymentReady;
|
package/package.json
CHANGED
|
@@ -1,25 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interactivethings/scripts",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"main": "index.js",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./dist/index.js",
|
|
7
|
+
"./tokens-studio": "./dist/tokens-studio/index.js",
|
|
8
|
+
"./types": "./dist/types.js"
|
|
9
|
+
},
|
|
10
|
+
"typesVersions": {
|
|
11
|
+
"*": {
|
|
12
|
+
"tokens-studio": [
|
|
13
|
+
"./dist/tokens-studio/index.d.ts"
|
|
14
|
+
],
|
|
15
|
+
"types": [
|
|
16
|
+
"./dist/types.d.ts"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
},
|
|
5
20
|
"repository": "git@github.com:interactivethings/ixt-scripts.git",
|
|
6
21
|
"author": "Interactive Things <we@interactivethings.com>",
|
|
7
22
|
"license": "MIT",
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"watch": "tsc --watch",
|
|
26
|
+
"lint": "oxlint",
|
|
27
|
+
"test": "vitest",
|
|
28
|
+
"start": "bun ./dist/cli.js"
|
|
29
|
+
},
|
|
8
30
|
"bin": {
|
|
31
|
+
"ixt": "dist/cli.js",
|
|
9
32
|
"wait-for-vercel-deploy": "dist/wait-for-vercel-deploy.js",
|
|
10
33
|
"mui-tokens-studio": "dist/mui-tokens-studio.js"
|
|
11
34
|
},
|
|
12
35
|
"files": [
|
|
13
36
|
"dist",
|
|
14
|
-
"README.md"
|
|
37
|
+
"README.md",
|
|
38
|
+
"codemods"
|
|
15
39
|
],
|
|
16
40
|
"dependencies": {
|
|
41
|
+
"@next/env": "^15.5.4",
|
|
42
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
43
|
+
"@semantic-release/git": "^10.0.1",
|
|
44
|
+
"@semantic-release/github": "^11.0.6",
|
|
17
45
|
"@types/argparse": "^2.0.12",
|
|
46
|
+
"@types/jscodeshift": "^0.11.10",
|
|
18
47
|
"argparse": "^2.0.1",
|
|
19
|
-
"
|
|
48
|
+
"jiti": "^2.6.1",
|
|
49
|
+
"ora": "^9.0.0",
|
|
50
|
+
"prompts": "^2.4.2",
|
|
51
|
+
"remeda": "^1.19.0",
|
|
52
|
+
"zod": "^4.1.11"
|
|
20
53
|
},
|
|
21
54
|
"devDependencies": {
|
|
22
|
-
"@types/node": "
|
|
23
|
-
"
|
|
55
|
+
"@types/node": "22",
|
|
56
|
+
"@types/prompts": "^2.4.9",
|
|
57
|
+
"jscodeshift": "^0.15.1",
|
|
58
|
+
"oxlint": "^1.19.0",
|
|
59
|
+
"typescript": "^5.2.2",
|
|
60
|
+
"vitest": "^0.34.6"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@next/env": "^15.5.4"
|
|
24
64
|
}
|
|
25
65
|
}
|