@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.
Files changed (41) hide show
  1. package/dist/cli.js +21 -12
  2. package/dist/cloudflare/cli.js +90 -0
  3. package/dist/cloudflare/cloudflare.js +44 -0
  4. package/dist/cloudflare/deployments.js +14 -0
  5. package/dist/config.js +12 -6
  6. package/dist/figma/cli.js +7 -5
  7. package/dist/figma/cli.test.js +8 -7
  8. package/dist/init/cli.js +9 -6
  9. package/dist/shared/cli.js +13 -0
  10. package/dist/shared/deployment-service.js +2 -0
  11. package/dist/shared/wait-deployment.js +29 -0
  12. package/dist/tokens-studio/cli.js +5 -3
  13. package/dist/tokens-studio/cli.test.js +8 -4
  14. package/dist/vercel/cli.js +7 -5
  15. package/dist/vercel/cli.test.js +9 -5
  16. package/dist/vercel/deployments.js +9 -36
  17. package/dist/vercel/vercel.js +31 -0
  18. package/package.json +5 -7
  19. package/dist/__tests__/figma-cli.test.js +0 -189
  20. package/dist/__tests__/tokens-studio-cli.test.js +0 -197
  21. package/dist/__tests__/vercel-cli.test.js +0 -86
  22. package/dist/cli.d.ts +0 -2
  23. package/dist/config.d.ts +0 -78
  24. package/dist/figma/api.d.ts +0 -71
  25. package/dist/figma/cli.d.ts +0 -20
  26. package/dist/figma/optimizeImage.js +0 -53
  27. package/dist/figma/utils.d.ts +0 -10
  28. package/dist/index.d.ts +0 -8
  29. package/dist/init/cli.d.ts +0 -3
  30. package/dist/mui-tokens-studio.js +0 -177
  31. package/dist/plugins/figma/index.js +0 -653
  32. package/dist/plugins/tokens-studio/utils.js +0 -155
  33. package/dist/tokens-studio/cli.d.ts +0 -8
  34. package/dist/tokens-studio/index.d.ts +0 -14
  35. package/dist/tokens-studio/mui.js +0 -212
  36. package/dist/tokens-studio/tailwind.js +0 -211
  37. package/dist/tokens-studio/utils.d.ts +0 -49
  38. package/dist/types.d.ts +0 -1
  39. package/dist/vercel/cli.d.ts +0 -4
  40. package/dist/vercel/waitForDeploymentReady.js +0 -43
  41. package/dist/wait-for-vercel-deploy.js +0 -79
