@quilted/create 0.1.31 → 0.1.32

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
@@ -204,32 +204,24 @@ arg.ArgError = ArgError;
204
204
 
205
205
  var arg_1 = arg;
206
206
 
207
- let _ = t => t,
208
- _t,
209
- _t2,
210
- _t3;
211
207
  async function createApp() {
212
208
  const argv = getArgv();
213
-
214
209
  if (argv['--help']) {
215
- var _argv$PackageManag;
216
-
217
- const additionalOptions = stripIndent(_t || (_t = _`
218
- ${0}
210
+ const additionalOptions = stripIndent`
211
+ ${cyan_1(`--template`)}
219
212
  The template to use for your new application. If you don’t specify a template,
220
213
  this command will ask you for one instead. Must be one of the following:
221
214
 
222
- - ${0}, a web app with a minimal file structure
223
- - ${0}, an entire web app in a single file
224
- `), cyan_1(`--template`), bold_1('basic'), bold_1('single-file'));
215
+ - ${bold_1('basic')}, a web app with a minimal file structure
216
+ - ${bold_1('single-file')}, an entire web app in a single file
217
+ `;
225
218
  printHelp({
226
219
  kind: 'app',
227
220
  options: additionalOptions,
228
- packageManager: (_argv$PackageManag = argv['--package-manager']) === null || _argv$PackageManag === void 0 ? void 0 : _argv$PackageManag.toLowerCase()
221
+ packageManager: argv['--package-manager']?.toLowerCase()
229
222
  });
230
223
  return;
231
224
  }
232
-
233
225
  const inWorkspace = fs.existsSync('quilt.workspace.ts');
234
226
  const name = await getName(argv, {
235
227
  inWorkspace
@@ -248,10 +240,8 @@ async function createApp() {
248
240
  });
249
241
  const partOfMonorepo = inWorkspace || createAsMonorepo;
250
242
  const appDirectory = createAsMonorepo ? path.join(directory, 'app') : directory;
251
-
252
243
  if (fs.existsSync(directory)) {
253
244
  await emptyDirectory(directory);
254
-
255
245
  if (appDirectory !== directory) {
256
246
  fs.mkdirSync(appDirectory, {
257
247
  recursive: true
@@ -262,26 +252,27 @@ async function createApp() {
262
252
  recursive: true
263
253
  });
264
254
  }
265
-
266
255
  const rootDirectory = inWorkspace ? process.cwd() : directory;
267
256
  const outputRoot = createOutputTarget(rootDirectory);
268
257
  const appTemplate = loadTemplate(template === 'basic' ? 'app-basic' : 'app-single-file');
269
- const workspaceTemplate = loadTemplate('workspace'); // If we aren’t already in a workspace, copy the workspace files over, which
270
- // are needed if we are making a monorepo or not.
258
+ const workspaceTemplate = loadTemplate('workspace');
271
259
 
260
+ // If we aren’t already in a workspace, copy the workspace files over, which
261
+ // are needed if we are making a monorepo or not.
272
262
  if (!inWorkspace) {
273
263
  await workspaceTemplate.copy(directory, file => {
274
264
  // When this is a single project, we use the project’s Quilt configuration as the base.
275
- if (file === 'quilt.workspace.ts') return createAsMonorepo; // We need to make some adjustments to the root package.json
265
+ if (file === 'quilt.workspace.ts') return createAsMonorepo;
276
266
 
267
+ // We need to make some adjustments to the root package.json
277
268
  return file !== 'package.json';
278
- }); // If we are creating a monorepo, we need to add the root package.json and
279
- // package manager workspace configuration.
269
+ });
280
270
 
271
+ // If we are creating a monorepo, we need to add the root package.json and
272
+ // package manager workspace configuration.
281
273
  if (createAsMonorepo) {
282
274
  const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
283
275
  workspacePackageJson.name = toValidPackageName(name);
284
-
285
276
  if (packageManager.type === 'pnpm') {
286
277
  await outputRoot.write('pnpm-workspace.yaml', await format(`
287
278
  packages:
@@ -292,7 +283,6 @@ async function createApp() {
292
283
  } else {
293
284
  workspacePackageJson.workspaces = ['packages/*'];
294
285
  }
295
-
296
286
  await outputRoot.write('package.json', await format(JSON.stringify(workspacePackageJson), {
297
287
  as: 'json-stringify'
298
288
  }));
@@ -314,26 +304,22 @@ async function createApp() {
314
304
  as: 'json'
315
305
  }));
316
306
  }
317
-
318
307
  if (setupExtras.has('github')) {
319
308
  await loadTemplate('github').copy(directory);
320
309
  }
321
-
322
310
  if (setupExtras.has('vscode')) {
323
311
  await loadTemplate('vscode').copy(directory);
324
312
  }
325
313
  }
326
-
327
314
  await appTemplate.copy(appDirectory, file => {
328
315
  // If we are in a monorepo, we can use all the template files as they are
329
316
  if (file === 'quilt.project.ts' || file === 'tsconfig.json') {
330
317
  return partOfMonorepo;
331
- } // We need to make some adjustments the project’s package.json
332
-
318
+ }
333
319
 
320
+ // We need to make some adjustments the project’s package.json
334
321
  return file !== 'package.json';
335
322
  });
336
-
337
323
  if (partOfMonorepo) {
338
324
  // Write the app’s package.json (the root one was already created)
339
325
  const projectPackageJson = JSON.parse(await appTemplate.read('package.json'));
@@ -343,50 +329,46 @@ async function createApp() {
343
329
  }));
344
330
  await Promise.all([addToTsConfig(appDirectory, outputRoot), addToPackageManagerWorkspaces(appDirectory, outputRoot, packageManager.type)]);
345
331
  }
346
-
347
332
  if (shouldInstall) {
348
- process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
349
-
333
+ process.stdout.write('\nInstalling dependencies...\n');
334
+ // TODO: better loading, handle errors
350
335
  await packageManager.install();
351
336
  process.stdout.moveCursor(0, -1);
352
337
  process.stdout.clearLine(1);
353
338
  console.log('Installed dependencies.');
354
339
  }
355
-
356
340
  const commands = [];
357
-
358
341
  if (!inWorkspace && directory !== process.cwd()) {
359
342
  commands.push(`cd ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), directory)))} ${dim_1('# Move into your new app’s directory')}`);
360
343
  }
361
-
362
344
  if (!shouldInstall) {
363
345
  commands.push(`${packageManager.commands.install()} ${dim_1('# Install all your dependencies')}`);
364
346
  }
365
-
366
347
  if (!inWorkspace) {
367
348
  // TODO: change this condition to check if git was initialized already
368
349
  commands.push(`git init && git add -A && git commit -m "Initial commit" ${dim_1('# Start your git history (optional)')}`);
369
350
  }
370
-
371
351
  commands.push(`${packageManager.commands.run('develop')} ${dim_1('# Start the development server')}`);
372
- const whatsNext = stripIndent(_t2 || (_t2 = _`
373
- Your new app is ready to go! There’s just ${0} you’ll need to take
352
+ const whatsNext = stripIndent`
353
+ Your new app is ready to go! There’s just ${commands.length > 1 ? 'a few more steps' : 'one more step'} you’ll need to take
374
354
  in order to start developing:
375
- `), commands.length > 1 ? 'a few more steps' : 'one more step');
355
+ `;
376
356
  console.log();
377
357
  console.log(whatsNext);
378
358
  console.log();
379
359
  console.log(commands.map(command => ` ${command}`).join('\n'));
380
- const followUp = stripIndent(_t3 || (_t3 = _`
360
+ const followUp = stripIndent`
381
361
  Quilt can also help you build, test, lint, and type-check your new application.
382
362
  You can learn more about building apps with Quilt by reading the documentation:
383
- ${0}
363
+ ${underline_1(magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation'))}
384
364
 
385
365
  Have fun! 🎉
386
- `), underline_1(magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation')));
366
+ `;
387
367
  console.log();
388
368
  console.log(followUp);
389
- } // Argument handling
369
+ }
370
+
371
+ // Argument handling
390
372
 
391
373
  function getArgv() {
392
374
  const argv = arg_1({
@@ -409,14 +391,12 @@ function getArgv() {
409
391
  });
410
392
  return argv;
411
393
  }
412
-
413
394
  async function getName(argv, {
414
395
  inWorkspace
415
396
  }) {
416
397
  let {
417
398
  '--name': name
418
399
  } = argv;
419
-
420
400
  if (name == null) {
421
401
  name = await prompt({
422
402
  type: 'text',
@@ -424,17 +404,12 @@ async function getName(argv, {
424
404
  initial: inWorkspace ? 'app' : 'my-quilt-app'
425
405
  });
426
406
  }
427
-
428
407
  return name;
429
408
  }
430
-
431
409
  async function getDirectory(argv, {
432
410
  name
433
411
  }) {
434
- var _argv$Directory;
435
-
436
- let directory = path.resolve((_argv$Directory = argv['--directory']) !== null && _argv$Directory !== void 0 ? _argv$Directory : toValidPackageName(name));
437
-
412
+ let directory = path.resolve(argv['--directory'] ?? toValidPackageName(name));
438
413
  while (!argv['--yes']) {
439
414
  if (fs.existsSync(directory) && !(await isEmpty(directory))) {
440
415
  const relativeDirectory = path.relative(process.cwd(), directory);
@@ -453,17 +428,13 @@ async function getDirectory(argv, {
453
428
  break;
454
429
  }
455
430
  }
456
-
457
431
  return directory;
458
432
  }
459
-
460
433
  const VALID_TEMPLATES = new Set(['basic', 'single-file']);
461
-
462
434
  async function getTemplate(argv) {
463
435
  if (argv['--template'] && VALID_TEMPLATES.has(argv['--template'])) {
464
436
  return argv['--template'];
465
437
  }
466
-
467
438
  const template = await prompt({
468
439
  type: 'select',
469
440
  message: 'What template would you like to use?',
@@ -474,9 +445,11 @@ async function getTemplate(argv) {
474
445
  }, {
475
446
  title: `${bold_1('Itty-bitty')}, an entire web app in a single file`,
476
447
  value: 'single-file'
477
- } // TODO: GraphQL API
448
+ }
449
+ // TODO: GraphQL API
478
450
  ]
479
451
  });
452
+
480
453
  return template;
481
454
  }
482
455