@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,275 +0,0 @@
1
- import * as path from 'path';
2
- import { relative } from 'path';
3
- import * as fs from 'fs';
4
- import { fileURLToPath } from 'url';
5
- import './index.mjs';
6
-
7
- function loadTemplate(name) {
8
- let templateRootPromise;
9
- return {
10
- async copy(to, handleFile) {
11
- templateRootPromise ?? (templateRootPromise = templateDirectory(name));
12
- const templateRoot = await templateRootPromise;
13
- const targetRoot = path.resolve(to);
14
- const files = fs.readdirSync(templateRoot).filter(file => !path.basename(file).startsWith('.'));
15
-
16
- for (const file of files) {
17
- if (handleFile) {
18
- if (!handleFile(file)) {
19
- continue;
20
- }
21
- }
22
-
23
- const targetPath = path.join(targetRoot, file.startsWith('_') ? `.${file.slice(1)}` : file);
24
- copy(path.join(templateRoot, file), targetPath);
25
- }
26
- },
27
-
28
- async read(file) {
29
- templateRootPromise ?? (templateRootPromise = templateDirectory(name));
30
- const templateRoot = await templateRootPromise;
31
- return fs.readFileSync(path.join(templateRoot, file), {
32
- encoding: 'utf8'
33
- });
34
- }
35
-
36
- };
37
- }
38
- function createOutputTarget(target) {
39
- return {
40
- root: target,
41
-
42
- read(file) {
43
- return fs.promises.readFile(path.resolve(target, file), {
44
- encoding: 'utf8'
45
- });
46
- },
47
-
48
- async write(file, content) {
49
- await writeFile(path.resolve(target, file), content);
50
- }
51
-
52
- };
53
- }
54
- let packageRootPromise;
55
-
56
- async function templateDirectory(name) {
57
- return path.join(await getPackageRoot(), 'templates', name);
58
- }
59
-
60
- async function getPackageRoot() {
61
- if (!packageRootPromise) {
62
- packageRootPromise = (async () => {
63
- const {
64
- packageDirectory
65
- } = await import('./index2.mjs');
66
- return packageDirectory({
67
- cwd: path.dirname(fileURLToPath(import.meta.url))
68
- });
69
- })();
70
- }
71
-
72
- return packageRootPromise;
73
- }
74
-
75
- function toValidPackageName(projectName) {
76
- return projectName.trim().toLowerCase().replace(/\s+/g, '-').replace(/^[._]/, '').replace(/[^a-z0-9-~@/]+/g, '-');
77
- }
78
-
79
- function copy(source, destination) {
80
- const stat = fs.statSync(source);
81
-
82
- if (stat.isDirectory()) {
83
- copyDirectory(source, destination);
84
- } else {
85
- fs.copyFileSync(source, destination);
86
- }
87
- }
88
-
89
- async function copyDirectory(source, destination) {
90
- fs.mkdirSync(destination, {
91
- recursive: true
92
- });
93
-
94
- for (const file of fs.readdirSync(source)) {
95
- const srcFile = path.resolve(source, file);
96
- const destFile = path.resolve(destination, file);
97
- copy(srcFile, destFile);
98
- }
99
- }
100
-
101
- async function writeFile(file, content) {
102
- await fs.promises.writeFile(file, content);
103
- }
104
- async function isEmpty(path) {
105
- return fs.readdirSync(path).length === 0;
106
- }
107
- async function emptyDirectory(dir) {
108
- if (!fs.existsSync(dir)) {
109
- return;
110
- }
111
-
112
- for (const file of fs.readdirSync(dir)) {
113
- fs.rmSync(path.resolve(dir, file), {
114
- force: true,
115
- recursive: true
116
- });
117
- }
118
- }
119
- function relativeDirectoryForDisplay(relativeDirectory) {
120
- return relativeDirectory.startsWith('.') ? relativeDirectory : `.${path.sep}${relativeDirectory}`;
121
- }
122
- async function format(content, {
123
- as: parser
124
- }) {
125
- const [{
126
- format
127
- }, {
128
- default: babel
129
- }, {
130
- default: yaml
131
- }] = await Promise.all([import('./standalone.mjs').then(function (n) { return n.s; }), import('./parser-babel.mjs').then(function (n) { return n.p; }), import('./parser-yaml.mjs').then(function (n) { return n.p; })]);
132
- return format(content, {
133
- arrowParens: 'always',
134
- bracketSpacing: false,
135
- singleQuote: true,
136
- trailingComma: 'all',
137
- parser,
138
- plugins: [babel, yaml]
139
- });
140
- }
141
-
142
- const ENDS_WITH_TSCONFIG = /[/]?tsconfig[.a-z0-9]*[.]json/i;
143
- async function addToTsConfig(directory, output) {
144
- const tsconfig = JSON.parse(await output.read('tsconfig.json'));
145
- tsconfig.references ?? (tsconfig.references = []);
146
- const relativePath = relative(output.root, directory);
147
- const relativeForDisplay = relativeDirectoryForDisplay(relativePath);
148
-
149
- if (tsconfig.references.length === 0) {
150
- tsconfig.references.push({
151
- path: relativeForDisplay
152
- });
153
- } else {
154
- let hasExistingReference = false;
155
- let referenceFormat = 'pretty-relative';
156
-
157
- for (const {
158
- path
159
- } of tsconfig.references) {
160
- if (path.startsWith('./')) {
161
- if (ENDS_WITH_TSCONFIG.test(path)) {
162
- referenceFormat = 'pretty-tsconfig';
163
-
164
- if (path === `${relativeForDisplay}/tsconfig.json`) {
165
- hasExistingReference = true;
166
- break;
167
- }
168
- }
169
-
170
- referenceFormat = 'pretty-relative';
171
-
172
- if (path === relativeForDisplay) {
173
- hasExistingReference = true;
174
- break;
175
- }
176
- } else if (ENDS_WITH_TSCONFIG.test(path)) {
177
- referenceFormat = 'tsconfig';
178
-
179
- if (path === `${relativePath}/tsconfig.json`) {
180
- hasExistingReference = true;
181
- break;
182
- }
183
- } else {
184
- referenceFormat = 'relative';
185
-
186
- if (path === relativePath) {
187
- hasExistingReference = true;
188
- break;
189
- }
190
- }
191
- }
192
-
193
- if (!hasExistingReference) {
194
- let path;
195
-
196
- if (referenceFormat === 'pretty-tsconfig') {
197
- path = `${relativeForDisplay}/tsconfig.json`;
198
- } else if (referenceFormat === 'pretty-relative') {
199
- path = relativeForDisplay;
200
- } else if (referenceFormat === 'tsconfig') {
201
- path = `${relativePath}/tsconfig.json`;
202
- } else {
203
- path = relativePath;
204
- }
205
-
206
- tsconfig.references.push({
207
- path
208
- });
209
- }
210
- }
211
-
212
- tsconfig.references = tsconfig.references.sort(({
213
- path: pathOne
214
- }, {
215
- path: pathTwo
216
- }) => pathOne.localeCompare(pathTwo));
217
- await output.write('tsconfig.json', await format(JSON.stringify(tsconfig), {
218
- as: 'json'
219
- }));
220
- }
221
-
222
- async function addToPackageManagerWorkspaces(directory, output, packageManager) {
223
- if (packageManager === 'pnpm') {
224
- const {
225
- parse,
226
- stringify
227
- } = await import('./index3.mjs').then(function (n) { return n.i; });
228
- const workspaceYaml = parse(await output.read('pnpm-workspace.yaml'));
229
- workspaceYaml.packages = await addToWorkspaces(relative(output.root, directory), workspaceYaml.packages ?? []);
230
- await output.write('pnpm-workspace.yaml', await format(stringify(workspaceYaml), {
231
- as: 'yaml'
232
- }));
233
- } else {
234
- const packageJson = JSON.parse(await output.read('package.json'));
235
- packageJson.workspaces = await addToWorkspaces(relative(output.root, directory), packageJson.workspaces ?? []);
236
- await output.write('package.json', await format(JSON.stringify(packageJson), {
237
- as: 'json-stringify'
238
- }));
239
- }
240
- }
241
-
242
- async function addToWorkspaces(relative, workspaces) {
243
- if (workspaces.length === 0) {
244
- return [relative];
245
- } // Default documentation seems to generally exclude leading `./` on paths
246
-
247
-
248
- let pretty = false;
249
- let hasMatch = false;
250
- const {
251
- default: minimatch
252
- } = await import('./minimatch.mjs').then(function (n) { return n.m; });
253
-
254
- for (const pattern of workspaces) {
255
- let normalizedPattern = pattern;
256
-
257
- if (pattern.startsWith('./')) {
258
- pretty = true;
259
- normalizedPattern = pattern.slice(2);
260
- }
261
-
262
- if (minimatch(relative, normalizedPattern)) {
263
- hasMatch = true;
264
- break;
265
- }
266
- }
267
-
268
- if (hasMatch) {
269
- return workspaces;
270
- }
271
-
272
- return [...workspaces, pretty ? relativeDirectoryForDisplay(relative) : relative].sort((patternOne, patternTwo) => patternOne.localeCompare(patternTwo));
273
- }
274
-
275
- export { addToTsConfig as a, addToPackageManagerWorkspaces as b, createOutputTarget as c, emptyDirectory as e, format as f, isEmpty as i, loadTemplate as l, relativeDirectoryForDisplay as r, toValidPackageName as t };
@@ -1,402 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- 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
- import 'tty';
7
- import 'url';
8
- import 'readline';
9
- import 'events';
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
- }
35
-
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;
52
-
53
- if (fs.existsSync(directory)) {
54
- await emptyDirectory(directory);
55
-
56
- if (packageDirectory !== directory) {
57
- fs.mkdirSync(packageDirectory, {
58
- recursive: true
59
- });
60
- }
61
- } else {
62
- fs.mkdirSync(packageDirectory, {
63
- recursive: true
64
- });
65
- }
66
-
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
- }
102
-
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
- }
118
-
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
- });
125
- }
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
240
-
241
- function getArgv() {
242
- const argv = arg_1({
243
- '--yes': Boolean,
244
- '-y': '--yes',
245
- '--name': String,
246
- '--directory': String,
247
- '--install': Boolean,
248
- '--no-install': Boolean,
249
- '--monorepo': Boolean,
250
- '--no-monorepo': Boolean,
251
- '--package-manager': String,
252
- '--extras': [String],
253
- '--no-extras': Boolean,
254
- '--react': Boolean,
255
- '--no-react': Boolean,
256
- '--public': Boolean,
257
- '--private': Boolean,
258
- '--registry': String,
259
- '--help': Boolean,
260
- '-h': '--help'
261
- }, {
262
- permissive: true
263
- });
264
- return argv;
265
- }
266
-
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;
281
- }
282
-
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;
319
- }
320
-
321
- async function getPublic(argv) {
322
- let isPublic;
323
-
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
- }
335
-
336
- return isPublic;
337
- }
338
-
339
- async function getReact(argv) {
340
- let useReact;
341
-
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
- }
353
-
354
- return useReact;
355
- }
356
-
357
- function adjustPackageJson(packageJson, {
358
- name,
359
- react,
360
- isPublic,
361
- registry
362
- }) {
363
- 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';
367
-
368
- if (scope) {
369
- packageJson.publishConfig[`${scope}/registry`] = finalRegistry;
370
- } else if (registry) {
371
- packageJson.publishConfig.registry = finalRegistry;
372
- }
373
-
374
- if (isPublic) {
375
- delete packageJson.private;
376
- } else {
377
- delete packageJson.publishConfig;
378
- }
379
-
380
- if (!react) {
381
- delete packageJson.dependencies['@types/react'];
382
- delete packageJson.devDependencies['react'];
383
- delete packageJson.peerDependencies['react'];
384
- delete packageJson.peerDependenciesMeta['react'];
385
- packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(extend => !extend.includes('react'));
386
- }
387
-
388
- return packageJson;
389
- }
390
-
391
- function sortKeys(object) {
392
- const newObject = {};
393
- const sortedEntries = Object.entries(object).sort(([keyOne], [keyTwo]) => keyOne.localeCompare(keyTwo));
394
-
395
- for (const [key, value] of sortedEntries) {
396
- newObject[key] = value;
397
- }
398
-
399
- return newObject;
400
- }
401
-
402
- export { createPackage };