@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,807 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index.cjs');
4
+ var packageManager = require('./package-manager.cjs');
5
+ var fs = require('fs');
6
+ var path = require('path');
7
+ var child_process = require('child_process');
8
+ require('tty');
9
+ require('url');
10
+ require('readline');
11
+ require('events');
12
+
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);
29
+ }
30
+
31
+ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
32
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
33
+
34
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4;
35
+
36
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
37
+
38
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { index._defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
39
+
40
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
41
+
42
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
43
+
44
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
45
+ function createProject() {
46
+ return _createProject.apply(this, arguments);
47
+ } // Argument handling
48
+
49
+ function _createProject() {
50
+ _createProject = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee() {
51
+ var argv, _argv$PackageManag, additionalOptions, inWorkspace, name, directory, isPublic, useReact, createAsMonorepo, shouldInstall, packageManager$1, setupExtras, partOfMonorepo, packageDirectory, rootDirectory, outputRoot, packageTemplate, workspaceTemplate, quiltProject, workspacePackageJson, _yield$Promise$all, _yield$Promise$all2, projectPackageJson, projectTSConfig, _workspacePackageJson, newPackageJson, _i, _Object$entries, _Object$entries$_i, key, value, _projectPackageJson, packageJsonInstructions, commands, whatsNext, followUp;
52
+
53
+ return index.regenerator.wrap(function _callee$(_context) {
54
+ while (1) {
55
+ switch (_context.prev = _context.next) {
56
+ case 0:
57
+ argv = getArgv();
58
+
59
+ if (!argv['--help']) {
60
+ _context.next = 5;
61
+ break;
62
+ }
63
+
64
+ additionalOptions = index.stripIndent(_templateObject || (_templateObject = index._taggedTemplateLiteral(["\n ", ", ", "\n Whether this package will use React. If you don\u2019t provide this option, the command\n will ask you about it later.\n\n ", ", ", "\n Whether this package will be published for other projects to install. If you do not\n provide this option, the command will ask you about it later.\n\n ", "\n The package registry to publish this package to. This option only applies if you create\n a public package. If you do not provide this option, it will use the default NPM registry.\n "])), index.cyan_1("--react"), index.cyan_1("--no-react"), index.cyan_1("--public"), index.cyan_1("--private"), index.cyan_1("--registry"));
65
+ index.printHelp({
66
+ kind: 'package',
67
+ options: additionalOptions,
68
+ packageManager: (_argv$PackageManag = argv['--package-manager']) === null || _argv$PackageManag === void 0 ? void 0 : _argv$PackageManag.toLowerCase()
69
+ });
70
+ return _context.abrupt("return");
71
+
72
+ case 5:
73
+ inWorkspace = fs__namespace.existsSync('quilt.workspace.ts');
74
+ _context.next = 8;
75
+ return getName(argv);
76
+
77
+ case 8:
78
+ name = _context.sent;
79
+ _context.next = 11;
80
+ return getDirectory(argv, {
81
+ name: name,
82
+ inWorkspace: inWorkspace
83
+ });
84
+
85
+ case 11:
86
+ directory = _context.sent;
87
+ _context.next = 14;
88
+ return getPublic(argv);
89
+
90
+ case 14:
91
+ isPublic = _context.sent;
92
+ _context.next = 17;
93
+ return getReact(argv);
94
+
95
+ case 17:
96
+ useReact = _context.sent;
97
+ _context.t0 = !inWorkspace;
98
+
99
+ if (!_context.t0) {
100
+ _context.next = 23;
101
+ break;
102
+ }
103
+
104
+ _context.next = 22;
105
+ return index.getCreateAsMonorepo(argv);
106
+
107
+ case 22:
108
+ _context.t0 = _context.sent;
109
+
110
+ case 23:
111
+ createAsMonorepo = _context.t0;
112
+ _context.next = 26;
113
+ return index.getShouldInstall(argv);
114
+
115
+ case 26:
116
+ shouldInstall = _context.sent;
117
+ _context.next = 29;
118
+ return index.getPackageManager(argv);
119
+
120
+ case 29:
121
+ packageManager$1 = _context.sent;
122
+ _context.next = 32;
123
+ return index.getExtrasToSetup(argv, {
124
+ inWorkspace: inWorkspace
125
+ });
126
+
127
+ case 32:
128
+ setupExtras = _context.sent;
129
+ partOfMonorepo = inWorkspace || createAsMonorepo;
130
+ packageDirectory = createAsMonorepo ? path__namespace.join(directory, "packages/".concat(packageManager.toValidPackageName(name.split('/').pop()))) : directory;
131
+
132
+ if (!fs__namespace.existsSync(directory)) {
133
+ _context.next = 41;
134
+ break;
135
+ }
136
+
137
+ _context.next = 38;
138
+ return packageManager.emptyDirectory(directory);
139
+
140
+ case 38:
141
+ if (packageDirectory !== directory) {
142
+ fs__namespace.mkdirSync(packageDirectory, {
143
+ recursive: true
144
+ });
145
+ }
146
+
147
+ _context.next = 42;
148
+ break;
149
+
150
+ case 41:
151
+ fs__namespace.mkdirSync(packageDirectory, {
152
+ recursive: true
153
+ });
154
+
155
+ case 42:
156
+ rootDirectory = inWorkspace ? process.cwd() : directory;
157
+ outputRoot = packageManager.createOutputTarget(rootDirectory);
158
+ packageTemplate = packageManager.loadTemplate('package');
159
+ workspaceTemplate = packageManager.loadTemplate('workspace');
160
+ _context.next = 48;
161
+ return packageTemplate.read('quilt.project.ts');
162
+
163
+ case 48:
164
+ quiltProject = _context.sent;
165
+
166
+ if (useReact) {
167
+ quiltProject = quiltProject.replace('react: false', 'react: true');
168
+ } // If we aren’t already in a workspace, copy the workspace files over, which
169
+ // are needed if we are making a monorepo or not.
170
+
171
+
172
+ if (inWorkspace) {
173
+ _context.next = 127;
174
+ break;
175
+ }
176
+
177
+ _context.next = 53;
178
+ return workspaceTemplate.copy(directory, function (file) {
179
+ // When this is a single project, we use the project’s Quilt configuration as the base.
180
+ if (file === 'quilt.workspace.ts') return createAsMonorepo; // We need to make some adjustments to the root package.json
181
+
182
+ return file !== 'package.json';
183
+ });
184
+
185
+ case 53:
186
+ if (!createAsMonorepo) {
187
+ _context.next = 78;
188
+ break;
189
+ }
190
+
191
+ _context.t1 = JSON;
192
+ _context.next = 57;
193
+ return workspaceTemplate.read('package.json');
194
+
195
+ case 57:
196
+ _context.t2 = _context.sent;
197
+ workspacePackageJson = _context.t1.parse.call(_context.t1, _context.t2);
198
+ workspacePackageJson.name = packageManager.toValidPackageName(name);
199
+
200
+ if (!(packageManager$1 === 'pnpm')) {
201
+ _context.next = 69;
202
+ break;
203
+ }
204
+
205
+ _context.t3 = outputRoot;
206
+ _context.next = 64;
207
+ return packageManager.format("\n packages:\n - './packages/*'\n ", {
208
+ as: 'yaml'
209
+ });
210
+
211
+ case 64:
212
+ _context.t4 = _context.sent;
213
+ _context.next = 67;
214
+ return _context.t3.write.call(_context.t3, 'pnpm-workspace.yaml', _context.t4);
215
+
216
+ case 67:
217
+ _context.next = 70;
218
+ break;
219
+
220
+ case 69:
221
+ workspacePackageJson.workspaces = ['packages/*'];
222
+
223
+ case 70:
224
+ _context.t5 = outputRoot;
225
+ _context.next = 73;
226
+ return packageManager.format(JSON.stringify(workspacePackageJson), {
227
+ as: 'json-stringify'
228
+ });
229
+
230
+ case 73:
231
+ _context.t6 = _context.sent;
232
+ _context.next = 76;
233
+ return _context.t5.write.call(_context.t5, 'package.json', _context.t6);
234
+
235
+ case 76:
236
+ _context.next = 121;
237
+ break;
238
+
239
+ case 78:
240
+ _context.next = 80;
241
+ return Promise.all([packageTemplate.read('package.json').then(function (content) {
242
+ return JSON.parse(content);
243
+ }), packageTemplate.read('tsconfig.json').then(function (content) {
244
+ return JSON.parse(content);
245
+ }), workspaceTemplate.read('package.json').then(function (content) {
246
+ return JSON.parse(content);
247
+ })]);
248
+
249
+ case 80:
250
+ _yield$Promise$all = _context.sent;
251
+ _yield$Promise$all2 = packageManager._slicedToArray(_yield$Promise$all, 3);
252
+ projectPackageJson = _yield$Promise$all2[0];
253
+ projectTSConfig = _yield$Promise$all2[1];
254
+ _workspacePackageJson = _yield$Promise$all2[2];
255
+ _workspacePackageJson.eslintConfig = projectPackageJson.eslintConfig;
256
+ _workspacePackageJson.browserslist = projectPackageJson.browserslist;
257
+ newPackageJson = {}; // We want to put the project’s dependencies in the package.json, respecting
258
+ // the preferred ordering (dependencies, peer dependencies, dev dependencies).
259
+
260
+ _i = 0, _Object$entries = Object.entries(projectPackageJson);
261
+
262
+ case 89:
263
+ if (!(_i < _Object$entries.length)) {
264
+ _context.next = 101;
265
+ break;
266
+ }
267
+
268
+ _Object$entries$_i = packageManager._slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
269
+
270
+ if (!(key !== 'devDependencies')) {
271
+ _context.next = 94;
272
+ break;
273
+ }
274
+
275
+ newPackageJson[key] = value;
276
+ return _context.abrupt("continue", 98);
277
+
278
+ case 94:
279
+ newPackageJson.dependencies = projectPackageJson.dependencies;
280
+ newPackageJson.peerDependencies = projectPackageJson.peerDependencies;
281
+ newPackageJson.peerDependenciesMeta = projectPackageJson.peerDependenciesMeta;
282
+ newPackageJson.devDependencies = sortKeys(_objectSpread(_objectSpread({}, _workspacePackageJson.devDependencies), projectPackageJson.devDependencies));
283
+
284
+ case 98:
285
+ _i++;
286
+ _context.next = 89;
287
+ break;
288
+
289
+ case 101:
290
+ adjustPackageJson(newPackageJson, {
291
+ name: packageManager.toValidPackageName(name),
292
+ react: useReact,
293
+ isPublic: isPublic,
294
+ registry: argv['--registry']
295
+ });
296
+ quiltProject = quiltProject.replace('quiltPackage', 'quiltWorkspace, quiltPackage').replace('quiltPackage(', 'quiltWorkspace(), quiltPackage(');
297
+ _context.t7 = outputRoot;
298
+ _context.next = 106;
299
+ return packageManager.format(quiltProject, {
300
+ as: 'typescript'
301
+ });
302
+
303
+ case 106:
304
+ _context.t8 = _context.sent;
305
+ _context.next = 109;
306
+ return _context.t7.write.call(_context.t7, 'quilt.project.ts', _context.t8);
307
+
308
+ case 109:
309
+ _context.t9 = outputRoot;
310
+ _context.next = 112;
311
+ return packageManager.format(JSON.stringify(newPackageJson), {
312
+ as: 'json-stringify'
313
+ });
314
+
315
+ case 112:
316
+ _context.t10 = _context.sent;
317
+ _context.next = 115;
318
+ return _context.t9.write.call(_context.t9, 'package.json', _context.t10);
319
+
320
+ case 115:
321
+ _context.t11 = outputRoot;
322
+ _context.next = 118;
323
+ return packageManager.format(JSON.stringify(projectTSConfig), {
324
+ as: 'json'
325
+ });
326
+
327
+ case 118:
328
+ _context.t12 = _context.sent;
329
+ _context.next = 121;
330
+ return _context.t11.write.call(_context.t11, 'tsconfig.json', _context.t12);
331
+
332
+ case 121:
333
+ if (!setupExtras.has('github')) {
334
+ _context.next = 124;
335
+ break;
336
+ }
337
+
338
+ _context.next = 124;
339
+ return packageManager.loadTemplate('github').copy(directory);
340
+
341
+ case 124:
342
+ if (!setupExtras.has('vscode')) {
343
+ _context.next = 127;
344
+ break;
345
+ }
346
+
347
+ _context.next = 127;
348
+ return packageManager.loadTemplate('vscode').copy(directory);
349
+
350
+ case 127:
351
+ _context.next = 129;
352
+ return packageTemplate.copy(packageDirectory, function (file) {
353
+ // If we are in a monorepo, we can use all the template files as they are
354
+ if (file === 'tsconfig.json') {
355
+ return partOfMonorepo;
356
+ } // We need to make some adjustments the project’s package.json and Quilt config
357
+
358
+
359
+ return file !== 'package.json' && file !== 'quilt.project.ts';
360
+ });
361
+
362
+ case 129:
363
+ if (!partOfMonorepo) {
364
+ _context.next = 148;
365
+ break;
366
+ }
367
+
368
+ _context.t13 = JSON;
369
+ _context.next = 133;
370
+ return packageTemplate.read('package.json');
371
+
372
+ case 133:
373
+ _context.t14 = _context.sent;
374
+ _projectPackageJson = _context.t13.parse.call(_context.t13, _context.t14);
375
+ _projectPackageJson.repository.directory = path__namespace.relative(directory, packageDirectory);
376
+ adjustPackageJson(_projectPackageJson, {
377
+ name: packageManager.toValidPackageName(name),
378
+ react: useReact,
379
+ isPublic: isPublic,
380
+ registry: argv['--registry']
381
+ });
382
+ _context.t15 = outputRoot;
383
+ _context.t16 = path__namespace.join(packageDirectory, 'package.json');
384
+ _context.next = 141;
385
+ return packageManager.format(JSON.stringify(_projectPackageJson), {
386
+ as: 'json-stringify'
387
+ });
388
+
389
+ case 141:
390
+ _context.t17 = _context.sent;
391
+ _context.next = 144;
392
+ return _context.t15.write.call(_context.t15, _context.t16, _context.t17);
393
+
394
+ case 144:
395
+ _context.next = 146;
396
+ return outputRoot.write(path__namespace.join(packageDirectory, 'quilt.project.ts'), quiltProject);
397
+
398
+ case 146:
399
+ _context.next = 148;
400
+ return Promise.all([packageManager.addToTsConfig(packageDirectory, outputRoot), packageManager.addToPackageManagerWorkspaces(packageDirectory, outputRoot, packageManager$1)]);
401
+
402
+ case 148:
403
+ if (shouldInstall) {
404
+ process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
405
+
406
+ child_process.execSync("".concat(packageManager$1, " install"), {
407
+ cwd: rootDirectory
408
+ });
409
+ process.stdout.moveCursor(0, -1);
410
+ process.stdout.clearLine(1);
411
+ console.log('Installed dependencies.');
412
+ }
413
+
414
+ packageJsonInstructions = index.stripIndent(_templateObject2 || (_templateObject2 = index._taggedTemplateLiteral(["\n Your new package is ready to go! However, before you go too much further,\n you should update the following fields in ", ":\n\n - ", ", where you provide a description of what your package does\n - ", ", where you should include the ", " of your project\u2019s repo\n\n Before you publish your package, you will also want to update the ", "\n field in the package.json file.\n "])), index.cyan_1(packageManager.relativeDirectoryForDisplay(path__namespace.relative(process.cwd(), path__namespace.join(packageDirectory, 'package.json')))), index.bold_1("\"description\""), index.bold_1("\"repository\""), index.bold_1("\"url\""), index.bold_1("\"version\""));
415
+ console.log();
416
+ console.log(packageJsonInstructions);
417
+ commands = [];
418
+
419
+ if (!inWorkspace && directory !== process.cwd()) {
420
+ commands.push("cd ".concat(index.cyan_1(packageManager.relativeDirectoryForDisplay(path__namespace.relative(process.cwd(), directory))), " ").concat(index.dim_1('# Move into your new package’s directory')));
421
+ }
422
+
423
+ if (!shouldInstall) {
424
+ commands.push("pnpm install ".concat(index.dim_1('# Install all your dependencies')));
425
+ }
426
+
427
+ if (!inWorkspace) {
428
+ // TODO: change this condition to check if git was initialized already
429
+ commands.push("git init && git add -A && git commit -m \"Initial commit\" ".concat(index.dim_1('# Start your git history (optional)')));
430
+ }
431
+
432
+ if (commands.length > 0) {
433
+ whatsNext = index.stripIndent(_templateObject3 || (_templateObject3 = index._taggedTemplateLiteral(["\n After you update your package.json, there\u2019s ", " you\u2019ll need to take\n in order to start building:\n "])), commands.length > 1 ? 'a few more steps' : 'one more step');
434
+ console.log();
435
+ console.log(whatsNext);
436
+ console.log();
437
+ console.log(commands.map(function (command) {
438
+ return " ".concat(command);
439
+ }).join('\n'));
440
+ }
441
+
442
+ followUp = index.stripIndent(_templateObject4 || (_templateObject4 = index._taggedTemplateLiteral(["\n Quilt can help you build, test, lint, and type-check your new package. You\n can learn more about building packages 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')));
443
+ console.log();
444
+ console.log(followUp);
445
+
446
+ case 160:
447
+ case "end":
448
+ return _context.stop();
449
+ }
450
+ }
451
+ }, _callee);
452
+ }));
453
+ return _createProject.apply(this, arguments);
454
+ }
455
+
456
+ function getArgv() {
457
+ var argv = index.arg_1({
458
+ '--yes': Boolean,
459
+ '-y': '--yes',
460
+ '--name': String,
461
+ '--directory': String,
462
+ '--install': Boolean,
463
+ '--no-install': Boolean,
464
+ '--monorepo': Boolean,
465
+ '--no-monorepo': Boolean,
466
+ '--package-manager': String,
467
+ '--extras': [String],
468
+ '--no-extras': Boolean,
469
+ '--react': Boolean,
470
+ '--no-react': Boolean,
471
+ '--public': Boolean,
472
+ '--private': Boolean,
473
+ '--registry': String,
474
+ '--help': Boolean,
475
+ '-h': '--help'
476
+ }, {
477
+ permissive: true
478
+ });
479
+ return argv;
480
+ }
481
+
482
+ function getName(_x) {
483
+ return _getName.apply(this, arguments);
484
+ }
485
+
486
+ function _getName() {
487
+ _getName = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee2(argv) {
488
+ var name;
489
+ return index.regenerator.wrap(function _callee2$(_context2) {
490
+ while (1) {
491
+ switch (_context2.prev = _context2.next) {
492
+ case 0:
493
+ name = argv['--name'];
494
+
495
+ if (!(name == null)) {
496
+ _context2.next = 5;
497
+ break;
498
+ }
499
+
500
+ _context2.next = 4;
501
+ return index.prompt({
502
+ type: 'text',
503
+ message: 'What would you like to name your new package?',
504
+ initial: '@my-team/package'
505
+ });
506
+
507
+ case 4:
508
+ name = _context2.sent;
509
+
510
+ case 5:
511
+ return _context2.abrupt("return", name);
512
+
513
+ case 6:
514
+ case "end":
515
+ return _context2.stop();
516
+ }
517
+ }
518
+ }, _callee2);
519
+ }));
520
+ return _getName.apply(this, arguments);
521
+ }
522
+
523
+ function getDirectory(_x2, _x3) {
524
+ return _getDirectory.apply(this, arguments);
525
+ }
526
+
527
+ function _getDirectory() {
528
+ _getDirectory = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee3(argv, _ref) {
529
+ var name, inWorkspace, directory, basePackageName, defaultDirectory, relativeDirectory, empty, promptDirectory;
530
+ return index.regenerator.wrap(function _callee3$(_context3) {
531
+ while (1) {
532
+ switch (_context3.prev = _context3.next) {
533
+ case 0:
534
+ name = _ref.name, inWorkspace = _ref.inWorkspace;
535
+ directory = argv['--directory'] ? path__namespace.resolve(argv['--directory']) : undefined;
536
+
537
+ if (!(directory == null)) {
538
+ _context3.next = 10;
539
+ break;
540
+ }
541
+
542
+ basePackageName = packageManager.toValidPackageName(name.split('/').pop());
543
+ defaultDirectory = inWorkspace ? "packages/".concat(basePackageName) : basePackageName;
544
+ _context3.t0 = path__namespace;
545
+ _context3.next = 8;
546
+ return index.prompt({
547
+ type: 'text',
548
+ message: 'Where would you like to create your new package?',
549
+ initial: defaultDirectory
550
+ });
551
+
552
+ case 8:
553
+ _context3.t1 = _context3.sent;
554
+ directory = _context3.t0.resolve.call(_context3.t0, _context3.t1);
555
+
556
+ case 10:
557
+ if (argv['--yes']) {
558
+ _context3.next = 32;
559
+ break;
560
+ }
561
+
562
+ _context3.t2 = fs__namespace.existsSync(directory);
563
+
564
+ if (!_context3.t2) {
565
+ _context3.next = 16;
566
+ break;
567
+ }
568
+
569
+ _context3.next = 15;
570
+ return packageManager.isEmpty(directory);
571
+
572
+ case 15:
573
+ _context3.t2 = !_context3.sent;
574
+
575
+ case 16:
576
+ if (!_context3.t2) {
577
+ _context3.next = 29;
578
+ break;
579
+ }
580
+
581
+ relativeDirectory = path__namespace.relative(process.cwd(), directory);
582
+ _context3.next = 20;
583
+ return index.prompt({
584
+ type: 'confirm',
585
+ message: "Directory ".concat(index.bold_1(packageManager.relativeDirectoryForDisplay(relativeDirectory)), " is not empty, is it safe to empty it?"),
586
+ initial: true
587
+ });
588
+
589
+ case 20:
590
+ empty = _context3.sent;
591
+
592
+ if (!empty) {
593
+ _context3.next = 23;
594
+ break;
595
+ }
596
+
597
+ return _context3.abrupt("break", 32);
598
+
599
+ case 23:
600
+ _context3.next = 25;
601
+ return index.prompt({
602
+ type: 'text',
603
+ message: 'What directory do you want to create your package in?'
604
+ });
605
+
606
+ case 25:
607
+ promptDirectory = _context3.sent;
608
+ directory = path__namespace.resolve(promptDirectory);
609
+ _context3.next = 30;
610
+ break;
611
+
612
+ case 29:
613
+ return _context3.abrupt("break", 32);
614
+
615
+ case 30:
616
+ _context3.next = 10;
617
+ break;
618
+
619
+ case 32:
620
+ return _context3.abrupt("return", directory);
621
+
622
+ case 33:
623
+ case "end":
624
+ return _context3.stop();
625
+ }
626
+ }
627
+ }, _callee3);
628
+ }));
629
+ return _getDirectory.apply(this, arguments);
630
+ }
631
+
632
+ function getPublic(_x4) {
633
+ return _getPublic.apply(this, arguments);
634
+ }
635
+
636
+ function _getPublic() {
637
+ _getPublic = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee4(argv) {
638
+ var isPublic;
639
+ return index.regenerator.wrap(function _callee4$(_context4) {
640
+ while (1) {
641
+ switch (_context4.prev = _context4.next) {
642
+ case 0:
643
+ if (!(argv['--public'] || argv['--yes'])) {
644
+ _context4.next = 4;
645
+ break;
646
+ }
647
+
648
+ isPublic = true;
649
+ _context4.next = 11;
650
+ break;
651
+
652
+ case 4:
653
+ if (!argv['--private']) {
654
+ _context4.next = 8;
655
+ break;
656
+ }
657
+
658
+ isPublic = false;
659
+ _context4.next = 11;
660
+ break;
661
+
662
+ case 8:
663
+ _context4.next = 10;
664
+ return index.prompt({
665
+ type: 'confirm',
666
+ message: 'Will you publish this package to use in other projects?',
667
+ initial: true
668
+ });
669
+
670
+ case 10:
671
+ isPublic = _context4.sent;
672
+
673
+ case 11:
674
+ return _context4.abrupt("return", isPublic);
675
+
676
+ case 12:
677
+ case "end":
678
+ return _context4.stop();
679
+ }
680
+ }
681
+ }, _callee4);
682
+ }));
683
+ return _getPublic.apply(this, arguments);
684
+ }
685
+
686
+ function getReact(_x5) {
687
+ return _getReact.apply(this, arguments);
688
+ }
689
+
690
+ function _getReact() {
691
+ _getReact = index._asyncToGenerator( /*#__PURE__*/index.regenerator.mark(function _callee5(argv) {
692
+ var useReact;
693
+ return index.regenerator.wrap(function _callee5$(_context5) {
694
+ while (1) {
695
+ switch (_context5.prev = _context5.next) {
696
+ case 0:
697
+ if (!(argv['--react'] || argv['--yes'])) {
698
+ _context5.next = 4;
699
+ break;
700
+ }
701
+
702
+ useReact = true;
703
+ _context5.next = 11;
704
+ break;
705
+
706
+ case 4:
707
+ if (!argv['--no-react']) {
708
+ _context5.next = 8;
709
+ break;
710
+ }
711
+
712
+ useReact = false;
713
+ _context5.next = 11;
714
+ break;
715
+
716
+ case 8:
717
+ _context5.next = 10;
718
+ return index.prompt({
719
+ type: 'confirm',
720
+ message: 'Will this package depend on React?',
721
+ initial: true
722
+ });
723
+
724
+ case 10:
725
+ useReact = _context5.sent;
726
+
727
+ case 11:
728
+ return _context5.abrupt("return", useReact);
729
+
730
+ case 12:
731
+ case "end":
732
+ return _context5.stop();
733
+ }
734
+ }
735
+ }, _callee5);
736
+ }));
737
+ return _getReact.apply(this, arguments);
738
+ }
739
+
740
+ function adjustPackageJson(packageJson, _ref2) {
741
+ var name = _ref2.name,
742
+ react = _ref2.react,
743
+ isPublic = _ref2.isPublic,
744
+ registry = _ref2.registry;
745
+ packageJson.name = name;
746
+ var packageParts = name.split('/');
747
+ var scope = packageParts[0].startsWith('@') ? packageParts[0] : undefined;
748
+ var finalRegistry = registry !== null && registry !== void 0 ? registry : 'https://registry.npmjs.org';
749
+
750
+ if (scope) {
751
+ packageJson.publishConfig["".concat(scope, "/registry")] = finalRegistry;
752
+ } else if (registry) {
753
+ packageJson.publishConfig.registry = finalRegistry;
754
+ }
755
+
756
+ if (isPublic) {
757
+ delete packageJson["private"];
758
+ } else {
759
+ delete packageJson.publishConfig;
760
+ }
761
+
762
+ if (!react) {
763
+ delete packageJson.dependencies['@types/react'];
764
+ delete packageJson.devDependencies['react'];
765
+ delete packageJson.peerDependencies['react'];
766
+ delete packageJson.peerDependenciesMeta['react'];
767
+ packageJson.eslintConfig["extends"] = packageJson.eslintConfig["extends"].filter(function (extend) {
768
+ return !extend.includes('react');
769
+ });
770
+ }
771
+
772
+ return packageJson;
773
+ }
774
+
775
+ function sortKeys(object) {
776
+ var newObject = {};
777
+ var sortedEntries = Object.entries(object).sort(function (_ref3, _ref4) {
778
+ var _ref5 = packageManager._slicedToArray(_ref3, 1),
779
+ keyOne = _ref5[0];
780
+
781
+ var _ref6 = packageManager._slicedToArray(_ref4, 1),
782
+ keyTwo = _ref6[0];
783
+
784
+ return keyOne.localeCompare(keyTwo);
785
+ });
786
+
787
+ var _iterator = _createForOfIteratorHelper(sortedEntries),
788
+ _step;
789
+
790
+ try {
791
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
792
+ var _step$value = packageManager._slicedToArray(_step.value, 2),
793
+ key = _step$value[0],
794
+ value = _step$value[1];
795
+
796
+ newObject[key] = value;
797
+ }
798
+ } catch (err) {
799
+ _iterator.e(err);
800
+ } finally {
801
+ _iterator.f();
802
+ }
803
+
804
+ return newObject;
805
+ }
806
+
807
+ exports.createProject = createProject;