@quilted/create 0.1.13 → 0.1.14

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 (67) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/cjs/app.cjs +303 -0
  3. package/build/cjs/index.cjs +5220 -5198
  4. package/build/cjs/index2.cjs +374 -0
  5. package/build/cjs/index3.cjs +50060 -0
  6. package/build/cjs/index4.cjs +7854 -0
  7. package/build/cjs/minimatch.cjs +1202 -0
  8. package/build/cjs/package-manager.cjs +300 -0
  9. package/build/cjs/package.cjs +410 -0
  10. package/build/esm/app.mjs +280 -0
  11. package/build/esm/index.mjs +5206 -5195
  12. package/build/esm/index2.mjs +365 -0
  13. package/build/esm/index3.mjs +50047 -0
  14. package/build/esm/index4.mjs +7852 -0
  15. package/build/esm/minimatch.mjs +1200 -0
  16. package/build/esm/package-manager.mjs +270 -0
  17. package/build/esm/package.mjs +387 -0
  18. package/build/tsconfig.tsbuildinfo +1 -1
  19. package/build/typescript/app.d.ts +2 -0
  20. package/build/typescript/app.d.ts.map +1 -0
  21. package/build/typescript/help.d.ts +6 -0
  22. package/build/typescript/help.d.ts.map +1 -0
  23. package/build/typescript/package.d.ts +2 -0
  24. package/build/typescript/package.d.ts.map +1 -0
  25. package/build/typescript/shared/package-manager.d.ts +3 -0
  26. package/build/typescript/shared/package-manager.d.ts.map +1 -0
  27. package/build/typescript/shared/prompts.d.ts +22 -0
  28. package/build/typescript/shared/prompts.d.ts.map +1 -0
  29. package/build/typescript/shared/tsconfig.d.ts +3 -0
  30. package/build/typescript/shared/tsconfig.d.ts.map +1 -0
  31. package/build/typescript/shared.d.ts +21 -0
  32. package/build/typescript/shared.d.ts.map +1 -0
  33. package/package.json +13 -3
  34. package/source/app.ts +387 -0
  35. package/source/create.ts +43 -383
  36. package/source/help.ts +132 -0
  37. package/source/package.ts +510 -0
  38. package/source/shared/package-manager.ts +74 -0
  39. package/source/shared/prompts.ts +133 -0
  40. package/source/shared/tsconfig.ts +90 -0
  41. package/source/shared.ts +165 -0
  42. package/templates/{app → app-basic}/App.tsx +4 -7
  43. package/templates/{app → app-basic}/features/Start/Start.module.css +0 -0
  44. package/templates/{app → app-basic}/features/Start/Start.tsx +1 -1
  45. package/templates/{app → app-basic}/features/Start/index.ts +0 -0
  46. package/templates/{app → app-basic}/foundation/Head.tsx +8 -8
  47. package/templates/{app → app-basic}/foundation/Http.tsx +10 -6
  48. package/templates/{app → app-basic}/package.json +10 -1
  49. package/templates/{app → app-basic}/quilt.project.ts +0 -0
  50. package/templates/{app → app-basic}/server.tsx +0 -0
  51. package/templates/{app → app-basic}/shared/types.ts +0 -0
  52. package/templates/{app → app-basic}/tsconfig.json +0 -0
  53. package/templates/app-single-file/App.tsx +168 -0
  54. package/templates/app-single-file/package.json +30 -0
  55. package/templates/app-single-file/quilt.project.ts +6 -0
  56. package/templates/app-single-file/tsconfig.json +9 -0
  57. package/templates/{workspace → github}/_github/workflows/actions/prepare/action.yml +0 -0
  58. package/templates/{workspace → github}/_github/workflows/ci.yml +0 -0
  59. package/templates/package/package.json +24 -9
  60. package/templates/package/quilt.project.ts +1 -1
  61. package/templates/vscode/_vscode/extensions.json +7 -0
  62. package/templates/vscode/_vscode/settings.json +17 -0
  63. package/templates/workspace/_gitignore +1 -1
  64. package/templates/workspace/_prettierignore +1 -0
  65. package/templates/workspace/package.json +1 -7
  66. package/templates/workspace/tsconfig.json +6 -1
  67. package/templates/workspace/pnpm-workspace.yaml +0 -3
