@quilted/create 0.1.21 → 0.1.24

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