@quilted/create 0.1.17 → 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 (53) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +30 -0
  3. package/build/tsconfig.tsbuildinfo +1 -1
  4. package/build/typescript/app.d.ts.map +1 -1
  5. package/build/typescript/package.d.ts +1 -1
  6. package/build/typescript/package.d.ts.map +1 -1
  7. package/package.json +5 -3
  8. package/quilt.project.ts +19 -5
  9. package/source/app.ts +0 -10
  10. package/source/create.ts +2 -2
  11. package/source/package.ts +6 -11
  12. package/templates/app-basic/features/Start/Start.test.tsx +12 -0
  13. package/templates/app-basic/foundation/Head/Head.test.tsx +25 -0
  14. package/templates/app-basic/foundation/{Head.tsx → Head/Head.tsx} +0 -0
  15. package/templates/app-basic/foundation/Head/index.ts +1 -0
  16. package/templates/app-basic/foundation/Http/Http.test.tsx +24 -0
  17. package/templates/app-basic/foundation/{Http.tsx → Http/Http.tsx} +0 -0
  18. package/templates/app-basic/foundation/Http/index.ts +1 -0
  19. package/templates/app-basic/quilt.project.ts +5 -5
  20. package/templates/app-basic/tests/mount.tsx +47 -0
  21. package/templates/app-basic/tsconfig.json +4 -3
  22. package/templates/app-single-file/quilt.project.ts +3 -4
  23. package/templates/app-single-file/tsconfig.json +2 -2
  24. package/templates/package/package.json +4 -2
  25. package/templates/package/quilt.project.ts +3 -4
  26. package/templates/package/source/index.ts +3 -1
  27. package/templates/package/source/tests/index.test.ts +8 -0
  28. package/templates/package/tsconfig.json +2 -2
  29. package/templates/workspace/package.json +1 -1
  30. package/tsconfig.json +1 -1
  31. package/bin/create-quilt.mjs +0 -2
  32. package/build/cjs/_commonjsHelpers.cjs +0 -10
  33. package/build/cjs/app.cjs +0 -303
  34. package/build/cjs/index.cjs +0 -6784
  35. package/build/cjs/index2.cjs +0 -374
  36. package/build/cjs/index3.cjs +0 -7854
  37. package/build/cjs/minimatch.cjs +0 -1202
  38. package/build/cjs/package-manager.cjs +0 -305
  39. package/build/cjs/package.cjs +0 -424
  40. package/build/cjs/parser-babel.cjs +0 -59
  41. package/build/cjs/parser-yaml.cjs +0 -182
  42. package/build/cjs/standalone.cjs +0 -147
  43. package/build/esm/_commonjsHelpers.mjs +0 -7
  44. package/build/esm/app.mjs +0 -280
  45. package/build/esm/index.mjs +0 -6743
  46. package/build/esm/index2.mjs +0 -365
  47. package/build/esm/index3.mjs +0 -7852
  48. package/build/esm/minimatch.mjs +0 -1200
  49. package/build/esm/package-manager.mjs +0 -275
  50. package/build/esm/package.mjs +0 -401
  51. package/build/esm/parser-babel.mjs +0 -57
  52. package/build/esm/parser-yaml.mjs +0 -180
  53. 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,401 +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
