@quilted/create 0.1.21 → 0.1.22

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.
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index.cjs');
4
- var packageManager = require('./package-manager.cjs');
5
3
  var fs = require('fs');
6
4
  var path = require('path');
7
5
  var child_process = require('child_process');
6
+ var index = require('./index.cjs');
7
+ var packageManager = require('./package-manager.cjs');
8
8
  require('tty');
9
9
  require('url');
10
10
  require('readline');
@@ -31,430 +31,245 @@ 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, _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; }
34
+ let _ = t => t,
35
+ _t,
36
+ _t2,
37
+ _t3,
38
+ _t4;
39
+ async function createProject() {
40
+ const argv = getArgv();
41
+
42
+ if (argv['--help']) {
43
+ var _argv$PackageManag;
44
+
45
+ const additionalOptions = index.stripIndent(_t || (_t = _`
46
+ ${0}, ${0}
47
+ Whether this package will use React. If you don’t provide this option, the command
48
+ will ask you about it later.
49
+
50
+ ${0}, ${0}
51
+ Whether this package will be published for other projects to install. If you do not
52
+ provide this option, the command will ask you about it later.
53
+
54
+ ${0}
55
+ The package registry to publish this package to. This option only applies if you create
56
+ a public package. If you do not provide this option, it will use the default NPM registry.
57
+ `), index.cyan_1(`--react`), index.cyan_1(`--no-react`), index.cyan_1(`--public`), index.cyan_1(`--private`), index.cyan_1(`--registry`));
58
+ index.printHelp({
59
+ kind: 'package',
60
+ options: additionalOptions,
61
+ packageManager: (_argv$PackageManag = argv['--package-manager']) === null || _argv$PackageManag === void 0 ? void 0 : _argv$PackageManag.toLowerCase()
62
+ });
63
+ return;
64
+ }
37
65
 
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; }
66
+ const inWorkspace = fs__namespace.existsSync('quilt.workspace.ts');
67
+ const name = await getName(argv);
68
+ const directory = await getDirectory(argv, {
69
+ name,
70
+ inWorkspace
71
+ });
72
+ const isPublic = await getPublic(argv);
73
+ const useReact = await getReact(argv);
74
+ const createAsMonorepo = !inWorkspace && (await index.getCreateAsMonorepo(argv));
75
+ const shouldInstall = await index.getShouldInstall(argv);
76
+ const packageManager$1 = await index.getPackageManager(argv);
77
+ const setupExtras = await index.getExtrasToSetup(argv, {
78
+ inWorkspace
79
+ });
80
+ const partOfMonorepo = inWorkspace || createAsMonorepo;
81
+ const packageDirectory = createAsMonorepo ? path__namespace.join(directory, `packages/${packageManager.toValidPackageName(name.split('/').pop())}`) : directory;
39
82
 
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; } } }; }
83
+ if (fs__namespace.existsSync(directory)) {
84
+ await packageManager.emptyDirectory(directory);
41
85
 
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); }
86
+ if (packageDirectory !== directory) {
87
+ fs__namespace.mkdirSync(packageDirectory, {
88
+ recursive: true
89
+ });
90
+ }
91
+ } else {
92
+ fs__namespace.mkdirSync(packageDirectory, {
93
+ recursive: true
94
+ });
95
+ }
43
96
 
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
97
+ const rootDirectory = inWorkspace ? process.cwd() : directory;
98
+ const outputRoot = packageManager.createOutputTarget(rootDirectory);
99
+ const packageTemplate = packageManager.loadTemplate('package');
100
+ const workspaceTemplate = packageManager.loadTemplate('workspace');
101
+ let quiltProject = await packageTemplate.read('quilt.project.ts');
102
+
103
+ if (useReact) {
104
+ quiltProject = quiltProject.replace('react: false', 'react: true');
105
+ } // If we aren’t already in a workspace, copy the workspace files over, which
106
+ // are needed if we are making a monorepo or not.
107
+
108
+
109
+ if (!inWorkspace) {
110
+ await workspaceTemplate.copy(directory, file => {
111
+ // When this is a single project, we use the project’s Quilt configuration as the base.
112
+ if (file === 'quilt.workspace.ts') return createAsMonorepo; // We need to make some adjustments to the root package.json
113
+
114
+ return file !== 'package.json';
115
+ }); // If we are creating a monorepo, we need to add the root package.json and
116
+ // package manager workspace configuration.
117
+
118
+ if (createAsMonorepo) {
119
+ const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
120
+ workspacePackageJson.name = packageManager.toValidPackageName(name);
121
+
122
+ if (packageManager$1 === 'pnpm') {
123
+ await outputRoot.write('pnpm-workspace.yaml', await packageManager.format(`
124
+ packages:
125
+ - './packages/*'
126
+ `, {
127
+ as: 'yaml'
128
+ }));
129
+ } else {
130
+ workspacePackageJson.workspaces = ['packages/*'];
131
+ }
48
132
 
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();
133
+ await outputRoot.write('package.json', await packageManager.format(JSON.stringify(workspacePackageJson), {
134
+ as: 'json-stringify'
135
+ }));
136
+ } else {
137
+ const [projectPackageJson, projectTSConfig, workspacePackageJson] = await Promise.all([packageTemplate.read('package.json').then(content => JSON.parse(content)), packageTemplate.read('tsconfig.json').then(content => JSON.parse(content)), workspaceTemplate.read('package.json').then(content => JSON.parse(content))]);
138
+ workspacePackageJson.eslintConfig = projectPackageJson.eslintConfig;
139
+ workspacePackageJson.browserslist = projectPackageJson.browserslist;
140
+ const newPackageJson = {}; // We want to put the project’s dependencies in the package.json, respecting
141
+ // the preferred ordering (dependencies, peer dependencies, dev dependencies).
142
+
143
+ for (const [key, value] of Object.entries(projectPackageJson)) {
144
+ if (key !== 'devDependencies') {
145
+ newPackageJson[key] = value;
146
+ continue;
449
147
  }
148
+
149
+ newPackageJson.dependencies = projectPackageJson.dependencies;
150
+ newPackageJson.peerDependencies = projectPackageJson.peerDependencies;
151
+ newPackageJson.peerDependenciesMeta = projectPackageJson.peerDependenciesMeta;
152
+ newPackageJson.devDependencies = sortKeys({ ...workspacePackageJson.devDependencies,
153
+ ...projectPackageJson.devDependencies
154
+ });
450
155
  }
451
- }, _callee);
452
- }));
453
- return _createProject.apply(this, arguments);
454
- }
156
+
157
+ adjustPackageJson(newPackageJson, {
158
+ name: packageManager.toValidPackageName(name),
159
+ react: useReact,
160
+ isPublic,
161
+ registry: argv['--registry']
162
+ });
163
+ quiltProject = quiltProject.replace('quiltPackage', 'quiltWorkspace, quiltPackage').replace('quiltPackage(', 'quiltWorkspace(), quiltPackage(');
164
+ await outputRoot.write('quilt.project.ts', await packageManager.format(quiltProject, {
165
+ as: 'typescript'
166
+ }));
167
+ await outputRoot.write('package.json', await packageManager.format(JSON.stringify(newPackageJson), {
168
+ as: 'json-stringify'
169
+ }));
170
+ await outputRoot.write('tsconfig.json', await packageManager.format(JSON.stringify(projectTSConfig), {
171
+ as: 'json'
172
+ }));
173
+ }
174
+
175
+ if (setupExtras.has('github')) {
176
+ await packageManager.loadTemplate('github').copy(directory);
177
+ }
178
+
179
+ if (setupExtras.has('vscode')) {
180
+ await packageManager.loadTemplate('vscode').copy(directory);
181
+ }
182
+ }
183
+
184
+ await packageTemplate.copy(packageDirectory, file => {
185
+ // If we are in a monorepo, we can use all the template files as they are
186
+ if (file === 'tsconfig.json') {
187
+ return partOfMonorepo;
188
+ } // We need to make some adjustments the project’s package.json and Quilt config
189
+
190
+
191
+ return file !== 'package.json' && file !== 'quilt.project.ts';
192
+ });
193
+
194
+ if (partOfMonorepo) {
195
+ // Write the package’s package.json (the root one was already created)
196
+ const projectPackageJson = JSON.parse(await packageTemplate.read('package.json'));
197
+ projectPackageJson.repository.directory = path__namespace.relative(directory, packageDirectory);
198
+ adjustPackageJson(projectPackageJson, {
199
+ name: packageManager.toValidPackageName(name),
200
+ react: useReact,
201
+ isPublic,
202
+ registry: argv['--registry']
203
+ });
204
+ await outputRoot.write(path__namespace.join(packageDirectory, 'package.json'), await packageManager.format(JSON.stringify(projectPackageJson), {
205
+ as: 'json-stringify'
206
+ }));
207
+ await outputRoot.write(path__namespace.join(packageDirectory, 'quilt.project.ts'), quiltProject);
208
+ await Promise.all([packageManager.addToTsConfig(packageDirectory, outputRoot), packageManager.addToPackageManagerWorkspaces(packageDirectory, outputRoot, packageManager$1)]);
209
+ }
210
+
211
+ if (shouldInstall) {
212
+ process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
213
+
214
+ child_process.execSync(`${packageManager$1} install`, {
215
+ cwd: rootDirectory
216
+ });
217
+ process.stdout.moveCursor(0, -1);
218
+ process.stdout.clearLine(1);
219
+ console.log('Installed dependencies.');
220
+ }
221
+
222
+ const packageJsonInstructions = index.stripIndent(_t2 || (_t2 = _`
223
+ Your new package is ready to go! However, before you go too much further,
224
+ you should update the following fields in ${0}:
225
+
226
+ - ${0}, where you provide a description of what your package does
227
+ - ${0}, where you should include the ${0} of your project’s repo
228
+
229
+ Before you publish your package, you will also want to update the ${0}
230
+ field in the package.json file.
231
+ `), 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"`));
232
+ console.log();
233
+ console.log(packageJsonInstructions);
234
+ const commands = [];
235
+
236
+ if (!inWorkspace && directory !== process.cwd()) {
237
+ commands.push(`cd ${index.cyan_1(packageManager.relativeDirectoryForDisplay(path__namespace.relative(process.cwd(), directory)))} ${index.dim_1('# Move into your new package’s directory')}`);
238
+ }
239
+
240
+ if (!shouldInstall) {
241
+ commands.push(`pnpm install ${index.dim_1('# Install all your dependencies')}`);
242
+ }
243
+
244
+ if (!inWorkspace) {
245
+ // TODO: change this condition to check if git was initialized already
246
+ commands.push(`git init && git add -A && git commit -m "Initial commit" ${index.dim_1('# Start your git history (optional)')}`);
247
+ }
248
+
249
+ if (commands.length > 0) {
250
+ const whatsNext = index.stripIndent(_t3 || (_t3 = _`
251
+ After you update your package.json, there’s ${0} you’ll need to take
252
+ in order to start building:
253
+ `), commands.length > 1 ? 'a few more steps' : 'one more step');
254
+ console.log();
255
+ console.log(whatsNext);
256
+ console.log();
257
+ console.log(commands.map(command => ` ${command}`).join('\n'));
258
+ }
259
+
260
+ const followUp = index.stripIndent(_t4 || (_t4 = _`
261
+ Quilt can help you build, test, lint, and type-check your new package. You
262
+ can learn more about building packages with Quilt by reading the documentation:
263
+ ${0}
264
+
265
+ Have fun! 🎉
266
+ `), index.underline_1(index.magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation')));
267
+ console.log();
268
+ console.log(followUp);
269
+ } // Argument handling
455
270
 
456
271
  function getArgv() {
457
- var argv = index.arg_1({
272
+ const argv = index.arg_1({
458
273
  '--yes': Boolean,
459
274
  '-y': '--yes',
460
275
  '--name': String,
@@ -479,282 +294,115 @@ function getArgv() {
479
294
  return argv;
480
295
  }
481
296
 
482
- function getName(_x) {
483
- return _getName.apply(this, arguments);
484
- }
297
+ async function getName(argv) {
298
+ let {
299
+ '--name': name
300
+ } = argv;
485
301
 
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
- }
302
+ if (name == null) {
303
+ name = await index.prompt({
304
+ type: 'text',
305
+ message: 'What would you like to name your new package?',
306
+ initial: '@my-team/package'
307
+ });
308
+ }
522
309
 
523
- function getDirectory(_x2, _x3) {
524
- return _getDirectory.apply(this, arguments);
310
+ return name;
525
311
  }
526
312
 
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
- }
313
+ async function getDirectory(argv, {
314
+ name,
315
+ inWorkspace
316
+ }) {
317
+ let directory = argv['--directory'] ? path__namespace.resolve(argv['--directory']) : undefined;
318
+
319
+ if (directory == null) {
320
+ const basePackageName = packageManager.toValidPackageName(name.split('/').pop());
321
+ const defaultDirectory = inWorkspace ? `packages/${basePackageName}` : basePackageName;
322
+ directory = path__namespace.resolve(await index.prompt({
323
+ type: 'text',
324
+ message: 'Where would you like to create your new package?',
325
+ initial: defaultDirectory
326
+ }));
327
+ }
631
328
 
632
- function getPublic(_x4) {
633
- return _getPublic.apply(this, arguments);
634
- }
329
+ while (!argv['--yes']) {
330
+ if (fs__namespace.existsSync(directory) && !(await packageManager.isEmpty(directory))) {
331
+ const relativeDirectory = path__namespace.relative(process.cwd(), directory);
332
+ const empty = await index.prompt({
333
+ type: 'confirm',
334
+ message: `Directory ${index.bold_1(packageManager.relativeDirectoryForDisplay(relativeDirectory))} is not empty, is it safe to empty it?`,
335
+ initial: true
336
+ });
337
+ if (empty) break;
338
+ const promptDirectory = await index.prompt({
339
+ type: 'text',
340
+ message: 'What directory do you want to create your package in?'
341
+ });
342
+ directory = path__namespace.resolve(promptDirectory);
343
+ } else {
344
+ break;
345
+ }
346
+ }
635
347
 
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);
348
+ return directory;
684
349
  }
685
350
 
686
- function getReact(_x5) {
687
- return _getReact.apply(this, arguments);
351
+ async function getPublic(argv) {
352
+ let isPublic;
353
+
354
+ if (argv['--public'] || argv['--yes']) {
355
+ isPublic = true;
356
+ } else if (argv['--private']) {
357
+ isPublic = false;
358
+ } else {
359
+ isPublic = await index.prompt({
360
+ type: 'confirm',
361
+ message: 'Will you publish this package to use in other projects?',
362
+ initial: true
363
+ });
364
+ }
365
+
366
+ return isPublic;
688
367
  }
689
368
 
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);
369
+ async function getReact(argv) {
370
+ let useReact;
371
+
372
+ if (argv['--react'] || argv['--yes']) {
373
+ useReact = true;
374
+ } else if (argv['--no-react']) {
375
+ useReact = false;
376
+ } else {
377
+ useReact = await index.prompt({
378
+ type: 'confirm',
379
+ message: 'Will this package depend on React?',
380
+ initial: true
381
+ });
382
+ }
383
+
384
+ return useReact;
738
385
  }
739
386
 
740
- function adjustPackageJson(packageJson, _ref2) {
741
- var name = _ref2.name,
742
- react = _ref2.react,
743
- isPublic = _ref2.isPublic,
744
- registry = _ref2.registry;
387
+ function adjustPackageJson(packageJson, {
388
+ name,
389
+ react,
390
+ isPublic,
391
+ registry
392
+ }) {
745
393
  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';
394
+ const packageParts = name.split('/');
395
+ const scope = packageParts[0].startsWith('@') ? packageParts[0] : undefined;
396
+ const finalRegistry = registry !== null && registry !== void 0 ? registry : 'https://registry.npmjs.org';
749
397
 
750
398
  if (scope) {
751
- packageJson.publishConfig["".concat(scope, "/registry")] = finalRegistry;
399
+ packageJson.publishConfig[`${scope}/registry`] = finalRegistry;
752
400
  } else if (registry) {
753
401
  packageJson.publishConfig.registry = finalRegistry;
754
402
  }
755
403
 
756
404
  if (isPublic) {
757
- delete packageJson["private"];
405
+ delete packageJson.private;
758
406
  } else {
759
407
  delete packageJson.publishConfig;
760
408
  }
@@ -764,41 +412,18 @@ function adjustPackageJson(packageJson, _ref2) {
764
412
  delete packageJson.devDependencies['react'];
765
413
  delete packageJson.peerDependencies['react'];
766
414
  delete packageJson.peerDependenciesMeta['react'];
767
- packageJson.eslintConfig["extends"] = packageJson.eslintConfig["extends"].filter(function (extend) {
768
- return !extend.includes('react');
769
- });
415
+ packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(extend => !extend.includes('react'));
770
416
  }
771
417
 
772
418
  return packageJson;
773
419
  }
774
420
 
775
421
  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];
422
+ const newObject = {};
423
+ const sortedEntries = Object.entries(object).sort(([keyOne], [keyTwo]) => keyOne.localeCompare(keyTwo));
783
424
 
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();
425
+ for (const [key, value] of sortedEntries) {
426
+ newObject[key] = value;
802
427
  }
803
428
 
804
429
  return newObject;