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