@quilted/create 0.1.28 → 0.1.30

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @quilted/create
2
2
 
3
+ ## 0.1.30
4
+
5
+ ### Patch Changes
6
+
7
+ - [`0a69e630`](https://github.com/lemonmade/quilt/commit/0a69e630d9da9233e676f6a5de863b3f836a667e) Thanks [@lemonmade](https://github.com/lemonmade)! - Add cli-kit package
8
+
9
+ ## 0.1.29
10
+
11
+ ### Patch Changes
12
+
13
+ - [`df633042`](https://github.com/lemonmade/quilt/commit/df633042aecadc8c978c5b492cc1d17d1d168690) Thanks [@lemonmade](https://github.com/lemonmade)! - Add explicit preact dependency
14
+
3
15
  ## 0.1.28
4
16
 
5
17
  ### Patch Changes
package/build/cjs/app.cjs CHANGED
@@ -3,34 +3,230 @@
3
3
  var fs = require('node:fs');
4
4
  var path = require('node:path');
5
5
  var node_child_process = require('node:child_process');
6
- var index = require('./index.cjs');
7
6
  var packageManager = require('./package-manager.cjs');
7
+ var index = require('./index.cjs');
8
8
  require('node:tty');
9
9
  require('node:url');
10
10
  require('node:readline');
11
11
  require('node:events');
12
12
 
13
13
  function _interopNamespace(e) {
14
- if (e && e.__esModule) return e;
15
- var n = Object.create(null);
16
- if (e) {
17
- Object.keys(e).forEach(function (k) {
18
- if (k !== 'default') {
19
- var d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: function () { return e[k]; }
23
- });
24
- }
25
- });
26
- }
27
- n["default"] = e;
28
- return Object.freeze(n);
14
+ if (e && e.__esModule) return e;
15
+ var n = Object.create(null);
16
+ if (e) {
17
+ Object.keys(e).forEach(function (k) {
18
+ if (k !== 'default') {
19
+ var d = Object.getOwnPropertyDescriptor(e, k);
20
+ Object.defineProperty(n, k, d.get ? d : {
21
+ enumerable: true,
22
+ get: function () { return e[k]; }
23
+ });
24
+ }
25
+ });
26
+ }
27
+ n["default"] = e;
28
+ return Object.freeze(n);
29
29
  }
30
30
 
31
31
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
32
32
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
33
33
 