package/dist/config.d.ts DELETED
@@ -1,78 +0,0 @@
1
- import { z } from "zod";
2
- /**
3
- * Figma configuration schema
4
- */
5
- export declare const FigmaAssetConfigSchema: z.ZodObject<{
6
- url: z.ZodString;
7
- output: z.ZodString;
8
- name: z.ZodString;
9
- }, z.core.$strip>;
10
- export declare const FigmaConfigSchema: z.ZodObject<{
11
- token: z.ZodOptional<z.ZodString>;
12
- assets: z.ZodDefault<z.ZodArray<z.ZodObject<{
13
- url: z.ZodString;
14
- output: z.ZodString;
15
- name: z.ZodString;
16
- }, z.core.$strip>>>;
17
- }, z.core.$strip>;
18
- /**
19
- * Tokens Studio configuration schema
20
- */
21
- export declare const TokensStudioConfigSchema: z.ZodObject<{
22
- input: z.ZodDefault<z.ZodString>;
23
- output: z.ZodOptional<z.ZodString>;
24
- handler: z.ZodOptional<z.ZodString>;
25
- }, z.core.$strip>;
26
- /**
27
- * Vercel configuration schema
28
- */
29
- export declare const VercelConfigSchema: z.ZodObject<{
30
- team: z.ZodOptional<z.ZodString>;
31
- project: z.ZodOptional<z.ZodString>;
32
- }, z.core.$strip>;
33
- /**
34
- * Main IXT Scripts configuration schema
35
- */
36
- export declare const IxtConfigSchema: z.ZodObject<{
37
- figma: z.ZodOptional<z.ZodObject<{
38
- token: z.ZodOptional<z.ZodString>;
39
- assets: z.ZodDefault<z.ZodArray<z.ZodObject<{
40
- url: z.ZodString;
41
- output: z.ZodString;
42
- name: z.ZodString;
43
- }, z.core.$strip>>>;
44
- }, z.core.$strip>>;
45
- tokensStudio: z.ZodOptional<z.ZodObject<{
46
- input: z.ZodDefault<z.ZodString>;
47
- output: z.ZodOptional<z.ZodString>;
48
- handler: z.ZodOptional<z.ZodString>;
49
- }, z.core.$strip>>;
50
- vercel: z.ZodOptional<z.ZodObject<{
51
- team: z.ZodOptional<z.ZodString>;
52
- project: z.ZodOptional<z.ZodString>;
53
- }, z.core.$strip>>;
54
- }, z.core.$strip>;
55
- export type IxtConfig = z.infer<typeof IxtConfigSchema>;
56
- export type FigmaConfig = z.infer<typeof FigmaConfigSchema>;
57
- export type FigmaAssetConfig = z.infer<typeof FigmaAssetConfigSchema>;
58
- export type TokensStudioConfig = z.infer<typeof TokensStudioConfigSchema>;
59
- export type VercelConfig = z.infer<typeof VercelConfigSchema>;
60
- /**
61
- * Helper function for type-safe configuration definition
62
- * Provides IntelliSense and validation for the configuration object
63
- */
64
- export declare function defineConfig(config: IxtConfig): IxtConfig;
65
- /**
66
- * Load configuration from a TypeScript file
67
- * Only supports .ts configuration files for better type safety
68
- */
69
- export declare function loadConfig(configPath?: string): Promise<IxtConfig>;
70
- /**
71
- * Merge CLI arguments with configuration
72
- * CLI arguments take precedence over config file values
73
- */
74
- export declare function mergeConfigWithArgs<T extends Record<string, any>>(config: IxtConfig, args: T, section: keyof IxtConfig): T & Partial<IxtConfig[keyof IxtConfig]>;
75
- /**
76
- * Validate that required values are present after merging config and args
77
- */
78
- export declare function validateRequiredConfig<T extends Record<string, any>>(mergedConfig: T, requiredFields: (keyof T)[]): void;
@@ -1,71 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- type Color = {
4
- r: number;
5
- g: number;
6
- b: number;
7
- a: number;
8
- };
9
- type FileId = string;
10
- type NodeId = string;
11
- export type FigmaNode = ({
12
- type: "RECTANGLE";
13
- fills: {
14
- type: "SOLID";
15
- color: Color;
16
- }[];
17
- effects: {
18
- type: "DROP_SHADOW";
19
- offset: {
20
- x: number;
21
- y: number;
22
- };
23
- color: Color;
24
- radius: number;
25
- }[];
26
- } | {
27
- type: "TEXT";
28
- style: {
29
- fontFamily: string;
30
- fontWeight: number;
31
- fontSize: number;
32
- letterSpacing: number;
33
- lineHeightPx: number;
34
- };
35
- }) & {
36
- name: string;
37
- id: string;
38
- };
39
- export declare const createAPI: (figmaToken: string) => {
40
- file: {
41
- fetch: (fileId: FileId) => Promise<any>;
42
- };
43
- nodes: {
44
- fetch: (fileId: FileId, ids: NodeId[]) => Promise<any>;
45
- };
46
- styles: {
47
- fetch: (fileId: FileId) => Promise<{
48
- nodes: {
49
- document: FigmaNode;
50
- }[];
51
- }>;
52
- };
53
- /**
54
- * Given a root node, fetches all exports of the nodes in the tree.
55
- * This is especially useful to fetch all icons or assets from a design system.
56
- */
57
- images: {
58
- fetch: (fileId: FileId, nodeIds: string[], { onFetchSources, onFetchImage, }?: {
59
- onFetchSources?: ((sources: {
60
- name: string;
61
- format: string;
62
- }[]) => void) | undefined;
63
- onFetchImage?: ((url: string) => void) | undefined;
64
- }) => Promise<{
65
- data: string | Buffer;
66
- name: string;
67
- format: string;
68
- }[]>;
69
- };
70
- };
71
- export {};
@@ -1,20 +0,0 @@
1
- /**
2
- * This script downloads the assets from Figma and saves them into the repository.
3
- * It is configured via the unified ixt configuration system.
4
- *
5
- * @example ixt.config.js
6
- * import { defineConfig } from '@interactivethings/scripts';
7
- *
8
- * export default defineConfig({
9
- * figma: {
10
- * assets: [{
11
- * name: "illustrations",
12
- * url: "https://www.figma.com/design/ElWWZIcOGFhiT06rzfIwRO/Design-System?node-id=11861-10071",
13
- * output: "src/assets/illustrations"
14
- * }]
15
- * }
16
- * });
17
- */
18
- import { ArgumentParser } from "argparse";
19
- export declare const configParser: (parser: ArgumentParser) => void;
20
- export declare const run: (parser: ArgumentParser) => Promise<void>;
@@ -1,53 +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
- 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;
@@ -1,10 +0,0 @@
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;
package/dist/index.d.ts DELETED
@@ -1,8 +0,0 @@
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";
@@ -1,3 +0,0 @@
1
- import { ArgumentParser } from "argparse";
2
- export declare function configParser(parser: ArgumentParser): void;
3
- export declare function run(mainParser: ArgumentParser): Promise<void>;
@@ -1,177 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- /**
4
- * This script transforms tokens exported with tokens-studio in Figma into
5
- * a format that is easier to work with when using MUI.
6
- * You can run it via `pnpm run design:tokens`
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const fs = require("fs");
10
- const argparse_1 = require("argparse");
11
- const remeda_1 = require("remeda");
12
- const simplifyValues = (x) => {
13
- if (typeof x === "string") {
14
- return x;
15
- }
16
- else if (typeof x === "object" && !!x) {
17
- if ("value" in x) {
18
- return x.value;
19
- }
20
- else {
21
- return (0, remeda_1.mapValues)(x, simplifyValues);
22
- }
23
- }
24
- };
25
- const kebabCase = (x) => {
26
- return x
27
- .split(" ")
28
- .map((t, i) => {
29
- if (i === 0) {
30
- return t.toLowerCase();
31
- }
32
- else {
33
- return `${t[0].toUpperCase()}${t.substring(1).toLowerCase()}`;
34
- }
35
- })
36
- .join("");
37
- };
38
- const renameColorKeys = (k) => {
39
- return kebabCase(k
40
- .replace(/-[a-zA-Z0-9]+/, "")
41
- .replace(" - ", " ")
42
- .replace(",", "")
43
- .replace(/^\d+\s+/, ""));
44
- };
45
- const renameColorKeysEntries = (obj) => {
46
- const visitor = (k, v) => {
47
- if (typeof v === "object") {
48
- return [renameColorKeys(k), mapEntries(v, visitor)];
49
- }
50
- else {
51
- return [renameColorKeys(k), v];
52
- }
53
- };
54
- return mapEntries(obj, visitor);
55
- };
56
- const mapEntries = (x, mapper) => {
57
- return Object.fromEntries(Object.entries(x).map(([k, v]) => mapper(k, v)));
58
- };
59
- const getPalette = (tokensData) => {
60
- const data = tokensData.global;
61
- const colorKeys = ["Base", "Functional"];
62
- let palette = (0, remeda_1.pick)(data, colorKeys);
63
- palette = (0, remeda_1.mapValues)(palette, simplifyValues);
64
- palette = renameColorKeysEntries(palette);
65
- palette = {
66
- ...palette.base,
67
- ...(0, remeda_1.pick)(palette, ["functional"]),
68
- };
69
- return palette;
70
- };
71
- const getTypography = (tokensData) => {
72
- const sizes = ["Desktop", "Mobile"];
73
- const res = {};
74
- const index = {};
75
- for (const k of [
76
- "fontFamilies",
77
- "lineHeights",
78
- "fontWeights",
79
- "fontSize",
80
- "letterSpacing",
81
- "textDecoration",
82
- ]) {
83
- for (const [vName, value] of Object.entries(tokensData.global[k])) {
84
- index[`${k}.${vName}`] = value;
85
- }
86
- }
87
- const maybeParseToNumber = (x) => {
88
- const parsed = Number(x);
89
- if (Number.isNaN(x)) {
90
- return x;
91
- }
92
- else {
93
- return parsed;
94
- }
95
- };
96
- const maybeParseToPx = (x) => {
97
- if (typeof x === "number") {
98
- return `${x}px`;
99
- }
100
- else {
101
- return x;
102
- }
103
- };
104
- const cleanupFns = {
105
- fontWeight: (x) => {
106
- const lowered = x.toLowerCase();
107
- if (lowered == "regular") {
108
- return 400;
109
- }
110
- return lowered;
111
- },
112
- fontSize: maybeParseToNumber,
113
- lineHeight: (x) => maybeParseToPx(maybeParseToNumber(x)),
114
- paragraphSpacing: maybeParseToNumber,
115
- letterSpacing: maybeParseToNumber,
116
- };
117
- const cleanup = (k, v) => {
118
- if (k in cleanupFns) {
119
- return [k, cleanupFns[k](v)];
120
- }
121
- else {
122
- return [k, v];
123
- }
124
- };
125
- const resolve = (str) => {
126
- if (str[0] === "{" && str[str.length - 1] === "}") {
127
- const path = str.substring(1, str.length - 1);
128
- return index[path]?.value;
129
- }
130
- else {
131
- return str;
132
- }
133
- };
134
- for (const size of sizes) {
135
- const typographies = tokensData.global[size];
136
- for (const [typo, typoDataRaw] of Object.entries(typographies)) {
137
- const typoData = typoDataRaw;
138
- const typoKey = kebabCase(typo.toLowerCase());
139
- res[typoKey] = res[typoKey] || {};
140
- res[typoKey][size.toLowerCase()] = mapEntries((0, remeda_1.mapValues)(typoData.value, resolve), cleanup);
141
- }
142
- }
143
- return res;
144
- };
145
- const getShadows = (tokenData) => {
146
- const transformShadow = (shadowData) => {
147
- const { color, x, y, blur, spread } = shadowData;
148
- return `${x}px ${y}px ${blur}px ${spread}px ${color}`;
149
- };
150
- const shadows = mapEntries(tokenData.global.Elevation, (k, v) => [
151
- `${Number(k.replace("dp", "").replace("pd", ""))}`,
152
- Array.isArray(v.value)
153
- ? v.value.map(transformShadow).join(", ")
154
- : transformShadow(v.value),
155
- ]);
156
- return shadows;
157
- };
158
- const transform = (tokenData) => {
159
- const palette = getPalette(tokenData);
160
- const typography = getTypography(tokenData);
161
- const shadows = getShadows(tokenData);
162
- return {
163
- palette,
164
- typography,
165
- shadows,
166
- };
167
- };
168
- const main = () => {
169
- const parser = new argparse_1.ArgumentParser();
170
- parser.add_argument("input");
171
- parser.add_argument("output");
172
- const args = parser.parse_args();
173
- const content = JSON.parse(fs.readFileSync(args.input).toString());
174
- const transformed = transform(content);
175
- fs.writeFileSync(args.output === "-" ? process.stdout.fd : args.output, JSON.stringify(transformed, null, 2));
176
- };
177
- main();