@quilted/create 0.1.29 → 0.1.31

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/build/esm/app.mjs CHANGED
@@ -1,13 +1,209 @@
1
1
  import * as fs from 'node:fs';
2
2
  import * as path from 'node:path';
3
- import { execSync } from 'node:child_process';
4
- import { s as stripIndent, c as cyan_1, b as bold_1, p as printHelp, g as getCreateAsMonorepo, a as getShouldInstall, d as getPackageManager, e as getExtrasToSetup, f as dim_1, u as underline_1, m as magenta_1, h as arg_1, i as prompt } from './index.mjs';
5
- import { e as emptyDirectory, t as toValidPackageName, f as format, m as mergeDependencies, l as loadTemplate, a as addToTsConfig, b as addToPackageManagerWorkspaces, r as relativeDirectoryForDisplay, i as isEmpty, c as createOutputTarget } from './package-manager.mjs';
3
+ import { c as cyan_1, b as bold_1, g as getCreateAsMonorepo, a as getShouldInstall, d as getPackageManager, e as getExtrasToSetup, f as emptyDirectory, t as toValidPackageName, h as format, m as mergeDependencies, l as loadTemplate, i as addToTsConfig, j as addToPackageManagerWorkspaces, r as relativeDirectoryForDisplay, k as dim_1, u as underline_1, n as magenta_1, o as isEmpty, p as createOutputTarget } from './shared/package-manager.mjs';
4
+ import { s as stripIndent, p as printHelp, a as prompt } from './index.mjs';
6
5
  import 'node:tty';
6
+ import 'node:child_process';
7
7
  import 'node:url';
8
8
  import 'node:readline';
9
9
  import 'node:events';
10
10
 
