@quilted/create 0.1.50 → 0.1.52

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 +12 -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 +318 -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 +296 -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 +426 -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 +24 -0
  37. package/templates/module/quilt.project.ts +5 -0
  38. package/templates/module/tsconfig.json +9 -0
@@ -1,365 +1,197 @@
1
- import path__default from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
- import process from 'node:process';
4
- import fs__default, { promises } from 'node:fs';
1
+ const flagSymbol = Symbol('arg flag');
5
2
 
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
- */
3
+ class ArgError extends Error {
4
+ constructor(msg, code) {
5
+ super(msg);
6
+ this.name = 'ArgError';
7
+ this.code = code;
10
8
 
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');
9
+ Object.setPrototypeOf(this, ArgError.prototype);
77
10
  }
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
11
  }
140
12
 
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,
13
+ function arg(
14
+ opts,
164
15
  {
165
- concurrency = Number.POSITIVE_INFINITY,
166
- preserveOrder = true,
167
- } = {},
16
+ argv = process.argv.slice(2),
17
+ permissive = false,
18
+ stopAtPositional = false
19
+ } = {}
168
20
  ) {
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;
21
+ if (!opts) {
22
+ throw new ArgError(
23
+ 'argument specification object is required',
24
+ 'ARG_CONFIG_NO_SPEC'
25
+ );
185
26
  }
186
- }
187
27
 
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);
28
+ const result = { _: [] };
217
29
 
218
- const statFunction = allowSymlinks ? promises.stat : promises.lstat;
30
+ const aliases = {};
31
+ const handlers = {};
219
32
 
