@quilted/create 0.1.20 → 0.1.23

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.
@@ -0,0 +1,285 @@
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
+ var _templateRootPromise;
12
+
13
+ (_templateRootPromise = templateRootPromise) !== null && _templateRootPromise !== void 0 ? _templateRootPromise : templateRootPromise = templateDirectory(name);
14
+ const templateRoot = await templateRootPromise;
15
+ const targetRoot = path.resolve(to);
16
+ const files = fs.readdirSync(templateRoot).filter(file => !path.basename(file).startsWith('.'));
17
+
18
+ for (const file of files) {
19
+ if (handleFile) {
20
+ if (!handleFile(file)) {
21
+ continue;
22
+ }
23
+ }
24
+
25
+ const targetPath = path.join(targetRoot, file.startsWith('_') ? `.${file.slice(1)}` : file);
26
+ copy(path.join(templateRoot, file), targetPath);
27
+ }
28
+ },
29
+
30
+ async read(file) {
31
+ var _templateRootPromise2;
32
+
33
+ (_templateRootPromise2 = templateRootPromise) !== null && _templateRootPromise2 !== void 0 ? _templateRootPromise2 : templateRootPromise = templateDirectory(name);
34
+ const templateRoot = await templateRootPromise;
35
+ return fs.readFileSync(path.join(templateRoot, file), {
36
+ encoding: 'utf8'
37
+ });
38
+ }
39
+
40
+ };
41
+ }
42
+ function createOutputTarget(target) {
43
+ return {
44
+ root: target,
45
+
46
+ read(file) {
47
+ return fs.promises.readFile(path.resolve(target, file), {
48
+ encoding: 'utf8'
49
+ });
50
+ },
51
+
52
+ async write(file, content) {
53
+ await writeFile(path.resolve(target, file), content);
54
+ }
55
+
56
+ };
57
+ }
58
+ let packageRootPromise;
59
+
60
+ async function templateDirectory(name) {
61
+ return path.join(await getPackageRoot(), 'templates', name);
62
+ }
63
+
64
+ async function getPackageRoot() {
65
+ if (!packageRootPromise) {
66
+ packageRootPromise = (async () => {
67
+ const {
68
+ packageDirectory
69
+ } = await import('./index2.mjs');
70
+ return packageDirectory({
71
+ cwd: path.dirname(fileURLToPath(import.meta.url))
72
+ });
73
+ })();
74
+ }
75
+
76
+ return packageRootPromise;
77
+ }
78
+
79
+ function toValidPackageName(projectName) {
80
+ return projectName.trim().toLowerCase().replace(/\s+/g, '-').replace(/^[._]/, '').replace(/[^a-z0-9-~@/]+/g, '-');
81
+ }
82
+
83
+ function copy(source, destination) {
84
+ const stat = fs.statSync(source);
85
+
86
+ if (stat.isDirectory()) {
87
+ copyDirectory(source, destination);
88
+ } else {
89
+ fs.copyFileSync(source, destination);
90
+ }
91
+ }
92
+
93
+ async function copyDirectory(source, destination) {
94
+ fs.mkdirSync(destination, {
95
+ recursive: true
96
+ });
97
+
98
+ for (const file of fs.readdirSync(source)) {
99
+ const srcFile = path.resolve(source, file);
100
+ const destFile = path.resolve(destination, file);
101
+ copy(srcFile, destFile);
102
+ }
103
+ }
104
+
105
+ async function writeFile(file, content) {
106
+ await fs.promises.writeFile(file, content);
107
+ }
108
+ async function isEmpty(path) {
109
+ return fs.readdirSync(path).length === 0;
110
+ }
111
+ async function emptyDirectory(dir) {
112
+ if (!fs.existsSync(dir)) {
113
+ return;
114
+ }
115
+
116
+ for (const file of fs.readdirSync(dir)) {
117
+ fs.rmSync(path.resolve(dir, file), {
118
+ force: true,
119
+ recursive: true
120
+ });
121
+ }
122
+ }
123
+ function relativeDirectoryForDisplay(relativeDirectory) {
124
+ return relativeDirectory.startsWith('.') ? relativeDirectory : `.${path.sep}${relativeDirectory}`;
125
+ }
126
+ async function format(content, {
127
+ as: parser
128
+ }) {
129
+ const [{
130
+ format
131
+ }, {
132
+ default: babel
133
+ }, {
134
+ default: yaml
135
+ }] = 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; })]);
136
+ return format(content, {
137
+ arrowParens: 'always',
138
+ bracketSpacing: false,
139
+ singleQuote: true,
140
+ trailingComma: 'all',
141
+ parser,
142
+ plugins: [babel, yaml]
143
+ });
144
+ }
145
+
146
+ const ENDS_WITH_TSCONFIG = /[/]?tsconfig[.a-z0-9]*[.]json/i;
147
+ async function addToTsConfig(directory, output) {
148
+ var _tsconfig$references;
149
+
150
+ const tsconfig = JSON.parse(await output.read('tsconfig.json'));
151
+ (_tsconfig$references = tsconfig.references) !== null && _tsconfig$references !== void 0 ? _tsconfig$references : tsconfig.references = [];
152
+ const relativePath = relative(output.root, directory);
153
+ const relativeForDisplay = relativeDirectoryForDisplay(relativePath);
154
+
155
+ if (tsconfig.references.length === 0) {
156
+ tsconfig.references.push({
157
+ path: relativeForDisplay
158
+ });
159
+ } else {
160
+ let hasExistingReference = false;
161
+ let referenceFormat = 'pretty-relative';
162
+
163
+ for (const {
164
+ path
165
+ } of tsconfig.references) {
166
+ if (path.startsWith('./')) {
167
+ if (ENDS_WITH_TSCONFIG.test(path)) {
168
+ referenceFormat = 'pretty-tsconfig';
169
+
170
+ if (path === `${relativeForDisplay}/tsconfig.json`) {
171
+ hasExistingReference = true;
172
+ break;
173
+ }
174
+ }
175
+
176
+ referenceFormat = 'pretty-relative';
177
+
178
+ if (path === relativeForDisplay) {
179
+ hasExistingReference = true;
180
+ break;
181
+ }
182
+ } else if (ENDS_WITH_TSCONFIG.test(path)) {
183
+ referenceFormat = 'tsconfig';
184
+
185
+ if (path === `${relativePath}/tsconfig.json`) {
186
+ hasExistingReference = true;
187
+ break;
188
+ }
189
+ } else {
190
+ referenceFormat = 'relative';
191
+
192
+ if (path === relativePath) {
193
+ hasExistingReference = true;
194
+ break;
195
+ }
196
+ }
197
+ }
198
+
199
+ if (!hasExistingReference) {
200
+ let path;
201
+
202
+ if (referenceFormat === 'pretty-tsconfig') {
203
+ path = `${relativeForDisplay}/tsconfig.json`;
204
+ } else if (referenceFormat === 'pretty-relative') {
205
+ path = relativeForDisplay;
206
+ } else if (referenceFormat === 'tsconfig') {
207
+ path = `${relativePath}/tsconfig.json`;
208
+ } else {
209
+ path = relativePath;
210
+ }
211
+
212
+ tsconfig.references.push({
213
+ path
214
+ });
215
+ }
216
+ }
217
+
218
+ tsconfig.references = tsconfig.references.sort(({
219
+ path: pathOne
220
+ }, {
221
+ path: pathTwo
222
+ }) => pathOne.localeCompare(pathTwo));
223
+ await output.write('tsconfig.json', await format(JSON.stringify(tsconfig), {
224
+ as: 'json'
225
+ }));
226
+ }
227
+
228
+ async function addToPackageManagerWorkspaces(directory, output, packageManager) {
229
+ if (packageManager === 'pnpm') {
230
+ var _workspaceYaml$packag;
231
+
232
+ const {
233
+ parse,
234
+ stringify
235
+ } = await import('./index3.mjs').then(function (n) { return n.i; });
236
+ const workspaceYaml = parse(await output.read('pnpm-workspace.yaml'));
237
+ workspaceYaml.packages = await addToWorkspaces(relative(output.root, directory), (_workspaceYaml$packag = workspaceYaml.packages) !== null && _workspaceYaml$packag !== void 0 ? _workspaceYaml$packag : []);
238
+ await output.write('pnpm-workspace.yaml', await format(stringify(workspaceYaml), {
239
+ as: 'yaml'
240
+ }));
241
+ } else {
242
+ var _packageJson$workspac;
243
+
244
+ const packageJson = JSON.parse(await output.read('package.json'));
245
+ packageJson.workspaces = await addToWorkspaces(relative(output.root, directory), (_packageJson$workspac = packageJson.workspaces) !== null && _packageJson$workspac !== void 0 ? _packageJson$workspac : []);
246
+ await output.write('package.json', await format(JSON.stringify(packageJson), {
247
+ as: 'json-stringify'
248
+ }));
249
+ }
250
+ }
251
+
252
+ async function addToWorkspaces(relative, workspaces) {
253
+ if (workspaces.length === 0) {
254
+ return [relative];
255
+ } // Default documentation seems to generally exclude leading `./` on paths
256
+
257
+
258
+ let pretty = false;
259
+ let hasMatch = false;
260
+ const {
261
+ default: minimatch
262
+ } = await import('./minimatch.mjs').then(function (n) { return n.m; });
263
+
264
+ for (const pattern of workspaces) {
265
+ let normalizedPattern = pattern;
266
+
267
+ if (pattern.startsWith('./')) {
268
+ pretty = true;
269
+ normalizedPattern = pattern.slice(2);
270
+ }
271
+
272
+ if (minimatch(relative, normalizedPattern)) {
273
+ hasMatch = true;
274
+ break;
275
+ }
276
+ }
277
+
278
+ if (hasMatch) {
279
+ return workspaces;
280
+ }
281
+
282
+ return [...workspaces, pretty ? relativeDirectoryForDisplay(relative) : relative].sort((patternOne, patternTwo) => patternOne.localeCompare(patternTwo));
283
+ }
284
+
285
+ 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 };
@@ -0,0 +1,409 @@
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
+ let _ = t => t,
12
+ _t,
13
+ _t2,
14
+ _t3,
15
+ _t4;
16
+ async function createProject() {
17
+ const argv = getArgv();
18
+
19
+ if (argv['--help']) {
20
+ var _argv$PackageManag;
21
+
22
+ const additionalOptions = stripIndent(_t || (_t = _`
23
+ ${0}, ${0}
24
+ Whether this package will use React. If you don’t provide this option, the command
25
+ will ask you about it later.
26
+
27
+ ${0}, ${0}
28
+ Whether this package will be published for other projects to install. If you do not
29
+ provide this option, the command will ask you about it later.
30
+
31
+ ${0}
32
+ The package registry to publish this package to. This option only applies if you create
33
+ a public package. If you do not provide this option, it will use the default NPM registry.
34
+ `), cyan_1(`--react`), cyan_1(`--no-react`), cyan_1(`--public`), cyan_1(`--private`), cyan_1(`--registry`));
35
+ printHelp({
36
+ kind: 'package',
37
+ options: additionalOptions,
38
+ packageManager: (_argv$PackageManag = argv['--package-manager']) === null || _argv$PackageManag === void 0 ? void 0 : _argv$PackageManag.toLowerCase()
39
+ });
40
+ return;
41
+ }
42
+
43
+ const inWorkspace = fs.existsSync('quilt.workspace.ts');
44
+ const name = await getName(argv);
45
+ const directory = await getDirectory(argv, {
46
+ name,
47
+ inWorkspace
48
+ });
49
+ const isPublic = await getPublic(argv);
50
+ const useReact = await getReact(argv);
51
+ const createAsMonorepo = !inWorkspace && (await getCreateAsMonorepo(argv));
52
+ const shouldInstall = await getShouldInstall(argv);
53
+ const packageManager = await getPackageManager(argv);
54
+ const setupExtras = await getExtrasToSetup(argv, {
55
+ inWorkspace
56
+ });
57
+ const partOfMonorepo = inWorkspace || createAsMonorepo;
58
+ const packageDirectory = createAsMonorepo ? path.join(directory, `packages/${toValidPackageName(name.split('/').pop())}`) : directory;
59
+
60
+ if (fs.existsSync(directory)) {
61
+ await emptyDirectory(directory);
62
+
63
+ if (packageDirectory !== directory) {
64
+ fs.mkdirSync(packageDirectory, {
65
+ recursive: true
66
+ });
67
+ }
68
+ } else {
69
+ fs.mkdirSync(packageDirectory, {
70
+ recursive: true
71
+ });
72
+ }
73
+
74
+ const rootDirectory = inWorkspace ? process.cwd() : directory;
75
+ const outputRoot = createOutputTarget(rootDirectory);
76
+ const packageTemplate = loadTemplate('package');
77
+ const workspaceTemplate = loadTemplate('workspace');
78
+ let quiltProject = await packageTemplate.read('quilt.project.ts');
79
+
80
+ if (useReact) {
81
+ quiltProject = quiltProject.replace('react: false', 'react: true');
82
+ } // If we aren’t already in a workspace, copy the workspace files over, which
83
+ // are needed if we are making a monorepo or not.
84
+
85
+
86
+ if (!inWorkspace) {
87
+ await workspaceTemplate.copy(directory, file => {
88
+ // When this is a single project, we use the project’s Quilt configuration as the base.
89
+ if (file === 'quilt.workspace.ts') return createAsMonorepo; // We need to make some adjustments to the root package.json
90
+
91
+ return file !== 'package.json';
92
+ }); // If we are creating a monorepo, we need to add the root package.json and
93
+ // package manager workspace configuration.
94
+
95
+ if (createAsMonorepo) {
96
+ const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
97
+ workspacePackageJson.name = toValidPackageName(name);
98
+
99
+ if (packageManager === 'pnpm') {
100
+ await outputRoot.write('pnpm-workspace.yaml', await format(`
101
+ packages:
102
+ - './packages/*'
103
+ `, {
104
+ as: 'yaml'
105
+ }));
106
+ } else {
107
+ workspacePackageJson.workspaces = ['packages/*'];
108
+ }
109
+
110
+ await outputRoot.write('package.json', await format(JSON.stringify(workspacePackageJson), {
111
+ as: 'json-stringify'
112
+ }));
113
+ } else {
114
+ const [projectPackageJson, projectTSConfig, workspacePackageJson] = await Promise.all([packageTemplate.read('package.json').then(content => JSON.parse(content)), packageTemplate.read('tsconfig.json').then(content => JSON.parse(content)), workspaceTemplate.read('package.json').then(content => JSON.parse(content))]);
115
+ workspacePackageJson.eslintConfig = projectPackageJson.eslintConfig;
116
+ workspacePackageJson.browserslist = projectPackageJson.browserslist;
117
+ const newPackageJson = {}; // We want to put the project’s dependencies in the package.json, respecting
118
+ // the preferred ordering (dependencies, peer dependencies, dev dependencies).
119
+
120
+ for (const [key, value] of Object.entries(projectPackageJson)) {
121
+ if (key !== 'devDependencies') {
122
+ newPackageJson[key] = value;
123
+ continue;
124
+ }
125
+
126
+ newPackageJson.dependencies = projectPackageJson.dependencies;
127
+ newPackageJson.peerDependencies = projectPackageJson.peerDependencies;
128
+ newPackageJson.peerDependenciesMeta = projectPackageJson.peerDependenciesMeta;
129
+ newPackageJson.devDependencies = sortKeys({ ...workspacePackageJson.devDependencies,
130
+ ...projectPackageJson.devDependencies
131
+ });
132
+ }
133
+
134
+ adjustPackageJson(newPackageJson, {
135
+ name: toValidPackageName(name),
136
+ react: useReact,
137
+ isPublic,
138
+ registry: argv['--registry']
139
+ });
140
+ quiltProject = quiltProject.replace('quiltPackage', 'quiltWorkspace, quiltPackage').replace('quiltPackage(', 'quiltWorkspace(), quiltPackage(');
141
+ await outputRoot.write('quilt.project.ts', await format(quiltProject, {
142
+ as: 'typescript'
143
+ }));
144
+ await outputRoot.write('package.json', await format(JSON.stringify(newPackageJson), {
145
+ as: 'json-stringify'
146
+ }));
147
+ await outputRoot.write('tsconfig.json', await format(JSON.stringify(projectTSConfig), {
148
+ as: 'json'
149
+ }));
150
+ }
151
+
152
+ if (setupExtras.has('github')) {
153
+ await loadTemplate('github').copy(directory);
154
+ }
155
+
156
+ if (setupExtras.has('vscode')) {
157
+ await loadTemplate('vscode').copy(directory);
158
+ }
159
+ }
160
+
161
+ await packageTemplate.copy(packageDirectory, file => {
162
+ // If we are in a monorepo, we can use all the template files as they are
163
+ if (file === 'tsconfig.json') {
164
+ return partOfMonorepo;
165
+ } // We need to make some adjustments the project’s package.json and Quilt config
166
+
167
+
168
+ return file !== 'package.json' && file !== 'quilt.project.ts';
169
+ });
170
+
171
+ if (partOfMonorepo) {
172
+ // Write the package’s package.json (the root one was already created)
173
+ const projectPackageJson = JSON.parse(await packageTemplate.read('package.json'));
174
+ projectPackageJson.repository.directory = path.relative(directory, packageDirectory);
175
+ adjustPackageJson(projectPackageJson, {
176
+ name: toValidPackageName(name),
177
+ react: useReact,
178
+ isPublic,
179
+ registry: argv['--registry']
180
+ });
181
+ await outputRoot.write(path.join(packageDirectory, 'package.json'), await format(JSON.stringify(projectPackageJson), {
182
+ as: 'json-stringify'
183
+ }));
184
+ await outputRoot.write(path.join(packageDirectory, 'quilt.project.ts'), quiltProject);
185
+ await Promise.all([addToTsConfig(packageDirectory, outputRoot), addToPackageManagerWorkspaces(packageDirectory, outputRoot, packageManager)]);
186
+ }
187
+
188
+ if (shouldInstall) {
189
+ process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
190
+
191
+ execSync(`${packageManager} install`, {
192
+ cwd: rootDirectory
193
+ });
194
+ process.stdout.moveCursor(0, -1);
195
+ process.stdout.clearLine(1);
196
+ console.log('Installed dependencies.');
197
+ }
198
+
199
+ const packageJsonInstructions = stripIndent(_t2 || (_t2 = _`
200
+ Your new package is ready to go! However, before you go too much further,
201
+ you should update the following fields in ${0}:
202
+
203
+ - ${0}, where you provide a description of what your package does
204
+ - ${0}, where you should include the ${0} of your project’s repo
205
+
206
+ Before you publish your package, you will also want to update the ${0}
207
+ field in the package.json file.
208
+ `), cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), path.join(packageDirectory, 'package.json')))), bold_1(`"description"`), bold_1(`"repository"`), bold_1(`"url"`), bold_1(`"version"`));
209
+ console.log();
210
+ console.log(packageJsonInstructions);
211
+ const commands = [];
212
+
213
+ if (!inWorkspace && directory !== process.cwd()) {
214
+ commands.push(`cd ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), directory)))} ${dim_1('# Move into your new package’s directory')}`);
215
+ }
216
+
217
+ if (!shouldInstall) {
218
+ commands.push(`pnpm install ${dim_1('# Install all your dependencies')}`);
219
+ }
220
+
221
+ if (!inWorkspace) {
222
+ // TODO: change this condition to check if git was initialized already
223
+ commands.push(`git init && git add -A && git commit -m "Initial commit" ${dim_1('# Start your git history (optional)')}`);
224
+ }
225
+
226
+ if (commands.length > 0) {
227
+ const whatsNext = stripIndent(_t3 || (_t3 = _`
228
+ After you update your package.json, there’s ${0} you’ll need to take
229
+ in order to start building:
230
+ `), commands.length > 1 ? 'a few more steps' : 'one more step');
231
+ console.log();
232
+ console.log(whatsNext);
233
+ console.log();
234
+ console.log(commands.map(command => ` ${command}`).join('\n'));
235
+ }
236
+
237
+ const followUp = stripIndent(_t4 || (_t4 = _`
238
+ Quilt can help you build, test, lint, and type-check your new package. You
239
+ can learn more about building packages with Quilt by reading the documentation:
240
+ ${0}
241
+
242
+ Have fun! 🎉
243
+ `), underline_1(magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation')));
244
+ console.log();
245
+ console.log(followUp);
246
+ } // Argument handling
247
+
248
+ function getArgv() {
249
+ const argv = arg_1({
250
+ '--yes': Boolean,
251
+ '-y': '--yes',
252
+ '--name': String,
253
+ '--directory': String,
254
+ '--install': Boolean,
255
+ '--no-install': Boolean,
256
+ '--monorepo': Boolean,
257
+ '--no-monorepo': Boolean,
258
+ '--package-manager': String,
259
+ '--extras': [String],
260
+ '--no-extras': Boolean,
261
+ '--react': Boolean,
262
+ '--no-react': Boolean,
263
+ '--public': Boolean,
264
+ '--private': Boolean,
265
+ '--registry': String,
266
+ '--help': Boolean,
267
+ '-h': '--help'
268
+ }, {
269
+ permissive: true
270
+ });
271
+ return argv;
272
+ }
273
+
274
+ async function getName(argv) {
275
+ let {
276
+ '--name': name
277
+ } = argv;
278
+
279
+ if (name == null) {
280
+ name = await prompt({
281
+ type: 'text',
282
+ message: 'What would you like to name your new package?',
283
+ initial: '@my-team/package'
284
+ });
285
+ }
286
+
287
+ return name;
288
+ }
289
+
290
+ async function getDirectory(argv, {
291
+ name,
292
+ inWorkspace
293
+ }) {
294
+ let directory = argv['--directory'] ? path.resolve(argv['--directory']) : undefined;
295
+
296
+ if (directory == null) {
297
+ const basePackageName = toValidPackageName(name.split('/').pop());
298
+ const defaultDirectory = inWorkspace ? `packages/${basePackageName}` : basePackageName;
299
+ directory = path.resolve(await prompt({
300
+ type: 'text',
301
+ message: 'Where would you like to create your new package?',
302
+ initial: defaultDirectory
303
+ }));
304
+ }
305
+
306
+ while (!argv['--yes']) {
307
+ if (fs.existsSync(directory) && !(await isEmpty(directory))) {
308
+ const relativeDirectory = path.relative(process.cwd(), directory);
309
+ const empty = await prompt({
310
+ type: 'confirm',
311
+ message: `Directory ${bold_1(relativeDirectoryForDisplay(relativeDirectory))} is not empty, is it safe to empty it?`,
312
+ initial: true
313
+ });
314
+ if (empty) break;
315
+ const promptDirectory = await prompt({
316
+ type: 'text',
317
+ message: 'What directory do you want to create your package in?'
318
+ });
319
+ directory = path.resolve(promptDirectory);
320
+ } else {
321
+ break;
322
+ }
323
+ }
324
+
325
+ return directory;
326
+ }
327
+
328
+ async function getPublic(argv) {
329
+ let isPublic;
330
+
331
+ if (argv['--public'] || argv['--yes']) {
332
+ isPublic = true;
333
+ } else if (argv['--private']) {
334
+ isPublic = false;
335
+ } else {
336
+ isPublic = await prompt({
337
+ type: 'confirm',
338
+ message: 'Will you publish this package to use in other projects?',
339
+ initial: true
340
+ });
341
+ }
342
+
343
+ return isPublic;
344
+ }
345
+
346
+ async function getReact(argv) {
347
+ let useReact;
348
+
349
+ if (argv['--react'] || argv['--yes']) {
350
+ useReact = true;
351
+ } else if (argv['--no-react']) {
352
+ useReact = false;
353
+ } else {
354
+ useReact = await prompt({
355
+ type: 'confirm',
356
+ message: 'Will this package depend on React?',
357
+ initial: true
358
+ });
359
+ }
360
+
361
+ return useReact;
362
+ }
363
+
364
+ function adjustPackageJson(packageJson, {
365
+ name,
366
+ react,
367
+ isPublic,
368
+ registry
369
+ }) {
370
+ packageJson.name = name;
371
+ const packageParts = name.split('/');
372
+ const scope = packageParts[0].startsWith('@') ? packageParts[0] : undefined;
373
+ const finalRegistry = registry !== null && registry !== void 0 ? registry : 'https://registry.npmjs.org';
374
+
375
+ if (scope) {
376
+ packageJson.publishConfig[`${scope}/registry`] = finalRegistry;
377
+ } else if (registry) {
378
+ packageJson.publishConfig.registry = finalRegistry;
379
+ }
380
+
381
+ if (isPublic) {
382
+ delete packageJson.private;
383
+ } else {
384
+ delete packageJson.publishConfig;
385
+ }
386
+
387
+ if (!react) {
388
+ delete packageJson.dependencies['@types/react'];
389
+ delete packageJson.devDependencies['react'];
390
+ delete packageJson.peerDependencies['react'];
391
+ delete packageJson.peerDependenciesMeta['react'];
392
+ packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(extend => !extend.includes('react'));
393
+ }
394
+
395
+ return packageJson;
396
+ }
397
+
398
+ function sortKeys(object) {
399
+ const newObject = {};
400
+ const sortedEntries = Object.entries(object).sort(([keyOne], [keyTwo]) => keyOne.localeCompare(keyTwo));
401
+
402
+ for (const [key, value] of sortedEntries) {
403
+ newObject[key] = value;
404
+ }
405
+
406
+ return newObject;
407
+ }
408
+
409
+ export { createProject };