@quilted/create 0.1.86 → 0.1.88

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 (40) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/build/cjs/module.cjs +47 -79
  3. package/build/cjs/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/dist/prompts.cjs +1 -1
  4. package/build/cjs/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/index.cjs +1 -1
  5. package/build/cjs/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/lib/prompts.cjs +1 -1
  6. package/build/cjs/package.cjs +3 -3
  7. package/build/cjs/shared.cjs +2 -1
  8. package/build/esm/module.mjs +47 -79
  9. package/build/esm/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/dist/prompts.mjs +1 -1
  10. package/build/esm/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/index.mjs +1 -1
  11. package/build/esm/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/lib/prompts.mjs +1 -1
  12. package/build/esm/package.mjs +3 -3
  13. package/build/esnext/module.esnext +47 -79
  14. package/build/esnext/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/dist/prompts.esnext +1 -1
  15. package/build/esnext/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/index.esnext +1 -1
  16. package/build/esnext/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/lib/prompts.esnext +1 -1
  17. package/build/esnext/package.esnext +3 -3
  18. package/build/tsconfig.tsbuildinfo +1 -1
  19. package/build/typescript/module.d.ts.map +1 -1
  20. package/build/typescript/shared.d.ts +1 -1
  21. package/build/typescript/shared.d.ts.map +1 -1
  22. package/package.json +1 -1
  23. package/source/module.ts +83 -128
  24. package/source/package.ts +4 -4
  25. package/source/shared.ts +0 -2
  26. package/templates/module/module.ts +3 -1
  27. package/templates/module/package.json +6 -9
  28. package/templates/module/rollup.config.js +3 -0
  29. package/templates/module/tsconfig.json +1 -1
  30. package/templates/package/package.json +7 -11
  31. package/templates/package/tsconfig.json +1 -1
  32. package/templates/module/quilt.project.ts +0 -5
  33. package/templates/package/quilt.project.ts +0 -5
  34. package/templates/package/source/tests/index.test.ts +0 -8
  35. package/templates/package-simple/README.md +0 -1
  36. package/templates/package-simple/package.json +0 -51
  37. package/templates/package-simple/source/index.ts +0 -3
  38. package/templates/package-simple/tsconfig.json +0 -10
  39. /package/templates/{package-simple → package}/rollup.config.js +0 -0
  40. /package/templates/{package-simple → package}/source/index.test.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @quilted/create
2
2
 
