skeleton 1.0.1 → 4.0.0-next.24
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 +4 -16
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1136 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -33
- package/dist/index.d.mts +0 -6
- package/dist/index.mjs +0 -1164
package/dist/index.js
ADDED
|
@@ -0,0 +1,1136 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import child_process from "node:child_process";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { detect, resolveCommand } from "package-manager-detector";
|
|
5
|
+
import { atRule, comment, parse } from "postcss";
|
|
6
|
+
import { parse as parse$1 } from "node-html-parser";
|
|
7
|
+
import { nanoid } from "nanoid";
|
|
8
|
+
import { Node, Project } from "ts-morph";
|
|
9
|
+
import detectIndent from "detect-indent";
|
|
10
|
+
import { coerce, lt } from "semver";
|
|
11
|
+
import MagicString from "magic-string";
|
|
12
|
+
import { parse as parse$2 } from "svelte/compiler";
|
|
13
|
+
import { walk } from "zimmerframe";
|
|
14
|
+
import { intro, isCancel, log, multiselect, outro, spinner } from "@clack/prompts";
|
|
15
|
+
import getLatestVersion from "latest-version";
|
|
16
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
17
|
+
import { dirname, extname, join } from "node:path";
|
|
18
|
+
import { glob } from "tinyglobby";
|
|
19
|
+
import { Argument, Command, Option } from "commander";
|
|
20
|
+
import { fileURLToPath } from "node:url";
|
|
21
|
+
import { bgBlueBright, bgGreenBright, black, dim, red } from "colorette";
|
|
22
|
+
|
|
23
|
+
//#region src/utility/install-dependencies.ts
|
|
24
|
+
const exec = promisify(child_process.exec);
|
|
25
|
+
async function installDependencies(cwd = process.cwd()) {
|
|
26
|
+
const pm = await detect({ cwd });
|
|
27
|
+
const resolvedCommand = resolveCommand(pm?.agent ?? "npm", "install", []);
|
|
28
|
+
if (!resolvedCommand) throw new Error("Could not resolve package manager command.");
|
|
29
|
+
return exec(`${resolvedCommand.command} ${resolvedCommand.args.join(" ")}`, { cwd });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/commands/migrate/migrations/skeleton-3/transformers/transform-classes.ts
|
|
34
|
+
const COLOR_PAIRING_REGEXES = [
|
|
35
|
+
{
|
|
36
|
+
find: /(\w+)-50-900-token\b/g,
|
|
37
|
+
replace: "$1-50-950"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
find: /(\w+)-100-800-token\b/g,
|
|
41
|
+
replace: "$1-100-900"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
find: /(\w+)-200-700-token\b/g,
|
|
45
|
+
replace: "$1-200-800"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
find: /(\w+)-300-600-token\b/g,
|
|
49
|
+
replace: "$1-300-700"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
find: /(\w+)-400-500-token\b/g,
|
|
53
|
+
replace: "$1-500"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
find: /(\w+)-900-50-token\b/g,
|
|
57
|
+
replace: "$1-950-50"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
find: /(\w+)-800-100-token\b/g,
|
|
61
|
+
replace: "$1-900-100"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
find: /(\w+)-700-200-token\b/g,
|
|
65
|
+
replace: "$1-800-200"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
find: /(\w+)-600-300-token\b/g,
|
|
69
|
+
replace: "$1-700-300"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
find: /(\w+)-500-400-token\b/g,
|
|
73
|
+
replace: "$1-600-400"
|
|
74
|
+
}
|
|
75
|
+
];
|
|
76
|
+
const BACKGROUND_REGEXES = [
|
|
77
|
+
{
|
|
78
|
+
find: /bg-(\w+)-backdrop-token\b/g,
|
|
79
|
+
replace: "bg-$1-50/50 dark:bg-$1-950/50"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
find: /bg-(\w+)-hover-token\b/g,
|
|
83
|
+
replace: "preset-tonal-$1"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
find: /bg-(\w+)-active-token\b/g,
|
|
87
|
+
replace: "preset-filled-$1-500"
|
|
88
|
+
}
|
|
89
|
+
];
|
|
90
|
+
const BORDER_RADIUS_REGEXES = [
|
|
91
|
+
{
|
|
92
|
+
find: /rounded-token\b/g,
|
|
93
|
+
replace: "rounded-base"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
find: /rounded-(tl|tr|bl|br)-token\b/g,
|
|
97
|
+
replace: "rounded-$1-base"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
find: /rounded-container-token\b/g,
|
|
101
|
+
replace: "rounded-container"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
find: /rounded-(tl|tr|bl|br)-container-token\b/g,
|
|
105
|
+
replace: "rounded-$1-container"
|
|
106
|
+
}
|
|
107
|
+
];
|
|
108
|
+
const BORDER_RING_REGEXES = [
|
|
109
|
+
{
|
|
110
|
+
find: /border-token\b/g,
|
|
111
|
+
replace: "border"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
find: /border-(\w+)-(\d+)-(\d+)-token\b/g,
|
|
115
|
+
replace: "border-$1-$2-$3"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
find: /ring-token\b/g,
|
|
119
|
+
replace: "ring"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
find: /ring-(\w+)-(\d+)-(\d+)-token\b/g,
|
|
123
|
+
replace: "ring-$1-$2-$3"
|
|
124
|
+
}
|
|
125
|
+
];
|
|
126
|
+
const TEXT_REGEXES = [
|
|
127
|
+
{
|
|
128
|
+
find: /font-headings-token\b/g,
|
|
129
|
+
replace: "heading-font-family"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
find: /font-token\b/g,
|
|
133
|
+
replace: "base-font-family"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
find: /text-token\b/g,
|
|
137
|
+
replace: "base-font-color"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
find: /text-on-(\w+)-token\b/g,
|
|
141
|
+
replace: "text-$1-contrast-500"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
find: /text-(\w+)-([^-]+)-([^-]+)-token\b/g,
|
|
145
|
+
replace: "text-$1-$2-$3"
|
|
146
|
+
}
|
|
147
|
+
];
|
|
148
|
+
const DECORATION_ACCENT_REGEXES = [{
|
|
149
|
+
find: /decoration-(\w+)-([^-]+)-([^-]+)-token\b/g,
|
|
150
|
+
replace: "decoration-$1-$2-$3"
|
|
151
|
+
}, {
|
|
152
|
+
find: /accent-(\w+)-token\b/g,
|
|
153
|
+
replace: "accent-$1-500"
|
|
154
|
+
}];
|
|
155
|
+
const PRESET_REGEXES = [
|
|
156
|
+
{
|
|
157
|
+
find: /variant-filled-(\w+)\b/g,
|
|
158
|
+
replace: "preset-filled-$1-500"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
find: /variant-filled\b/g,
|
|
162
|
+
replace: "preset-filled"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
find: /variant-ghost-(\w+)\b/g,
|
|
166
|
+
replace: "preset-tonal-$1 border border-$1-500"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
find: /variant-ghost\b/g,
|
|
170
|
+
replace: "preset-tonal border border-surface-500"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
find: /variant-soft-(\w+)\b/g,
|
|
174
|
+
replace: "preset-tonal-$1"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
find: /variant-soft\b/g,
|
|
178
|
+
replace: "preset-tonal"
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
find: /variant-ringed-(\w+)\b/g,
|
|
182
|
+
replace: "preset-outlined-$1-500"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
find: /variant-ringed\b/g,
|
|
186
|
+
replace: "preset-outlined"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
find: /variant-glass-(\w+)\b/g,
|
|
190
|
+
replace: "preset-tonal-$1"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
find: /variant-glass\b/g,
|
|
194
|
+
replace: "preset-tonal"
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
find: /variant-gradient-(\w+)-(\w+)\b/g,
|
|
198
|
+
replace: "from-$1-500 to-$2-500"
|
|
199
|
+
}
|
|
200
|
+
];
|
|
201
|
+
const TAILWIND_COMPONENT_REGEXES = [
|
|
202
|
+
(
|
|
203
|
+
/**
|
|
204
|
+
* Disabled until further discussion
|
|
205
|
+
* @see https://github.com/skeletonlabs/skeleton/pull/2972#discussion_r1857260763
|
|
206
|
+
*/
|
|
207
|
+
{
|
|
208
|
+
find: /btn-xl\b/g,
|
|
209
|
+
replace: "btn-lg"
|
|
210
|
+
}),
|
|
211
|
+
{
|
|
212
|
+
find: /btn-icon-xl\b/g,
|
|
213
|
+
replace: "btn-icon-lg"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
find: /btn-group\b/g,
|
|
217
|
+
replace: ""
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
find: /table-hover\b/g,
|
|
221
|
+
replace: ""
|
|
222
|
+
}
|
|
223
|
+
];
|
|
224
|
+
const CLASS_REGEXES = [
|
|
225
|
+
...COLOR_PAIRING_REGEXES,
|
|
226
|
+
...BACKGROUND_REGEXES,
|
|
227
|
+
...BORDER_RADIUS_REGEXES,
|
|
228
|
+
...BORDER_RING_REGEXES,
|
|
229
|
+
...TEXT_REGEXES,
|
|
230
|
+
...DECORATION_ACCENT_REGEXES,
|
|
231
|
+
...PRESET_REGEXES,
|
|
232
|
+
...TAILWIND_COMPONENT_REGEXES
|
|
233
|
+
];
|
|
234
|
+
function transformClasses(code) {
|
|
235
|
+
return { code: CLASS_REGEXES.reduce((result, migration) => {
|
|
236
|
+
return result.replace(migration.find, migration.replace);
|
|
237
|
+
}, code) };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/commands/migrate/migrations/skeleton-3/transformers/transform-stylesheet.ts
|
|
242
|
+
function transformStyleSheet(code) {
|
|
243
|
+
const parsed = parse(code);
|
|
244
|
+
parsed.walkAtRules("apply", (atRule$1) => {
|
|
245
|
+
atRule$1.params = transformClasses(atRule$1.params).code;
|
|
246
|
+
});
|
|
247
|
+
return { code: parsed.toString() };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/commands/migrate/migrations/skeleton-3/transformers/transform-app.css.ts
|
|
252
|
+
function getTailwindImport(root) {
|
|
253
|
+
let tailwindImport;
|
|
254
|
+
root.walkAtRules("import", (atRule$1) => {
|
|
255
|
+
if (atRule$1.params.includes("tailwindcss")) tailwindImport = atRule$1;
|
|
256
|
+
});
|
|
257
|
+
return tailwindImport;
|
|
258
|
+
}
|
|
259
|
+
function transformAppCss(code, theme) {
|
|
260
|
+
code = transformStyleSheet(code).code;
|
|
261
|
+
const root = parse(code);
|
|
262
|
+
const nodes = [];
|
|
263
|
+
nodes.push(atRule({
|
|
264
|
+
name: "import",
|
|
265
|
+
params: "\"@skeletonlabs/skeleton\""
|
|
266
|
+
}));
|
|
267
|
+
nodes.push(atRule({
|
|
268
|
+
name: "import",
|
|
269
|
+
params: "\"@skeletonlabs/skeleton/optional/presets\""
|
|
270
|
+
}));
|
|
271
|
+
switch (theme.type) {
|
|
272
|
+
case "preset":
|
|
273
|
+
nodes.push(atRule({
|
|
274
|
+
name: "import",
|
|
275
|
+
params: `"@skeletonlabs/skeleton/themes/${theme.value}"`
|
|
276
|
+
}));
|
|
277
|
+
break;
|
|
278
|
+
case "custom":
|
|
279
|
+
nodes.push(comment({ text: `Add your theme import for your theme: "${theme.value}" here` }));
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
const tailwindImport = getTailwindImport(root);
|
|
283
|
+
if (tailwindImport) root.insertAfter(tailwindImport, nodes);
|
|
284
|
+
else root.prepend(nodes);
|
|
285
|
+
return { code: root.toString() };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/commands/migrate/migrations/skeleton-3/utility/theme-mappings.ts
|
|
290
|
+
const THEME_MAPPINGS = {
|
|
291
|
+
skeleton: {
|
|
292
|
+
type: "preset",
|
|
293
|
+
value: "legacy"
|
|
294
|
+
},
|
|
295
|
+
"gold-nouveau": {
|
|
296
|
+
type: "preset",
|
|
297
|
+
value: "nouveau"
|
|
298
|
+
},
|
|
299
|
+
wintry: {
|
|
300
|
+
type: "preset",
|
|
301
|
+
value: "wintry"
|
|
302
|
+
},
|
|
303
|
+
modern: {
|
|
304
|
+
type: "preset",
|
|
305
|
+
value: "modern"
|
|
306
|
+
},
|
|
307
|
+
rocket: {
|
|
308
|
+
type: "preset",
|
|
309
|
+
value: "rocket"
|
|
310
|
+
},
|
|
311
|
+
seafoam: {
|
|
312
|
+
type: "preset",
|
|
313
|
+
value: "seafoam"
|
|
314
|
+
},
|
|
315
|
+
vintage: {
|
|
316
|
+
type: "preset",
|
|
317
|
+
value: "vintage"
|
|
318
|
+
},
|
|
319
|
+
sahara: {
|
|
320
|
+
type: "preset",
|
|
321
|
+
value: "sahara"
|
|
322
|
+
},
|
|
323
|
+
hamlindigo: {
|
|
324
|
+
type: "preset",
|
|
325
|
+
value: "hamlindigo"
|
|
326
|
+
},
|
|
327
|
+
crimson: {
|
|
328
|
+
type: "preset",
|
|
329
|
+
value: "crimson"
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/commands/migrate/migrations/skeleton-3/transformers/transform-app.html.ts
|
|
335
|
+
function transformAppHtml(code) {
|
|
336
|
+
const parsed = parse$1(code);
|
|
337
|
+
const html = parsed.querySelector("html");
|
|
338
|
+
const body = parsed.querySelector("body");
|
|
339
|
+
if (!(html && body)) return {
|
|
340
|
+
code,
|
|
341
|
+
meta: { theme: void 0 }
|
|
342
|
+
};
|
|
343
|
+
const theme = body.getAttribute("data-theme");
|
|
344
|
+
if (!theme) return {
|
|
345
|
+
code,
|
|
346
|
+
meta: { theme: void 0 }
|
|
347
|
+
};
|
|
348
|
+
let type;
|
|
349
|
+
body.removeAttribute("data-theme");
|
|
350
|
+
if (Object.hasOwn(THEME_MAPPINGS, theme)) {
|
|
351
|
+
html.setAttribute("data-theme", THEME_MAPPINGS[theme].value);
|
|
352
|
+
type = "preset";
|
|
353
|
+
} else {
|
|
354
|
+
html.setAttribute("data-theme", theme);
|
|
355
|
+
type = "custom";
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
code: parsed.toString(),
|
|
359
|
+
meta: { theme: {
|
|
360
|
+
value: theme,
|
|
361
|
+
type
|
|
362
|
+
} }
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/utility/ts-morph/add-named-import.ts
|
|
368
|
+
function addNamedImport(file, specifier, name) {
|
|
369
|
+
const existingImportDeclaration = file.getImportDeclaration((importDeclaration) => {
|
|
370
|
+
return importDeclaration.getModuleSpecifier().getLiteralText() === specifier;
|
|
371
|
+
});
|
|
372
|
+
if (existingImportDeclaration) {
|
|
373
|
+
if (!existingImportDeclaration.getNamedImports().some((namedImport) => namedImport.getName() === name)) existingImportDeclaration.addNamedImport(name);
|
|
374
|
+
} else file.addImportDeclaration({
|
|
375
|
+
moduleSpecifier: specifier,
|
|
376
|
+
namedImports: [name]
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/utility/ts-morph/parse-source-file.ts
|
|
382
|
+
const project = new Project({
|
|
383
|
+
useInMemoryFileSystem: true,
|
|
384
|
+
skipAddingFilesFromTsConfig: true,
|
|
385
|
+
skipFileDependencyResolution: true,
|
|
386
|
+
skipLoadingLibFiles: true
|
|
387
|
+
});
|
|
388
|
+
function parseSourceFile(code) {
|
|
389
|
+
return project.createSourceFile(`${nanoid()}.ts`, code);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
//#endregion
|
|
393
|
+
//#region src/commands/migrate/migrations/skeleton-3/utility/export-mappings.ts
|
|
394
|
+
const EXPORT_MAPPINGS = {
|
|
395
|
+
AccordionItem: {
|
|
396
|
+
namedImport: {
|
|
397
|
+
type: "renamed",
|
|
398
|
+
value: "Accordion"
|
|
399
|
+
},
|
|
400
|
+
identifier: {
|
|
401
|
+
type: "renamed",
|
|
402
|
+
value: "Accordion.Item"
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
AppShell: {
|
|
406
|
+
namedImport: { type: "removed" },
|
|
407
|
+
identifier: { type: "removed" }
|
|
408
|
+
},
|
|
409
|
+
Apollo: {
|
|
410
|
+
namedImport: { type: "removed" },
|
|
411
|
+
identifier: { type: "removed" }
|
|
412
|
+
},
|
|
413
|
+
AppRailAnchor: {
|
|
414
|
+
namedImport: { type: "removed" },
|
|
415
|
+
identifier: { type: "removed" }
|
|
416
|
+
},
|
|
417
|
+
Autocomplete: {
|
|
418
|
+
namedImport: { type: "removed" },
|
|
419
|
+
identifier: { type: "removed" }
|
|
420
|
+
},
|
|
421
|
+
BlueNight: {
|
|
422
|
+
namedImport: { type: "removed" },
|
|
423
|
+
identifier: { type: "removed" }
|
|
424
|
+
},
|
|
425
|
+
CodeBlock: {
|
|
426
|
+
namedImport: { type: "removed" },
|
|
427
|
+
identifier: { type: "removed" }
|
|
428
|
+
},
|
|
429
|
+
ConicGradient: {
|
|
430
|
+
namedImport: { type: "removed" },
|
|
431
|
+
identifier: { type: "removed" }
|
|
432
|
+
},
|
|
433
|
+
Drawer: {
|
|
434
|
+
namedImport: { type: "removed" },
|
|
435
|
+
identifier: { type: "removed" }
|
|
436
|
+
},
|
|
437
|
+
Emerald: {
|
|
438
|
+
namedImport: { type: "removed" },
|
|
439
|
+
identifier: { type: "removed" }
|
|
440
|
+
},
|
|
441
|
+
GreenFall: {
|
|
442
|
+
namedImport: { type: "removed" },
|
|
443
|
+
identifier: { type: "removed" }
|
|
444
|
+
},
|
|
445
|
+
LightSwitch: {
|
|
446
|
+
namedImport: { type: "removed" },
|
|
447
|
+
identifier: { type: "removed" }
|
|
448
|
+
},
|
|
449
|
+
ListBox: {
|
|
450
|
+
namedImport: { type: "removed" },
|
|
451
|
+
identifier: { type: "removed" }
|
|
452
|
+
},
|
|
453
|
+
ListBoxItem: {
|
|
454
|
+
namedImport: { type: "removed" },
|
|
455
|
+
identifier: { type: "removed" }
|
|
456
|
+
},
|
|
457
|
+
Modal: {
|
|
458
|
+
namedImport: { type: "removed" },
|
|
459
|
+
identifier: { type: "removed" }
|
|
460
|
+
},
|
|
461
|
+
Noir: {
|
|
462
|
+
namedImport: { type: "removed" },
|
|
463
|
+
identifier: { type: "removed" }
|
|
464
|
+
},
|
|
465
|
+
NoirLight: {
|
|
466
|
+
namedImport: { type: "removed" },
|
|
467
|
+
identifier: { type: "removed" }
|
|
468
|
+
},
|
|
469
|
+
RecursiveTreeView: {
|
|
470
|
+
namedImport: { type: "removed" },
|
|
471
|
+
identifier: { type: "removed" }
|
|
472
|
+
},
|
|
473
|
+
RecursiveTreeViewItem: {
|
|
474
|
+
namedImport: { type: "removed" },
|
|
475
|
+
identifier: { type: "removed" }
|
|
476
|
+
},
|
|
477
|
+
Rustic: {
|
|
478
|
+
namedImport: { type: "removed" },
|
|
479
|
+
identifier: { type: "removed" }
|
|
480
|
+
},
|
|
481
|
+
Step: {
|
|
482
|
+
namedImport: { type: "removed" },
|
|
483
|
+
identifier: { type: "removed" }
|
|
484
|
+
},
|
|
485
|
+
Stepper: {
|
|
486
|
+
namedImport: { type: "removed" },
|
|
487
|
+
identifier: { type: "removed" }
|
|
488
|
+
},
|
|
489
|
+
Summer84: {
|
|
490
|
+
namedImport: { type: "removed" },
|
|
491
|
+
identifier: { type: "removed" }
|
|
492
|
+
},
|
|
493
|
+
Table: {
|
|
494
|
+
namedImport: { type: "removed" },
|
|
495
|
+
identifier: { type: "removed" }
|
|
496
|
+
},
|
|
497
|
+
TableOfContents: {
|
|
498
|
+
namedImport: { type: "removed" },
|
|
499
|
+
identifier: { type: "removed" }
|
|
500
|
+
},
|
|
501
|
+
TreeView: {
|
|
502
|
+
namedImport: { type: "removed" },
|
|
503
|
+
identifier: { type: "removed" }
|
|
504
|
+
},
|
|
505
|
+
TreeViewItem: {
|
|
506
|
+
namedImport: { type: "removed" },
|
|
507
|
+
identifier: { type: "removed" }
|
|
508
|
+
},
|
|
509
|
+
XPro: {
|
|
510
|
+
namedImport: { type: "removed" },
|
|
511
|
+
identifier: { type: "removed" }
|
|
512
|
+
},
|
|
513
|
+
autoModeWatcher: {
|
|
514
|
+
namedImport: { type: "removed" },
|
|
515
|
+
identifier: { type: "removed" }
|
|
516
|
+
},
|
|
517
|
+
clipboard: {
|
|
518
|
+
namedImport: { type: "removed" },
|
|
519
|
+
identifier: { type: "removed" }
|
|
520
|
+
},
|
|
521
|
+
filter: {
|
|
522
|
+
namedImport: { type: "removed" },
|
|
523
|
+
identifier: { type: "removed" }
|
|
524
|
+
},
|
|
525
|
+
focusTrap: {
|
|
526
|
+
namedImport: { type: "removed" },
|
|
527
|
+
identifier: { type: "removed" }
|
|
528
|
+
},
|
|
529
|
+
getDrawerStore: {
|
|
530
|
+
namedImport: { type: "removed" },
|
|
531
|
+
identifier: { type: "removed" }
|
|
532
|
+
},
|
|
533
|
+
getModalStore: {
|
|
534
|
+
namedImport: { type: "removed" },
|
|
535
|
+
identifier: { type: "removed" }
|
|
536
|
+
},
|
|
537
|
+
getModeAutoPrefers: {
|
|
538
|
+
namedImport: { type: "removed" },
|
|
539
|
+
identifier: { type: "removed" }
|
|
540
|
+
},
|
|
541
|
+
getModeOsPrefers: {
|
|
542
|
+
namedImport: { type: "removed" },
|
|
543
|
+
identifier: { type: "removed" }
|
|
544
|
+
},
|
|
545
|
+
getModeUserPrefers: {
|
|
546
|
+
namedImport: { type: "removed" },
|
|
547
|
+
identifier: { type: "removed" }
|
|
548
|
+
},
|
|
549
|
+
getToastStore: {
|
|
550
|
+
namedImport: { type: "removed" },
|
|
551
|
+
identifier: { type: "removed" }
|
|
552
|
+
},
|
|
553
|
+
initializeStores: {
|
|
554
|
+
namedImport: { type: "removed" },
|
|
555
|
+
identifier: { type: "removed" }
|
|
556
|
+
},
|
|
557
|
+
localStorageStore: {
|
|
558
|
+
namedImport: { type: "removed" },
|
|
559
|
+
identifier: { type: "removed" }
|
|
560
|
+
},
|
|
561
|
+
modeCurrent: {
|
|
562
|
+
namedImport: { type: "removed" },
|
|
563
|
+
identifier: { type: "removed" }
|
|
564
|
+
},
|
|
565
|
+
modeOsPrefers: {
|
|
566
|
+
namedImport: { type: "removed" },
|
|
567
|
+
identifier: { type: "removed" }
|
|
568
|
+
},
|
|
569
|
+
modeUserPrefers: {
|
|
570
|
+
namedImport: { type: "removed" },
|
|
571
|
+
identifier: { type: "removed" }
|
|
572
|
+
},
|
|
573
|
+
popup: {
|
|
574
|
+
namedImport: { type: "removed" },
|
|
575
|
+
identifier: { type: "removed" }
|
|
576
|
+
},
|
|
577
|
+
prefersReducedMotionStore: {
|
|
578
|
+
namedImport: { type: "removed" },
|
|
579
|
+
identifier: { type: "removed" }
|
|
580
|
+
},
|
|
581
|
+
setInitialClassState: {
|
|
582
|
+
namedImport: { type: "removed" },
|
|
583
|
+
identifier: { type: "removed" }
|
|
584
|
+
},
|
|
585
|
+
setModeCurrent: {
|
|
586
|
+
namedImport: { type: "removed" },
|
|
587
|
+
identifier: { type: "removed" }
|
|
588
|
+
},
|
|
589
|
+
setModeUserPrefers: {
|
|
590
|
+
namedImport: { type: "removed" },
|
|
591
|
+
identifier: { type: "removed" }
|
|
592
|
+
},
|
|
593
|
+
storeHighlightJs: {
|
|
594
|
+
namedImport: { type: "removed" },
|
|
595
|
+
identifier: { type: "removed" }
|
|
596
|
+
},
|
|
597
|
+
storePopup: {
|
|
598
|
+
namedImport: { type: "removed" },
|
|
599
|
+
identifier: { type: "removed" }
|
|
600
|
+
},
|
|
601
|
+
tableMapperValues: {
|
|
602
|
+
namedImport: { type: "removed" },
|
|
603
|
+
identifier: { type: "removed" }
|
|
604
|
+
},
|
|
605
|
+
tableSourceMapper: {
|
|
606
|
+
namedImport: { type: "removed" },
|
|
607
|
+
identifier: { type: "removed" }
|
|
608
|
+
},
|
|
609
|
+
tableSourceValues: {
|
|
610
|
+
namedImport: { type: "removed" },
|
|
611
|
+
identifier: { type: "removed" }
|
|
612
|
+
},
|
|
613
|
+
tocCrawler: {
|
|
614
|
+
namedImport: { type: "removed" },
|
|
615
|
+
identifier: { type: "removed" }
|
|
616
|
+
},
|
|
617
|
+
tocStore: {
|
|
618
|
+
namedImport: { type: "removed" },
|
|
619
|
+
identifier: { type: "removed" }
|
|
620
|
+
},
|
|
621
|
+
AppRail: {
|
|
622
|
+
namedImport: {
|
|
623
|
+
type: "renamed",
|
|
624
|
+
value: "Navigation"
|
|
625
|
+
},
|
|
626
|
+
identifier: {
|
|
627
|
+
type: "renamed",
|
|
628
|
+
value: "Navigation"
|
|
629
|
+
}
|
|
630
|
+
},
|
|
631
|
+
AppRailTile: {
|
|
632
|
+
namedImport: {
|
|
633
|
+
type: "renamed",
|
|
634
|
+
value: "Navigation"
|
|
635
|
+
},
|
|
636
|
+
identifier: {
|
|
637
|
+
type: "renamed",
|
|
638
|
+
value: "Navigation.Tile"
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
FileButton: {
|
|
642
|
+
namedImport: {
|
|
643
|
+
type: "renamed",
|
|
644
|
+
value: "FileUpload"
|
|
645
|
+
},
|
|
646
|
+
identifier: {
|
|
647
|
+
type: "renamed",
|
|
648
|
+
value: "FileUpload"
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
FileDropzone: {
|
|
652
|
+
namedImport: {
|
|
653
|
+
type: "renamed",
|
|
654
|
+
value: "FileUpload"
|
|
655
|
+
},
|
|
656
|
+
identifier: {
|
|
657
|
+
type: "renamed",
|
|
658
|
+
value: "FileUpload"
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
InputChip: {
|
|
662
|
+
namedImport: {
|
|
663
|
+
type: "renamed",
|
|
664
|
+
value: "TagsInput"
|
|
665
|
+
},
|
|
666
|
+
identifier: {
|
|
667
|
+
type: "renamed",
|
|
668
|
+
value: "TagsInput"
|
|
669
|
+
}
|
|
670
|
+
},
|
|
671
|
+
Paginator: {
|
|
672
|
+
namedImport: {
|
|
673
|
+
type: "renamed",
|
|
674
|
+
value: "Pagination"
|
|
675
|
+
},
|
|
676
|
+
identifier: {
|
|
677
|
+
type: "renamed",
|
|
678
|
+
value: "Pagination"
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
ProgressBar: {
|
|
682
|
+
namedImport: {
|
|
683
|
+
type: "renamed",
|
|
684
|
+
value: "Progress"
|
|
685
|
+
},
|
|
686
|
+
identifier: {
|
|
687
|
+
type: "renamed",
|
|
688
|
+
value: "Progress"
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
ProgressRadial: {
|
|
692
|
+
namedImport: {
|
|
693
|
+
type: "renamed",
|
|
694
|
+
value: "ProgressRing"
|
|
695
|
+
},
|
|
696
|
+
identifier: {
|
|
697
|
+
type: "renamed",
|
|
698
|
+
value: "ProgressRing"
|
|
699
|
+
}
|
|
700
|
+
},
|
|
701
|
+
RadioGroup: {
|
|
702
|
+
namedImport: {
|
|
703
|
+
type: "renamed",
|
|
704
|
+
value: "Segment"
|
|
705
|
+
},
|
|
706
|
+
identifier: {
|
|
707
|
+
type: "renamed",
|
|
708
|
+
value: "Segment"
|
|
709
|
+
}
|
|
710
|
+
},
|
|
711
|
+
RadioItem: {
|
|
712
|
+
namedImport: {
|
|
713
|
+
type: "renamed",
|
|
714
|
+
value: "Segment"
|
|
715
|
+
},
|
|
716
|
+
identifier: {
|
|
717
|
+
type: "renamed",
|
|
718
|
+
value: "Segment.Item"
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
RangeSlider: {
|
|
722
|
+
namedImport: {
|
|
723
|
+
type: "renamed",
|
|
724
|
+
value: "Slider"
|
|
725
|
+
},
|
|
726
|
+
identifier: {
|
|
727
|
+
type: "renamed",
|
|
728
|
+
value: "Slider"
|
|
729
|
+
}
|
|
730
|
+
},
|
|
731
|
+
Ratings: {
|
|
732
|
+
namedImport: {
|
|
733
|
+
type: "renamed",
|
|
734
|
+
value: "Rating"
|
|
735
|
+
},
|
|
736
|
+
identifier: {
|
|
737
|
+
type: "renamed",
|
|
738
|
+
value: "Rating"
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
SlideToggle: {
|
|
742
|
+
namedImport: {
|
|
743
|
+
type: "renamed",
|
|
744
|
+
value: "Switch"
|
|
745
|
+
},
|
|
746
|
+
identifier: {
|
|
747
|
+
type: "renamed",
|
|
748
|
+
value: "Switch"
|
|
749
|
+
}
|
|
750
|
+
},
|
|
751
|
+
TabAnchor: {
|
|
752
|
+
namedImport: {
|
|
753
|
+
type: "renamed",
|
|
754
|
+
value: "Tabs"
|
|
755
|
+
},
|
|
756
|
+
identifier: {
|
|
757
|
+
type: "renamed",
|
|
758
|
+
value: "Tabs.Control"
|
|
759
|
+
}
|
|
760
|
+
},
|
|
761
|
+
TabGroup: {
|
|
762
|
+
namedImport: {
|
|
763
|
+
type: "renamed",
|
|
764
|
+
value: "Tabs"
|
|
765
|
+
},
|
|
766
|
+
identifier: {
|
|
767
|
+
type: "renamed",
|
|
768
|
+
value: "Tabs"
|
|
769
|
+
}
|
|
770
|
+
},
|
|
771
|
+
Toast: {
|
|
772
|
+
namedImport: {
|
|
773
|
+
type: "renamed",
|
|
774
|
+
value: "ToastProvider"
|
|
775
|
+
},
|
|
776
|
+
identifier: {
|
|
777
|
+
type: "renamed",
|
|
778
|
+
value: "ToastProvider"
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
//#endregion
|
|
784
|
+
//#region src/commands/migrate/migrations/skeleton-3/transformers/transform-module.ts
|
|
785
|
+
function transformModule(code) {
|
|
786
|
+
const file = parseSourceFile(code);
|
|
787
|
+
const skeletonImports = [];
|
|
788
|
+
file.forEachDescendant((node) => {
|
|
789
|
+
if (Node.isImportDeclaration(node)) {
|
|
790
|
+
if (node.getModuleSpecifier().getLiteralText() === "@skeletonlabs/skeleton") node.setModuleSpecifier("@skeletonlabs/skeleton-svelte");
|
|
791
|
+
}
|
|
792
|
+
if (Node.isImportSpecifier(node) && node.getImportDeclaration().getModuleSpecifier().getLiteralText() === "@skeletonlabs/skeleton-svelte") {
|
|
793
|
+
const name = node.getName();
|
|
794
|
+
if (Object.hasOwn(EXPORT_MAPPINGS, name)) {
|
|
795
|
+
const exportMapping = EXPORT_MAPPINGS[name];
|
|
796
|
+
switch (exportMapping?.namedImport.type) {
|
|
797
|
+
case "renamed":
|
|
798
|
+
if (exportMapping.namedImport.value.match(/^[A-Za-z]+\.[A-Za-z]+$/)) break;
|
|
799
|
+
node.remove();
|
|
800
|
+
addNamedImport(file, "@skeletonlabs/skeleton-svelte", exportMapping.namedImport.value);
|
|
801
|
+
break;
|
|
802
|
+
case "removed": {
|
|
803
|
+
const parent = node.getImportDeclaration();
|
|
804
|
+
if (parent.getNamedImports().length === 1 && !parent.getDefaultImport() && !parent.getNamespaceImport()) parent.remove();
|
|
805
|
+
else node.remove();
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
skeletonImports.push(name);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
file.forEachDescendant((node) => {
|
|
814
|
+
if (!node.wasForgotten() && Node.isIdentifier(node) && !Node.isImportSpecifier(node.getParent())) {
|
|
815
|
+
const name = node.getText();
|
|
816
|
+
if (Object.hasOwn(EXPORT_MAPPINGS, name) && skeletonImports.includes(name)) {
|
|
817
|
+
const exportMapping = EXPORT_MAPPINGS[name];
|
|
818
|
+
if (exportMapping?.identifier.type === "renamed") {
|
|
819
|
+
const updated = exportMapping.identifier.value;
|
|
820
|
+
if (updated !== node.getText()) node.replaceWithText(updated);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
if (!node.wasForgotten() && Node.isStringLiteral(node) && !Node.isImportDeclaration(node.getParent())) {
|
|
825
|
+
const transformed = transformClasses(node.getText()).code;
|
|
826
|
+
if (transformed !== node.getText()) node.replaceWithText(transformed);
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
return {
|
|
830
|
+
code: file.getFullText(),
|
|
831
|
+
meta: { skeletonImports }
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
//#endregion
|
|
836
|
+
//#region src/utility/sort-properties-alphabetically.ts
|
|
837
|
+
function sortPropertiesAlphabetically(object) {
|
|
838
|
+
const orderedObject = {};
|
|
839
|
+
const sortedEntries = Object.entries(object).sort(([a], [b]) => a.localeCompare(b));
|
|
840
|
+
for (const [key, value] of sortedEntries) orderedObject[key] = value;
|
|
841
|
+
return orderedObject;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
//#endregion
|
|
845
|
+
//#region src/commands/migrate/migrations/skeleton-3/transformers/transform-package.json.ts
|
|
846
|
+
function transformPackageJson(code, skeletonVersion, skeletonSvelteVersion) {
|
|
847
|
+
let isUsingComponents = false;
|
|
848
|
+
const pkg$1 = JSON.parse(code);
|
|
849
|
+
for (const field of ["dependencies", "devDependencies"]) {
|
|
850
|
+
if (!pkg$1[field]) continue;
|
|
851
|
+
const coerced = coerce(pkg$1[field]["@skeletonlabs/skeleton"]);
|
|
852
|
+
if (coerced && lt(coerced.version, "3.0.0")) {
|
|
853
|
+
isUsingComponents = true;
|
|
854
|
+
delete pkg$1[field]["@skeletonlabs/skeleton"];
|
|
855
|
+
pkg$1[field]["@skeletonlabs/skeleton-svelte"] = `^${skeletonSvelteVersion}`;
|
|
856
|
+
}
|
|
857
|
+
if (pkg$1[field]["@skeletonlabs/tw-plugin"]) {
|
|
858
|
+
delete pkg$1[field]["@skeletonlabs/tw-plugin"];
|
|
859
|
+
pkg$1[field]["@skeletonlabs/skeleton"] = `^${skeletonVersion}`;
|
|
860
|
+
}
|
|
861
|
+
pkg$1[field] = sortPropertiesAlphabetically(pkg$1[field]);
|
|
862
|
+
}
|
|
863
|
+
return {
|
|
864
|
+
code: JSON.stringify(pkg$1, void 0, detectIndent(code).indent || " "),
|
|
865
|
+
meta: { isUsingComponents }
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
//#endregion
|
|
870
|
+
//#region src/commands/migrate/migrations/skeleton-3/transformers/transform-svelte.ts
|
|
871
|
+
function renameComponent(s, node, name) {
|
|
872
|
+
const adjustedStart = node.start + 1;
|
|
873
|
+
s.update(adjustedStart, adjustedStart + node.name.length, name);
|
|
874
|
+
const indexOfNonSelfClosingTag = s.original.slice(node.start, node.end).lastIndexOf("</");
|
|
875
|
+
if (indexOfNonSelfClosingTag === -1 || node.start + indexOfNonSelfClosingTag > node.end) return;
|
|
876
|
+
s.update(node.start + indexOfNonSelfClosingTag + 2, node.start + indexOfNonSelfClosingTag + 2 + node.name.length, name);
|
|
877
|
+
}
|
|
878
|
+
function transformScript(s, script) {
|
|
879
|
+
if (!script || !("start" in script.content && typeof script.content.start === "number" && "end" in script.content && typeof script.content.end === "number")) return { meta: { skeletonImports: [] } };
|
|
880
|
+
const content = s.original.slice(script.content.start, script.content.end);
|
|
881
|
+
const transformed = transformModule(content);
|
|
882
|
+
s.overwrite(script.content.start, script.content.end, transformed.code);
|
|
883
|
+
return { meta: transformed.meta };
|
|
884
|
+
}
|
|
885
|
+
function transformCss(s, css) {
|
|
886
|
+
if (!css) return;
|
|
887
|
+
const transformed = transformStyleSheet(s.original.slice(css.content.start, css.content.end));
|
|
888
|
+
s.overwrite(css.content.start, css.content.end, transformed.code);
|
|
889
|
+
}
|
|
890
|
+
function hasRange(node) {
|
|
891
|
+
return "start" in node && "end" in node && typeof node.start === "number" && typeof node.end === "number";
|
|
892
|
+
}
|
|
893
|
+
function transformFragment(s, fragment, skeletonImports) {
|
|
894
|
+
walk(fragment, {}, {
|
|
895
|
+
Literal(node, ctx) {
|
|
896
|
+
const parent = ctx.path.at(-1);
|
|
897
|
+
if (typeof node.raw === "string" && node.raw !== "" && !(parent && parent.type === "ImportDeclaration") && hasRange(node)) s.update(node.start, node.end, transformClasses(node.raw).code);
|
|
898
|
+
ctx.next();
|
|
899
|
+
},
|
|
900
|
+
Text(node, ctx) {
|
|
901
|
+
if (node.data !== "" && hasRange(node)) s.update(node.start, node.end, transformClasses(node.data).code);
|
|
902
|
+
ctx.next();
|
|
903
|
+
},
|
|
904
|
+
ClassDirective(node, ctx) {
|
|
905
|
+
if (!(node.expression.type === "Identifier" && !("loc" in node.expression) && node.name === node.expression.name) && hasRange(node)) {
|
|
906
|
+
const adjustedStart = node.start + 6;
|
|
907
|
+
s.update(adjustedStart, adjustedStart + node.name.length, transformClasses(node.name).code);
|
|
908
|
+
}
|
|
909
|
+
ctx.next();
|
|
910
|
+
},
|
|
911
|
+
Component(node, ctx) {
|
|
912
|
+
if (Object.hasOwn(EXPORT_MAPPINGS, node.name) && skeletonImports.includes(node.name)) {
|
|
913
|
+
const exportMapping = EXPORT_MAPPINGS[node.name];
|
|
914
|
+
if (exportMapping?.identifier.type === "renamed" && hasRange(node)) renameComponent(s, node, exportMapping.identifier.value);
|
|
915
|
+
}
|
|
916
|
+
ctx.next();
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
return { code: s.toString() };
|
|
920
|
+
}
|
|
921
|
+
function transformSvelte(code) {
|
|
922
|
+
const s = new MagicString(code);
|
|
923
|
+
const root = parse$2(code, { modern: true });
|
|
924
|
+
const skeletonImports = [...transformScript(s, root.module).meta.skeletonImports, ...transformScript(s, root.instance).meta.skeletonImports];
|
|
925
|
+
transformFragment(s, root.fragment, skeletonImports);
|
|
926
|
+
transformCss(s, root.css);
|
|
927
|
+
return { code: s.toString() };
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
//#endregion
|
|
931
|
+
//#region src/commands/migrate/migrations/skeleton-3/utility/constants.ts
|
|
932
|
+
const FALLBACK_THEME = {
|
|
933
|
+
type: "preset",
|
|
934
|
+
value: "cerberus"
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region src/commands/migrate/migrations/skeleton-3/index.ts
|
|
939
|
+
async function skeleton_3_default(options) {
|
|
940
|
+
const cwd = options.cwd ?? process.cwd();
|
|
941
|
+
const migrations = [];
|
|
942
|
+
const packageJson = {
|
|
943
|
+
name: "package.json",
|
|
944
|
+
paths: await glob("package.json", { cwd })
|
|
945
|
+
};
|
|
946
|
+
const appHtml = {
|
|
947
|
+
name: "src/app.html",
|
|
948
|
+
paths: await glob("src/app.html", { cwd })
|
|
949
|
+
};
|
|
950
|
+
const appCss = {
|
|
951
|
+
name: "src/app.css",
|
|
952
|
+
paths: await glob("src/app.css", { cwd })
|
|
953
|
+
};
|
|
954
|
+
for (const file of [
|
|
955
|
+
packageJson,
|
|
956
|
+
appHtml,
|
|
957
|
+
appCss
|
|
958
|
+
]) {
|
|
959
|
+
if (file.paths.length === 0) cli.error(`"${file.name}" not found in directory "${cwd}".`);
|
|
960
|
+
if (file.paths.length > 1) cli.error(`Multiple "${file.name}" entries found in directory: "${cwd}", please ensure there is only one`);
|
|
961
|
+
}
|
|
962
|
+
const availableSourceFolders = await glob("*", {
|
|
963
|
+
cwd,
|
|
964
|
+
onlyDirectories: true,
|
|
965
|
+
ignore: ["node_modules"]
|
|
966
|
+
});
|
|
967
|
+
const sourceFolders = await multiselect({
|
|
968
|
+
message: "What folders make use of Skeleton? (classes, imports, etc.)",
|
|
969
|
+
options: availableSourceFolders.map((folder) => ({
|
|
970
|
+
label: folder,
|
|
971
|
+
value: folder
|
|
972
|
+
})),
|
|
973
|
+
initialValues: availableSourceFolders
|
|
974
|
+
});
|
|
975
|
+
if (isCancel(sourceFolders)) {
|
|
976
|
+
cli.error("Migration canceled, nothing written to disk");
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
const packageSpinner = spinner();
|
|
980
|
+
packageSpinner.start(`Migrating ${packageJson.name}...`);
|
|
981
|
+
try {
|
|
982
|
+
const packageJsonCode = await readFile(packageJson.paths.at(0), "utf8");
|
|
983
|
+
const skeletonVersion = await getLatestVersion("@skeletonlabs/skeleton", { version: ">=3.0.0-0 <4.0.0" });
|
|
984
|
+
const skeletonSvelteVersion = await getLatestVersion("@skeletonlabs/skeleton-svelte", { version: ">=1.0.0-0 <2.0.0" });
|
|
985
|
+
const transformedPackageJson = transformPackageJson(packageJsonCode, skeletonVersion, skeletonSvelteVersion);
|
|
986
|
+
migrations.push({
|
|
987
|
+
path: packageJson.paths.at(0),
|
|
988
|
+
content: transformedPackageJson.code
|
|
989
|
+
});
|
|
990
|
+
packageSpinner.stop(`Successfully migrated ${packageJson.name}!`);
|
|
991
|
+
} catch (error) {
|
|
992
|
+
packageSpinner.stop(`Failed to migrate ${packageJson.name}: ${error instanceof Error ? error.message : "Unknown error"}`, 1);
|
|
993
|
+
cli.error("Migration canceled, nothing written to disk");
|
|
994
|
+
}
|
|
995
|
+
let theme;
|
|
996
|
+
const appHtmlSpinner = spinner();
|
|
997
|
+
appHtmlSpinner.start(`Migrating ${appHtml.name}...`);
|
|
998
|
+
try {
|
|
999
|
+
const appHtmlCode = await readFile(appHtml.paths.at(0), "utf8");
|
|
1000
|
+
const transformedAppHtml = transformAppHtml(appHtmlCode);
|
|
1001
|
+
if (transformedAppHtml.meta.theme && Object.hasOwn(THEME_MAPPINGS, transformedAppHtml.meta.theme.value)) theme = THEME_MAPPINGS[transformedAppHtml.meta.theme.value];
|
|
1002
|
+
else if (transformedAppHtml.meta.theme) theme = transformedAppHtml.meta.theme;
|
|
1003
|
+
else theme = FALLBACK_THEME;
|
|
1004
|
+
migrations.push({
|
|
1005
|
+
path: appHtml.paths.at(0),
|
|
1006
|
+
content: transformedAppHtml.code
|
|
1007
|
+
});
|
|
1008
|
+
appHtmlSpinner.stop(`Successfully migrated ${appHtml.name}!`);
|
|
1009
|
+
} catch (error) {
|
|
1010
|
+
appHtmlSpinner.stop(`Failed to migrate ${appHtml.name}: ${error instanceof Error ? error.message : "Unknown error"}`, 1);
|
|
1011
|
+
cli.error("Migration canceled, nothing written to disk");
|
|
1012
|
+
}
|
|
1013
|
+
const appCssSpinner = spinner();
|
|
1014
|
+
appCssSpinner.start(`Migrating ${appCss.name}...`);
|
|
1015
|
+
try {
|
|
1016
|
+
const appCssCode = await readFile(appCss.paths.at(0), "utf8");
|
|
1017
|
+
const transformedAppCss = transformAppCss(appCssCode, theme ?? FALLBACK_THEME);
|
|
1018
|
+
migrations.push({
|
|
1019
|
+
path: appCss.paths.at(0),
|
|
1020
|
+
content: transformedAppCss.code
|
|
1021
|
+
});
|
|
1022
|
+
appCssSpinner.stop(`Successfully migrated ${appCss.name}!`);
|
|
1023
|
+
} catch (error) {
|
|
1024
|
+
appCssSpinner.stop(`Failed to migrate ${appCss.name}: ${error instanceof Error ? error.message : "Unknown error"}`, 1);
|
|
1025
|
+
cli.error("Migration canceled, nothing written to disk");
|
|
1026
|
+
}
|
|
1027
|
+
if (sourceFolders.length > 0) {
|
|
1028
|
+
const sourceFiles = await glob(sourceFolders.map((folder) => `${folder}**/*.{svelte,js,mjs,ts,mts,css,pcss,postcss}`), {
|
|
1029
|
+
cwd,
|
|
1030
|
+
ignore: ["node_modules", "src/app.css"]
|
|
1031
|
+
});
|
|
1032
|
+
const sourceFilesSpinner = spinner();
|
|
1033
|
+
sourceFilesSpinner.start(`Migrating source files...`);
|
|
1034
|
+
for (const sourceFile of sourceFiles) {
|
|
1035
|
+
sourceFilesSpinner.message(`Migrating ${sourceFile}...`);
|
|
1036
|
+
const extension = extname(sourceFile);
|
|
1037
|
+
try {
|
|
1038
|
+
const code = await readFile(sourceFile, "utf8");
|
|
1039
|
+
switch (extension) {
|
|
1040
|
+
case ".svelte": {
|
|
1041
|
+
const transformedSvelte = transformSvelte(code);
|
|
1042
|
+
migrations.push({
|
|
1043
|
+
path: sourceFile,
|
|
1044
|
+
content: transformedSvelte.code
|
|
1045
|
+
});
|
|
1046
|
+
break;
|
|
1047
|
+
}
|
|
1048
|
+
case ".js":
|
|
1049
|
+
case ".mjs":
|
|
1050
|
+
case ".ts":
|
|
1051
|
+
case ".mts": {
|
|
1052
|
+
const transformedModule = transformModule(code);
|
|
1053
|
+
migrations.push({
|
|
1054
|
+
path: sourceFile,
|
|
1055
|
+
content: transformedModule.code
|
|
1056
|
+
});
|
|
1057
|
+
break;
|
|
1058
|
+
}
|
|
1059
|
+
case ".css":
|
|
1060
|
+
case ".pcss":
|
|
1061
|
+
case ".postcss": {
|
|
1062
|
+
const transformedStyleSheet = transformStyleSheet(code);
|
|
1063
|
+
migrations.push({
|
|
1064
|
+
path: sourceFile,
|
|
1065
|
+
content: transformedStyleSheet.code
|
|
1066
|
+
});
|
|
1067
|
+
break;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
sourceFilesSpinner.message(`Successfully migrated ${sourceFile}!`);
|
|
1071
|
+
} catch (error) {
|
|
1072
|
+
sourceFilesSpinner.stop(`Failed to migrate ${sourceFile}: ${error instanceof Error ? error.message : "Unknown error"}`, 1);
|
|
1073
|
+
cli.error("Migration canceled, nothing written to disk");
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
sourceFilesSpinner.stop("Successfully migrated all source files!");
|
|
1077
|
+
}
|
|
1078
|
+
const writeSpinner = spinner();
|
|
1079
|
+
writeSpinner.start("Applying all migrations...");
|
|
1080
|
+
try {
|
|
1081
|
+
await Promise.all(migrations.map(({ path, content }) => writeFile(path, content)));
|
|
1082
|
+
writeSpinner.stop("Successfully applied all migrations!");
|
|
1083
|
+
} catch (error) {
|
|
1084
|
+
writeSpinner.stop(`Failed to apply migrations: ${error instanceof Error ? error.message.replace("\n", " ") : "Unknown error"}`, 1);
|
|
1085
|
+
cli.error("Migration canceled");
|
|
1086
|
+
}
|
|
1087
|
+
const installDependenciesSpinner = spinner();
|
|
1088
|
+
installDependenciesSpinner.start("Updating dependencies...");
|
|
1089
|
+
try {
|
|
1090
|
+
await installDependencies(cwd);
|
|
1091
|
+
installDependenciesSpinner.stop("Successfully updated dependencies!");
|
|
1092
|
+
} catch (error) {
|
|
1093
|
+
installDependenciesSpinner.stop(`Failed to update dependencies: ${error instanceof Error ? error.message : "Unknown error"}`, 1);
|
|
1094
|
+
cli.error("Migration canceled");
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
log.info("Migration complete! Visit https://skeleton.dev for more information.");
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
//#endregion
|
|
1101
|
+
//#region src/commands/migrate/index.ts
|
|
1102
|
+
const MIGRATIONS = { "skeleton-3": skeleton_3_default };
|
|
1103
|
+
const migrate = new Command("migrate").description("Run a migration").addArgument(new Argument("<migration>", "The migration to run").choices(Object.keys(MIGRATIONS))).addOption(new Option("--cwd <cwd>", "The directory to run the migration in")).action((migration, options) => MIGRATIONS[migration](options));
|
|
1104
|
+
|
|
1105
|
+
//#endregion
|
|
1106
|
+
//#region src/utility/get-our-package-json.ts
|
|
1107
|
+
async function getOurPackageJson() {
|
|
1108
|
+
const packageJsonPath = join(dirname(fileURLToPath(import.meta.url)), "../package.json");
|
|
1109
|
+
const content = await readFile(packageJsonPath, "utf8");
|
|
1110
|
+
return JSON.parse(content);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
//#endregion
|
|
1114
|
+
//#region src/index.ts
|
|
1115
|
+
const pkg = await getOurPackageJson();
|
|
1116
|
+
const cli = new Command().name(pkg.name).description(pkg.description).version(pkg.version).addCommand(migrate).copyInheritedSettings(migrate).configureOutput({
|
|
1117
|
+
writeOut: log.info,
|
|
1118
|
+
writeErr(str) {
|
|
1119
|
+
outro(red(str.replace("\n", " ")));
|
|
1120
|
+
process.exit(1);
|
|
1121
|
+
}
|
|
1122
|
+
}).hook("preAction", (_, ctx) => {
|
|
1123
|
+
const args = ctx.args.join(" ");
|
|
1124
|
+
log.message(dim(`Running "${`${ctx.name()}${args ? ` ${args}` : ""}`}"...`));
|
|
1125
|
+
});
|
|
1126
|
+
async function main() {
|
|
1127
|
+
intro(bgBlueBright(black(" Welcome to the Skeleton CLI 💀 ")));
|
|
1128
|
+
if (process.argv.length === 2) cli.error("error: no command provided");
|
|
1129
|
+
await cli.parseAsync(process.argv);
|
|
1130
|
+
outro(bgGreenBright(black(" All Done! ")));
|
|
1131
|
+
}
|
|
1132
|
+
await main();
|
|
1133
|
+
|
|
1134
|
+
//#endregion
|
|
1135
|
+
export { cli };
|
|
1136
|
+
//# sourceMappingURL=index.js.map
|