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