-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvelte.js
executable file
·81 lines (72 loc) · 1.77 KB
/
svelte.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env zx
import { create } from 'create-svelte';
import 'zx/globals';
/** @typedef {Parameters<typeof create>[1]} Options */
await $`rm -rf svelte`;
await $`mkdir -p svelte`;
cd('svelte');
const bool = [false, true];
const templates = [
// template
['default', 'skeleton', 'skeletonlib'],
// types
[null, 'checkjs', 'typescript'],
// prettier
bool,
// eslint
bool,
// playwright
bool,
// vitest
bool,
// svelte5
bool,
].reduce((acc, arr) => acc.flatMap(el => arr.map(val => [...el, val])), [[]]);
function properties([template, types, prettier, eslint, playwright, vitest, svelte5]) {
const path = [
template,
types && `-${types}`,
prettier && '-prettier',
eslint && '-eslint',
playwright && '-playwright',
vitest && '-vitest',
svelte5 && '-svelte5',
]
.filter(Boolean)
.join('');
const name = `svelte-${path}`;
/** @type {Options} */
const options = {
name,
template,
types,
prettier,
eslint,
playwright,
vitest,
svelte5,
};
return [path, options];
}
// non-parallel version
// const failed = [];
// for (const template of templates) {
// const [path, options] = properties(template);
// try {
// await create(path, options);
// } catch (e) {
// failed.push([path, options]);
// }
// }
const results = await Promise.allSettled(
templates.map(template => create(...properties(template))),
);
const failed = results
.map((result, i) => (result.status === 'rejected' ? properties(templates[i]) : null))
.filter(Boolean);
if (failed.length > 0) {
console.warn('Failed templates:');
console.warn(failed.map(([path]) => path).join(', '), '\n');
console.warn(failed.map(([path, options]) => `${path}: ${JSON.stringify(options)}`).join('\n\n'));
}
cd('..');