@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/esm/app.mjs CHANGED
@@ -1,365 +1,201 @@
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
- }
1
+ import * as fs from 'node:fs';
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';
6
+ import 'node:tty';
7
+ import 'node:url';
8
+ import 'node:readline';
9
+ import 'node:events';
10
+
11
+ let _ = t => t,
12
+ _t,
13
+ _t2,
14
+ _t3;
15
+ async function createApp() {
16
+ const argv = getArgv();
17
+
18
+ if (argv['--help']) {
19
+ var _argv$PackageManag;
20
+
21
+ const additionalOptions = stripIndent(_t || (_t = _`
22
+ ${0}
23
+ The template to use for your new application. If you don’t specify a template,
24
+ this command will ask you for one instead. Must be one of the following:
25
+
26
+ - ${0}, a web app with a minimal file structure
27
+ - ${0}, an entire web app in a single file
28
+ `), cyan_1(`--template`), bold_1('basic'), bold_1('single-file'));
29
+ printHelp({
30
+ kind: 'app',
31
+ options: additionalOptions,
32
+ packageManager: (_argv$PackageManag = argv['--package-manager']) === null || _argv$PackageManag === void 0 ? void 0 : _argv$PackageManag.toLowerCase()
33
+ });
34
+ return;
35
+ }
36
+
37
+ const inWorkspace = fs.existsSync('quilt.workspace.ts');
38
+ const name = await getName(argv, {
39
+ inWorkspace
40
+ });
41
+ const directory = await getDirectory(argv, {
42
+ name
43
+ });
44
+ const template = await getTemplate(argv);
45
+ const createAsMonorepo = !inWorkspace && (await getCreateAsMonorepo(argv));
46
+ const shouldInstall = await getShouldInstall(argv);
47
+ const packageManager = await getPackageManager(argv);
48
+ const setupExtras = await getExtrasToSetup(argv, {
49
+ inWorkspace
50
+ });
51
+ const partOfMonorepo = inWorkspace || createAsMonorepo;
52
+ const appDirectory = createAsMonorepo ? path.join(directory, 'app') : directory;
53
+
54
+ if (fs.existsSync(directory)) {
55
+ await emptyDirectory(directory);
56
+
57
+ if (appDirectory !== directory) {
58
+ fs.mkdirSync(appDirectory, {
59
+ recursive: true
60
+ });
61
+ }
62
+ } else {
63
+ fs.mkdirSync(appDirectory, {
64
+ recursive: true
65
+ });
66
+ }
67
+
68
+ const rootDirectory = inWorkspace ? process.cwd() : directory;
69
+ const outputRoot = createOutputTarget(rootDirectory);
70
+ const appTemplate = loadTemplate(template === 'basic' ? 'app-basic' : 'app-single-file');
71
+ const workspaceTemplate = loadTemplate('workspace'); // If we aren’t already in a workspace, copy the workspace files over, which
72
+ // are needed if we are making a monorepo or not.
73
+
74
+ if (!inWorkspace) {
75
+ await workspaceTemplate.copy(directory, file => {
76
+ // When this is a single project, we use the project’s Quilt configuration as the base.
77
+ if (file === 'quilt.workspace.ts') return createAsMonorepo; // We need to make some adjustments to the root package.json
78
+
79
+ return file !== 'package.json';
80
+ }); // If we are creating a monorepo, we need to add the root package.json and
81
+ // package manager workspace configuration.
82
+
83
+ if (createAsMonorepo) {
84
+ const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
85
+ workspacePackageJson.name = toValidPackageName(name);
86
+
87
+ if (packageManager === 'pnpm') {
88
+ await outputRoot.write('pnpm-workspace.yaml', await format(`
89
+ packages:
90
+ - './packages/*'
91
+ `, {
92
+ as: 'yaml'
93
+ }));
94
+ } else {
95
+ workspacePackageJson.workspaces = ['packages/*'];
355
96
  }
356
- }, _callee);
357
- }));
358
- return _createApp.apply(this, arguments);
359
- }
97
+
98
+ await outputRoot.write('package.json', await format(JSON.stringify(workspacePackageJson), {
99
+ as: 'json-stringify'
100
+ }));
101
+ } else {
102
+ 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))]);
103
+ workspacePackageJson.name = toValidPackageName(name);
104
+ workspacePackageJson.eslintConfig = projectPackageJson.eslintConfig;
105
+ workspacePackageJson.browserslist = projectPackageJson.browserslist;
106
+ workspacePackageJson.devDependencies = mergeDependencies(workspacePackageJson.devDependencies, projectPackageJson.devDependencies);
107
+ let quiltProject = await appTemplate.read('quilt.project.ts');
108
+ quiltProject = quiltProject.replace('quiltApp', 'quiltWorkspace, quiltApp').replace('quiltApp(', 'quiltWorkspace(), quiltApp(');
109
+ await outputRoot.write('quilt.project.ts', await format(quiltProject, {
110
+ as: 'typescript'
111
+ }));
112
+ await outputRoot.write('package.json', await format(JSON.stringify(workspacePackageJson), {
113
+ as: 'json-stringify'
114
+ }));
115
+ await outputRoot.write('tsconfig.json', await format(JSON.stringify(projectTSConfig), {
116
+ as: 'json'
117
+ }));
118
+ }
119
+
120
+ if (setupExtras.has('github')) {
121
+ await loadTemplate('github').copy(directory);
122
+ }
123
+
124
+ if (setupExtras.has('vscode')) {
125
+ await loadTemplate('vscode').copy(directory);
126
+ }
127
+ }
128
+
129
+ await appTemplate.copy(appDirectory, file => {
130
+ // If we are in a monorepo, we can use all the template files as they are
131
+ if (file === 'quilt.project.ts' || file === 'tsconfig.json') {
132
+ return partOfMonorepo;
133
+ } // We need to make some adjustments the project’s package.json
134
+
135
+
136
+ return file !== 'package.json';
137
+ });
138
+
139
+ if (partOfMonorepo) {
140
+ // Write the app’s package.json (the root one was already created)
141
+ const projectPackageJson = JSON.parse(await appTemplate.read('package.json'));
142
+ projectPackageJson.name = path.basename(appDirectory);
143
+ await outputRoot.write(path.join(appDirectory, 'package.json'), await format(JSON.stringify(projectPackageJson), {
144
+ as: 'json-stringify'
145
+ }));
146
+ await Promise.all([addToTsConfig(appDirectory, outputRoot), addToPackageManagerWorkspaces(appDirectory, outputRoot, packageManager)]);
147
+ }
148
+
149
+ if (shouldInstall) {
150
+ process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
151
+
152
+ execSync(`${packageManager} install`, {
153
+ cwd: rootDirectory
154
+ });
155
+ process.stdout.moveCursor(0, -1);
156
+ process.stdout.clearLine(1);
157
+ console.log('Installed dependencies.');
158
+ }
159
+
160
+ const commands = [];
161
+
162
+ const packageManagerRun = command => packageManager === 'npm' ? `npm run ${command}` : `pnpm ${command}`;
163
+
164
+ if (!inWorkspace && directory !== process.cwd()) {
165
+ commands.push(`cd ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), directory)))} ${dim_1('# Move into your new app’s directory')}`);
166
+ }
167
+
168
+ if (!shouldInstall) {
169
+ commands.push(`${packageManager} install ${dim_1('# Install all your dependencies')}`);
170
+ }
171
+
172
+ if (!inWorkspace) {
173
+ // TODO: change this condition to check if git was initialized already
174
+ commands.push(`git init && git add -A && git commit -m "Initial commit" ${dim_1('# Start your git history (optional)')}`);
175
+ }
176
+
177
+ commands.push(`${packageManagerRun('develop')} ${dim_1('# Start the development server')}`);
178
+ const whatsNext = stripIndent(_t2 || (_t2 = _`
179
+ Your new app is ready to go! There’s just ${0} you’ll need to take
180
+ in order to start developing:
181
+ `), commands.length > 1 ? 'a few more steps' : 'one more step');
182
+ console.log();
183
+ console.log(whatsNext);
184
+ console.log();
185
+ console.log(commands.map(command => ` ${command}`).join('\n'));
186
+ const followUp = stripIndent(_t3 || (_t3 = _`
187
+ Quilt can also help you build, test, lint, and type-check your new application.
188
+ You can learn more about building apps with Quilt by reading the documentation:
189
+ ${0}
190
+
191
+ Have fun! 🎉
192
+ `), underline_1(magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation')));
193
+ console.log();
194
+ console.log(followUp);
195
+ } // Argument handling
360
196
 
361
197
  function getArgv() {
362
- var argv = arg_1({
198
+ const argv = arg_1({
363
199
  '--yes': Boolean,
364
200
  '-y': '--yes',
365
201
  '--name': String,
@@ -380,188 +216,74 @@ function getArgv() {
380
216
  return argv;
381
217
  }
382
218
 
383
- function getName(_x, _x2) {
384
- return _getName.apply(this, arguments);
219
+ async function getName(argv, {
220
+ inWorkspace
221
+ }) {
222
+ let {
223
+ '--name': name
224
+ } = argv;
225
+
226
+ if (name == null) {
227
+ name = await prompt({
228
+ type: 'text',
229
+ message: 'What would you like to name your new app?',
230
+ initial: inWorkspace ? 'app' : 'my-quilt-app'
231
+ });
232
+ }
233
+
234
+ return name;
385
235
  }
386
236
 
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);
237
+ async function getDirectory(argv, {
238
+ name
239
+ }) {
240
+ var _argv$Directory;
241
+
242
+ let directory = path.resolve((_argv$Directory = argv['--directory']) !== null && _argv$Directory !== void 0 ? _argv$Directory : toValidPackageName(name));
243
+
244
+ while (!argv['--yes']) {
245
+ if (fs.existsSync(directory) && !(await isEmpty(directory))) {
246
+ const relativeDirectory = path.relative(process.cwd(), directory);
247
+ const empty = await prompt({
248
+ type: 'confirm',
249
+ message: `Directory ${bold_1(relativeDirectoryForDisplay(relativeDirectory))} is not empty, is it safe to empty it?`,
250
+ initial: true
251
+ });
252
+ if (empty) break;
253
+ const promptDirectory = await prompt({
254
+ type: 'text',
255
+ message: 'What directory do you want to create your new app in?'
256
+ });
257
+ directory = path.resolve(promptDirectory);
258
+ } else {
259
+ break;
260
+ }
261
+ }
262
+
263
+ return directory;
423
264
  }
424
265
 
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);
266
+ const VALID_TEMPLATES = new Set(['basic', 'single-file']);
267
+
268
+ async function getTemplate(argv) {
269
+ if (argv['--template'] && VALID_TEMPLATES.has(argv['--template'])) {
270
+ return argv['--template'];
271
+ }
272
+
273
+ const template = await prompt({
274
+ type: 'select',
275
+ message: 'What template would you like to use?',
276
+ hint: `Use ${bold_1('arrow keys')} to select, and ${bold_1('return')} to submit`,
277
+ choices: [{
278
+ title: `${bold_1('The basics')}, a web app with a minimal file structure`,
279
+ value: 'basic'
280
+ }, {
281
+ title: `${bold_1('Itty-bitty')}, an entire web app in a single file`,
282
+ value: 'single-file'
283
+ } // TODO: GraphQL API
284
+ ]
285
+ });
286
+ return template;
565
287
  }
566
288
 
567
289
  export { createApp };