11
+ const flagSymbol = Symbol('arg flag');
12
+
13
+ class ArgError extends Error {
14
+ constructor(msg, code) {
15
+ super(msg);
16
+ this.name = 'ArgError';
17
+ this.code = code;
18
+
19
+ Object.setPrototypeOf(this, ArgError.prototype);
20
+ }
21
+ }
22
+
23
+ function arg(
24
+ opts,
25
+ {
26
+ argv = process.argv.slice(2),
27
+ permissive = false,
28
+ stopAtPositional = false
29
+ } = {}
30
+ ) {
31
+ if (!opts) {
32
+ throw new ArgError(
33
+ 'argument specification object is required',
34
+ 'ARG_CONFIG_NO_SPEC'
35
+ );
36
+ }
37
+
38
+ const result = { _: [] };
39
+
40
+ const aliases = {};
41
+ const handlers = {};
42
+
43
+ for (const key of Object.keys(opts)) {
44
+ if (!key) {
45
+ throw new ArgError(
46
+ 'argument key cannot be an empty string',
47
+ 'ARG_CONFIG_EMPTY_KEY'
48
+ );
49
+ }
50
+
51
+ if (key[0] !== '-') {
52
+ throw new ArgError(
53
+ `argument key must start with '-' but found: '${key}'`,
54
+ 'ARG_CONFIG_NONOPT_KEY'
55
+ );
56
+ }
57
+
58
+ if (key.length === 1) {
59
+ throw new ArgError(
60
+ `argument key must have a name; singular '-' keys are not allowed: ${key}`,
61
+ 'ARG_CONFIG_NONAME_KEY'
62
+ );
63
+ }
64
+
65
+ if (typeof opts[key] === 'string') {
66
+ aliases[key] = opts[key];
67
+ continue;
68
+ }
69
+
70
+ let type = opts[key];
71
+ let isFlag = false;
72
+
73
+ if (
74
+ Array.isArray(type) &&
75
+ type.length === 1 &&
76
+ typeof type[0] === 'function'
77
+ ) {
78
+ const [fn] = type;
79
+ type = (value, name, prev = []) => {
80
+ prev.push(fn(value, name, prev[prev.length - 1]));
81
+ return prev;
82
+ };
83
+ isFlag = fn === Boolean || fn[flagSymbol] === true;
84
+ } else if (typeof type === 'function') {
85
+ isFlag = type === Boolean || type[flagSymbol] === true;
86
+ } else {
87
+ throw new ArgError(
88
+ `type missing or not a function or valid array type: ${key}`,
89
+ 'ARG_CONFIG_VAD_TYPE'
90
+ );
91
+ }
92
+
93
+ if (key[1] !== '-' && key.length > 2) {
94
+ throw new ArgError(
95
+ `short argument keys (with a single hyphen) must have only one character: ${key}`,
96
+ 'ARG_CONFIG_SHORTOPT_TOOLONG'
97
+ );
98
+ }
99
+
100
+ handlers[key] = [type, isFlag];
101
+ }
102
+
103
+ for (let i = 0, len = argv.length; i < len; i++) {
104
+ const wholeArg = argv[i];
105
+
106
+ if (stopAtPositional && result._.length > 0) {
107
+ result._ = result._.concat(argv.slice(i));
108
+ break;
109
+ }
110
+
111
+ if (wholeArg === '--') {
112
+ result._ = result._.concat(argv.slice(i + 1));
113
+ break;
114
+ }
115
+
116
+ if (wholeArg.length > 1 && wholeArg[0] === '-') {
117
+ /* eslint-disable operator-linebreak */
118
+ const separatedArguments =
119
+ wholeArg[1] === '-' || wholeArg.length === 2
120
+ ? [wholeArg]
121
+ : wholeArg
122
+ .slice(1)
123
+ .split('')
124
+ .map((a) => `-${a}`);
125
+ /* eslint-enable operator-linebreak */
126
+
127
+ for (let j = 0; j < separatedArguments.length; j++) {
128
+ const arg = separatedArguments[j];
129
+ const [originalArgName, argStr] =
130
+ arg[1] === '-' ? arg.split(/=(.*)/, 2) : [arg, undefined];
131
+
132
+ let argName = originalArgName;
133
+ while (argName in aliases) {
134
+ argName = aliases[argName];
135
+ }
136
+
137
+ if (!(argName in handlers)) {
138
+ if (permissive) {
139
+ result._.push(arg);
140
+ continue;
141
+ } else {
142
+ throw new ArgError(
143
+ `unknown or unexpected option: ${originalArgName}`,
144
+ 'ARG_UNKNOWN_OPTION'
145
+ );
146
+ }
147
+ }
148
+
149
+ const [type, isFlag] = handlers[argName];
150
+
151
+ if (!isFlag && j + 1 < separatedArguments.length) {
152
+ throw new ArgError(
153
+ `option requires argument (but was followed by another short argument): ${originalArgName}`,
154
+ 'ARG_MISSING_REQUIRED_SHORTARG'
155
+ );
156
+ }
157
+
158
+ if (isFlag) {
159
+ result[argName] = type(true, argName, result[argName]);
160
+ } else if (argStr === undefined) {
161
+ if (
162
+ argv.length < i + 2 ||
163
+ (argv[i + 1].length > 1 &&
164
+ argv[i + 1][0] === '-' &&
165
+ !(
166
+ argv[i + 1].match(/^-?\d*(\.(?=\d))?\d*$/) &&
167
+ (type === Number ||
168
+ // eslint-disable-next-line no-undef
169
+ (typeof BigInt !== 'undefined' && type === BigInt))
170
+ ))
171
+ ) {
172
+ const extended =
173
+ originalArgName === argName ? '' : ` (alias for ${argName})`;
174
+ throw new ArgError(
175
+ `option requires argument: ${originalArgName}${extended}`,
176
+ 'ARG_MISSING_REQUIRED_LONGARG'
177
+ );
178
+ }
179
+
180
+ result[argName] = type(argv[i + 1], argName, result[argName]);
181
+ ++i;
182
+ } else {
183
+ result[argName] = type(argStr, argName, result[argName]);
184
+ }
185
+ }
186
+ } else {
187
+ result._.push(wholeArg);
188
+ }
189
+ }
190
+
191
+ return result;
192
+ }
193
+
194
+ arg.flag = (fn) => {
195
+ fn[flagSymbol] = true;
196
+ return fn;
197
+ };
198
+
199
+ // Utility types
200
+ arg.COUNT = arg.flag((v, name, existingCount) => (existingCount || 0) + 1);
201
+
202
+ // Expose error class
203
+ arg.ArgError = ArgError;
204
+
205
+ var arg_1 = arg;
206
+
11
207
  let _ = t => t,
