@quilted/create 0.1.20 → 0.1.21

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.
@@ -0,0 +1,7 @@
1
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
+
3
+ function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }
6
+
7
+ export { commonjsGlobal as c, getDefaultExportFromCjs as g };
@@ -0,0 +1,567 @@
1
+ import { r as relativeDirectoryForDisplay, a as addToTsConfig, b as addToPackageManagerWorkspaces, f as format, l as loadTemplate, _ as _slicedToArray, t as toValidPackageName, c as createOutputTarget, e as emptyDirectory, i as isEmpty } from './package-manager.mjs';
2
+ import { _ as _asyncToGenerator, r as regenerator, c as cyan_1, d as dim_1, s as stripIndent, a as _taggedTemplateLiteral, u as underline_1, m as magenta_1, g as getExtrasToSetup, b as getPackageManager, e as getShouldInstall, f as getCreateAsMonorepo, h as bold_1, p as printHelp, i as arg_1, j as prompt } from './index.mjs';
3
+ import * as fs from 'fs';
4
+ import * as path from 'path';
5
+ import { execSync } from 'child_process';
6
+ import 'url';
7
+ import 'tty';
8
+ import 'readline';
9
+ import 'events';
10
+
11
+ var _templateObject, _templateObject2, _templateObject3;
12
+ function createApp() {
13
+ return _createApp.apply(this, arguments);
14
+ } // Argument handling
15
+
16
+ function _createApp() {
17
+ _createApp = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
18
+ var argv, _argv$PackageManag, additionalOptions, inWorkspace, name, directory, template, createAsMonorepo, shouldInstall, packageManager, setupExtras, partOfMonorepo, appDirectory, rootDirectory, outputRoot, appTemplate, workspaceTemplate, workspacePackageJson, _yield$Promise$all, _yield$Promise$all2, projectPackageJson, projectTSConfig, _workspacePackageJson, quiltProject, _projectPackageJson, commands, whatsNext, followUp;
19
+
20
+ return regenerator.wrap(function _callee$(_context) {
21
+ while (1) {
22
+ switch (_context.prev = _context.next) {
23
+ case 0:
24
+ argv = getArgv();
25
+
26
+ if (!argv['--help']) {
27
+ _context.next = 5;
28
+ break;
29
+ }
30
+
31
+ additionalOptions = stripIndent(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", "\n The template to use for your new application. If you don\u2019t specify a template,\n this command will ask you for one instead. Must be one of the following:\n\n - ", ", a web app with a minimal file structure\n - ", ", an entire web app in a single file\n "])), cyan_1("--template"), bold_1('basic'), bold_1('single-file'));
32
+ printHelp({
33
+ kind: 'app',
34
+ options: additionalOptions,
35
+ packageManager: (_argv$PackageManag = argv['--package-manager']) === null || _argv$PackageManag === void 0 ? void 0 : _argv$PackageManag.toLowerCase()
36
+ });
37
+ return _context.abrupt("return");
38
+
39
+ case 5:
40
+ inWorkspace = fs.existsSync('quilt.workspace.ts');
41
+ _context.next = 8;
42
+ return getName(argv, {
43
+ inWorkspace: inWorkspace
44
+ });
45
+
46
+ case 8:
47
+ name = _context.sent;
48
+ _context.next = 11;
49
+ return getDirectory(argv, {
50
+ name: name
51
+ });
52
+
53
+ case 11:
54
+ directory = _context.sent;
55
+ _context.next = 14;
56
+ return getTemplate(argv);
57
+
58
+ case 14:
59
+ template = _context.sent;
60
+ _context.t0 = !inWorkspace;
61
+
62
+ if (!_context.t0) {
63
+ _context.next = 20;
64
+ break;
65
+ }
66
+
67
+ _context.next = 19;
68
+ return getCreateAsMonorepo(argv);
69
+
70
+ case 19:
71
+ _context.t0 = _context.sent;
72
+
73
+ case 20:
74
+ createAsMonorepo = _context.t0;
75
+ _context.next = 23;
76
+ return getShouldInstall(argv);
77
+
78
+ case 23:
79
+ shouldInstall = _context.sent;
80
+ _context.next = 26;
81
+ return getPackageManager(argv);
82
+
83
+ case 26:
84
+ packageManager = _context.sent;
85
+ _context.next = 29;
86
+ return getExtrasToSetup(argv, {
87
+ inWorkspace: inWorkspace
88
+ });
89
+
90
+ case 29:
91
+ setupExtras = _context.sent;
92
+ partOfMonorepo = inWorkspace || createAsMonorepo;
93
+ appDirectory = createAsMonorepo ? path.join(directory, 'app') : directory;
94
+
95
+ if (!fs.existsSync(directory)) {
96
+ _context.next = 38;
97
+ break;
98
+ }
99
+
100
+ _context.next = 35;
101
+ return emptyDirectory(directory);
102
+
103
+ case 35:
104
+ if (appDirectory !== directory) {
105
+ fs.mkdirSync(appDirectory, {
106
+ recursive: true
107
+ });
108
+ }
109
+
110
+ _context.next = 39;
111
+ break;
112
+
113
+ case 38:
114
+ fs.mkdirSync(appDirectory, {
115
+ recursive: true
116
+ });
117
+
118
+ case 39:
119
+ rootDirectory = inWorkspace ? process.cwd() : directory;
120
+ outputRoot = createOutputTarget(rootDirectory);
121
+ appTemplate = loadTemplate(template === 'basic' ? 'app-basic' : 'app-single-file');
122
+ workspaceTemplate = loadTemplate('workspace'); // If we aren’t already in a workspace, copy the workspace files over, which
123
+ // are needed if we are making a monorepo or not.
124
+
125
+ if (inWorkspace) {
126
+ _context.next = 109;
127
+ break;
128
+ }
129
+
130
+ _context.next = 46;
131
+ return workspaceTemplate.copy(directory, function (file) {
132
+ // When this is a single project, we use the project’s Quilt configuration as the base.
133
+ if (file === 'quilt.workspace.ts') return createAsMonorepo; // We need to make some adjustments to the root package.json
134
+
135
+ return file !== 'package.json';
136
+ });
137
+
138
+ case 46:
139
+ if (!createAsMonorepo) {
140
+ _context.next = 71;
141
+ break;
142
+ }
143
+
144
+ _context.t1 = JSON;
145
+ _context.next = 50;
146
+ return workspaceTemplate.read('package.json');
147
+
148
+ case 50:
149
+ _context.t2 = _context.sent;
150
+ workspacePackageJson = _context.t1.parse.call(_context.t1, _context.t2);
151
+ workspacePackageJson.name = toValidPackageName(name);
152
+
153
+ if (!(packageManager === 'pnpm')) {
154
+ _context.next = 62;
155
+ break;
156
+ }
157
+
158
+ _context.t3 = outputRoot;
159
+ _context.next = 57;
160
+ return format("\n packages:\n - './packages/*'\n ", {
161
+ as: 'yaml'
162
+ });
163
+
164
+ case 57:
165
+ _context.t4 = _context.sent;
166
+ _context.next = 60;
167
+ return _context.t3.write.call(_context.t3, 'pnpm-workspace.yaml', _context.t4);
168
+
169
+ case 60:
170
+ _context.next = 63;
171
+ break;
172
+
173
+ case 62:
174
+ workspacePackageJson.workspaces = ['packages/*'];
175
+
176
+ case 63:
177
+ _context.t5 = outputRoot;
178
+ _context.next = 66;
179
+ return format(JSON.stringify(workspacePackageJson), {
180
+ as: 'json-stringify'
181
+ });
182
+
183
+ case 66:
184
+ _context.t6 = _context.sent;
185
+ _context.next = 69;
186
+ return _context.t5.write.call(_context.t5, 'package.json', _context.t6);
187
+
188
+ case 69:
189
+ _context.next = 103;
190
+ break;
191
+
192
+ case 71:
193
+ _context.next = 73;
194
+ return Promise.all([appTemplate.read('package.json').then(function (content) {
195
+ return JSON.parse(content);
196
+ }), appTemplate.read('tsconfig.json').then(function (content) {
197
+ return JSON.parse(content);
198
+ }), workspaceTemplate.read('package.json').then(function (content) {
199
+ return JSON.parse(content);
200
+ })]);
201
+
202
+ case 73:
203
+ _yield$Promise$all = _context.sent;
204
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
205
+ projectPackageJson = _yield$Promise$all2[0];
206
+ projectTSConfig = _yield$Promise$all2[1];
207
+ _workspacePackageJson = _yield$Promise$all2[2];
208
+ _workspacePackageJson.name = toValidPackageName(name);
209
+ _workspacePackageJson.eslintConfig = projectPackageJson.eslintConfig;
210
+ _workspacePackageJson.browserslist = projectPackageJson.browserslist;
211
+ _context.next = 83;
212
+ return appTemplate.read('quilt.project.ts');
213
+
214
+ case 83:
215
+ quiltProject = _context.sent;
216
+ quiltProject = quiltProject.replace('quiltApp', 'quiltWorkspace, quiltApp').replace('quiltApp(', 'quiltWorkspace(), quiltApp(');
217
+ _context.t7 = outputRoot;
218
+ _context.next = 88;
219
+ return format(quiltProject, {
220
+ as: 'typescript'
221
+ });
222
+
223
+ case 88:
224
+ _context.t8 = _context.sent;
225
+ _context.next = 91;
226
+ return _context.t7.write.call(_context.t7, 'quilt.project.ts', _context.t8);
227
+
228
+ case 91:
229
+ _context.t9 = outputRoot;
230
+ _context.next = 94;
231
+ return format(JSON.stringify(_workspacePackageJson), {
232
+ as: 'json-stringify'
233
+ });
234
+
235
+ case 94:
236
+ _context.t10 = _context.sent;
237
+ _context.next = 97;
238
+ return _context.t9.write.call(_context.t9, 'package.json', _context.t10);
239
+
240
+ case 97:
241
+ _context.t11 = outputRoot;
242
+ _context.next = 100;
243
+ return format(JSON.stringify(projectTSConfig), {
244
+ as: 'json'
245
+ });
246
+
247
+ case 100:
248
+ _context.t12 = _context.sent;
249
+ _context.next = 103;
250
+ return _context.t11.write.call(_context.t11, 'tsconfig.json', _context.t12);
251
+
252
+ case 103:
253
+ if (!setupExtras.has('github')) {
254
+ _context.next = 106;
255
+ break;
256
+ }
257
+
258
+ _context.next = 106;
259
+ return loadTemplate('github').copy(directory);
260
+
261
+ case 106:
262
+ if (!setupExtras.has('vscode')) {
263
+ _context.next = 109;
264
+ break;
265
+ }
266
+
267
+ _context.next = 109;
268
+ return loadTemplate('vscode').copy(directory);
269
+
270
+ case 109:
271
+ _context.next = 111;
272
+ return appTemplate.copy(appDirectory, function (file) {
273
+ // If we are in a monorepo, we can use all the template files as they are
274
+ if (file === 'quilt.project.ts' || file === 'tsconfig.json') {
275
+ return partOfMonorepo;
276
+ } // We need to make some adjustments the project’s package.json
277
+
278
+
279
+ return file !== 'package.json';
280
+ });
281
+
282
+ case 111:
283
+ if (!partOfMonorepo) {
284
+ _context.next = 127;
285
+ break;
286
+ }
287
+
288
+ _context.t13 = JSON;
289
+ _context.next = 115;
290
+ return appTemplate.read('package.json');
291
+
292
+ case 115:
293
+ _context.t14 = _context.sent;
294
+ _projectPackageJson = _context.t13.parse.call(_context.t13, _context.t14);
295
+ _projectPackageJson.name = path.basename(appDirectory);
296
+ _context.t15 = outputRoot;
297
+ _context.t16 = path.join(appDirectory, 'package.json');
298
+ _context.next = 122;
299
+ return format(JSON.stringify(_projectPackageJson), {
300
+ as: 'json-stringify'
301
+ });
302
+
303
+ case 122:
304
+ _context.t17 = _context.sent;
305
+ _context.next = 125;
306
+ return _context.t15.write.call(_context.t15, _context.t16, _context.t17);
307
+
308
+ case 125:
309
+ _context.next = 127;
310
+ return Promise.all([addToTsConfig(appDirectory, outputRoot), addToPackageManagerWorkspaces(appDirectory, outputRoot, packageManager)]);
311
+
312
+ case 127:
313
+ if (shouldInstall) {
314
+ process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
315
+
316
+ execSync("".concat(packageManager, " install"), {
317
+ cwd: rootDirectory
318
+ });
319
+ process.stdout.moveCursor(0, -1);
320
+ process.stdout.clearLine(1);
321
+ console.log('Installed dependencies.');
322
+ }
323
+
324
+ commands = [];
325
+
326
+ if (!inWorkspace && directory !== process.cwd()) {
327
+ commands.push("cd ".concat(cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), directory))), " ").concat(dim_1('# Move into your new app’s directory')));
328
+ }
329
+
330
+ if (!shouldInstall) {
331
+ commands.push("pnpm install ".concat(dim_1('# Install all your dependencies')));
332
+ }
333
+
334
+ if (!inWorkspace) {
335
+ // TODO: change this condition to check if git was initialized already
336
+ commands.push("git init && git add -A && git commit -m \"Initial commit\" ".concat(dim_1('# Start your git history (optional)')));
337
+ }
338
+
339
+ commands.push("pnpm develop ".concat(dim_1('# Start the development server')));
340
+ whatsNext = stripIndent(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n Your new app is ready to go! There\u2019s just ", " you\u2019ll need to take\n in order to start developing:\n "])), commands.length > 1 ? 'a few more steps' : 'one more step');
341
+ console.log();
342
+ console.log(whatsNext);
343
+ console.log();
344
+ console.log(commands.map(function (command) {
345
+ return " ".concat(command);
346
+ }).join('\n'));
347
+ followUp = stripIndent(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n Quilt can also help you build, test, lint, and type-check your new application.\n You can learn more about building apps with Quilt by reading the documentation:\n ", "\n\n Have fun! \uD83C\uDF89\n "])), underline_1(magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation')));
348
+ console.log();
349
+ console.log(followUp);
350
+
351
+ case 141:
352
+ case "end":
353
+ return _context.stop();
354
+ }
355
+ }
356
+ }, _callee);
357
+ }));
358
+ return _createApp.apply(this, arguments);
359
+ }
360
+
361
+ function getArgv() {
362
+ var argv = arg_1({
363
+ '--yes': Boolean,
364
+ '-y': '--yes',
365
+ '--name': String,
366
+ '--template': String,
367
+ '--directory': String,
368
+ '--install': Boolean,
369
+ '--no-install': Boolean,
370
+ '--monorepo': Boolean,
371
+ '--no-monorepo': Boolean,
372
+ '--package-manager': String,
373
+ '--extras': [String],
374
+ '--no-extras': Boolean,
375
+ '--help': Boolean,
376
+ '-h': '--help'
377
+ }, {
378
+ permissive: true
379
+ });
380
+ return argv;
381
+ }
382
+
383
+ function getName(_x, _x2) {
384
+ return _getName.apply(this, arguments);
385
+ }
386
+
387
+ function _getName() {
388
+ _getName = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(argv, _ref) {
389
+ var inWorkspace, name;
390
+ return regenerator.wrap(function _callee2$(_context2) {
391
+ while (1) {
392
+ switch (_context2.prev = _context2.next) {
393
+ case 0:
394
+ inWorkspace = _ref.inWorkspace;
395
+ name = argv['--name'];
396
+
397
+ if (!(name == null)) {
398
+ _context2.next = 6;
399
+ break;
400
+ }
401
+
402
+ _context2.next = 5;
403
+ return prompt({
404
+ type: 'text',
405
+ message: 'What would you like to name your new app?',
406
+ initial: inWorkspace ? 'app' : 'my-quilt-app'
407
+ });
408
+
409
+ case 5:
410
+ name = _context2.sent;
411
+
412
+ case 6:
413
+ return _context2.abrupt("return", name);
414
+
415
+ case 7:
416
+ case "end":
417
+ return _context2.stop();
418
+ }
419
+ }
420
+ }, _callee2);
421
+ }));
422
+ return _getName.apply(this, arguments);
423
+ }
424
+
425
+ function getDirectory(_x3, _x4) {
426
+ return _getDirectory.apply(this, arguments);
427
+ }
428
+
429
+ function _getDirectory() {
430
+ _getDirectory = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(argv, _ref2) {
431
+ var _argv$Directory;
432
+
433
+ var name, directory, relativeDirectory, empty, promptDirectory;
434
+ return regenerator.wrap(function _callee3$(_context3) {
435
+ while (1) {
436
+ switch (_context3.prev = _context3.next) {
437
+ case 0:
438
+ name = _ref2.name;
439
+ directory = path.resolve((_argv$Directory = argv['--directory']) !== null && _argv$Directory !== void 0 ? _argv$Directory : toValidPackageName(name));
440
+
441
+ case 2:
442
+ if (argv['--yes']) {
443
+ _context3.next = 24;
444
+ break;
445
+ }
446
+
447
+ _context3.t0 = fs.existsSync(directory);
448
+
449
+ if (!_context3.t0) {
450
+ _context3.next = 8;
451
+ break;
452
+ }
453
+
454
+ _context3.next = 7;
455
+ return isEmpty(directory);
456
+
457
+ case 7:
458
+ _context3.t0 = !_context3.sent;
459
+
460
+ case 8:
461
+ if (!_context3.t0) {
462
+ _context3.next = 21;
463
+ break;
464
+ }
465
+
466
+ relativeDirectory = path.relative(process.cwd(), directory);
467
+ _context3.next = 12;
468
+ return prompt({
469
+ type: 'confirm',
470
+ message: "Directory ".concat(bold_1(relativeDirectoryForDisplay(relativeDirectory)), " is not empty, is it safe to empty it?"),
471
+ initial: true
472
+ });
473
+
474
+ case 12:
475
+ empty = _context3.sent;
476
+
477
+ if (!empty) {
478
+ _context3.next = 15;
479
+ break;
480
+ }
481
+
482
+ return _context3.abrupt("break", 24);
483
+
484
+ case 15:
485
+ _context3.next = 17;
486
+ return prompt({
487
+ type: 'text',
488
+ message: 'What directory do you want to create your new app in?'
489
+ });
490
+
491
+ case 17:
492
+ promptDirectory = _context3.sent;
493
+ directory = path.resolve(promptDirectory);
494
+ _context3.next = 22;
495
+ break;
496
+
497
+ case 21:
498
+ return _context3.abrupt("break", 24);
499
+
500
+ case 22:
501
+ _context3.next = 2;
502
+ break;
503
+
504
+ case 24:
505
+ return _context3.abrupt("return", directory);
506
+
507
+ case 25:
508
+ case "end":
509
+ return _context3.stop();
510
+ }
511
+ }
512
+ }, _callee3);
513
+ }));
514
+ return _getDirectory.apply(this, arguments);
515
+ }
516
+
517
+ var VALID_TEMPLATES = new Set(['basic', 'single-file']);
518
+
519
+ function getTemplate(_x5) {
520
+ return _getTemplate.apply(this, arguments);
521
+ }
522
+
523
+ function _getTemplate() {
524
+ _getTemplate = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(argv) {
525
+ var template;
526
+ return regenerator.wrap(function _callee4$(_context4) {
527
+ while (1) {
528
+ switch (_context4.prev = _context4.next) {
529
+ case 0:
530
+ if (!(argv['--template'] && VALID_TEMPLATES.has(argv['--template']))) {
531
+ _context4.next = 2;
532
+ break;
533
+ }
534
+
535
+ return _context4.abrupt("return", argv['--template']);
536
+
537
+ case 2:
538
+ _context4.next = 4;
539
+ return prompt({
540
+ type: 'select',
541
+ message: 'What template would you like to use?',
542
+ hint: "Use ".concat(bold_1('arrow keys'), " to select, and ").concat(bold_1('return'), " to submit"),
543
+ choices: [{
544
+ title: "".concat(bold_1('The basics'), ", a web app with a minimal file structure"),
545
+ value: 'basic'
546
+ }, {
547
+ title: "".concat(bold_1('Itty-bitty'), ", an entire web app in a single file"),
548
+ value: 'single-file'
549
+ } // TODO: GraphQL API
550
+ ]
551
+ });
552
+
553
+ case 4:
554
+ template = _context4.sent;
555
+ return _context4.abrupt("return", template);
556
+
557
+ case 6:
558
+ case "end":
559
+ return _context4.stop();
560
+ }
561
+ }
562
+ }, _callee4);
563
+ }));
564
+ return _getTemplate.apply(this, arguments);
565
+ }
566
+
567
+ export { createApp };