@interactivethings/scripts 0.0.9 → 2.0.2

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 +208 -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 +103 -0
  12. package/dist/config.d.ts +78 -0
  13. package/dist/config.js +167 -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 +163 -0
  18. package/dist/figma/cli.test.js +197 -0
  19. package/dist/figma/images.js +63 -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 +53 -0
  25. package/dist/init/cli.d.ts +3 -0
  26. package/dist/init/cli.js +320 -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 +153 -0
  34. package/dist/tokens-studio/cli.test.js +160 -0
  35. package/dist/tokens-studio/index.d.ts +14 -0
  36. package/dist/tokens-studio/index.js +56 -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 +41 -0
  48. package/dist/vercel/waitForDeploymentReady.js +43 -0
  49. package/package.json +46 -6
@@ -0,0 +1,320 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.configParser = configParser;
40
+ exports.run = run;
41
+ const fs = __importStar(require("fs/promises"));
42
+ const path = __importStar(require("path"));
43
+ const prompts_1 = __importDefault(require("prompts"));
44
+ const ora_1 = __importDefault(require("ora"));
45
+ function configParser(parser) {
46
+ parser.add_argument("--force", {
47
+ action: "store_true",
48
+ help: "Overwrite existing configuration files",
49
+ });
50
+ }
51
+ async function run(args) {
52
+ console.log("🚀 Welcome to Interactive Things Scripts setup!\n");
53
+ console.log("This wizard will help you configure your project for optimal development workflow.\n");
54
+ // Check if config already exists
55
+ const configPath = path.join(process.cwd(), "ixt.config.ts");
56
+ const configExists = await fs
57
+ .access(configPath)
58
+ .then(() => true)
59
+ .catch(() => false);
60
+ if (configExists && !args.force) {
61
+ console.log("⚠️ Configuration file already exists at ixt.config.ts");
62
+ console.log("Use --force to overwrite the existing configuration.\n");
63
+ const { shouldContinue } = await (0, prompts_1.default)({
64
+ type: "confirm",
65
+ name: "shouldContinue",
66
+ message: "Do you want to continue anyway?",
67
+ initial: false,
68
+ });
69
+ if (!shouldContinue) {
70
+ console.log("Setup cancelled.");
71
+ return;
72
+ }
73
+ }
74
+ // Collect user preferences
75
+ const answers = await collectUserPreferences();
76
+ // Generate configuration
77
+ const config = generateConfig(answers);
78
+ // Create necessary directories and files
79
+ const spinner = (0, ora_1.default)("Setting up your project...").start();
80
+ try {
81
+ await createProjectStructure(answers);
82
+ await writeConfigFile(config);
83
+ await copyExampleFiles(answers);
84
+ spinner.succeed("Project setup completed successfully!");
85
+ console.log("\n✨ Your project is now configured!");
86
+ console.log("\nNext steps:");
87
+ console.log("1. Review the generated ixt.config.ts file");
88
+ if (answers.useFigma) {
89
+ console.log("2. Update your Figma asset URLs in the config");
90
+ console.log("3. Set your FIGMA_TOKEN environment variable");
91
+ }
92
+ if (answers.useTokensStudio) {
93
+ console.log(`2. Place your design tokens in the ${answers.tokensInputDir} directory`);
94
+ console.log("3. Run 'ixt tokens-studio' to transform your tokens");
95
+ }
96
+ if (answers.useVercel) {
97
+ console.log("2. Configure your Vercel project settings");
98
+ console.log("3. Use 'ixt vercel' commands for deployment utilities");
99
+ }
100
+ console.log("\nFor more information, check the README.md file.");
101
+ }
102
+ catch (error) {
103
+ spinner.fail("Setup failed");
104
+ throw error;
105
+ }
106
+ }
107
+ async function collectUserPreferences() {
108
+ const questions = [
109
+ {
110
+ type: "confirm",
111
+ name: "useFigma",
112
+ message: "Will you be downloading assets from Figma?",
113
+ initial: true,
114
+ },
115
+ ];
116
+ let answers = await (0, prompts_1.default)(questions);
117
+ // Figma-specific questions
118
+ if (answers.useFigma) {
119
+ const figmaQuestions = await (0, prompts_1.default)([
120
+ {
121
+ type: "password",
122
+ name: "figmaToken",
123
+ message: "Enter your Figma API token (or leave empty to use FIGMA_TOKEN env var):",
124
+ validate: (value) => value.length === 0 || value.length > 10 || "Token seems too short",
125
+ },
126
+ {
127
+ type: "confirm",
128
+ name: "addAssetNow",
129
+ message: "Would you like to add a Figma asset configuration now?",
130
+ initial: true,
131
+ },
132
+ ]);
133
+ answers = { ...answers, ...figmaQuestions };
134
+ if (figmaQuestions.addAssetNow) {
135
+ const assetQuestions = await (0, prompts_1.default)([
136
+ {
137
+ type: "text",
138
+ name: "assetName",
139
+ message: 'Asset collection name (e.g., "icons", "illustrations"):',
140
+ validate: (value) => value.length > 0 || "Name is required",
141
+ },
142
+ {
143
+ type: "text",
144
+ name: "assetUrl",
145
+ message: "Figma URL for this asset collection:",
146
+ validate: (value) => value.includes("figma.com") || "Please provide a valid Figma URL",
147
+ },
148
+ {
149
+ type: "text",
150
+ name: "assetOutput",
151
+ message: "Output directory for assets:",
152
+ initial: "src/assets",
153
+ validate: (value) => value.length > 0 || "Output directory is required",
154
+ },
155
+ ]);
156
+ if (assetQuestions.assetName) {
157
+ answers.figmaAssets = [
158
+ {
159
+ name: assetQuestions.assetName,
160
+ url: assetQuestions.assetUrl,
161
+ output: assetQuestions.assetOutput,
162
+ },
163
+ ];
164
+ }
165
+ }
166
+ }
167
+ // Tokens Studio questions
168
+ const tokensQuestions = await (0, prompts_1.default)([
169
+ {
170
+ type: "confirm",
171
+ name: "useTokensStudio",
172
+ message: "Will you be using design tokens from Tokens Studio?",
173
+ initial: false,
174
+ },
175
+ ]);
176
+ answers = { ...answers, ...tokensQuestions };
177
+ if (answers.useTokensStudio) {
178
+ const tokensConfig = await (0, prompts_1.default)([
179
+ {
180
+ type: "text",
181
+ name: "tokensInputDir",
182
+ message: "Directory containing your design tokens:",
183
+ initial: "./tokens",
184
+ validate: (value) => value.length > 0 || "Input directory is required",
185
+ },
186
+ {
187
+ type: "text",
188
+ name: "tokensOutputFile",
189
+ message: "Output file for transformed tokens:",
190
+ initial: "src/theme/tokens.json",
191
+ validate: (value) => value.length > 0 || "Output file is required",
192
+ },
193
+ ]);
194
+ answers = { ...answers, ...tokensConfig };
195
+ // Styling framework question (only if using tokens)
196
+ const frameworkQuestion = await (0, prompts_1.default)([
197
+ {
198
+ type: "select",
199
+ name: "stylingFramework",
200
+ message: "Which styling framework transform would you like to use?",
201
+ choices: [
202
+ { title: "Material-UI (MUI)", value: "mui" },
203
+ { title: "Tailwind CSS", value: "tailwind" },
204
+ { title: "Custom transform", value: "custom" },
205
+ ],
206
+ initial: 0,
207
+ },
208
+ ]);
209
+ answers = { ...answers, ...frameworkQuestion };
210
+ }
211
+ // Vercel questions
212
+ const vercelQuestions = await (0, prompts_1.default)([
213
+ {
214
+ type: "confirm",
215
+ name: "useVercel",
216
+ message: "Will you be deploying with Vercel?",
217
+ initial: false,
218
+ },
219
+ ]);
220
+ answers = { ...answers, ...vercelQuestions };
221
+ if (answers.useVercel) {
222
+ const vercelConfig = await (0, prompts_1.default)([
223
+ {
224
+ type: "text",
225
+ name: "vercelTeam",
226
+ message: "Vercel team/organization name (optional):",
227
+ },
228
+ {
229
+ type: "text",
230
+ name: "vercelProject",
231
+ message: "Vercel project name (optional):",
232
+ },
233
+ ]);
234
+ answers = { ...answers, ...vercelConfig };
235
+ }
236
+ return answers;
237
+ }
238
+ function generateConfig(answers) {
239
+ const config = {};
240
+ if (answers.useFigma) {
241
+ config.figma = {
242
+ token: answers.figmaToken || undefined,
243
+ assets: answers.figmaAssets || [],
244
+ };
245
+ }
246
+ if (answers.useTokensStudio) {
247
+ config.tokensStudio = {
248
+ input: answers.tokensInputDir,
249
+ output: answers.tokensOutputFile,
250
+ };
251
+ // Add handler path based on styling framework choice
252
+ if (answers.stylingFramework && answers.stylingFramework !== "custom") {
253
+ config.tokensStudio.handler = `./ixt/transforms/${answers.stylingFramework}-transform.ts`;
254
+ }
255
+ }
256
+ if (answers.useVercel && (answers.vercelTeam || answers.vercelProject)) {
257
+ config.vercel = {};
258
+ if (answers.vercelTeam)
259
+ config.vercel.team = answers.vercelTeam;
260
+ if (answers.vercelProject)
261
+ config.vercel.project = answers.vercelProject;
262
+ }
263
+ return config;
264
+ }
265
+ async function createProjectStructure(answers) {
266
+ const cwd = process.cwd();
267
+ // Create ixt directory
268
+ const ixtDir = path.join(cwd, "ixt");
269
+ await fs.mkdir(ixtDir, { recursive: true });
270
+ // Create transforms directory if using tokens
271
+ if (answers.useTokensStudio) {
272
+ const transformsDir = path.join(ixtDir, "transforms");
273
+ await fs.mkdir(transformsDir, { recursive: true });
274
+ // Create tokens input directory
275
+ if (answers.tokensInputDir) {
276
+ await fs.mkdir(path.join(cwd, answers.tokensInputDir), {
277
+ recursive: true,
278
+ });
279
+ }
280
+ // Create output directory for tokens
281
+ if (answers.tokensOutputFile) {
282
+ const outputDir = path.dirname(path.join(cwd, answers.tokensOutputFile));
283
+ await fs.mkdir(outputDir, { recursive: true });
284
+ }
285
+ }
286
+ // Create assets directories if using Figma
287
+ if (answers.useFigma && answers.figmaAssets) {
288
+ for (const asset of answers.figmaAssets) {
289
+ await fs.mkdir(path.join(cwd, asset.output), { recursive: true });
290
+ }
291
+ }
292
+ }
293
+ async function writeConfigFile(config) {
294
+ const configPath = path.join(process.cwd(), "ixt.config.ts");
295
+ const configContent = `import { defineConfig } from '@interactivethings/scripts';
296
+
297
+ export default defineConfig(${JSON.stringify(config, null, 2)});
298
+ `;
299
+ await fs.writeFile(configPath, configContent, "utf-8");
300
+ }
301
+ async function copyExampleFiles(answers) {
302
+ if (!answers.useTokensStudio ||
303
+ !answers.stylingFramework ||
304
+ answers.stylingFramework === "custom") {
305
+ return;
306
+ }
307
+ const cwd = process.cwd();
308
+ const examplesDir = path.join(__dirname, "../../examples");
309
+ const transformsDir = path.join(cwd, "ixt/transforms");
310
+ // Copy the appropriate transform file
311
+ const sourceFile = path.join(examplesDir, `${answers.stylingFramework}-transform.ts`);
312
+ const targetFile = path.join(transformsDir, `${answers.stylingFramework}-transform.ts`);
313
+ try {
314
+ const content = await fs.readFile(sourceFile, "utf-8");
315
+ await fs.writeFile(targetFile, content, "utf-8");
316
+ }
317
+ catch (error) {
318
+ console.warn(`Warning: Could not copy ${answers.stylingFramework}-transform.ts example file:`, error instanceof Error ? error.message : String(error));
319
+ }
320
+ }
File without changes