@quilted/create 0.1.50 → 0.1.51

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 (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/cjs/app.cjs +16 -211
  3. package/build/cjs/index.cjs +13 -1
  4. package/build/cjs/index2.cjs +157 -326
  5. package/build/cjs/index3.cjs +307 -7793
  6. package/build/cjs/index4.cjs +7402 -7181
  7. package/build/cjs/index5.cjs +7633 -0
  8. package/build/cjs/module.cjs +302 -0
  9. package/build/cjs/package.cjs +1 -1
  10. package/build/cjs/shared/package-manager.cjs +2 -2
  11. package/build/esm/app.mjs +1 -196
  12. package/build/esm/index.mjs +13 -1
  13. package/build/esm/index2.mjs +157 -325
  14. package/build/esm/index3.mjs +306 -7793
  15. package/build/esm/index4.mjs +7402 -7174
  16. package/build/esm/index5.mjs +7624 -0
  17. package/build/esm/module.mjs +280 -0
  18. package/build/esm/package.mjs +1 -1
  19. package/build/esm/shared/package-manager.mjs +2 -2
  20. package/build/tsconfig.tsbuildinfo +1 -1
  21. package/build/typescript/help.d.ts +1 -1
  22. package/build/typescript/help.d.ts.map +1 -1
  23. package/build/typescript/module.d.ts +2 -0
  24. package/build/typescript/module.d.ts.map +1 -0
  25. package/build/typescript/shared/prompts.d.ts +2 -2
  26. package/build/typescript/shared/prompts.d.ts.map +1 -1
  27. package/build/typescript/shared.d.ts +1 -1
  28. package/build/typescript/shared.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/source/create.ts +7 -1
  31. package/source/help.ts +6 -1
  32. package/source/module.ts +412 -0
  33. package/source/shared/prompts.ts +2 -2
  34. package/source/shared.ts +2 -0
  35. package/templates/module/module.ts +3 -0
  36. package/templates/module/package.json +21 -0
  37. package/templates/module/quilt.project.ts +5 -0
  38. package/templates/module/tsconfig.json +9 -0
@@ -1,368 +1,199 @@
1
1
  'use strict';
2
2
 
3
- var path = require('node:path');
4
- var node_url = require('node:url');
5
- var process = require('node:process');
6
- var fs = require('node:fs');
3
+ const flagSymbol = Symbol('arg flag');
7
4
 
8
- /*
9
- How it works:
10
- `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.
11
- */
5
+ class ArgError extends Error {
6
+ constructor(msg, code) {
7
+ super(msg);
8
+ this.name = 'ArgError';
9
+ this.code = code;
12
10
 
13
- class Node {
14
- value;
15
- next;
16
-
17
- constructor(value) {
18
- this.value = value;
19
- }
20
- }
21
-
22
- class Queue {
23
- #head;
24
- #tail;
25
- #size;
26
-
27
- constructor() {
28
- this.clear();
29
- }
30
-
31
- enqueue(value) {
32
- const node = new Node(value);
33
-
34
- if (this.#head) {
35
- this.#tail.next = node;
36
- this.#tail = node;
37
- } else {
38
- this.#head = node;
39
- this.#tail = node;
40
- }
41
-
42
- this.#size++;
43
- }
44
-
45
- dequeue() {
46
- const current = this.#head;
47
- if (!current) {
48
- return;
49
- }
50
-
51
- this.#head = this.#head.next;
52
- this.#size--;
53
- return current.value;
54
- }
55
-
56
- clear() {
57
- this.#head = undefined;
58
- this.#tail = undefined;
59
- this.#size = 0;
60
- }
61
-
62
- get size() {
63
- return this.#size;
64
- }
65
-
66
- * [Symbol.iterator]() {
67
- let current = this.#head;
68
-
69
- while (current) {
70
- yield current.value;
71
- current = current.next;
72
- }
73
- }
74
- }
75
-
76
- function pLimit(concurrency) {
77
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
78
- throw new TypeError('Expected `concurrency` to be a number from 1 and up');
11
+ Object.setPrototypeOf(this, ArgError.prototype);
79
12
  }
80
-
81
- const queue = new Queue();
82
- let activeCount = 0;
83
-
84
- const next = () => {
85
- activeCount--;
86
-
87
- if (queue.size > 0) {
88
- queue.dequeue()();
89
- }
90
- };
91
-
92
- const run = async (fn, resolve, args) => {
93
- activeCount++;
94
-
95
- const result = (async () => fn(...args))();
96
-
97
- resolve(result);
98
-
99
- try {
100
- await result;
101
- } catch {}
102
-
103
- next();
104
- };
105
-
106
- const enqueue = (fn, resolve, args) => {
107
- queue.enqueue(run.bind(undefined, fn, resolve, args));
108
-
109
- (async () => {
110
- // This function needs to wait until the next microtask before comparing
111
- // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
112
- // when the run function is dequeued and called. The comparison in the if-statement
113
- // needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
114
- await Promise.resolve();
115
-
116
- if (activeCount < concurrency && queue.size > 0) {
117
- queue.dequeue()();
118
- }
119
- })();
120
- };
121
-
122
- const generator = (fn, ...args) => new Promise(resolve => {
123
- enqueue(fn, resolve, args);
124
- });
125
-
126
- Object.defineProperties(generator, {
127
- activeCount: {
128
- get: () => activeCount,
129
- },
130
- pendingCount: {
131
- get: () => queue.size,
132
- },
133
- clearQueue: {
134
- value: () => {
135
- queue.clear();
136
- },
137
- },
138
- });
139
-
140
- return generator;
141
13
  }
142
14
 
143
- class EndError extends Error {
144
- constructor(value) {
145
- super();
146
- this.value = value;
147
- }
148
- }
149
-
150
- // The input can also be a promise, so we await it.
151
- const testElement = async (element, tester) => tester(await element);
152
-
153
- // The input can also be a promise, so we `Promise.all()` them both.
154
- const finder = async element => {
155
- const values = await Promise.all(element);
156
- if (values[1] === true) {
157
- throw new EndError(values[0]);
158
- }
159
-
160
- return false;
161
- };
162
-
163
- async function pLocate(
164
- iterable,
165
- tester,
15
+ function arg(
16
+ opts,
166
17
  {
167
- concurrency = Number.POSITIVE_INFINITY,
168
- preserveOrder = true,
169
- } = {},
18
+ argv = process.argv.slice(2),
19
+ permissive = false,
20
+ stopAtPositional = false
21
+ } = {}
170
22
  ) {
171
- const limit = pLimit(concurrency);
172
-
173
- // Start all the promises concurrently with optional limit.
174
- const items = [...iterable].map(element => [element, limit(testElement, element, tester)]);
175
-
176
- // Check the promises either serially or concurrently.
177
- const checkLimit = pLimit(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
178
-
179
- try {
180
- await Promise.all(items.map(element => checkLimit(finder, element)));
181
- } catch (error) {
182
- if (error instanceof EndError) {
183
- return error.value;
184
- }
185
-
186
- throw error;
23
+ if (!opts) {
24
+ throw new ArgError(
25
+ 'argument specification object is required',
26
+ 'ARG_CONFIG_NO_SPEC'
27
+ );
187
28
  }
188
- }
189
29
 
190
- const typeMappings = {
191
- directory: 'isDirectory',
192
- file: 'isFile',
193
- };
194
-
195
- function checkType(type) {
196
- if (type in typeMappings) {
197
- return;
198
- }
199
-
200
- throw new Error(`Invalid type specified: ${type}`);
201
- }
202
-
203
- const matchType = (type, stat) => type === undefined || stat[typeMappings[type]]();
204
-
205
- const toPath$1 = urlOrPath => urlOrPath instanceof URL ? node_url.fileURLToPath(urlOrPath) : urlOrPath;
206
-
207
- async function locatePath(
208
- paths,
209
- {
210
- cwd = process.cwd(),
211
- type = 'file',
212
- allowSymlinks = true,
213
- concurrency,
214
- preserveOrder,
215
- } = {},
216
- ) {
217
- checkType(type);
218
- cwd = toPath$1(cwd);
30
+ const result = { _: [] };
219
31
 
220
- const statFunction = allowSymlinks ? fs.promises.stat : fs.promises.lstat;
32
+ const aliases = {};
33
+ const handlers = {};
221
34
 
222
- return pLocate(paths, async path_ => {
223
- try {
224
- const stat = await statFunction(path.resolve(cwd, path_));
225
- return matchType(type, stat);
226
- } catch {
227
- return false;
35
+ for (const key of Object.keys(opts)) {
36
+ if (!key) {
37
+ throw new ArgError(
38
+ 'argument key cannot be an empty string',
39
+ 'ARG_CONFIG_EMPTY_KEY'
40
+ );
228
41
  }
229
- }, {concurrency, preserveOrder});
230
- }
231
-
232
- function locatePathSync(
233
- paths,
234
- {
235
- cwd = process.cwd(),
236
- type = 'file',
237
- allowSymlinks = true,
238
- } = {},
239
- ) {
240
- checkType(type);
241
- cwd = toPath$1(cwd);
242
-
243
- const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
244
-
245
- for (const path_ of paths) {
246
- try {
247
- const stat = statFunction(path.resolve(cwd, path_));
248
-
249
- if (matchType(type, stat)) {
250
- return path_;
251
- }
252
- } catch {}
253
- }
254
- }
255
-
256
- const toPath = urlOrPath => urlOrPath instanceof URL ? node_url.fileURLToPath(urlOrPath) : urlOrPath;
257
-
258
- const findUpStop = Symbol('findUpStop');
259
42
 
260
- async function findUpMultiple(name, options = {}) {
261
- let directory = path.resolve(toPath(options.cwd) || '');
262
- const {root} = path.parse(directory);
263
- const stopAt = path.resolve(directory, options.stopAt || root);
264
- const limit = options.limit || Number.POSITIVE_INFINITY;
265
- const paths = [name].flat();
266
-
267
- const runMatcher = async locateOptions => {
268
- if (typeof name !== 'function') {
269
- return locatePath(paths, locateOptions);
43
+ if (key[0] !== '-') {
44
+ throw new ArgError(
45
+ `argument key must start with '-' but found: '${key}'`,
46
+ 'ARG_CONFIG_NONOPT_KEY'
47
+ );
270
48
  }
271
49
 
272
- const foundPath = await name(locateOptions.cwd);
273
- if (typeof foundPath === 'string') {
274
- return locatePath([foundPath], locateOptions);
50
+ if (key.length === 1) {
51
+ throw new ArgError(
52
+ `argument key must have a name; singular '-' keys are not allowed: ${key}`,
53
+ 'ARG_CONFIG_NONAME_KEY'
54
+ );
275
55
  }
276
56
 
277
- return foundPath;
278
- };
279
-
280
- const matches = [];
281
- // eslint-disable-next-line no-constant-condition
282
- while (true) {
283
- // eslint-disable-next-line no-await-in-loop
284
- const foundPath = await runMatcher({...options, cwd: directory});
285
-
286
- if (foundPath === findUpStop) {
287
- break;
57
+ if (typeof opts[key] === 'string') {
58
+ aliases[key] = opts[key];
59
+ continue;
288
60
  }
289
61
 
290
- if (foundPath) {
291
- matches.push(path.resolve(directory, foundPath));
292
- }
293
-
294
- if (directory === stopAt || matches.length >= limit) {
295
- break;
296
- }
297
-
298
- directory = path.dirname(directory);
299
- }
300
-
301
- return matches;
302
- }
303
-
304
- function findUpMultipleSync(name, options = {}) {
305
- let directory = path.resolve(toPath(options.cwd) || '');
306
- const {root} = path.parse(directory);
307
- const stopAt = options.stopAt || root;
308
- const limit = options.limit || Number.POSITIVE_INFINITY;
309
- const paths = [name].flat();
62
+ let type = opts[key];
63
+ let isFlag = false;
310
64
 
311
- const runMatcher = locateOptions => {
312
- if (typeof name !== 'function') {
313
- return locatePathSync(paths, locateOptions);
65
+ if (
66
+ Array.isArray(type) &&
67
+ type.length === 1 &&
68
+ typeof type[0] === 'function'
69
+ ) {
70
+ const [fn] = type;
71
+ type = (value, name, prev = []) => {
72
+ prev.push(fn(value, name, prev[prev.length - 1]));
73
+ return prev;
74
+ };
75
+ isFlag = fn === Boolean || fn[flagSymbol] === true;
76
+ } else if (typeof type === 'function') {
77
+ isFlag = type === Boolean || type[flagSymbol] === true;
78
+ } else {
79
+ throw new ArgError(
80
+ `type missing or not a function or valid array type: ${key}`,
81
+ 'ARG_CONFIG_VAD_TYPE'
82
+ );
314
83
  }
315
84
 
316
- const foundPath = name(locateOptions.cwd);
317
- if (typeof foundPath === 'string') {
318
- return locatePathSync([foundPath], locateOptions);
85
+ if (key[1] !== '-' && key.length > 2) {
86
+ throw new ArgError(
87
+ `short argument keys (with a single hyphen) must have only one character: ${key}`,
88
+ 'ARG_CONFIG_SHORTOPT_TOOLONG'
89
+ );
319
90
  }
320
91
 
321
- return foundPath;
322
- };
92
+ handlers[key] = [type, isFlag];
93
+ }
323
94
 
324
- const matches = [];
325
- // eslint-disable-next-line no-constant-condition
326
- while (true) {
327
- const foundPath = runMatcher({...options, cwd: directory});
95
+ for (let i = 0, len = argv.length; i < len; i++) {
96
+ const wholeArg = argv[i];
328
97
 
329
- if (foundPath === findUpStop) {
98
+ if (stopAtPositional && result._.length > 0) {
99
+ result._ = result._.concat(argv.slice(i));
330
100
  break;
331
101
  }
332
102
 
333
- if (foundPath) {
334
- matches.push(path.resolve(directory, foundPath));
335
- }
336
-
337
- if (directory === stopAt || matches.length >= limit) {
103
+ if (wholeArg === '--') {
104
+ result._ = result._.concat(argv.slice(i + 1));
338
105
  break;
339
106
  }
340
107
 
341
- directory = path.dirname(directory);
108
+ if (wholeArg.length > 1 && wholeArg[0] === '-') {
109
+ /* eslint-disable operator-linebreak */
110
+ const separatedArguments =
111
+ wholeArg[1] === '-' || wholeArg.length === 2
112
+ ? [wholeArg]
113
+ : wholeArg
114
+ .slice(1)
115
+ .split('')
116
+ .map((a) => `-${a}`);
117
+ /* eslint-enable operator-linebreak */
118
+
119
+ for (let j = 0; j < separatedArguments.length; j++) {
120
+ const arg = separatedArguments[j];
121
+ const [originalArgName, argStr] =
122
+ arg[1] === '-' ? arg.split(/=(.*)/, 2) : [arg, undefined];
123
+
124
+ let argName = originalArgName;
125
+ while (argName in aliases) {
126
+ argName = aliases[argName];
127
+ }
128
+
129
+ if (!(argName in handlers)) {
130
+ if (permissive) {
131
+ result._.push(arg);
132
+ continue;
133
+ } else {
134
+ throw new ArgError(
135
+ `unknown or unexpected option: ${originalArgName}`,
136
+ 'ARG_UNKNOWN_OPTION'
137
+ );
138
+ }
139
+ }
140
+
141
+ const [type, isFlag] = handlers[argName];
142
+
143
+ if (!isFlag && j + 1 < separatedArguments.length) {
144
+ throw new ArgError(
145
+ `option requires argument (but was followed by another short argument): ${originalArgName}`,
146
+ 'ARG_MISSING_REQUIRED_SHORTARG'
147
+ );
148
+ }
149
+
150
+ if (isFlag) {
151
+ result[argName] = type(true, argName, result[argName]);
152
+ } else if (argStr === undefined) {
153
+ if (
154
+ argv.length < i + 2 ||
155
+ (argv[i + 1].length > 1 &&
156
+ argv[i + 1][0] === '-' &&
157
+ !(
158
+ argv[i + 1].match(/^-?\d*(\.(?=\d))?\d*$/) &&
159
+ (type === Number ||
160
+ // eslint-disable-next-line no-undef
161
+ (typeof BigInt !== 'undefined' && type === BigInt))
162
+ ))
163
+ ) {
164
+ const extended =
165
+ originalArgName === argName ? '' : ` (alias for ${argName})`;
166
+ throw new ArgError(
167
+ `option requires argument: ${originalArgName}${extended}`,
168
+ 'ARG_MISSING_REQUIRED_LONGARG'
169
+ );
170
+ }
171
+
172
+ result[argName] = type(argv[i + 1], argName, result[argName]);
173
+ ++i;
174
+ } else {
175
+ result[argName] = type(argStr, argName, result[argName]);
176
+ }
177
+ }
178
+ } else {
179
+ result._.push(wholeArg);
180
+ }
342
181
  }
343
182
 
344
- return matches;
183
+ return result;
345
184
  }
346
185
 
347
- async function findUp(name, options = {}) {
348
- const matches = await findUpMultiple(name, {...options, limit: 1});
349
- return matches[0];
350
- }
186
+ arg.flag = (fn) => {
187
+ fn[flagSymbol] = true;
188
+ return fn;
189
+ };
351
190
 
352
- function findUpSync(name, options = {}) {
353
- const matches = findUpMultipleSync(name, {...options, limit: 1});
354
- return matches[0];
355
- }
191
+ // Utility types
192
+ arg.COUNT = arg.flag((v, name, existingCount) => (existingCount || 0) + 1);
356
193
 
357
- async function packageDirectory({cwd} = {}) {
358
- const filePath = await findUp('package.json', {cwd});
359
- return filePath && path.dirname(filePath);
360
- }
194
+ // Expose error class
195
+ arg.ArgError = ArgError;
361
196
 
362
- function packageDirectorySync({cwd} = {}) {
363
- const filePath = findUpSync('package.json', {cwd});
364
- return filePath && path.dirname(filePath);
365
- }
197
+ var arg_1 = arg;
366
198
 
367
- exports.packageDirectory = packageDirectory;
368
- exports.packageDirectorySync = packageDirectorySync;
199
+ exports.arg_1 = arg_1;