12
208
  _t,
13
209
  _t2,
@@ -44,7 +240,9 @@ async function createApp() {
44
240
  const template = await getTemplate(argv);
45
241
  const createAsMonorepo = !inWorkspace && (await getCreateAsMonorepo(argv));
46
242
  const shouldInstall = await getShouldInstall(argv);
47
- const packageManager = await getPackageManager(argv);
243
+ const packageManager = await getPackageManager(argv, {
244
+ root: directory
245
+ });
48
246
  const setupExtras = await getExtrasToSetup(argv, {
49
247
  inWorkspace
50
248
  });
@@ -84,7 +282,7 @@ async function createApp() {
84
282
  const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
85
283
  workspacePackageJson.name = toValidPackageName(name);
86
284
 
87
- if (packageManager === 'pnpm') {
285
+ if (packageManager.type === 'pnpm') {
88
286
  await outputRoot.write('pnpm-workspace.yaml', await format(`
89
287
  packages:
90
288
  - './packages/*'
@@ -143,15 +341,13 @@ async function createApp() {
143
341
  await outputRoot.write(path.join(appDirectory, 'package.json'), await format(JSON.stringify(projectPackageJson), {
144
342
  as: 'json-stringify'
145
343
  }));
146
- await Promise.all([addToTsConfig(appDirectory, outputRoot), addToPackageManagerWorkspaces(appDirectory, outputRoot, packageManager)]);
344
+ await Promise.all([addToTsConfig(appDirectory, outputRoot), addToPackageManagerWorkspaces(appDirectory, outputRoot, packageManager.type)]);
147
345
  }
148
346
 
149
347
  if (shouldInstall) {
150
348
  process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
151
349
 
152
- execSync(`${packageManager} install`, {
153
- cwd: rootDirectory
154
- });
350
+ await packageManager.install();
155
351
  process.stdout.moveCursor(0, -1);
156
352
  process.stdout.clearLine(1);
157
353
  console.log('Installed dependencies.');
@@ -159,14 +355,12 @@ async function createApp() {
159
355
 
160
356
  const commands = [];
161
357
 
162
- const packageManagerRun = command => packageManager === 'npm' ? `npm run ${command}` : `pnpm ${command}`;
163
-
164
358
  if (!inWorkspace && directory !== process.cwd()) {
165
359
  commands.push(`cd ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), directory)))} ${dim_1('# Move into your new app’s directory')}`);
166
360
  }
167
361
 
168
362
  if (!shouldInstall) {
169
- commands.push(`${packageManager} install ${dim_1('# Install all your dependencies')}`);
363
+ commands.push(`${packageManager.commands.install()} ${dim_1('# Install all your dependencies')}`);
170
364
  }
171
365
 
172
366
  if (!inWorkspace) {
@@ -174,7 +368,7 @@ async function createApp() {
174
368
  commands.push(`git init && git add -A && git commit -m "Initial commit" ${dim_1('# Start your git history (optional)')}`);
175
369
  }
176
370
 
177
- commands.push(`${packageManagerRun('develop')} ${dim_1('# Start the development server')}`);
371
+ commands.push(`${packageManager.commands.run('develop')} ${dim_1('# Start the development server')}`);
178
372
  const whatsNext = stripIndent(_t2 || (_t2 = _`
179
373
  Your new app is ready to go! There’s just ${0} you’ll need to take
180
374
  in order to start developing: