@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.
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
+ var fs = require('node:fs');
4
+ var path = require('node:path');
5
+ var node_child_process = require('node:child_process');
3
6
  var index = require('./index.cjs');
4
7
  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');
8
+ require('node:tty');
9
+ require('node:url');
10
+ require('node:readline');
11
+ require('node:events');
12
12
 
13
13
  function _interopNamespace(e) {
14
14
  if (e && e.__esModule) return e;
@@ -31,430 +31,243 @@ 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 = packageManager.mergeDependencies(workspacePackageJson.devDependencies, projectPackageJson.devDependencies);
450
153
  }
451
- }, _callee);
452
- }));
453
- return _createProject.apply(this, arguments);
454
- }
154
+
155
+ adjustPackageJson(newPackageJson, {
156
+ name: packageManager.toValidPackageName(name),
157
+ react: useReact,
158
+ isPublic,
159
+ registry: argv['--registry']
160
+ });
161
+ quiltProject = quiltProject.replace('quiltPackage', 'quiltWorkspace, quiltPackage').replace('quiltPackage(', 'quiltWorkspace(), quiltPackage(');
162
+ await outputRoot.write('quilt.project.ts', await packageManager.format(quiltProject, {
163
+ as: 'typescript'
164
+ }));
165
+ await outputRoot.write('package.json', await packageManager.format(JSON.stringify(newPackageJson), {
166
+ as: 'json-stringify'
167
+ }));
168
+ await outputRoot.write('tsconfig.json', await packageManager.format(JSON.stringify(projectTSConfig), {
169
+ as: 'json'
170
+ }));
171
+ }
172
+
173
+ if (setupExtras.has('github')) {
174
+ await packageManager.loadTemplate('github').copy(directory);
175
+ }
176
+
177
+ if (setupExtras.has('vscode')) {
178
+ await packageManager.loadTemplate('vscode').copy(directory);
179
+ }
180
+ }
181
+
182
+ await packageTemplate.copy(packageDirectory, file => {
183
+ // If we are in a monorepo, we can use all the template files as they are
184
+ if (file === 'tsconfig.json') {
185
+ return partOfMonorepo;
186
+ } // We need to make some adjustments the project’s package.json and Quilt config
187
+
188
+
189
+ return file !== 'package.json' && file !== 'quilt.project.ts';
190
+ });
191
+
192
+ if (partOfMonorepo) {
193
+ // Write the package’s package.json (the root one was already created)
194
+ const projectPackageJson = JSON.parse(await packageTemplate.read('package.json'));
195
+ projectPackageJson.repository.directory = path__namespace.relative(directory, packageDirectory);
196
+ adjustPackageJson(projectPackageJson, {
197
+ name: packageManager.toValidPackageName(name),
198
+ react: useReact,
199
+ isPublic,
200
+ registry: argv['--registry']
201
+ });
202
+ await outputRoot.write(path__namespace.join(packageDirectory, 'package.json'), await packageManager.format(JSON.stringify(projectPackageJson), {
203
+ as: 'json-stringify'
204
+ }));
205
+ await outputRoot.write(path__namespace.join(packageDirectory, 'quilt.project.ts'), quiltProject);
206
+ await Promise.all([packageManager.addToTsConfig(packageDirectory, outputRoot), packageManager.addToPackageManagerWorkspaces(packageDirectory, outputRoot, packageManager$1)]);
207
+ }
208
+
209
+ if (shouldInstall) {
210
+ process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
211
+
212
+ node_child_process.execSync(`${packageManager$1} install`, {
213
+ cwd: rootDirectory
214
+ });
215
+ process.stdout.moveCursor(0, -1);
216
+ process.stdout.clearLine(1);
217
+ console.log('Installed dependencies.');
218
+ }
219
+
220
+ const packageJsonInstructions = index.stripIndent(_t2 || (_t2 = _`
221
+ Your new package is ready to go! However, before you go too much further,
222
+ you should update the following fields in ${0}:
223
+
224
+ - ${0}, where you provide a description of what your package does
225
+ - ${0}, where you should include the ${0} of your project’s repo
226
+
227
+ Before you publish your package, you will also want to update the ${0}
228
+ field in the package.json file.
229
+ `), 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"`));
230
+ console.log();
231
+ console.log(packageJsonInstructions);
232
+ const commands = [];
233
+
234
+ if (!inWorkspace && directory !== process.cwd()) {
235
+ commands.push(`cd ${index.cyan_1(packageManager.relativeDirectoryForDisplay(path__namespace.relative(process.cwd(), directory)))} ${index.dim_1('# Move into your new package’s directory')}`);
236
+ }
237
+
238
+ if (!shouldInstall) {
239
+ commands.push(`pnpm install ${index.dim_1('# Install all your dependencies')}`);
240
+ }
241
+
242
+ if (!inWorkspace) {
243
+ // TODO: change this condition to check if git was initialized already
244
+ commands.push(`git init && git add -A && git commit -m "Initial commit" ${index.dim_1('# Start your git history (optional)')}`);
245
+ }
246
+
247
+ if (commands.length > 0) {
248
+ const whatsNext = index.stripIndent(_t3 || (_t3 = _`
249
+ After you update your package.json, there’s ${0} you’ll need to take
250
+ in order to start building:
251
+ `), commands.length > 1 ? 'a few more steps' : 'one more step');
252
+ console.log();
253
+ console.log(whatsNext);
254
+ console.log();
255
+ console.log(commands.map(command => ` ${command}`).join('\n'));
256
+ }
257
+
258
+ const followUp = index.stripIndent(_t4 || (_t4 = _`
259
+ Quilt can help you build, test, lint, and type-check your new package. You
260
+ can learn more about building packages with Quilt by reading the documentation:
261
+ ${0}
262
+
263
+ Have fun! 🎉
264
+ `), index.underline_1(index.magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation')));
265
+ console.log();
266
+ console.log(followUp);
267
+ } // Argument handling
455
268
 
456
269
  function getArgv() {
457
- var argv = index.arg_1({
270
+ const argv = index.arg_1({
458
271
  '--yes': Boolean,
459
272
  '-y': '--yes',
460
273
  '--name': String,
@@ -479,282 +292,115 @@ function getArgv() {
479
292
  return argv;
480
293
  }
481
294
 
482
- function getName(_x) {
483
- return _getName.apply(this, arguments);
484
- }
295
+ async function getName(argv) {
296
+ let {
297
+ '--name': name
298
+ } = argv;
485
299
 
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
- }
300
+ if (name == null) {
301
+ name = await index.prompt({
302
+ type: 'text',
303
+ message: 'What would you like to name your new package?',
304
+ initial: '@my-team/package'
305
+ });
306
+ }
522
307
 
523
- function getDirectory(_x2, _x3) {
524
- return _getDirectory.apply(this, arguments);
308
+ return name;
525
309
  }
526
310
 
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
- }
311
+ async function getDirectory(argv, {
312
+ name,
313
+ inWorkspace
314
+ }) {
315
+ let directory = argv['--directory'] ? path__namespace.resolve(argv['--directory']) : undefined;
316
+
317
+ if (directory == null) {
318
+ const basePackageName = packageManager.toValidPackageName(name.split('/').pop());
319
+ const defaultDirectory = inWorkspace ? `packages/${basePackageName}` : basePackageName;
320
+ directory = path__namespace.resolve(await index.prompt({
321
+ type: 'text',
322
+ message: 'Where would you like to create your new package?',
323
+ initial: defaultDirectory
324
+ }));
325
+ }
631
326
 
632
- function getPublic(_x4) {
633
- return _getPublic.apply(this, arguments);
634
- }
327
+ while (!argv['--yes']) {
328
+ if (fs__namespace.existsSync(directory) && !(await packageManager.isEmpty(directory))) {
329
+ const relativeDirectory = path__namespace.relative(process.cwd(), directory);
330
+ const empty = await index.prompt({
331
+ type: 'confirm',
332
+ message: `Directory ${index.bold_1(packageManager.relativeDirectoryForDisplay(relativeDirectory))} is not empty, is it safe to empty it?`,
333
+ initial: true
334
+ });
335
+ if (empty) break;
336
+ const promptDirectory = await index.prompt({
337
+ type: 'text',
338
+ message: 'What directory do you want to create your package in?'
339
+ });
340
+ directory = path__namespace.resolve(promptDirectory);
341
+ } else {
342
+ break;
343
+ }
344
+ }
635
345
 
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);
346
+ return directory;
684
347
  }
685
348
 
686
- function getReact(_x5) {
687
- return _getReact.apply(this, arguments);
349
+ async function getPublic(argv) {
350
+ let isPublic;
351
+
352
+ if (argv['--public'] || argv['--yes']) {
353
+ isPublic = true;
354
+ } else if (argv['--private']) {
355
+ isPublic = false;
356
+ } else {
357
+ isPublic = await index.prompt({
358
+ type: 'confirm',
359
+ message: 'Will you publish this package to use in other projects?',
360
+ initial: true
361
+ });
362
+ }
363
+
364
+ return isPublic;
688
365
  }
689
366
 
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);
367
+ async function getReact(argv) {
368
+ let useReact;
369
+
370
+ if (argv['--react'] || argv['--yes']) {
371
+ useReact = true;
372
+ } else if (argv['--no-react']) {
373
+ useReact = false;
374
+ } else {
375
+ useReact = await index.prompt({
376
+ type: 'confirm',
377
+ message: 'Will this package depend on React?',
378
+ initial: true
379
+ });
380
+ }
381
+
382
+ return useReact;
738
383
  }
739
384
 
740
- function adjustPackageJson(packageJson, _ref2) {
741
- var name = _ref2.name,
742
- react = _ref2.react,
743
- isPublic = _ref2.isPublic,
744
- registry = _ref2.registry;
385
+ function adjustPackageJson(packageJson, {
386
+ name,
387
+ react,
388
+ isPublic,
389
+ registry
390
+ }) {
745
391
  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';
392
+ const packageParts = name.split('/');
393
+ const scope = packageParts[0].startsWith('@') ? packageParts[0] : undefined;
394
+ const finalRegistry = registry !== null && registry !== void 0 ? registry : 'https://registry.npmjs.org';
749
395
 
750
396
  if (scope) {
751
- packageJson.publishConfig["".concat(scope, "/registry")] = finalRegistry;
397
+ packageJson.publishConfig[`${scope}/registry`] = finalRegistry;
752
398
  } else if (registry) {
753
399
  packageJson.publishConfig.registry = finalRegistry;
754
400
  }
755
401
 
756
402
  if (isPublic) {
757
- delete packageJson["private"];
403
+ delete packageJson.private;
758
404
  } else {
759
405
  delete packageJson.publishConfig;
760
406
  }
@@ -764,44 +410,10 @@ function adjustPackageJson(packageJson, _ref2) {
764
410
  delete packageJson.devDependencies['react'];
765
411
  delete packageJson.peerDependencies['react'];
766
412
  delete packageJson.peerDependenciesMeta['react'];
767
- packageJson.eslintConfig["extends"] = packageJson.eslintConfig["extends"].filter(function (extend) {
768
- return !extend.includes('react');
769
- });
413
+ packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(extend => !extend.includes('react'));
770
414
  }
771
415
 
772
416
  return packageJson;
773
417
  }
774
418
 
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
419
  exports.createProject = createProject;