34
+ const flagSymbol = Symbol('arg flag');
35
+
36
+ class ArgError extends Error {
37
+ constructor(msg, code) {
38
+ super(msg);
39
+ this.name = 'ArgError';
40
+ this.code = code;
41
+
42
+ Object.setPrototypeOf(this, ArgError.prototype);
43
+ }
44
+ }
45
+
46
+ function arg(
47
+ opts,
48
+ {
49
+ argv = process.argv.slice(2),
50
+ permissive = false,
51
+ stopAtPositional = false
52
+ } = {}
53
+ ) {
54
+ if (!opts) {
55
+ throw new ArgError(
56
+ 'argument specification object is required',
57
+ 'ARG_CONFIG_NO_SPEC'
58
+ );
59
+ }
60
+
61
+ const result = { _: [] };
62
+
63
+ const aliases = {};
64
+ const handlers = {};
65
+
66
+ for (const key of Object.keys(opts)) {
67
+ if (!key) {
68
+ throw new ArgError(
69
+ 'argument key cannot be an empty string',
70
+ 'ARG_CONFIG_EMPTY_KEY'
71
+ );
72
+ }
73
+
74
+ if (key[0] !== '-') {
75
+ throw new ArgError(
76
+ `argument key must start with '-' but found: '${key}'`,
77
+ 'ARG_CONFIG_NONOPT_KEY'
78
+ );
79
+ }
80
+
81
+ if (key.length === 1) {
82
+ throw new ArgError(
83
+ `argument key must have a name; singular '-' keys are not allowed: ${key}`,
84
+ 'ARG_CONFIG_NONAME_KEY'
85
+ );
86
+ }
87
+
88
+ if (typeof opts[key] === 'string') {
89
+ aliases[key] = opts[key];
90
+ continue;
91
+ }
92
+
93
+ let type = opts[key];
94
+ let isFlag = false;
95
+
96
+ if (
97
+ Array.isArray(type) &&
98
+ type.length === 1 &&
99
+ typeof type[0] === 'function'
100
+ ) {
101
+ const [fn] = type;
102
+ type = (value, name, prev = []) => {
103
+ prev.push(fn(value, name, prev[prev.length - 1]));
104
+ return prev;
105
+ };
106
+ isFlag = fn === Boolean || fn[flagSymbol] === true;
107
+ } else if (typeof type === 'function') {
108
+ isFlag = type === Boolean || type[flagSymbol] === true;
109
+ } else {
110
+ throw new ArgError(
111
+ `type missing or not a function or valid array type: ${key}`,
112
+ 'ARG_CONFIG_VAD_TYPE'
113
+ );
114
+ }
115
+
116
+ if (key[1] !== '-' && key.length > 2) {
117
+ throw new ArgError(
118
+ `short argument keys (with a single hyphen) must have only one character: ${key}`,
119
+ 'ARG_CONFIG_SHORTOPT_TOOLONG'
120
+ );
121
+ }
122
+
123
+ handlers[key] = [type, isFlag];
124
+ }
125
+
126
+ for (let i = 0, len = argv.length; i < len; i++) {
127
+ const wholeArg = argv[i];
128
+
129
+ if (stopAtPositional && result._.length > 0) {
130
+ result._ = result._.concat(argv.slice(i));
131
+ break;
132
+ }
133
+
134
+ if (wholeArg === '--') {
135
+ result._ = result._.concat(argv.slice(i + 1));
136
+ break;
137
+ }
138
+
139
+ if (wholeArg.length > 1 && wholeArg[0] === '-') {
140
+ /* eslint-disable operator-linebreak */
141
+ const separatedArguments =
142
+ wholeArg[1] === '-' || wholeArg.length === 2
143
+ ? [wholeArg]
144
+ : wholeArg
145
+ .slice(1)
146
+ .split('')
147
+ .map((a) => `-${a}`);
148
+ /* eslint-enable operator-linebreak */
149
+
150
+ for (let j = 0; j < separatedArguments.length; j++) {
151
+ const arg = separatedArguments[j];
152
+ const [originalArgName, argStr] =
153
+ arg[1] === '-' ? arg.split(/=(.*)/, 2) : [arg, undefined];
154
+
155
+ let argName = originalArgName;
156
+ while (argName in aliases) {
157
+ argName = aliases[argName];
158
+ }
159
+
160
+ if (!(argName in handlers)) {
161
+ if (permissive) {
162
+ result._.push(arg);
163
+ continue;
164
+ } else {
165
+ throw new ArgError(
166
+ `unknown or unexpected option: ${originalArgName}`,
167
+ 'ARG_UNKNOWN_OPTION'
168
+ );
169
+ }
170
+ }
171
+
172
+ const [type, isFlag] = handlers[argName];
173
+
174
+ if (!isFlag && j + 1 < separatedArguments.length) {
175
+ throw new ArgError(
176
+ `option requires argument (but was followed by another short argument): ${originalArgName}`,
177
+ 'ARG_MISSING_REQUIRED_SHORTARG'
178
+ );
179
+ }
180
+
181
+ if (isFlag) {
182
+ result[argName] = type(true, argName, result[argName]);
183
+ } else if (argStr === undefined) {
184
+ if (
185
+ argv.length < i + 2 ||
186
+ (argv[i + 1].length > 1 &&
187
+ argv[i + 1][0] === '-' &&
188
+ !(
189
+ argv[i + 1].match(/^-?\d*(\.(?=\d))?\d*$/) &&
190
+ (type === Number ||
191
+ // eslint-disable-next-line no-undef
192
+ (typeof BigInt !== 'undefined' && type === BigInt))
193
+ ))
194
+ ) {
195
+ const extended =
196
+ originalArgName === argName ? '' : ` (alias for ${argName})`;
197
+ throw new ArgError(
198
+ `option requires argument: ${originalArgName}${extended}`,
199
+ 'ARG_MISSING_REQUIRED_LONGARG'
200
+ );
201
+ }
202
+
203
+ result[argName] = type(argv[i + 1], argName, result[argName]);
204
+ ++i;
205
+ } else {
206
+ result[argName] = type(argStr, argName, result[argName]);
207
+ }
208
+ }
209
+ } else {
210
+ result._.push(wholeArg);
211
+ }
212
+ }
213
+
214
+ return result;
215
+ }
216
+
217
+ arg.flag = (fn) => {
218
+ fn[flagSymbol] = true;
219
+ return fn;
220
+ };
221
+
222
+ // Utility types
223
+ arg.COUNT = arg.flag((v, name, existingCount) => (existingCount || 0) + 1);
224
+
225
+ // Expose error class
226
+ arg.ArgError = ArgError;
227
+
228
+ var arg_1 = arg;
229
+
34
230
  let _ = t => t,
35
231
  _t,
36
232
  _t2,
