@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,245 +1,437 @@
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';
1
3
  import * as fs from 'fs';
2
4
  import * as path from 'path';
3
5
  import { execSync } from '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, l as loadTemplate, a as addToTsConfig, b as addToPackageManagerWorkspaces, r as relativeDirectoryForDisplay, i as isEmpty, c as createOutputTarget } from './package-manager.mjs';
6
6
  import 'tty';
7
7
  import 'url';
8
8
  import 'readline';
9
9
  import 'events';
10
10
 
11
- async function createPackage() {
12
- const argv = getArgv();
13
-
14
- if (argv['--help']) {
15
- const additionalOptions = stripIndent`
16
- ${cyan_1(`--react`)}, ${cyan_1(`--no-react`)}
17
- Whether this package will use React. If you don’t provide this option, the command
18
- will ask you about it later.
19
-
20
- ${cyan_1(`--public`)}, ${cyan_1(`--private`)}
21
- Whether this package will be published for other projects to install. If you do not
22
- provide this option, the command will ask you about it later.
23
-
24
- ${cyan_1(`--registry`)}
25
- The package registry to publish this package to. This option only applies if you create
26
- a public package. If you do not provide this option, it will use the default NPM registry.
27
- `;
28
- printHelp({
29
- kind: 'package',
30
- options: additionalOptions,
31
- packageManager: argv['--package-manager']?.toLowerCase()
32
- });
33
- return;
34
- }
11
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4;
35
12
 
36
- const inWorkspace = fs.existsSync('quilt.workspace.ts');
37
- const name = await getName(argv);
38
- const directory = await getDirectory(argv, {
39
- name,
40
- inWorkspace
41
- });
42
- const isPublic = await getPublic(argv);
43
- const useReact = await getReact(argv);
44
- const createAsMonorepo = !inWorkspace && (await getCreateAsMonorepo(argv));
45
- const shouldInstall = await getShouldInstall(argv);
46
- const packageManager = await getPackageManager(argv);
47
- const setupExtras = await getExtrasToSetup(argv, {
48
- inWorkspace
49
- });
50
- const partOfMonorepo = inWorkspace || createAsMonorepo;
51
- const packageDirectory = createAsMonorepo ? path.join(directory, `packages/${toValidPackageName(name.split('/').pop())}`) : directory;
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; }
52
14
 
53
- if (fs.existsSync(directory)) {
54
- await emptyDirectory(directory);
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; }
55
16
 
56
- if (packageDirectory !== directory) {
57
- fs.mkdirSync(packageDirectory, {
58
- recursive: true
59
- });
60
- }
61
- } else {
62
- fs.mkdirSync(packageDirectory, {
63
- recursive: true
64
- });
65
- }
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; } } }; }
66
18
 
67
- const rootDirectory = inWorkspace ? process.cwd() : directory;
68
- const outputRoot = createOutputTarget(rootDirectory);
69
- const packageTemplate = loadTemplate('package');
70
- const workspaceTemplate = loadTemplate('workspace');
71
- let quiltProject = await packageTemplate.read('quilt.project.ts');
72
-
73
- if (useReact) {
74
- quiltProject = quiltProject.replace('react: false', 'react: true');
75
- } // If we aren’t already in a workspace, copy the workspace files over, which
76
- // are needed if we are making a monorepo or not.
77
-
78
-
79
- if (!inWorkspace) {
80
- await workspaceTemplate.copy(directory, file => {
81
- // When this is a single project, we use the project’s Quilt configuration as the base.
82
- if (file === 'quilt.workspace.ts') return createAsMonorepo; // We need to make some adjustments to the root package.json
83
-
84
- return file !== 'package.json';
85
- }); // If we are creating a monorepo, we need to add the root package.json and
86
- // package manager workspace configuration.
87
-
88
- if (createAsMonorepo) {
89
- const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
90
- workspacePackageJson.name = toValidPackageName(name);
91
-
92
- if (packageManager === 'pnpm') {
93
- await outputRoot.write('pnpm-workspace.yaml', await format(`
94
- packages:
95
- - './packages/*'
96
- `, {
97
- as: 'yaml'
98
- }));
99
- } else {
100
- workspacePackageJson.workspaces = ['packages/*'];
101
- }
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); }
102
20
 