3
+ ## 0.1.88
4
+
5
+ ### Patch Changes
6
+
7
+ - [`78f914d3`](https://github.com/lemonmade/quilt/commit/78f914d36e5a70b76ea9364529e9a00269065fb6) Thanks [@lemonmade](https://github.com/lemonmade)! - Add better module template
8
+
9
+ ## 0.1.87
10
+
11
+ ### Patch Changes
12
+
13
+ - [`5dd69774`](https://github.com/lemonmade/quilt/commit/5dd69774bdeb7ba3a983691d4f0fc5c5a4996a70) Thanks [@lemonmade](https://github.com/lemonmade)! - Remove testing dependency from package template
14
+
15
+ - [`a231e2c2`](https://github.com/lemonmade/quilt/commit/a231e2c27c9ef0d98493c0957ee6ba217a2c8990) Thanks [@lemonmade](https://github.com/lemonmade)! - Remove `require` output for package template
16
+
17
+ - [`c585681e`](https://github.com/lemonmade/quilt/commit/c585681e2c756c8defd0d8a6d4ae818aea639453) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix name for created packages
18
+
3
19
  ## 0.1.86
4
20
 
5
21
  ### Patch Changes
@@ -92,99 +92,67 @@ async function createModule() {
92
92
  const rootDirectory = inWorkspace ? process.cwd() : directory;
93
93
  const outputRoot = shared.createOutputTarget(rootDirectory);
94
94
  const moduleTemplate = shared.loadTemplate('module');
95
- const workspaceTemplate = shared.loadTemplate('workspace');
96
-
97
- // If we aren’t already in a workspace, copy the workspace files over, which
98
- // are needed if we are making a monorepo or not.
99
- if (!inWorkspace) {
95
+ const workspaceTemplate = shared.loadTemplate('workspace-simple');
96
+ if (createAsMonorepo) {
100
97
  await workspaceTemplate.copy(directory, file => {
101
- // When this is a single project, we use the project’s Quilt configuration as the base.
102
- if (file === 'quilt.workspace.ts') return createAsMonorepo;
103
-
104
- // We need to make some adjustments to the root package.json
105
- if (file === 'package.json') return false;
106
- return true;
98
+ // We will adjust the package.json before writing it
99
+ return file !== 'package.json';
107
100
  });
108
-
109
- // If we are creating a monorepo, we need to add the root package.json and
110
- // package manager workspace configuration.
111
- if (createAsMonorepo) {
112
- const moduleRelativeToRoot = shared.relativeDirectoryForDisplay(path__namespace.relative(directory, moduleDirectory));
113
- const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
114
- workspacePackageJson.name = shared.toValidPackageName(name);
115
- workspacePackageJson.workspaces = [moduleRelativeToRoot, './packages/*'];
116
- if (packageManager$1.type === 'pnpm') {
117
- await outputRoot.write('pnpm-workspace.yaml', await shared.format(`
118
- packages:
119
- - '${moduleRelativeToRoot}'
120
- - './packages/*'
121
- `, {
122
- as: 'yaml'
123
- }));
124
- }
125
- await outputRoot.write('package.json', await shared.format(JSON.stringify(workspacePackageJson), {
126
- as: 'json-stringify'
127
- }));
128
- } else {
129
- const [projectPackageJson, projectTSConfig, workspacePackageJson] = await Promise.all([moduleTemplate.read('package.json').then(content => JSON.parse(content)), moduleTemplate.read('tsconfig.json').then(content => JSON.parse(content)), workspaceTemplate.read('package.json').then(content => JSON.parse(content))]);
130
- const combinedPackageJson = shared.mergeWorkspaceAndProjectPackageJsons(projectPackageJson, workspacePackageJson);
131
- adjustPackageJson(combinedPackageJson, {
132
- name,
133
- entry,
134
- react: useReact
135
- });
136
- delete combinedPackageJson.workspaces;
137
- await outputRoot.write('package.json', await shared.format(JSON.stringify(combinedPackageJson), {
138
- as: 'json-stringify'
139
- }));
140
- await outputRoot.write('tsconfig.json', await shared.format(JSON.stringify(projectTSConfig), {
141
- as: 'json'
101
+ const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
102
+ workspacePackageJson.name = shared.toValidPackageName(name);
103
+ const moduleRelativeToRoot = shared.relativeDirectoryForDisplay(path__namespace.relative(directory, moduleDirectory));
104
+ if (packageManager$1.type === 'pnpm') {
105
+ await outputRoot.write('pnpm-workspace.yaml', await shared.format(`
106
+ packages:
107
+ - './packages/*'
108
+ - '${moduleRelativeToRoot}'
109
+ `, {
110
+ as: 'yaml'
142
111
  }));
143
112
  }
144
- if (setupExtras.has('github')) {
145
- await shared.loadTemplate('github').copy(directory);
146
- }
147
- if (setupExtras.has('vscode')) {
148
- await shared.loadTemplate('vscode').copy(directory);
149
- }
113
+ await outputRoot.write('package.json', await shared.format(JSON.stringify(workspacePackageJson), {
114
+ as: 'json-stringify'
115
+ }));
150
116
  }
151
117
  await moduleTemplate.copy(moduleDirectory, file => {
152
- // If we are in a monorepo, we can use all the template files as they are
153
- if (file === 'quilt.project.ts' || file === 'tsconfig.json') {
154
- return partOfMonorepo;
155
- }
156
-
157
- // We will adjust the entry file
158
- if (file === 'module.ts') return false;
159
-
160
- // We need to make some adjustments the project’s package.json and quilt
161
- // config
162
- if (file === 'package.json' || file === 'quilt.project.ts') return false;
163
- return true;
118
+ // We will adjust the package.json before writing them
119
+ return file !== 'package.json';
164
120
  });
165
- let quiltProject = await moduleTemplate.read('quilt.project.ts');
166
- if (!partOfMonorepo) {
167
- quiltProject = quiltProject.replace('quiltModule', 'quiltWorkspace, quiltModule').replace('quiltModule(', 'quiltWorkspace(), quiltModule(');
168
- }
169
- if (!useReact) {
170
- quiltProject = quiltProject.replace('quiltPackage()', 'quiltPackage({react: false})');
171
- }
172
- await outputRoot.write(path__namespace.join(moduleDirectory, 'quilt.project.ts'), await shared.format(quiltProject, {
173
- as: 'typescript'
174
- }));
175
- await outputRoot.write(path__namespace.join(moduleDirectory, entry), await moduleTemplate.read('module.ts'));
176
121
  if (partOfMonorepo) {
177
- // Write the app’s package.json (the root one was already created)
122
+ // Add the package to the workspace configuration files
123
+ await Promise.all([tsconfig.addToTsConfig(moduleDirectory, outputRoot), packageManager.addToPackageManagerWorkspaces(moduleDirectory, outputRoot, packageManager$1.type)]);
124
+
125
+ // Write the package’s package.json (the root one was already created)
178
126
  const projectPackageJson = JSON.parse(await moduleTemplate.read('package.json'));
179
127
  adjustPackageJson(projectPackageJson, {
180
- name,
181
- entry,
182
- react: useReact
128
+ name: shared.toValidPackageName(name),
129
+ react: useReact,
130
+ entry
183
131
  });
184
132
  await outputRoot.write(path__namespace.join(moduleDirectory, 'package.json'), await shared.format(JSON.stringify(projectPackageJson), {
185
133
  as: 'json-stringify'
186
134
  }));
187
- await Promise.all([tsconfig.addToTsConfig(moduleDirectory, outputRoot), packageManager.addToPackageManagerWorkspaces(moduleDirectory, outputRoot, packageManager$1.type)]);
135
+ } else {
136
+ // Write the package’s package.json by combining elements of the root and
137
+ // package templates
138
+ const [projectPackageJson, workspacePackageJson] = await Promise.all([moduleTemplate.read('package.json').then(content => JSON.parse(content)), workspaceTemplate.read('package.json').then(content => JSON.parse(content))]);
139
+ const mergedPackageJson = shared.mergeWorkspaceAndProjectPackageJsons(projectPackageJson, workspacePackageJson);
140
+ adjustPackageJson(mergedPackageJson, {
141
+ name: shared.toValidPackageName(name),
142
+ react: useReact,
143
+ entry
144
+ });
145
+ await outputRoot.write('package.json', await shared.format(JSON.stringify(mergedPackageJson), {
146
+ as: 'json-stringify'
147
+ }));
148
+ }
149
+ if (!inWorkspace) {
150
+ if (setupExtras.has('github')) {
151
+ await shared.loadTemplate('github').copy(directory);
152
+ }
153
+ if (setupExtras.has('vscode')) {
154
+ await shared.loadTemplate('vscode').copy(directory);
155
+ }
188
156
  }
189
157
  if (shouldInstall) {
190
158
  console.log();
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var prompts = require('../../../../../../_virtual/prompts.cjs');
3
+ var prompts = require('../../../../../../_virtual/prompts2.cjs');
4
4
  var index = require('./elements/index.cjs');
5
5
 
6
6
  var hasRequiredPrompts;
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _commonjsHelpers = require('../../../../../_virtual/_commonjsHelpers.cjs');
6
- var index = require('./dist/index.cjs');
7
6
  var index$1 = require('./lib/index.cjs');
7
+ var index = require('./dist/index.cjs');
8
8
 
9
9
  function isNodeLT(tar) {
10
10
  tar = (Array.isArray(tar) ? tar : tar.split('.')).map(Number);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var prompts = require('../../../../../../_virtual/prompts2.cjs');
3
+ var prompts = require('../../../../../../_virtual/prompts.cjs');
4
4
  var index = require('./elements/index.cjs');
5
5
 
6
6
  var hasRequiredPrompts;
@@ -116,7 +116,7 @@ async function createProject() {
116
116
  }
117
117
  const rootDirectory = inWorkspace ? process.cwd() : directory;
118
118
  const outputRoot = shared.createOutputTarget(rootDirectory);
119
- const packageTemplate = shared.loadTemplate('package-simple');
119
+ const packageTemplate = shared.loadTemplate('package');
120
120
  const workspaceTemplate = shared.loadTemplate('workspace-simple');
121
121
  if (createAsMonorepo) {
122
122
  await workspaceTemplate.copy(directory, file => {
@@ -302,8 +302,8 @@ async function getName(args) {
302
302
  _,
303
303
  '--name': nameArgument
304
304
  } = args;
305
- let name = nameArgument ?? _[0];
306
- if (name == null) {
305
+ let name = nameArgument ?? _[1];
306
+ if (name == null || name.startsWith('--')) {
307
307
  name = await prompt.prompt({
308
308
  type: 'text',
309
309
  message: 'What would you like to name your new package?',
@@ -4,6 +4,7 @@ var fs = require('node:fs');
4
4
  var path = require('node:path');
5
5
  var node_url = require('node:url');
6
6
 
7
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
7
8
  function _interopNamespaceDefault(e) {
8
9
  var n = Object.create(null);
9
10
  if (e) {
@@ -80,7 +81,7 @@ async function getPackageRoot() {
80
81
  packageDirectory
81
82
  } = await Promise.resolve().then(function () { return require('./node_modules/.pnpm/pkg-dir@6.0.1/node_modules/pkg-dir/index.cjs'); });
82
83
  return packageDirectory({
83
- cwd: path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('shared.cjs', document.baseURI).href))))
84
+ cwd: path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('shared.cjs', document.baseURI).href))))
84
85
  });
85
86
  })();
86
87
  }
@@ -70,99 +70,67 @@ async function createModule() {
70
70
  const rootDirectory = inWorkspace ? process.cwd() : directory;
71
71
  const outputRoot = createOutputTarget(rootDirectory);
72
72
  const moduleTemplate = loadTemplate('module');
73
- const workspaceTemplate = loadTemplate('workspace');
74
-
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
- if (!inWorkspace) {
73
+ const workspaceTemplate = loadTemplate('workspace-simple');
74
+ if (createAsMonorepo) {
78
75
  await workspaceTemplate.copy(directory, file => {
79
- // When this is a single project, we use the project’s Quilt configuration as the base.
80
- if (file === 'quilt.workspace.ts') return createAsMonorepo;
81
-
82
- // We need to make some adjustments to the root package.json
83
- if (file === 'package.json') return false;
84
- return true;
76
+ // We will adjust the package.json before writing it
77
+ return file !== 'package.json';
85
78
  });
86
-
87
- // If we are creating a monorepo, we need to add the root package.json and
88
- // package manager workspace configuration.
89
- if (createAsMonorepo) {
90
- const moduleRelativeToRoot = relativeDirectoryForDisplay(path.relative(directory, moduleDirectory));
91
- const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
92
- workspacePackageJson.name = toValidPackageName(name);
93
- workspacePackageJson.workspaces = [moduleRelativeToRoot, './packages/*'];
94
- if (packageManager.type === 'pnpm') {
95
- await outputRoot.write('pnpm-workspace.yaml', await format(`
96
- packages:
97
- - '${moduleRelativeToRoot}'
98
- - './packages/*'
99
- `, {
100
- as: 'yaml'
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([moduleTemplate.read('package.json').then(content => JSON.parse(content)), moduleTemplate.read('tsconfig.json').then(content => JSON.parse(content)), workspaceTemplate.read('package.json').then(content => JSON.parse(content))]);
108
- const combinedPackageJson = mergeWorkspaceAndProjectPackageJsons(projectPackageJson, workspacePackageJson);
109
- adjustPackageJson(combinedPackageJson, {
110
- name,
111
- entry,
112
- react: useReact
113
- });
114
- delete combinedPackageJson.workspaces;
115
- await outputRoot.write('package.json', await format(JSON.stringify(combinedPackageJson), {
116
- as: 'json-stringify'
117
- }));
118
- await outputRoot.write('tsconfig.json', await format(JSON.stringify(projectTSConfig), {
119
- as: 'json'
79
+ const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
80
+ workspacePackageJson.name = toValidPackageName(name);
81
+ const moduleRelativeToRoot = relativeDirectoryForDisplay(path.relative(directory, moduleDirectory));
82
+ if (packageManager.type === 'pnpm') {
83
+ await outputRoot.write('pnpm-workspace.yaml', await format(`
84
+ packages:
85
+ - './packages/*'
86
+ - '${moduleRelativeToRoot}'
87
+ `, {
88
+ as: 'yaml'
120
89
  }));
121
90
  }
122
- if (setupExtras.has('github')) {
123
- await loadTemplate('github').copy(directory);
124
- }
125
- if (setupExtras.has('vscode')) {
126
- await loadTemplate('vscode').copy(directory);
127
- }
91
+ await outputRoot.write('package.json', await format(JSON.stringify(workspacePackageJson), {
92
+ as: 'json-stringify'
93
+ }));
128
94
  }
129
95
  await moduleTemplate.copy(moduleDirectory, file => {
130
- // If we are in a monorepo, we can use all the template files as they are
131
- if (file === 'quilt.project.ts' || file === 'tsconfig.json') {
132
- return partOfMonorepo;
133
- }
134
-
135
- // We will adjust the entry file
136
- if (file === 'module.ts') return false;
137
-
138
- // We need to make some adjustments the project’s package.json and quilt
139
- // config
140
- if (file === 'package.json' || file === 'quilt.project.ts') return false;
141
- return true;
96
+ // We will adjust the package.json before writing them
97
+ return file !== 'package.json';
142
98
  });
143
- let quiltProject = await moduleTemplate.read('quilt.project.ts');
144
- if (!partOfMonorepo) {
145
- quiltProject = quiltProject.replace('quiltModule', 'quiltWorkspace, quiltModule').replace('quiltModule(', 'quiltWorkspace(), quiltModule(');
146
- }
147
- if (!useReact) {
148
- quiltProject = quiltProject.replace('quiltPackage()', 'quiltPackage({react: false})');
149
- }
150
- await outputRoot.write(path.join(moduleDirectory, 'quilt.project.ts'), await format(quiltProject, {
151
- as: 'typescript'
152
- }));
153
- await outputRoot.write(path.join(moduleDirectory, entry), await moduleTemplate.read('module.ts'));
154
99
  if (partOfMonorepo) {
155
- // Write the app’s package.json (the root one was already created)
100
+ // Add the package to the workspace configuration files
101
+ await Promise.all([addToTsConfig(moduleDirectory, outputRoot), addToPackageManagerWorkspaces(moduleDirectory, outputRoot, packageManager.type)]);
102
+
103
+ // Write the package’s package.json (the root one was already created)
156
104
  const projectPackageJson = JSON.parse(await moduleTemplate.read('package.json'));
157
105
  adjustPackageJson(projectPackageJson, {
158
- name,
159
- entry,
160
- react: useReact
106
+ name: toValidPackageName(name),
107
+ react: useReact,
108
+ entry
161
109
  });
162
110
  await outputRoot.write(path.join(moduleDirectory, 'package.json'), await format(JSON.stringify(projectPackageJson), {
163
111
  as: 'json-stringify'
164
112
  }));
165
- await Promise.all([addToTsConfig(moduleDirectory, outputRoot), addToPackageManagerWorkspaces(moduleDirectory, outputRoot, packageManager.type)]);
113
+ } else {
114
+ // Write the package’s package.json by combining elements of the root and
115
+ // package templates
116
+ const [projectPackageJson, workspacePackageJson] = await Promise.all([moduleTemplate.read('package.json').then(content => JSON.parse(content)), workspaceTemplate.read('package.json').then(content => JSON.parse(content))]);
117
+ const mergedPackageJson = mergeWorkspaceAndProjectPackageJsons(projectPackageJson, workspacePackageJson);
118
+ adjustPackageJson(mergedPackageJson, {
119
+ name: toValidPackageName(name),
120
+ react: useReact,
121
+ entry
122
+ });
123
+ await outputRoot.write('package.json', await format(JSON.stringify(mergedPackageJson), {
124
+ as: 'json-stringify'
125
+ }));
126
+ }
127
+ if (!inWorkspace) {
128
+ if (setupExtras.has('github')) {
129
+ await loadTemplate('github').copy(directory);
130
+ }
131
+ if (setupExtras.has('vscode')) {
132
+ await loadTemplate('vscode').copy(directory);
133
+ }
166
134
  }
167
135
  if (shouldInstall) {
168
136
  console.log();
@@ -1,4 +1,4 @@
1
- import { __exports as prompts } from '../../../../../../_virtual/prompts.mjs';
1
+ import { __exports as prompts } from '../../../../../../_virtual/prompts2.mjs';
2
2
  import { __require as requireElements } from './elements/index.mjs';
3
3
 
4
4
  var hasRequiredPrompts;
@@ -1,6 +1,6 @@
1
1
  import { getDefaultExportFromCjs } from '../../../../../_virtual/_commonjsHelpers.mjs';
2
- import { __require as requireDist } from './dist/index.mjs';
3
2
  import { __require as requireLib } from './lib/index.mjs';
3
+ import { __require as requireDist } from './dist/index.mjs';
4
4
 
5
5
  function isNodeLT(tar) {
6
6
  tar = (Array.isArray(tar) ? tar : tar.split('.')).map(Number);
@@ -1,4 +1,4 @@
1
- import { __exports as prompts } from '../../../../../../_virtual/prompts2.mjs';
1
+ import { __exports as prompts } from '../../../../../../_virtual/prompts.mjs';
2
2
  import { __require as requireElements } from './elements/index.mjs';
3
3
 
4
4
  var hasRequiredPrompts;
@@ -94,7 +94,7 @@ async function createProject() {
94
94
  }
95
95
  const rootDirectory = inWorkspace ? process.cwd() : directory;
96
96
  const outputRoot = createOutputTarget(rootDirectory);
97
- const packageTemplate = loadTemplate('package-simple');
97
+ const packageTemplate = loadTemplate('package');
98
98
  const workspaceTemplate = loadTemplate('workspace-simple');
99
99
  if (createAsMonorepo) {
100
100
  await workspaceTemplate.copy(directory, file => {
@@ -280,8 +280,8 @@ async function getName(args) {
280
280
  _,
281
281
  '--name': nameArgument
282
282
  } = args;
283
- let name = nameArgument ?? _[0];
284
- if (name == null) {
283
+ let name = nameArgument ?? _[1];
284
+ if (name == null || name.startsWith('--')) {
285
285
  name = await prompt({
286
286
  type: 'text',
287
287
  message: 'What would you like to name your new package?',
@@ -70,99 +70,67 @@ async function createModule() {
70
70
  const rootDirectory = inWorkspace ? process.cwd() : directory;
71
71
  const outputRoot = createOutputTarget(rootDirectory);
72
72
  const moduleTemplate = loadTemplate('module');
73
- const workspaceTemplate = loadTemplate('workspace');
74
-
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
- if (!inWorkspace) {
73
+ const workspaceTemplate = loadTemplate('workspace-simple');
74
+ if (createAsMonorepo) {
78
75
  await workspaceTemplate.copy(directory, file => {
79
- // When this is a single project, we use the project’s Quilt configuration as the base.
80
- if (file === 'quilt.workspace.ts') return createAsMonorepo;
81
-
82
- // We need to make some adjustments to the root package.json
83
- if (file === 'package.json') return false;
84
- return true;
76
+ // We will adjust the package.json before writing it
77
+ return file !== 'package.json';
85
78
  });
86
-
87
- // If we are creating a monorepo, we need to add the root package.json and
88
- // package manager workspace configuration.
89
- if (createAsMonorepo) {
90
- const moduleRelativeToRoot = relativeDirectoryForDisplay(path.relative(directory, moduleDirectory));
91
- const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
92
- workspacePackageJson.name = toValidPackageName(name);
93
- workspacePackageJson.workspaces = [moduleRelativeToRoot, './packages/*'];
94
- if (packageManager.type === 'pnpm') {
95
- await outputRoot.write('pnpm-workspace.yaml', await format(`
96
- packages:
97
- - '${moduleRelativeToRoot}'
98
- - './packages/*'
99
- `, {
100
- as: 'yaml'
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([moduleTemplate.read('package.json').then(content => JSON.parse(content)), moduleTemplate.read('tsconfig.json').then(content => JSON.parse(content)), workspaceTemplate.read('package.json').then(content => JSON.parse(content))]);
108
- const combinedPackageJson = mergeWorkspaceAndProjectPackageJsons(projectPackageJson, workspacePackageJson);
109
- adjustPackageJson(combinedPackageJson, {
110
- name,
111
- entry,
112
- react: useReact
113
- });
114
- delete combinedPackageJson.workspaces;
115
- await outputRoot.write('package.json', await format(JSON.stringify(combinedPackageJson), {
116
- as: 'json-stringify'
117
- }));
118
- await outputRoot.write('tsconfig.json', await format(JSON.stringify(projectTSConfig), {
119
- as: 'json'
79
+ const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
80
+ workspacePackageJson.name = toValidPackageName(name);
81
+ const moduleRelativeToRoot = relativeDirectoryForDisplay(path.relative(directory, moduleDirectory));
82
+ if (packageManager.type === 'pnpm') {
83
+ await outputRoot.write('pnpm-workspace.yaml', await format(`
84
+ packages:
85
+ - './packages/*'
86
+ - '${moduleRelativeToRoot}'
87
+ `, {
88
+ as: 'yaml'
120
89
  }));
121
90
  }
122
- if (setupExtras.has('github')) {
123
- await loadTemplate('github').copy(directory);
124
- }
125
- if (setupExtras.has('vscode')) {
126
- await loadTemplate('vscode').copy(directory);
127
- }
91
+ await outputRoot.write('package.json', await format(JSON.stringify(workspacePackageJson), {
92
+ as: 'json-stringify'
93
+ }));
128
94
  }
129
95
  await moduleTemplate.copy(moduleDirectory, file => {
130
- // If we are in a monorepo, we can use all the template files as they are
131
- if (file === 'quilt.project.ts' || file === 'tsconfig.json') {
132
- return partOfMonorepo;
133
- }
134
-
135
- // We will adjust the entry file
136
- if (file === 'module.ts') return false;
137
-
138
- // We need to make some adjustments the project’s package.json and quilt
139
- // config
140
- if (file === 'package.json' || file === 'quilt.project.ts') return false;
141
- return true;
96
+ // We will adjust the package.json before writing them
97
+ return file !== 'package.json';
142
98
  });
143
- let quiltProject = await moduleTemplate.read('quilt.project.ts');
144
- if (!partOfMonorepo) {
145
- quiltProject = quiltProject.replace('quiltModule', 'quiltWorkspace, quiltModule').replace('quiltModule(', 'quiltWorkspace(), quiltModule(');
146
- }
147
- if (!useReact) {
148
- quiltProject = quiltProject.replace('quiltPackage()', 'quiltPackage({react: false})');
149
- }
150
- await outputRoot.write(path.join(moduleDirectory, 'quilt.project.ts'), await format(quiltProject, {
151
- as: 'typescript'
152
- }));
153
- await outputRoot.write(path.join(moduleDirectory, entry), await moduleTemplate.read('module.ts'));
154
99
  if (partOfMonorepo) {
155
- // Write the app’s package.json (the root one was already created)
100
+ // Add the package to the workspace configuration files
101
+ await Promise.all([addToTsConfig(moduleDirectory, outputRoot), addToPackageManagerWorkspaces(moduleDirectory, outputRoot, packageManager.type)]);
102
+
103
+ // Write the package’s package.json (the root one was already created)
156
104
  const projectPackageJson = JSON.parse(await moduleTemplate.read('package.json'));
157
105
  adjustPackageJson(projectPackageJson, {
158
- name,
159
- entry,
160
- react: useReact
106
+ name: toValidPackageName(name),
107
+ react: useReact,
108
+ entry
161
109
  });
162
110
  await outputRoot.write(path.join(moduleDirectory, 'package.json'), await format(JSON.stringify(projectPackageJson), {
163
111
  as: 'json-stringify'
164
112
  }));
165
- await Promise.all([addToTsConfig(moduleDirectory, outputRoot), addToPackageManagerWorkspaces(moduleDirectory, outputRoot, packageManager.type)]);
113
+ } else {
114
+ // Write the package’s package.json by combining elements of the root and
115
+ // package templates
116
+ const [projectPackageJson, workspacePackageJson] = await Promise.all([moduleTemplate.read('package.json').then(content => JSON.parse(content)), workspaceTemplate.read('package.json').then(content => JSON.parse(content))]);
117
+ const mergedPackageJson = mergeWorkspaceAndProjectPackageJsons(projectPackageJson, workspacePackageJson);
118
+ adjustPackageJson(mergedPackageJson, {
119
+ name: toValidPackageName(name),
120
+ react: useReact,
121
+ entry
122
+ });
123
+ await outputRoot.write('package.json', await format(JSON.stringify(mergedPackageJson), {
124
+ as: 'json-stringify'
125
+ }));
126
+ }
127
+ if (!inWorkspace) {
128
+ if (setupExtras.has('github')) {
129
+ await loadTemplate('github').copy(directory);
130
+ }
131
+ if (setupExtras.has('vscode')) {
132
+ await loadTemplate('vscode').copy(directory);
133
+ }
166
134
  }
167
135
  if (shouldInstall) {
168
136
  console.log();
@@ -1,4 +1,4 @@
1
- import { __exports as prompts } from '../../../../../../_virtual/prompts.esnext';
1
+ import { __exports as prompts } from '../../../../../../_virtual/prompts2.esnext';
2
2
  import { __require as requireElements } from './elements/index.esnext';
3
3
 
4
4
  var hasRequiredPrompts;
@@ -1,6 +1,6 @@
1
1
  import { getDefaultExportFromCjs } from '../../../../../_virtual/_commonjsHelpers.esnext';
2
- import { __require as requireDist } from './dist/index.esnext';
3
2
  import { __require as requireLib } from './lib/index.esnext';
3
+ import { __require as requireDist } from './dist/index.esnext';
4
4
 
5
5
  function isNodeLT(tar) {
6
6
  tar = (Array.isArray(tar) ? tar : tar.split('.')).map(Number);
@@ -1,4 +1,4 @@
1
- import { __exports as prompts } from '../../../../../../_virtual/prompts2.esnext';
1
+ import { __exports as prompts } from '../../../../../../_virtual/prompts.esnext';
2
2
  import { __require as requireElements } from './elements/index.esnext';
3
3
 
4
4
  var hasRequiredPrompts;
@@ -94,7 +94,7 @@ async function createProject() {
94
94
  }
95
95
  const rootDirectory = inWorkspace ? process.cwd() : directory;
96
96
  const outputRoot = createOutputTarget(rootDirectory);
97
- const packageTemplate = loadTemplate('package-simple');
97
+ const packageTemplate = loadTemplate('package');
98
98
  const workspaceTemplate = loadTemplate('workspace-simple');
99
99
  if (createAsMonorepo) {
100
100
  await workspaceTemplate.copy(directory, file => {
@@ -280,8 +280,8 @@ async function getName(args) {
280
280
  _,
281
281
  '--name': nameArgument
282
282
  } = args;
283
- let name = nameArgument ?? _[0];
284
- if (name == null) {
283
+ let name = nameArgument ?? _[1];
284
+ if (name == null || name.startsWith('--')) {
285
285
  name = await prompt({
286
286
  type: 'text',
287
287
  message: 'What would you like to name your new package?',