@@ -48,7 +244,7 @@ async function createApp() {
48
244
 
49
245
  - ${0}, a web app with a minimal file structure
50
246
  - ${0}, an entire web app in a single file
51
- `), index.cyan_1(`--template`), index.bold_1('basic'), index.bold_1('single-file'));
247
+ `), packageManager.cyan_1(`--template`), packageManager.bold_1('basic'), packageManager.bold_1('single-file'));
52
248
  index.printHelp({
53
249
  kind: 'app',
54
250
  options: additionalOptions,
@@ -65,10 +261,10 @@ async function createApp() {
65
261
  name
66
262
  });
67
263
  const template = await getTemplate(argv);
68
- const createAsMonorepo = !inWorkspace && (await index.getCreateAsMonorepo(argv));
69
- const shouldInstall = await index.getShouldInstall(argv);
70
- const packageManager$1 = await index.getPackageManager(argv);
71
- const setupExtras = await index.getExtrasToSetup(argv, {
264
+ const createAsMonorepo = !inWorkspace && (await packageManager.getCreateAsMonorepo(argv));
265
+ const shouldInstall = await packageManager.getShouldInstall(argv);
266
+ const packageManager$1 = await packageManager.getPackageManager(argv);
267
+ const setupExtras = await packageManager.getExtrasToSetup(argv, {
72
268
  inWorkspace
73
269
  });
74
270
  const partOfMonorepo = inWorkspace || createAsMonorepo;
@@ -185,19 +381,19 @@ async function createApp() {
185
381
  const packageManagerRun = command => packageManager$1 === 'npm' ? `npm run ${command}` : `pnpm ${command}`;
186
382
 
187
383
  if (!inWorkspace && directory !== process.cwd()) {
188
- commands.push(`cd ${index.cyan_1(packageManager.relativeDirectoryForDisplay(path__namespace.relative(process.cwd(), directory)))} ${index.dim_1('# Move into your new app’s directory')}`);
384
+ commands.push(`cd ${packageManager.cyan_1(packageManager.relativeDirectoryForDisplay(path__namespace.relative(process.cwd(), directory)))} ${packageManager.dim_1('# Move into your new app’s directory')}`);
189
385
  }
190
386
 
191
387
  if (!shouldInstall) {
192
- commands.push(`${packageManager$1} install ${index.dim_1('# Install all your dependencies')}`);
388
+ commands.push(`${packageManager$1} install ${packageManager.dim_1('# Install all your dependencies')}`);
193
389
  }
194
390
 
195
391
  if (!inWorkspace) {
196
392
  // TODO: change this condition to check if git was initialized already
197
- commands.push(`git init && git add -A && git commit -m "Initial commit" ${index.dim_1('# Start your git history (optional)')}`);
393
+ commands.push(`git init && git add -A && git commit -m "Initial commit" ${packageManager.dim_1('# Start your git history (optional)')}`);
198
394
  }
199
395
 
200
- commands.push(`${packageManagerRun('develop')} ${index.dim_1('# Start the development server')}`);
396
+ commands.push(`${packageManagerRun('develop')} ${packageManager.dim_1('# Start the development server')}`);
201
397
  const whatsNext = index.stripIndent(_t2 || (_t2 = _`
202
398
  Your new app is ready to go! There’s just ${0} you’ll need to take
203
399
  in order to start developing:
@@ -212,13 +408,13 @@ async function createApp() {
212
408
  ${0}
213
409
 
214
410
  Have fun! 🎉
215
- `), index.underline_1(index.magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation')));
411
+ `), packageManager.underline_1(packageManager.magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation')));
216
412
  console.log();
217
413
  console.log(followUp);
218
414
  } // Argument handling
219
415
 
220
416
  function getArgv() {
221
- const argv = index.arg_1({
417
+ const argv = arg_1({
222
418
  '--yes': Boolean,
223
419
  '-y': '--yes',
224
420
  '--name': String,
@@ -269,7 +465,7 @@ async function getDirectory(argv, {
269
465
  const relativeDirectory = path__namespace.relative(process.cwd(), directory);
270
466
  const empty = await index.prompt({
271
467
  type: 'confirm',
272
- message: `Directory ${index.bold_1(packageManager.relativeDirectoryForDisplay(relativeDirectory))} is not empty, is it safe to empty it?`,
468
+ message: `Directory ${packageManager.bold_1(packageManager.relativeDirectoryForDisplay(relativeDirectory))} is not empty, is it safe to empty it?`,
273
469
  initial: true
274
470
  });
275
471
  if (empty) break;
@@ -296,12 +492,12 @@ async function getTemplate(argv) {
296
492
  const template = await index.prompt({
297
493
  type: 'select',
298
494
  message: 'What template would you like to use?',
299
- hint: `Use ${index.bold_1('arrow keys')} to select, and ${index.bold_1('return')} to submit`,
495
+ hint: `Use ${packageManager.bold_1('arrow keys')} to select, and ${packageManager.bold_1('return')} to submit`,
300
496
  choices: [{
301
- title: `${index.bold_1('The basics')}, a web app with a minimal file structure`,
497
+ title: `${packageManager.bold_1('The basics')}, a web app with a minimal file structure`,
302
498
  value: 'basic'
303
499
  }, {
304
- title: `${index.bold_1('Itty-bitty')}, an entire web app in a single file`,
500
+ title: `${packageManager.bold_1('Itty-bitty')}, an entire web app in a single file`,
305
501
  value: 'single-file'
306
502
  } // TODO: GraphQL API
307
503
  ]