- const addBackToTSConfigInclude = new Set(['quilt.project.ts', '*.test.ts', '*.test.tsx']);
134
- projectTSConfig.exclude = projectTSConfig.exclude.filter(excluded => !addBackToTSConfigInclude.has(excluded));
135
- quiltProject = quiltProject.replace('quiltPackage', 'quiltWorkspace, quiltPackage').replace('quiltPackage(', 'quiltWorkspace(), quiltPackage(');
136
- await outputRoot.write('quilt.project.ts', await format(quiltProject, {
137
- as: 'typescript'
138
- }));
139
- await outputRoot.write('package.json', await format(JSON.stringify(newPackageJson), {
140
- as: 'json-stringify'
141
- }));
142
- await outputRoot.write('tsconfig.json', await format(JSON.stringify(projectTSConfig), {
143
- as: 'json'
144
- }));
145
- }
146
-
147
- if (setupExtras.has('github')) {
148
- await loadTemplate('github').copy(directory);
149
- }
150
-
151
- if (setupExtras.has('vscode')) {
152
- await loadTemplate('vscode').copy(directory);
153
- }
154
- }
155
-
156
- await packageTemplate.copy(packageDirectory, file => {
157
- // If we are in a monorepo, we can use all the template files as they are
158
- if (file === 'tsconfig.json') {
159
- return partOfMonorepo;
160
- } // We need to make some adjustments the project’s package.json and Quilt config
161
-
162
-
163
- return file !== 'package.json' && file !== 'quilt.project.ts';
164
- });
165
-
166
- if (partOfMonorepo) {
167
- // Write the package’s package.json (the root one was already created)
168
- const projectPackageJson = JSON.parse(await packageTemplate.read('package.json'));
169
- projectPackageJson.repository.directory = path.relative(directory, packageDirectory);
170
- adjustPackageJson(projectPackageJson, {
171
- name: toValidPackageName(name),
172
- react: useReact,
173
- isPublic,
174
- registry: argv['--registry']
175
- });
176
- await outputRoot.write(path.join(packageDirectory, 'package.json'), await format(JSON.stringify(projectPackageJson), {
177
- as: 'json-stringify'
178
- }));
179
- await outputRoot.write(path.join(packageDirectory, 'quilt.project.ts'), quiltProject);
180
- await Promise.all([addToTsConfig(packageDirectory, outputRoot), addToPackageManagerWorkspaces(packageDirectory, outputRoot, packageManager)]);
181
- }
182
-
183
- if (shouldInstall) {
184
- process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
185
-
186
- execSync(`${packageManager} install`, {
187
- cwd: rootDirectory
188
- });
189
- process.stdout.moveCursor(0, -1);
190
- process.stdout.clearLine(1);
191
- console.log('Installed dependencies.');
192
- }
193
-
194
- const packageJsonInstructions = stripIndent`
195
- Your new package is ready to go! However, before you go too much further,
196
- you should update the following fields in ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), path.join(packageDirectory, 'package.json'))))}:
197
-
198
- - ${bold_1(`"description"`)}, where you provide a description of what your package does
199
- - ${bold_1(`"repository"`)}, where you should include the ${bold_1(`"url"`)} of your project’s repo
200
- `;
201
- console.log();
202
- console.log(packageJsonInstructions);
203
- const commands = [];
204
-
205
- if (!inWorkspace && directory !== process.cwd()) {
206
- commands.push(`cd ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), directory)))} ${dim_1('# Move into your new package’s directory')}`);
207
- }
208
-
209
- if (!shouldInstall) {
210
- commands.push(`pnpm install ${dim_1('# Install all your dependencies')}`);
211
- }
212
-
213
- if (!inWorkspace) {
214
- // TODO: change this condition to check if git was initialized already
215
- commands.push(`git init && git add -A && git commit -m "Initial commit" ${dim_1('# Start your git history (optional)')}`);
216
- }
217
-
218
- if (commands.length > 0) {
219
- const whatsNext = stripIndent`
220
- After you update your package.json, there’s ${commands.length > 1 ? 'a few more steps' : 'one more step'} you’ll need to take
221
- in order to start building:
222
- `;
223
- console.log();
224
- console.log(whatsNext);
225
- console.log();
226
- console.log(commands.map(command => ` ${command}`).join('\n'));
227
- }
228
-
229
- const followUp = stripIndent`
230
- Quilt can help you build, test, lint, and type-check your new package. You
231
- can learn more about building packages with Quilt by reading the documentation:
232
- ${underline_1(magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation'))}
233
-
234
- Have fun! 🎉
235
- `;
236
- console.log();
237
- console.log(followUp);
238
- } // Argument handling
239
-
240
- function getArgv() {
241
- const argv = arg_1({
242
- '--yes': Boolean,
243
- '-y': '--yes',
244
- '--name': String,
245
- '--directory': String,
246
- '--install': Boolean,
247
- '--no-install': Boolean,
248
- '--monorepo': Boolean,
249
- '--no-monorepo': Boolean,
250
- '--package-manager': String,
251
- '--extras': [String],
252
- '--no-extras': Boolean,
253
- '--react': Boolean,
254
- '--no-react': Boolean,
255
- '--public': Boolean,
256
- '--private': Boolean,
257
- '--registry': String,
258
- '--help': Boolean,
259
- '-h': '--help'
260
- }, {
261
- permissive: true
262
- });
263
- return argv;
264
- }
265
-
266
- async function getName(argv) {
267
- let {
268
- '--name': name
269
- } = argv;
270
-
271
- if (name == null) {
272
- name = await prompt({
273
- type: 'text',
274
- message: 'What would you like to name your new package?',
275
- initial: '@my-team/package'
276
- });
277
- }
278
-
279
- return name;
280
- }
281
-
282
- async function getDirectory(argv, {
283
- name,
284
- inWorkspace
285
- }) {
286
- let directory = argv['--directory'] ? path.resolve(argv['--directory']) : undefined;
287
-
288
- if (directory == null) {
289
- const basePackageName = toValidPackageName(name.split('/').pop());
290
- const defaultDirectory = inWorkspace ? `packages/${basePackageName}` : basePackageName;
291
- directory = path.resolve(await prompt({
292
- type: 'text',
293
- message: 'Where would you like to create your new package?',
294
- initial: defaultDirectory
295
- }));
296
- }
297
-
298
- while (!argv['--yes']) {
299
- if (fs.existsSync(directory) && !(await isEmpty(directory))) {
300
- const relativeDirectory = path.relative(process.cwd(), directory);
301
- const empty = await prompt({
302
- type: 'confirm',
303
- message: `Directory ${bold_1(relativeDirectoryForDisplay(relativeDirectory))} is not empty, is it safe to empty it?`,
304
- initial: true
305
- });
306
- if (empty) break;
307
- const promptDirectory = await prompt({
308
- type: 'text',
309
- message: 'What directory do you want to create your package in?'
310
- });
311
- directory = path.resolve(promptDirectory);
312
- } else {
313
- break;
314
- }
315
- }
316
-
317
- return directory;
318
- }
319
-
320
- async function getPublic(argv) {
321
- let isPublic;
322
-
323
- if (argv['--public'] || argv['--yes']) {
324
- isPublic = true;
325
- } else if (argv['--private']) {
326
- isPublic = false;
327
- } else {
328
- isPublic = await prompt({
329
- type: 'confirm',
330
- message: 'Will you publish this package to use in other projects?',
331
- initial: true
332
- });
333
- }
334
-
335
- return isPublic;
336
- }
337
-
338
- async function getReact(argv) {
339
- let useReact;
340
-
341
- if (argv['--react'] || argv['--yes']) {
342
- useReact = true;
343
- } else if (argv['--no-react']) {
344
- useReact = false;
345
- } else {
346
- useReact = await prompt({
347
- type: 'confirm',
348
- message: 'Will this package depend on React?',
349
- initial: true
350
- });
351
- }
352
-
353
- return useReact;
354
- }
355
-
356
- function adjustPackageJson(packageJson, {
357
- name,
358
- react,
359
- isPublic,
360
- registry
361
- }) {
362
- packageJson.name = name;
363
- const packageParts = name.split('/');
364
- const scope = packageParts[0].startsWith('@') ? packageParts[0] : undefined;
365
- const finalRegistry = registry ?? 'https://registry.npmjs.org';
366
-
367
- if (scope) {
368
- packageJson.publishConfig[`${scope}/registry`] = finalRegistry;
369
- } else if (registry) {
370
- packageJson.publishConfig.registry = finalRegistry;
371
- }
372
-
373
- if (isPublic) {
374
- delete packageJson.private;
375
- } else {
376
- delete packageJson.publishConfig;
377
- }
378
-
379
- if (!react) {
380
- delete packageJson.dependencies['@types/react'];
381
- delete packageJson.devDependencies['react'];
382
- delete packageJson.peerDependencies['react'];
383
- delete packageJson.peerDependenciesMeta['react'];
384
- packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(extend => !extend.includes('react'));
385
- }
386
-
387
- return packageJson;
388
- }
389
-
390
- function sortKeys(object) {
391
- const newObject = {};
392
- const sortedEntries = Object.entries(object).sort(([keyOne], [keyTwo]) => keyOne.localeCompare(keyTwo));
393
-
394
- for (const [key, value] of sortedEntries) {
395
- newObject[key] = value;
396
- }
397
-
398
- return newObject;
399
- }
400
-
401
- export { createPackage };