220
- return pLocate(paths, async path_ => {
221
- try {
222
- const stat = await statFunction(path__default.resolve(cwd, path_));
223
- return matchType(type, stat);
224
- } catch {
225
- return false;
33
+ for (const key of Object.keys(opts)) {
34
+ if (!key) {
35
+ throw new ArgError(
36
+ 'argument key cannot be an empty string',
37
+ 'ARG_CONFIG_EMPTY_KEY'
38
+ );
226
39
  }
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__default.statSync : fs__default.lstatSync;
242
-
243
- for (const path_ of paths) {
244
- try {
245
- const stat = statFunction(path__default.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
40
 
258
- async function findUpMultiple(name, options = {}) {
259
- let directory = path__default.resolve(toPath(options.cwd) || '');
260
- const {root} = path__default.parse(directory);
261
- const stopAt = path__default.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);
41
+ if (key[0] !== '-') {
42
+ throw new ArgError(
43
+ `argument key must start with '-' but found: '${key}'`,
44
+ 'ARG_CONFIG_NONOPT_KEY'
45
+ );
268
46
  }
269
47
 
270
- const foundPath = await name(locateOptions.cwd);
271
- if (typeof foundPath === 'string') {
272
- return locatePath([foundPath], locateOptions);
48
+ if (key.length === 1) {
49
+ throw new ArgError(
50
+ `argument key must have a name; singular '-' keys are not allowed: ${key}`,
51
+ 'ARG_CONFIG_NONAME_KEY'
52
+ );
273
53
  }
274
54
 
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;
55
+ if (typeof opts[key] === 'string') {
56
+ aliases[key] = opts[key];
57
+ continue;
286
58
  }
287
59
 
288
- if (foundPath) {
289
- matches.push(path__default.resolve(directory, foundPath));
290
- }
291
-
292
- if (directory === stopAt || matches.length >= limit) {
293
- break;
294
- }
295
-
296
- directory = path__default.dirname(directory);
297
- }
298
-
299
- return matches;
300
- }
301
-
302
- function findUpMultipleSync(name, options = {}) {
303
- let directory = path__default.resolve(toPath(options.cwd) || '');
304
- const {root} = path__default.parse(directory);
305
- const stopAt = options.stopAt || root;
306
- const limit = options.limit || Number.POSITIVE_INFINITY;
307
- const paths = [name].flat();
60
+ let type = opts[key];
61
+ let isFlag = false;
308
62
 
309
- const runMatcher = locateOptions => {
310
- if (typeof name !== 'function') {
311
- return locatePathSync(paths, locateOptions);
63
+ if (
64
+ Array.isArray(type) &&
65
+ type.length === 1 &&
66
+ typeof type[0] === 'function'
67
+ ) {
68
+ const [fn] = type;
69
+ type = (value, name, prev = []) => {
70
+ prev.push(fn(value, name, prev[prev.length - 1]));
71
+ return prev;
72
+ };
73
+ isFlag = fn === Boolean || fn[flagSymbol] === true;
74
+ } else if (typeof type === 'function') {
75
+ isFlag = type === Boolean || type[flagSymbol] === true;
76
+ } else {
77
+ throw new ArgError(
78
+ `type missing or not a function or valid array type: ${key}`,
79
+ 'ARG_CONFIG_VAD_TYPE'
80
+ );
312
81
  }
313
82
 
314
- const foundPath = name(locateOptions.cwd);
315
- if (typeof foundPath === 'string') {
316
- return locatePathSync([foundPath], locateOptions);
83
+ if (key[1] !== '-' && key.length > 2) {
84
+ throw new ArgError(
85
+ `short argument keys (with a single hyphen) must have only one character: ${key}`,
86
+ 'ARG_CONFIG_SHORTOPT_TOOLONG'
87
+ );
317
88
  }
318
89
 
319
- return foundPath;
320
- };
90
+ handlers[key] = [type, isFlag];
91
+ }
321
92
 
322
- const matches = [];
323
- // eslint-disable-next-line no-constant-condition
324
- while (true) {
325
- const foundPath = runMatcher({...options, cwd: directory});
93
+ for (let i = 0, len = argv.length; i < len; i++) {
94
+ const wholeArg = argv[i];
326
95
 
327
- if (foundPath === findUpStop) {
96
+ if (stopAtPositional && result._.length > 0) {
97
+ result._ = result._.concat(argv.slice(i));
328
98
  break;
329
99
  }
330
100
 
331
- if (foundPath) {
332
- matches.push(path__default.resolve(directory, foundPath));
333
- }
334
-
335
- if (directory === stopAt || matches.length >= limit) {
101
+ if (wholeArg === '--') {
102
+ result._ = result._.concat(argv.slice(i + 1));
336
103
  break;
337
104
  }
338
105
 
339
- directory = path__default.dirname(directory);
106
+ if (wholeArg.length > 1 && wholeArg[0] === '-') {
107
+ /* eslint-disable operator-linebreak */
108
+ const separatedArguments =
109
+ wholeArg[1] === '-' || wholeArg.length === 2
110
+ ? [wholeArg]
111
+ : wholeArg
112
+ .slice(1)
113
+ .split('')
114
+ .map((a) => `-${a}`);
115
+ /* eslint-enable operator-linebreak */
116
+
117
+ for (let j = 0; j < separatedArguments.length; j++) {
118
+ const arg = separatedArguments[j];
119
+ const [originalArgName, argStr] =
120
+ arg[1] === '-' ? arg.split(/=(.*)/, 2) : [arg, undefined];
121
+
122
+ let argName = originalArgName;
123
+ while (argName in aliases) {
124
+ argName = aliases[argName];
125
+ }
126
+
127
+ if (!(argName in handlers)) {
128
+ if (permissive) {
129
+ result._.push(arg);
130
+ continue;
131
+ } else {
132
+ throw new ArgError(
133
+ `unknown or unexpected option: ${originalArgName}`,
134
+ 'ARG_UNKNOWN_OPTION'
135
+ );
136
+ }
137
+ }
138
+
139
+ const [type, isFlag] = handlers[argName];
140
+
141
+ if (!isFlag && j + 1 < separatedArguments.length) {
142
+ throw new ArgError(
143
+ `option requires argument (but was followed by another short argument): ${originalArgName}`,
144
+ 'ARG_MISSING_REQUIRED_SHORTARG'
145
+ );
146
+ }
147
+
148
+ if (isFlag) {
149
+ result[argName] = type(true, argName, result[argName]);
150
+ } else if (argStr === undefined) {
151
+ if (
152
+ argv.length < i + 2 ||
153
+ (argv[i + 1].length > 1 &&
154
+ argv[i + 1][0] === '-' &&
155
+ !(
156
+ argv[i + 1].match(/^-?\d*(\.(?=\d))?\d*$/) &&
157
+ (type === Number ||
158
+ // eslint-disable-next-line no-undef
159
+ (typeof BigInt !== 'undefined' && type === BigInt))
160
+ ))
161
+ ) {
162
+ const extended =
163
+ originalArgName === argName ? '' : ` (alias for ${argName})`;
164
+ throw new ArgError(
165
+ `option requires argument: ${originalArgName}${extended}`,
166
+ 'ARG_MISSING_REQUIRED_LONGARG'
167
+ );
168
+ }
169
+
170
+ result[argName] = type(argv[i + 1], argName, result[argName]);
171
+ ++i;
172
+ } else {
173
+ result[argName] = type(argStr, argName, result[argName]);
174
+ }
175
+ }
176
+ } else {
177
+ result._.push(wholeArg);
178
+ }
340
179
  }
341
180
 
342
- return matches;
181
+ return result;
343
182
  }
344
183
 
345
- async function findUp(name, options = {}) {
346
- const matches = await findUpMultiple(name, {...options, limit: 1});
347
- return matches[0];
348
- }
184
+ arg.flag = (fn) => {
185
+ fn[flagSymbol] = true;
186
+ return fn;
187
+ };
349
188
 
350
- function findUpSync(name, options = {}) {
351
- const matches = findUpMultipleSync(name, {...options, limit: 1});
352
- return matches[0];
353
- }
189
+ // Utility types
190
+ arg.COUNT = arg.flag((v, name, existingCount) => (existingCount || 0) + 1);
354
191
 
355
- async function packageDirectory({cwd} = {}) {
356
- const filePath = await findUp('package.json', {cwd});
357
- return filePath && path__default.dirname(filePath);
358
- }
192
+ // Expose error class
193
+ arg.ArgError = ArgError;
359
194
 
360
- function packageDirectorySync({cwd} = {}) {
361
- const filePath = findUpSync('package.json', {cwd});
362
- return filePath && path__default.dirname(filePath);
363
- }
195
+ var arg_1 = arg;
364
196
 
365
- export { packageDirectory, packageDirectorySync };
197
+ export { arg_1 as a };