@quilted/create 0.1.19 → 0.1.20

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/tsconfig.tsbuildinfo +1 -1
  3. package/build/typescript/package.d.ts +1 -1
  4. package/package.json +5 -3
  5. package/quilt.project.ts +19 -5
  6. package/source/create.ts +2 -2
  7. package/source/package.ts +1 -1
  8. package/templates/app-basic/quilt.project.ts +5 -5
  9. package/templates/app-basic/tsconfig.json +1 -1
  10. package/templates/app-single-file/quilt.project.ts +3 -4
  11. package/templates/app-single-file/tsconfig.json +1 -1
  12. package/templates/package/package.json +2 -2
  13. package/templates/package/quilt.project.ts +3 -4
  14. package/templates/package/tsconfig.json +1 -1
  15. package/tsconfig.json +1 -1
  16. package/bin/create-quilt.mjs +0 -2
  17. package/build/cjs/_commonjsHelpers.cjs +0 -10
  18. package/build/cjs/app.cjs +0 -301
  19. package/build/cjs/index.cjs +0 -6784
  20. package/build/cjs/index2.cjs +0 -374
  21. package/build/cjs/index3.cjs +0 -7854
  22. package/build/cjs/minimatch.cjs +0 -1202
  23. package/build/cjs/package-manager.cjs +0 -305
  24. package/build/cjs/package.cjs +0 -425
  25. package/build/cjs/parser-babel.cjs +0 -59
  26. package/build/cjs/parser-yaml.cjs +0 -182
  27. package/build/cjs/standalone.cjs +0 -147
  28. package/build/esm/_commonjsHelpers.mjs +0 -7
  29. package/build/esm/app.mjs +0 -278
  30. package/build/esm/index.mjs +0 -6743
  31. package/build/esm/index2.mjs +0 -365
  32. package/build/esm/index3.mjs +0 -7852
  33. package/build/esm/minimatch.mjs +0 -1200
  34. package/build/esm/package-manager.mjs +0 -275
  35. package/build/esm/package.mjs +0 -402
  36. package/build/esm/parser-babel.mjs +0 -57
  37. package/build/esm/parser-yaml.mjs +0 -180
  38. package/build/esm/standalone.mjs +0 -145
@@ -1,425 +0,0 @@
1
- 'use strict';
2
-
3
- var fs = require('fs');
4
- var path = require('path');
5
- var child_process = require('child_process');
6
- var index = require('./index.cjs');
7
- var packageManager = require('./package-manager.cjs');
8
- require('tty');
9
- require('url');
10
- require('readline');
11
- require('events');
12
-
13
- function _interopNamespace(e) {
14
- if (e && e.__esModule) return e;
15
- var n = Object.create(null);
16
- if (e) {
17
- Object.keys(e).forEach(function (k) {
18
- if (k !== 'default') {
19
- var d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: function () { return e[k]; }
23
- });
24
- }
25
- });
26
- }
27
- n["default"] = e;
28
- return Object.freeze(n);
29
- }
30
-
31
- var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
32
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
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
- }
58
-
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;
75
-
76
- if (fs__namespace.existsSync(directory)) {
77
- await packageManager.emptyDirectory(directory);
78
-
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
- }
89
-
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
- }
125
-
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
- }
141
-
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
- });
148
- }
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
263
-
264
- function getArgv() {
265
- const argv = index.arg_1({
266
- '--yes': Boolean,
267
- '-y': '--yes',
268
- '--name': String,
269
- '--directory': String,
270
- '--install': Boolean,
271
- '--no-install': Boolean,
272
- '--monorepo': Boolean,
273
- '--no-monorepo': Boolean,
274
- '--package-manager': String,
275
- '--extras': [String],
276
- '--no-extras': Boolean,
277
- '--react': Boolean,
278
- '--no-react': Boolean,
279
- '--public': Boolean,
280
- '--private': Boolean,
281
- '--registry': String,
282
- '--help': Boolean,
283
- '-h': '--help'
284
- }, {
285
- permissive: true
286
- });
287
- return argv;
288
- }
289
-
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;
304
- }
305
-
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;
342
- }
343
-
344
- async function getPublic(argv) {
345
- let isPublic;
346
-
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
- }
358
-
359
- return isPublic;
360
- }
361
-
362
- async function getReact(argv) {
363
- let useReact;
364
-
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
- }
376
-
377
- return useReact;
378
- }
379
-
380
- function adjustPackageJson(packageJson, {
381
- name,
382
- react,
383
- isPublic,
384
- registry
385
- }) {
386
- 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';
390
-
391
- if (scope) {
392
- packageJson.publishConfig[`${scope}/registry`] = finalRegistry;
393
- } else if (registry) {
394
- packageJson.publishConfig.registry = finalRegistry;
395
- }
396
-
397
- if (isPublic) {
398
- delete packageJson.private;
399
- } else {
400
- delete packageJson.publishConfig;
401
- }
402
-
403
- if (!react) {
404
- delete packageJson.dependencies['@types/react'];
405
- delete packageJson.devDependencies['react'];
406
- delete packageJson.peerDependencies['react'];
407
- delete packageJson.peerDependenciesMeta['react'];
408
- packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(extend => !extend.includes('react'));
409
- }
410
-
411
- return packageJson;
412
- }
413
-
414
- function sortKeys(object) {
415
- const newObject = {};
416
- const sortedEntries = Object.entries(object).sort(([keyOne], [keyTwo]) => keyOne.localeCompare(keyTwo));
417
-
418
- for (const [key, value] of sortedEntries) {
419
- newObject[key] = value;
420
- }
421
-
422
- return newObject;
423
- }
424
-
425
- exports.createPackage = createPackage;