103
- await outputRoot.write('package.json', await format(JSON.stringify(workspacePackageJson), {
104
- as: 'json-stringify'
105
- }));
106
- } else {
107
- 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))]);
108
- workspacePackageJson.eslintConfig = projectPackageJson.eslintConfig;
109
- workspacePackageJson.browserslist = projectPackageJson.browserslist;
110
- const newPackageJson = {}; // We want to put the project’s dependencies in the package.json, respecting
111
- // the preferred ordering (dependencies, peer dependencies, dev dependencies).
112
-
113
- for (const [key, value] of Object.entries(projectPackageJson)) {
114
- if (key !== 'devDependencies') {
115
- newPackageJson[key] = value;
116
- continue;
117
- }
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
118
25
 
119
- newPackageJson.dependencies = projectPackageJson.dependencies;
120
- newPackageJson.peerDependencies = projectPackageJson.peerDependencies;
121
- newPackageJson.peerDependenciesMeta = projectPackageJson.peerDependenciesMeta;
122
- newPackageJson.devDependencies = sortKeys({ ...workspacePackageJson.devDependencies,
123
- ...projectPackageJson.devDependencies
124
- });
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();
426
+ }
125
427
  }
126
-
127
- adjustPackageJson(newPackageJson, {
128
- name: toValidPackageName(name),
129
- react: useReact,
130
- isPublic,
131
- registry: argv['--registry']
132
- });
133
- quiltProject = quiltProject.replace('quiltPackage', 'quiltWorkspace, quiltPackage').replace('quiltPackage(', 'quiltWorkspace(), quiltPackage(');
134
- await outputRoot.write('quilt.project.ts', await format(quiltProject, {
135
- as: 'typescript'
136
- }));
137
- await outputRoot.write('package.json', await format(JSON.stringify(newPackageJson), {
138
- as: 'json-stringify'
139
- }));
140
- await outputRoot.write('tsconfig.json', await format(JSON.stringify(projectTSConfig), {
141
- as: 'json'
142
- }));
143
- }
144
-
145
- if (setupExtras.has('github')) {
146
- await loadTemplate('github').copy(directory);
147
- }
148
-
149
- if (setupExtras.has('vscode')) {
150
- await loadTemplate('vscode').copy(directory);
151
- }
152
- }
153
-
154
- await packageTemplate.copy(packageDirectory, file => {
155
- // If we are in a monorepo, we can use all the template files as they are
156
- if (file === 'tsconfig.json') {
157
- return partOfMonorepo;
158
- } // We need to make some adjustments the project’s package.json and Quilt config
159
-
160
-
161
- return file !== 'package.json' && file !== 'quilt.project.ts';
162
- });
163
-
164
- if (partOfMonorepo) {
165
- // Write the package’s package.json (the root one was already created)
166
- const projectPackageJson = JSON.parse(await packageTemplate.read('package.json'));
167
- projectPackageJson.repository.directory = path.relative(directory, packageDirectory);
168
- adjustPackageJson(projectPackageJson, {
169
- name: toValidPackageName(name),
170
- react: useReact,
171
- isPublic,
172
- registry: argv['--registry']
173
- });
174
- await outputRoot.write(path.join(packageDirectory, 'package.json'), await format(JSON.stringify(projectPackageJson), {
175
- as: 'json-stringify'
176
- }));
177
- await outputRoot.write(path.join(packageDirectory, 'quilt.project.ts'), quiltProject);
178
- await Promise.all([addToTsConfig(packageDirectory, outputRoot), addToPackageManagerWorkspaces(packageDirectory, outputRoot, packageManager)]);
179
- }
180
-
181
- if (shouldInstall) {
182
- process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
183
-
184
- execSync(`${packageManager} install`, {
185
- cwd: rootDirectory
186
- });
187
- process.stdout.moveCursor(0, -1);
188
- process.stdout.clearLine(1);
189
- console.log('Installed dependencies.');
190
- }
191
-
192
- const packageJsonInstructions = stripIndent`
193
- Your new package is ready to go! However, before you go too much further,
194
- you should update the following fields in ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), path.join(packageDirectory, 'package.json'))))}:
195
-
196
- - ${bold_1(`"description"`)}, where you provide a description of what your package does
197
- - ${bold_1(`"repository"`)}, where you should include the ${bold_1(`"url"`)} of your project’s repo
198
-
199
- Before you publish your package, you will also want to update the ${bold_1(`"version"`)}
200
- field in the package.json file.
201
- `;
202
- console.log();
203
- console.log(packageJsonInstructions);
204
- const commands = [];
205
-
206
- if (!inWorkspace && directory !== process.cwd()) {
207
- commands.push(`cd ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), directory)))} ${dim_1('# Move into your new package’s directory')}`);
208
- }
209
-
210
- if (!shouldInstall) {
211
- commands.push(`pnpm install ${dim_1('# Install all your dependencies')}`);
212
- }
213
-
214
- if (!inWorkspace) {
215
- // TODO: change this condition to check if git was initialized already
216
- commands.push(`git init && git add -A && git commit -m "Initial commit" ${dim_1('# Start your git history (optional)')}`);
217
- }
218
-
219
- if (commands.length > 0) {
220
- const whatsNext = stripIndent`
221
- After you update your package.json, there’s ${commands.length > 1 ? 'a few more steps' : 'one more step'} you’ll need to take
222
- in order to start building:
223
- `;
224
- console.log();
225
- console.log(whatsNext);
226
- console.log();
227
- console.log(commands.map(command => ` ${command}`).join('\n'));
228
- }
229
-
230
- const followUp = stripIndent`
231
- Quilt can help you build, test, lint, and type-check your new package. You
232
- can learn more about building packages with Quilt by reading the documentation:
233
- ${underline_1(magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation'))}
234
-
235
- Have fun! 🎉
236
- `;
237
- console.log();
238
- console.log(followUp);
239
- } // Argument handling
428
+ }, _callee);
429
+ }));
430
+ return _createProject.apply(this, arguments);
431
+ }
240
432
 
