@quilted/create 0.1.18 → 0.1.21

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