@@ -0,0 +1,365 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import process from 'node:process';
4
+ import fs, { promises } from 'node:fs';
5
+
6
+ /*
7
+ How it works:
8
+ `this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
9
+ */
10
+
11
+ class Node {
12
+ value;
13
+ next;
14
+
15
+ constructor(value) {
16
+ this.value = value;
17
+ }
18
+ }
19
+
20
+ class Queue {
21
+ #head;
22
+ #tail;
23
+ #size;
24
+
25
+ constructor() {
26
+ this.clear();
27
+ }
28
+
29
+ enqueue(value) {
30
+ const node = new Node(value);
31
+
32
+ if (this.#head) {
33
+ this.#tail.next = node;
34
+ this.#tail = node;
35
+ } else {
36
+ this.#head = node;
37
+ this.#tail = node;
38
+ }
39
+
40
+ this.#size++;
41
+ }
42
+
43
+ dequeue() {
44
+ const current = this.#head;
45
+ if (!current) {
46
+ return;
47
+ }
48
+
49
+ this.#head = this.#head.next;
50
+ this.#size--;
51
+ return current.value;
52
+ }
53
+
54
+ clear() {
55
+ this.#head = undefined;
56
+ this.#tail = undefined;
57
+ this.#size = 0;
58
+ }
59
+
60
+ get size() {
61
+ return this.#size;
62
+ }
63
+
64
+ * [Symbol.iterator]() {
65
+ let current = this.#head;
66
+
67
+ while (current) {
68
+ yield current.value;
69
+ current = current.next;
70
+ }
71
+ }
72
+ }
73
+
74
+ function pLimit(concurrency) {
75
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
76
+ throw new TypeError('Expected `concurrency` to be a number from 1 and up');
77
+ }
78
+
79
+ const queue = new Queue();
80
+ let activeCount = 0;
81
+
82
+ const next = () => {
83
+ activeCount--;
84
+
85
+ if (queue.size > 0) {
86
+ queue.dequeue()();
87
+ }
88
+ };
89
+
90
+ const run = async (fn, resolve, args) => {
91
+ activeCount++;
92
+
93
+ const result = (async () => fn(...args))();
94
+
95
+ resolve(result);
96
+
97
+ try {
98
+ await result;
99
+ } catch {}
100
+
101
+ next();
102
+ };
103
+
104
+ const enqueue = (fn, resolve, args) => {
105
+ queue.enqueue(run.bind(undefined, fn, resolve, args));
106
+
107
+ (async () => {
108
+ // This function needs to wait until the next microtask before comparing
109
+ // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
110
+ // when the run function is dequeued and called. The comparison in the if-statement
111
+ // needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
112
+ await Promise.resolve();
113
+
114
+ if (activeCount < concurrency && queue.size > 0) {
115
+ queue.dequeue()();
116
+ }
117
+ })();
118
+ };
119
+
120
+ const generator = (fn, ...args) => new Promise(resolve => {
121
+ enqueue(fn, resolve, args);
122
+ });
123
+
124
+ Object.defineProperties(generator, {
125
+ activeCount: {
126
+ get: () => activeCount,
127
+ },
128
+ pendingCount: {
129
+ get: () => queue.size,
130
+ },
131
+ clearQueue: {
132
+ value: () => {
133
+ queue.clear();
134
+ },
135
+ },
136
+ });
137
+
138
+ return generator;
139
+ }
140
+
141
+ class EndError extends Error {
142
+ constructor(value) {
143
+ super();
144
+ this.value = value;
145
+ }
146
+ }
147
+
148
+ // The input can also be a promise, so we await it.
149
+ const testElement = async (element, tester) => tester(await element);
150
+
151
+ // The input can also be a promise, so we `Promise.all()` them both.
152
+ const finder = async element => {
153
+ const values = await Promise.all(element);
154
+ if (values[1] === true) {
155
+ throw new EndError(values[0]);
156
+ }
157
+
158
+ return false;
159
+ };
160
+
161
+ async function pLocate(
162
+ iterable,
163
+ tester,
164
+ {
165
+ concurrency = Number.POSITIVE_INFINITY,
166
+ preserveOrder = true,
167
+ },
168
+ ) {
169
+ const limit = pLimit(concurrency);
170
+
171
+ // Start all the promises concurrently with optional limit.
172
+ const items = [...iterable].map(element => [element, limit(testElement, element, tester)]);
173
+
174
+ // Check the promises either serially or concurrently.
175
+ const checkLimit = pLimit(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
176
+
177
+ try {
178
+ await Promise.all(items.map(element => checkLimit(finder, element)));
179
+ } catch (error) {
180
+ if (error instanceof EndError) {
181
+ return error.value;
182
+ }
183
+
184
+ throw error;
185
+ }
186
+ }
187
+
188
+ const typeMappings = {
189
+ directory: 'isDirectory',
190
+ file: 'isFile',
191
+ };
192
+
193
+ function checkType(type) {
194
+ if (type in typeMappings) {
195
+ return;
196
+ }
197
+
198
+ throw new Error(`Invalid type specified: ${type}`);
199
+ }
200
+
201
+ const matchType = (type, stat) => type === undefined || stat[typeMappings[type]]();
202
+
203
+ const toPath$1 = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
204
+
205
+ async function locatePath(
206
+ paths,
207
+ {
208
+ cwd = process.cwd(),
209
+ type = 'file',
210
+ allowSymlinks = true,
211
+ concurrency,
212
+ preserveOrder,
213
+ } = {},
214
+ ) {
215
+ checkType(type);
216
+ cwd = toPath$1(cwd);
217
+
218
+ const statFunction = allowSymlinks ? promises.stat : promises.lstat;
219
+
220
+ return pLocate(paths, async path_ => {
221
+ try {
222
+ const stat = await statFunction(path.resolve(cwd, path_));
223
+ return matchType(type, stat);
224
+ } catch {
225
+ return false;
226
+ }
227
+ }, {concurrency, preserveOrder});
228
+ }
229
+
230
+ function locatePathSync(
231
+ paths,
232
+ {
233
+ cwd = process.cwd(),
234
+ type = 'file',
235
+ allowSymlinks = true,
236
+ } = {},
237
+ ) {
238
+ checkType(type);
239
+ cwd = toPath$1(cwd);
240
+
241
+ const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
242
+
243
+ for (const path_ of paths) {
244
+ try {
245
+ const stat = statFunction(path.resolve(cwd, path_));
246
+
247
+ if (matchType(type, stat)) {
248
+ return path_;
249
+ }
250
+ } catch {}
251
+ }
252
+ }
253
+
254
+ const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
255
+
256
+ const findUpStop = Symbol('findUpStop');
257
+
258
+ async function findUpMultiple(name, options) {
259
+ let directory = path.resolve(toPath(options.cwd) || '');
260
+ const {root} = path.parse(directory);
261
+ const stopAt = path.resolve(directory, options.stopAt || root);
262
+ const limit = options.limit || Number.POSITIVE_INFINITY;
263
+ const paths = [name].flat();
264
+
265
+ const runMatcher = async locateOptions => {
266
+ if (typeof name !== 'function') {
267
+ return locatePath(paths, locateOptions);
268
+ }
269
+
270
+ const foundPath = await name(locateOptions.cwd);
271
+ if (typeof foundPath === 'string') {
272
+ return locatePath([foundPath], locateOptions);
273
+ }
274
+
275
+ return foundPath;
276
+ };
277
+
278
+ const matches = [];
279
+ // eslint-disable-next-line no-constant-condition
280
+ while (true) {
281
+ // eslint-disable-next-line no-await-in-loop
282
+ const foundPath = await runMatcher({...options, cwd: directory});
283
+
284
+ if (foundPath === findUpStop) {
285
+ break;
286
+ }
287
+
288
+ if (foundPath) {
289
+ matches.push(path.resolve(directory, foundPath));
290
+ }
291
+
292
+ if (directory === stopAt || matches.length >= limit) {
293
+ break;
294
+ }
295
+
296
+ directory = path.dirname(directory);
297
+ }
298
+
299
+ return matches;
300
+ }
301
+
302
+ function findUpMultipleSync(name, options) {
303
+ let directory = path.resolve(toPath(options.cwd) || '');
304
+ const {root} = path.parse(directory);
305
+ const stopAt = options.stopAt || root;
306
+ const limit = options.limit || Number.POSITIVE_INFINITY;
307
+ const paths = [name].flat();
308
+
309
+ const runMatcher = locateOptions => {
310
+ if (typeof name !== 'function') {
311
+ return locatePathSync(paths, locateOptions);
312
+ }
313
+
314
+ const foundPath = name(locateOptions.cwd);
315
+ if (typeof foundPath === 'string') {
316
+ return locatePathSync([foundPath], locateOptions);
317
+ }
318
+
319
+ return foundPath;
320
+ };
321
+
322
+ const matches = [];
323
+ // eslint-disable-next-line no-constant-condition
324
+ while (true) {
325
+ const foundPath = runMatcher({...options, cwd: directory});
326
+
327
+ if (foundPath === findUpStop) {
328
+ break;
329
+ }
330
+
331
+ if (foundPath) {
332
+ matches.push(path.resolve(directory, foundPath));
333
+ }
334
+
335
+ if (directory === stopAt || matches.length >= limit) {
336
+ break;
337
+ }
338
+
339
+ directory = path.dirname(directory);
340
+ }
341
+
342
+ return matches;
343
+ }
344
+
345
+ async function findUp(name, options) {
346
+ const matches = await findUpMultiple(name, {...options, limit: 1});
347
+ return matches[0];
348
+ }
349
+
350
+ function findUpSync(name, options) {
351
+ const matches = findUpMultipleSync(name, {...options, limit: 1});
352
+ return matches[0];
353
+ }
354
+
355
+ async function packageDirectory({cwd} = {}) {
356
+ const filePath = await findUp('package.json', {cwd});
357
+ return filePath && path.dirname(filePath);
358
+ }
359
+
360
+ function packageDirectorySync({cwd} = {}) {
361
+ const filePath = findUpSync('package.json', {cwd});
362
+ return filePath && path.dirname(filePath);
363
+ }
364
+
365
+ export { packageDirectory, packageDirectorySync };