241
433
  function getArgv() {
242
- const argv = arg_1({
434
+ var argv = arg_1({
243
435
  '--yes': Boolean,
244
436
  '-y': '--yes',
245
437
  '--name': String,
@@ -264,115 +456,282 @@ function getArgv() {
264
456
  return argv;
265
457
  }
266
458
 
267
- async function getName(argv) {
268
- let {
269
- '--name': name
270
- } = argv;
271
-
272
- if (name == null) {
273
- name = await prompt({
274
- type: 'text',
275
- message: 'What would you like to name your new package?',
276
- initial: '@my-team/package'
277
- });
278
- }
279
-
280
- return name;
459
+ function getName(_x) {
460
+ return _getName.apply(this, arguments);
281
461
  }
282
462
 
283
- async function getDirectory(argv, {
284
- name,
285
- inWorkspace
286
- }) {
287
- let directory = argv['--directory'] ? path.resolve(argv['--directory']) : undefined;
288
-
289
- if (directory == null) {
290
- const basePackageName = toValidPackageName(name.split('/').pop());
291
- const defaultDirectory = inWorkspace ? `packages/${basePackageName}` : basePackageName;
292
- directory = path.resolve(await prompt({
293
- type: 'text',
294
- message: 'Where would you like to create your new package?',
295
- initial: defaultDirectory
296
- }));
297
- }
298
-
299
- while (!argv['--yes']) {
300
- if (fs.existsSync(directory) && !(await isEmpty(directory))) {
301
- const relativeDirectory = path.relative(process.cwd(), directory);
302
- const empty = await prompt({
303
- type: 'confirm',
304
- message: `Directory ${bold_1(relativeDirectoryForDisplay(relativeDirectory))} is not empty, is it safe to empty it?`,
305
- initial: true
306
- });
307
- if (empty) break;
308
- const promptDirectory = await prompt({
309
- type: 'text',
310
- message: 'What directory do you want to create your package in?'
311
- });
312
- directory = path.resolve(promptDirectory);
313
- } else {
314
- break;
315
- }
316
- }
317
-
318
- return directory;
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);
319
498
  }
320
499
 
321
- async function getPublic(argv) {
322
- let isPublic;
500
+ function getDirectory(_x2, _x3) {
501
+ return _getDirectory.apply(this, arguments);
502
+ }
323
503
 
324
- if (argv['--public'] || argv['--yes']) {
325
- isPublic = true;
326
- } else if (argv['--private']) {
327
- isPublic = false;
328
- } else {
329
- isPublic = await prompt({
330
- type: 'confirm',
331
- message: 'Will you publish this package to use in other projects?',
332
- initial: true
333
- });
334
- }
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
+ }
335
608
 
336
- return isPublic;
609
+ function getPublic(_x4) {
610
+ return _getPublic.apply(this, arguments);
337
611
  }
338
612
 
339
- async function getReact(argv) {
340
- let useReact;
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);
661
+ }
341
662
 
342
- if (argv['--react'] || argv['--yes']) {
343
- useReact = true;
344
- } else if (argv['--no-react']) {
345
- useReact = false;
346
- } else {
347
- useReact = await prompt({
348
- type: 'confirm',
349
- message: 'Will this package depend on React?',
350
- initial: true
351
- });
352
- }
663
+ function getReact(_x5) {
664
+ return _getReact.apply(this, arguments);
665
+ }
353
666
 
354
- return useReact;
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);
355
715
  }
356
716
 
357
- function adjustPackageJson(packageJson, {
358
- name,
359
- react,
360
- isPublic,
361
- registry
362
- }) {
717
+ function adjustPackageJson(packageJson, _ref2) {
718
+ var name = _ref2.name,
719
+ react = _ref2.react,
720
+ isPublic = _ref2.isPublic,
721
+ registry = _ref2.registry;
363
722
  packageJson.name = name;
364
- const packageParts = name.split('/');
365
- const scope = packageParts[0].startsWith('@') ? packageParts[0] : undefined;
366
- const finalRegistry = registry ?? 'https://registry.npmjs.org';
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';
367
726
 
368
727
  if (scope) {
369
- packageJson.publishConfig[`${scope}/registry`] = finalRegistry;
728
+ packageJson.publishConfig["".concat(scope, "/registry")] = finalRegistry;
370
729
  } else if (registry) {
371
730
  packageJson.publishConfig.registry = finalRegistry;
372
731
  }
373
732
 
374
733
  if (isPublic) {
375
- delete packageJson.private;
734
+ delete packageJson["private"];
376
735
  } else {
377
736
  delete packageJson.publishConfig;
378
737
  }
@@ -382,21 +741,44 @@ function adjustPackageJson(packageJson, {
382
741
  delete packageJson.devDependencies['react'];
383
742
  delete packageJson.peerDependencies['react'];
384
743
  delete packageJson.peerDependenciesMeta['react'];
385
- packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(extend => !extend.includes('react'));
744
+ packageJson.eslintConfig["extends"] = packageJson.eslintConfig["extends"].filter(function (extend) {
745
+ return !extend.includes('react');
746
+ });
386
747
  }
387
748
 
388
749
  return packageJson;
389
750
  }
390
751
 
391
752
  function sortKeys(object) {
392
- const newObject = {};
393
- const sortedEntries = Object.entries(object).sort(([keyOne], [keyTwo]) => keyOne.localeCompare(keyTwo));
753
+ var newObject = {};
754
+ var sortedEntries = Object.entries(object).sort(function (_ref3, _ref4) {
755
+ var _ref5 = _slicedToArray(_ref3, 1),
756
+ keyOne = _ref5[0];
394
757
 
395
- for (const [key, value] of sortedEntries) {
396
- newObject[key] = value;
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();
397
779
  }
398
780
 
399
781
  return newObject;
400
782
  }
401
783
 
402
- export { createPackage };
784
+ export { createProject };