@quilted/create 0.1.31 → 0.1.33

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.
@@ -5,13 +5,12 @@ var path = require('node:path');
5
5
  var index = require('./index.cjs');
6
6
  var packageManager = require('./shared/package-manager.cjs');
7
7
  require('node:tty');
8
- require('node:url');
9
8
  require('node:readline');
10
9
  require('node:events');
11
10
  require('node:child_process');
11
+ require('node:url');
12
12
 
13
- function _interopNamespace(e) {
14
- if (e && e.__esModule) return e;
13
+ function _interopNamespaceDefault(e) {
15
14
  var n = Object.create(null);
16
15
  if (e) {
17
16
  Object.keys(e).forEach(function (k) {
@@ -28,41 +27,32 @@ function _interopNamespace(e) {
28
27
  return Object.freeze(n);
29
28
  }
30
29
 
31
- var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
32
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
30
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
31
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
33
32
 
34
- let _ = t => t,
35
- _t,
36
- _t2,
37
- _t3,
38
- _t4;
39
33
  async function createProject() {
40
34
  const args = getArguments();
41
-
42
35
  if (args['--help']) {
43
- var _args$PackageManag;
44
-
45
- const additionalOptions = index.stripIndent(_t || (_t = _`
46
- ${0}, ${0}
36
+ const additionalOptions = index.stripIndent`
37
+ ${index.cyan_1(`--react`)}, ${index.cyan_1(`--no-react`)}
47
38
  Whether this package will use React. If you don’t provide this option, the command
48
39
  will ask you about it later.
49
40
 
50
- ${0}, ${0}
41
+ ${index.cyan_1(`--public`)}, ${index.cyan_1(`--private`)}
51
42
  Whether this package will be published for other projects to install. If you do not
52
43
  provide this option, the command will ask you about it later.
53
44
 
54
- ${0}
45
+ ${index.cyan_1(`--registry`)}
55
46
  The package registry to publish this package to. This option only applies if you create
56
47
  a public package. If you do not provide this option, it will use the default NPM registry.
57
- `), index.cyan_1(`--react`), index.cyan_1(`--no-react`), index.cyan_1(`--public`), index.cyan_1(`--private`), index.cyan_1(`--registry`));
48
+ `;
58
49
  index.printHelp({
59
50
  kind: 'package',
60
51
  options: additionalOptions,
61
- packageManager: (_args$PackageManag = args['--package-manager']) === null || _args$PackageManag === void 0 ? void 0 : _args$PackageManag.toLowerCase()
52
+ packageManager: args['--package-manager']?.toLowerCase()
62
53
  });
63
54
  return;
64
55
  }
65
-
66
56
  const inWorkspace = fs__namespace.existsSync('quilt.workspace.ts');
67
57
  const name = await getName(args);
68
58
  const directory = await getDirectory(args, {
@@ -81,10 +71,8 @@ async function createProject() {
81
71
  });
82
72
  const partOfMonorepo = inWorkspace || createAsMonorepo;
83
73
  const packageDirectory = createAsMonorepo ? path__namespace.join(directory, `packages/${packageManager.toValidPackageName(name.split('/').pop())}`) : directory;
84
-
85
74
  if (fs__namespace.existsSync(directory)) {
86
75
  await packageManager.emptyDirectory(directory);
87
-
88
76
  if (packageDirectory !== directory) {
89
77
  fs__namespace.mkdirSync(packageDirectory, {
90
78
  recursive: true
@@ -95,27 +83,28 @@ async function createProject() {
95
83
  recursive: true
96
84
  });
97
85
  }
98
-
99
86
  const rootDirectory = inWorkspace ? process.cwd() : directory;
100
87
  const outputRoot = packageManager.createOutputTarget(rootDirectory);
101
88
  const packageTemplate = packageManager.loadTemplate('package');
102
89
  const workspaceTemplate = packageManager.loadTemplate('workspace');
103
- let quiltProject = await packageTemplate.read('quilt.project.ts'); // If we aren’t already in a workspace, copy the workspace files over, which
104
- // are needed if we are making a monorepo or not.
90
+ let quiltProject = await packageTemplate.read('quilt.project.ts');
105
91
 
92
+ // If we aren’t already in a workspace, copy the workspace files over, which
93
+ // are needed if we are making a monorepo or not.
106
94
  if (!inWorkspace) {
107
95
  await workspaceTemplate.copy(directory, file => {
108
96
  // When this is a single project, we use the project’s Quilt configuration as the base.
109
- if (file === 'quilt.workspace.ts') return createAsMonorepo; // We need to make some adjustments to the root package.json
97
+ if (file === 'quilt.workspace.ts') return createAsMonorepo;
110
98
 
99
+ // We need to make some adjustments to the root package.json
111
100
  return file !== 'package.json';
112
- }); // If we are creating a monorepo, we need to add the root package.json and
113
- // package manager workspace configuration.
101
+ });
114
102
 
103
+ // If we are creating a monorepo, we need to add the root package.json and
104
+ // package manager workspace configuration.
115
105
  if (createAsMonorepo) {
116
106
  const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
117
107
  workspacePackageJson.name = packageManager.toValidPackageName(name);
118
-
119
108
  if (packageManager$1.type === 'pnpm') {
120
109
  await outputRoot.write('pnpm-workspace.yaml', await packageManager.format(`
121
110
  packages:
@@ -126,7 +115,6 @@ async function createProject() {
126
115
  } else {
127
116
  workspacePackageJson.workspaces = ['packages/*'];
128
117
  }
129
-
130
118
  await outputRoot.write('package.json', await packageManager.format(JSON.stringify(workspacePackageJson), {
131
119
  as: 'json-stringify'
132
120
  }));
@@ -134,21 +122,20 @@ async function createProject() {
134
122
  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))]);
135
123
  workspacePackageJson.eslintConfig = projectPackageJson.eslintConfig;
136
124
  workspacePackageJson.browserslist = projectPackageJson.browserslist;
137
- const newPackageJson = {}; // We want to put the project’s dependencies in the package.json, respecting
138
- // the preferred ordering (dependencies, peer dependencies, dev dependencies).
125
+ const newPackageJson = {};
139
126
 
127
+ // We want to put the project’s dependencies in the package.json, respecting
128
+ // the preferred ordering (dependencies, peer dependencies, dev dependencies).
140
129
  for (const [key, value] of Object.entries(projectPackageJson)) {
141
130
  if (key !== 'devDependencies') {
142
131
  newPackageJson[key] = value;
143
132
  continue;
144
133
  }
145
-
146
134
  newPackageJson.dependencies = projectPackageJson.dependencies;
147
135
  newPackageJson.peerDependencies = projectPackageJson.peerDependencies;
148
136
  newPackageJson.peerDependenciesMeta = projectPackageJson.peerDependenciesMeta;
149
137
  newPackageJson.devDependencies = packageManager.mergeDependencies(workspacePackageJson.devDependencies, projectPackageJson.devDependencies);
150
138
  }
151
-
152
139
  adjustPackageJson(newPackageJson, {
153
140
  name: packageManager.toValidPackageName(name),
154
141
  react: useReact,
@@ -166,26 +153,22 @@ async function createProject() {
166
153
  as: 'json'
167
154
  }));
168
155
  }
169
-
170
156
  if (setupExtras.has('github')) {
171
157
  await packageManager.loadTemplate('github').copy(directory);
172
158
  }
173
-
174
159
  if (setupExtras.has('vscode')) {
175
160
  await packageManager.loadTemplate('vscode').copy(directory);
176
161
  }
177
162
  }
178
-
179
163
  await packageTemplate.copy(packageDirectory, file => {
180
164
  // If we are in a monorepo, we can use all the template files as they are
181
165
  if (file === 'tsconfig.json') {
182
166
  return partOfMonorepo;
183
- } // We need to make some adjustments the project’s package.json and Quilt config
184
-
167
+ }
185
168
 
169
+ // We need to make some adjustments the project’s package.json and Quilt config
186
170
  return file !== 'package.json' && file !== 'quilt.project.ts';
187
171
  });
188
-
189
172
  if (partOfMonorepo) {
190
173
  // Write the package’s package.json (the root one was already created)
191
174
  const projectPackageJson = JSON.parse(await packageTemplate.read('package.json'));
@@ -202,64 +185,59 @@ async function createProject() {
202
185
  await outputRoot.write(path__namespace.join(packageDirectory, 'quilt.project.ts'), quiltProject);
203
186
  await Promise.all([packageManager.addToTsConfig(packageDirectory, outputRoot), packageManager.addToPackageManagerWorkspaces(packageDirectory, outputRoot, packageManager$1.type)]);
204
187
  }
205
-
206
188
  if (shouldInstall) {
207
- process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
208
-
189
+ process.stdout.write('\nInstalling dependencies...\n');
190
+ // TODO: better loading, handle errors
209
191
  await packageManager$1.install();
210
192
  process.stdout.moveCursor(0, -1);
211
193
  process.stdout.clearLine(1);
212
194
  console.log('Installed dependencies.');
213
195
  }
214
-
215
- const packageJsonInstructions = index.stripIndent(_t2 || (_t2 = _`
196
+ const packageJsonInstructions = index.stripIndent`
216
197
  Your new package is ready to go! However, before you go too much further,
217
- you should update the following fields in ${0}:
198
+ you should update the following fields in ${index.cyan_1(packageManager.relativeDirectoryForDisplay(path__namespace.relative(process.cwd(), path__namespace.join(packageDirectory, 'package.json'))))}:
218
199
 
219
- - ${0}, where you provide a description of what your package does
220
- - ${0}, where you should include the ${0} of your project’s repo
200
+ - ${index.bold_1(`"description"`)}, where you provide a description of what your package does
201
+ - ${index.bold_1(`"repository"`)}, where you should include the ${index.bold_1(`"url"`)} of your project’s repo
221
202
 
222
- Before you publish your package, you will also want to update the ${0}
203
+ Before you publish your package, you will also want to update the ${index.bold_1(`"version"`)}
223
204
  field in the package.json file.
224
- `), index.cyan_1(packageManager.relativeDirectoryForDisplay(path__namespace.relative(process.cwd(), path__namespace.join(packageDirectory, 'package.json')))), index.bold_1(`"description"`), index.bold_1(`"repository"`), index.bold_1(`"url"`), index.bold_1(`"version"`));
205
+ `;
225
206
  console.log();
226
207
  console.log(packageJsonInstructions);
227
208
  const commands = [];
228
-
229
209
  if (!inWorkspace && directory !== process.cwd()) {
230
210
  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
211
  }
232
-
233
212
  if (!shouldInstall) {
234
213
  commands.push(`${packageManager$1.commands.install()} ${index.dim_1('# Install all your dependencies')}`);
235
214
  }
236
-
237
215
  if (!inWorkspace) {
238
216
  // TODO: change this condition to check if git was initialized already
239
217
  commands.push(`git init && git add -A && git commit -m "Initial commit" ${index.dim_1('# Start your git history (optional)')}`);
240
218
  }
241
-
242
219
  if (commands.length > 0) {
243
- const whatsNext = index.stripIndent(_t3 || (_t3 = _`
244
- After you update your package.json, there’s ${0} you’ll need to take
220
+ const whatsNext = index.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
245
222
  in order to start building:
246
- `), commands.length > 1 ? 'a few more steps' : 'one more step');
223
+ `;
247
224
  console.log();
248
225
  console.log(whatsNext);
249
226
  console.log();
250
227
  console.log(commands.map(command => ` ${command}`).join('\n'));
251
228
  }
252
-
253
- const followUp = index.stripIndent(_t4 || (_t4 = _`
229
+ const followUp = index.stripIndent`
254
230
  Quilt can help you build, test, lint, and type-check your new package. You
255
231
  can learn more about building packages with Quilt by reading the documentation:
256
- ${0}
232
+ ${index.underline_1(index.magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation'))}
257
233
 
258
234
  Have fun! 🎉
259
- `), index.underline_1(index.magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation')));
235
+ `;
260
236
  console.log();
261
237
  console.log(followUp);
262
- } // Argument handling
238
+ }
239
+
240
+ // Argument handling
263
241
 
264
242
  function getArguments() {
265
243
  const args = index.parseArguments({
@@ -286,12 +264,10 @@ function getArguments() {
286
264
  });
287
265
  return args;
288
266
  }
289
-
290
267
  async function getName(args) {
291
268
  let {
292
269
  '--name': name
293
270
  } = args;
294
-
295
271
  if (name == null) {
296
272
  name = await index.prompt({
297
273
  type: 'text',
@@ -299,16 +275,13 @@ async function getName(args) {
299
275
  initial: '@my-team/package'
300
276
  });
301
277
  }
302
-
303
278
  return name;
304
279
  }
305
-
306
280
  async function getDirectory(args, {
307
281
  name,
308
282
  inWorkspace
309
283
  }) {
310
284
  let directory = args['--directory'] ? path__namespace.resolve(args['--directory']) : undefined;
311
-
312
285
  if (directory == null) {
313
286
  const basePackageName = packageManager.toValidPackageName(name.split('/').pop());
314
287
  const defaultDirectory = inWorkspace ? `packages/${basePackageName}` : basePackageName;
@@ -318,7 +291,6 @@ async function getDirectory(args, {
318
291
  initial: defaultDirectory
319
292
  }));
320
293
  }
321
-
322
294
  while (!args['--yes']) {
323
295
  if (fs__namespace.existsSync(directory) && !(await packageManager.isEmpty(directory))) {
324
296
  const relativeDirectory = path__namespace.relative(process.cwd(), directory);
@@ -337,13 +309,10 @@ async function getDirectory(args, {
337
309
  break;
338
310
  }
339
311
  }
340
-
341
312
  return directory;
342
313
  }
343
-
344
314
  async function getPublic(args) {
345
315
  let isPublic;
346
-
347
316
  if (args['--public'] || args['--yes']) {
348
317
  isPublic = true;
349
318
  } else if (args['--private']) {
@@ -355,13 +324,10 @@ async function getPublic(args) {
355
324
  initial: true
356
325
  });
357
326
  }
358
-
359
327
  return isPublic;
360
328
  }
361
-
362
329
  async function getReact(args) {
363
330
  let useReact;
364
-
365
331
  if (args['--react'] || args['--yes']) {
366
332
  useReact = true;
367
333
  } else if (args['--no-react']) {
@@ -373,10 +339,8 @@ async function getReact(args) {
373
339
  initial: true
374
340
  });
375
341
  }
376
-
377
342
  return useReact;
378
343
  }
379
-
380
344
  function adjustPackageJson(packageJson, {
381
345
  name,
382
346
  react,
@@ -386,20 +350,17 @@ function adjustPackageJson(packageJson, {
386
350
  packageJson.name = name;
387
351
  const packageParts = name.split('/');
388
352
  const scope = packageParts[0].startsWith('@') ? packageParts[0] : undefined;
389
- const finalRegistry = registry !== null && registry !== void 0 ? registry : 'https://registry.npmjs.org';
390
-
353
+ const finalRegistry = registry ?? 'https://registry.npmjs.org';
391
354
  if (scope) {
392
355
  packageJson.publishConfig[`${scope}/registry`] = finalRegistry;
393
356
  } else if (registry) {
394
357
  packageJson.publishConfig.registry = finalRegistry;
395
358
  }
396
-
397
359
  if (isPublic) {
398
360
  delete packageJson.private;
399
361
  } else {
400
362
  delete packageJson.publishConfig;
401
363
  }
402
-
403
364
  if (!react) {
404
365
  delete packageJson.dependencies['@types/react'];
405
366
  delete packageJson.devDependencies['react'];
@@ -407,7 +368,6 @@ function adjustPackageJson(packageJson, {
407
368
  delete packageJson.peerDependenciesMeta['react'];
408
369
  packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(extend => !extend.includes('react'));
409
370
  }
410
-
411
371
  return packageJson;
412
372
  }
413
373