@quilted/create 0.1.87 → 0.1.89

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 +12 -0
  2. package/build/cjs/module.cjs +65 -100
  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 +1 -1
  7. package/build/cjs/shared.cjs +2 -1
  8. package/build/esm/module.mjs +65 -100
  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 +1 -1
  13. package/build/esnext/module.esnext +65 -100
  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 +1 -1
  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 +99 -151
  24. package/source/package.ts +1 -1
  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 -49
  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/source/module.ts CHANGED
@@ -33,9 +33,19 @@ export async function createModule() {
33
33
  const argv = getArgv();
34
34
 
35
35
  if (argv['--help']) {
36
+ const additionalOptions = stripIndent`
37
+ ${color.cyan(`--entry [entry]`)}
38
+ The entry file for your module. This should be a relative path from the root
39
+ of the project, and should include the file extension.
40
+
41
+ ${color.cyan(`--react`)}
42
+ Whether this package will use React. Defaults to false.
43
+ `;
44
+
36
45
  printHelp({
37
46
  kind: 'module',
38
47
  packageManager: argv['--package-manager']?.toLowerCase(),
48
+ options: additionalOptions,
39
49
  });
40
50
  return;
41
51
  }
@@ -76,147 +86,72 @@ export async function createModule() {
76
86
  const rootDirectory = inWorkspace ? process.cwd() : directory;
77
87
  const outputRoot = createOutputTarget(rootDirectory);
78
88
  const moduleTemplate = loadTemplate('module');
79
- const workspaceTemplate = loadTemplate('workspace');
89
+ const workspaceTemplate = loadTemplate('workspace-simple');
80
90
 
81
- // If we aren’t already in a workspace, copy the workspace files over, which
82
- // are needed if we are making a monorepo or not.
83
- if (!inWorkspace) {
91
+ if (createAsMonorepo) {
84
92
  await workspaceTemplate.copy(directory, (file) => {
85
- // When this is a single project, we use the project’s Quilt configuration as the base.
86
- if (file === 'quilt.workspace.ts') return createAsMonorepo;
87
-
88
- // We need to make some adjustments to the root package.json
89
- if (file === 'package.json') return false;
90
-
91
- return true;
93
+ // We will adjust the package.json before writing it
94
+ return file !== 'package.json';
92
95
  });
93
96
 
94
- // If we are creating a monorepo, we need to add the root package.json and
95
- // package manager workspace configuration.
96
- if (createAsMonorepo) {
97
- const moduleRelativeToRoot = relativeDirectoryForDisplay(
98
- path.relative(directory, moduleDirectory),
99
- );
100
-
101
- const workspacePackageJson = JSON.parse(
102
- await workspaceTemplate.read('package.json'),
103
- );
104
-
105
- workspacePackageJson.name = toValidPackageName(name!);
106
- workspacePackageJson.workspaces = [moduleRelativeToRoot, './packages/*'];
107
-
108
- if (packageManager.type === 'pnpm') {
109
- await outputRoot.write(
110
- 'pnpm-workspace.yaml',
111
- await format(
112
- `
113
- packages:
114
- - '${moduleRelativeToRoot}'
115
- - './packages/*'
116
- `,
117
- {as: 'yaml'},
118
- ),
119
- );
120
- }
121
-
122
- await outputRoot.write(
123
- 'package.json',
124
- await format(JSON.stringify(workspacePackageJson), {
125
- as: 'json-stringify',
126
- }),
127
- );
128
- } else {
129
- const [projectPackageJson, projectTSConfig, workspacePackageJson] =
130
- await Promise.all([
131
- moduleTemplate
132
- .read('package.json')
133
- .then((content) => JSON.parse(content)),
134
- moduleTemplate
135
- .read('tsconfig.json')
136
- .then((content) => JSON.parse(content)),
137
- workspaceTemplate
138
- .read('package.json')
139
- .then((content) => JSON.parse(content)),
140
- ]);
141
-
142
- const combinedPackageJson = mergeWorkspaceAndProjectPackageJsons(
143
- projectPackageJson,
144
- workspacePackageJson,
145
- );
97
+ const workspacePackageJson = JSON.parse(
98
+ await workspaceTemplate.read('package.json'),
99
+ );
146
100
 
147
- adjustPackageJson(combinedPackageJson, {name, entry, react: useReact});
148
- delete combinedPackageJson.workspaces;
101
+ workspacePackageJson.name = toValidPackageName(name!);
149
102
 
150
- await outputRoot.write(
151
- 'package.json',
152
- await format(JSON.stringify(combinedPackageJson), {
153
- as: 'json-stringify',
154
- }),
155
- );
103
+ const moduleRelativeToRoot = relativeDirectoryForDisplay(
104
+ path.relative(directory, moduleDirectory),
105
+ );
156
106
 
107
+ if (packageManager.type === 'pnpm') {
157
108
  await outputRoot.write(
158
- 'tsconfig.json',
159
- await format(JSON.stringify(projectTSConfig), {as: 'json'}),
109
+ 'pnpm-workspace.yaml',
110
+ await format(
111
+ `
112
+ packages:
113
+ - './packages/*'
114
+ - '${moduleRelativeToRoot}'
115
+ `,
116
+ {as: 'yaml'},
117
+ ),
160
118
  );
161
119
  }
162
120
 
163
- if (setupExtras.has('github')) {
164
- await loadTemplate('github').copy(directory);
165
- }
166
-
167
- if (setupExtras.has('vscode')) {
168
- await loadTemplate('vscode').copy(directory);
169
- }
121
+ await outputRoot.write(
122
+ 'package.json',
123
+ await format(JSON.stringify(workspacePackageJson), {
124
+ as: 'json-stringify',
125
+ }),
126
+ );
170
127
  }
171
128
 
172
129
  await moduleTemplate.copy(moduleDirectory, (file) => {
173
- // If we are in a monorepo, we can use all the template files as they are
174
- if (file === 'quilt.project.ts' || file === 'tsconfig.json') {
175
- return partOfMonorepo;
176
- }
177
-
178
- // We will adjust the entry file
179
- if (file === 'module.ts') return false;
180
-
181
- // We need to make some adjustments the project’s package.json and quilt
182
- // config
183
- if (file === 'package.json' || file === 'quilt.project.ts') return false;
184
-
185
- return true;
130
+ // We will adjust the package.json before writing them
131
+ return file !== 'package.json';
186
132
  });
187
133
 
188
- let quiltProject = await moduleTemplate.read('quilt.project.ts');
189
-
190
- if (!partOfMonorepo) {
191
- quiltProject = quiltProject
192
- .replace('quiltModule', 'quiltWorkspace, quiltModule')
193
- .replace('quiltModule(', 'quiltWorkspace(), quiltModule(');
194
- }
195
-
196
- if (!useReact) {
197
- quiltProject = quiltProject.replace(
198
- 'quiltPackage()',
199
- 'quiltPackage({react: false})',
200
- );
201
- }
202
-
203
- await outputRoot.write(
204
- path.join(moduleDirectory, 'quilt.project.ts'),
205
- await format(quiltProject, {as: 'typescript'}),
206
- );
207
-
208
- await outputRoot.write(
209
- path.join(moduleDirectory, entry),
210
- await moduleTemplate.read('module.ts'),
211
- );
212
-
213
134
  if (partOfMonorepo) {
214
- // Write the app’s package.json (the root one was already created)
135
+ // Add the package to the workspace configuration files
136
+ await Promise.all([
137
+ addToTsConfig(moduleDirectory, outputRoot),
138
+ addToPackageManagerWorkspaces(
139
+ moduleDirectory,
140
+ outputRoot,
141
+ packageManager.type,
142
+ ),
143
+ ]);
144
+
145
+ // Write the package’s package.json (the root one was already created)
215
146
  const projectPackageJson = JSON.parse(
216
147
  await moduleTemplate.read('package.json'),
217
148
  );
218
149
 
219
- adjustPackageJson(projectPackageJson, {name, entry, react: useReact});
150
+ adjustPackageJson(projectPackageJson, {
151
+ name: toValidPackageName(name),
152
+ react: useReact,
153
+ entry,
154
+ });
220
155
 
221
156
  await outputRoot.write(
222
157
  path.join(moduleDirectory, 'package.json'),
@@ -224,15 +159,45 @@ export async function createModule() {
224
159
  as: 'json-stringify',
225
160
  }),
226
161
  );
227
-
228
- await Promise.all([
229
- addToTsConfig(moduleDirectory, outputRoot),
230
- addToPackageManagerWorkspaces(
231
- moduleDirectory,
232
- outputRoot,
233
- packageManager.type,
234
- ),
162
+ } else {
163
+ // Write the package’s package.json by combining elements of the root and
164
+ // package templates
165
+ const [projectPackageJson, workspacePackageJson] = await Promise.all([
166
+ moduleTemplate
167
+ .read('package.json')
168
+ .then((content) => JSON.parse(content)),
169
+ workspaceTemplate
170
+ .read('package.json')
171
+ .then((content) => JSON.parse(content)),
235
172
  ]);
173
+
174
+ const mergedPackageJson = mergeWorkspaceAndProjectPackageJsons(
175
+ projectPackageJson,
176
+ workspacePackageJson,
177
+ );
178
+
179
+ adjustPackageJson(mergedPackageJson, {
180
+ name: toValidPackageName(name!),
181
+ react: useReact,
182
+ entry,
183
+ });
184
+
185
+ await outputRoot.write(
186
+ 'package.json',
187
+ await format(JSON.stringify(mergedPackageJson), {
188
+ as: 'json-stringify',
189
+ }),
190
+ );
191
+ }
192
+
193
+ if (!inWorkspace) {
194
+ if (setupExtras.has('github')) {
195
+ await loadTemplate('github').copy(directory);
196
+ }
197
+
198
+ if (setupExtras.has('vscode')) {
199
+ await loadTemplate('vscode').copy(directory);
200
+ }
236
201
  }
237
202
 
238
203
  if (shouldInstall) {
@@ -310,7 +275,6 @@ function getArgv() {
310
275
  '--extras': [String],
311
276
  '--no-extras': Boolean,
312
277
  '--react': Boolean,
313
- '--no-react': Boolean,
314
278
  '--help': Boolean,
315
279
  '-h': '--help',
316
280
  },
@@ -320,8 +284,10 @@ function getArgv() {
320
284
  return argv;
321
285
  }
322
286
 
323
- async function getName(argv: Arguments) {
324
- let {'--name': name} = argv;
287
+ async function getName(args: Arguments) {
288
+ const {_, '--name': nameArgument} = args;
289
+
290
+ let name = nameArgument ?? _[1];
325
291
 
326
292
  if (name == null) {
327
293
  name = await prompt({
@@ -388,21 +354,7 @@ async function getDirectory(argv: Arguments, {name}: {name: string}) {
388
354
  }
389
355
 
390
356
  async function getReact(args: Arguments) {
391
- let useReact: boolean;
392
-
393
- if (args['--react'] || args['--yes']) {
394
- useReact = true;
395
- } else if (args['--no-react']) {
396
- useReact = false;
397
- } else {
398
- useReact = await prompt({
399
- type: 'confirm',
400
- message: 'Will this module depend on React?',
401
- initial: false,
402
- });
403
- }
404
-
405
- return useReact;
357
+ return Boolean(args['--react']);
406
358
  }
407
359
 
408
360
  function adjustPackageJson(
@@ -418,7 +370,7 @@ function adjustPackageJson(
418
370
  },
419
371
  ) {
420
372
  packageJson.name = name;
421
- packageJson.main = `./${entry}`;
373
+ packageJson.exports['.'] = `./${entry}`;
422
374
 
423
375
  if (!react) {
424
376
  delete packageJson.devDependencies['@types/react'];
@@ -426,10 +378,6 @@ function adjustPackageJson(
426
378
  delete packageJson.devDependencies['preact'];
427
379
  delete packageJson.devDependencies['react'];
428
380
  delete packageJson.devDependencies['react-dom'];
429
-
430
- packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(
431
- (extend: string) => !extend.includes('react'),
432
- );
433
381
  }
434
382
 
435
383
  return packageJson;
package/source/package.ts CHANGED
@@ -102,7 +102,7 @@ export async function createProject() {
102
102
 
103
103
  const rootDirectory = inWorkspace ? process.cwd() : directory;
104
104
  const outputRoot = createOutputTarget(rootDirectory);
105
- const packageTemplate = loadTemplate('package-simple');
105
+ const packageTemplate = loadTemplate('package');
106
106
  const workspaceTemplate = loadTemplate('workspace-simple');
107
107
 
108
108
  if (createAsMonorepo) {
package/source/shared.ts CHANGED
@@ -7,7 +7,6 @@ export {prompt} from '@quilted/cli-kit';
7
7
  export function loadTemplate(
8
8
  name:
9
9
  | 'package'
10
- | 'package-simple'
11
10
  | 'app-basic'
12
11
  | 'app-empty'
13
12
  | 'app-graphql'
@@ -86,7 +85,6 @@ let packageRootPromise: Promise<string> | undefined;
86
85
  async function templateDirectory(
87
86
  name:
88
87
  | 'package'
89
- | 'package-simple'
90
88
  | 'app-basic'
91
89
  | 'app-empty'
92
90
  | 'app-graphql'
@@ -1,3 +1,5 @@
1
1
  // Replace this module with whatever you want to run in a browser!
2
2
 
3
- export {};
3
+ export function run() {
4
+ return 'Go build something fun!';
5
+ }
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "template-module",
3
3
  "type": "module",
4
- "main": "./module.ts",
4
+ "exports": {
5
+ ".": "./module.ts"
6
+ },
5
7
  "version": "0.0.0",
6
8
  "private": true,
7
9
  "dependencies": {},
@@ -13,12 +15,7 @@
13
15
  "react-dom": "npm:@quilted/react-dom@^18.2.0"
14
16
  },
15
17
  "browserslist": [
16
- "extends @quilted/browserslist-config/modules"
17
- ],
18
- "eslintConfig": {
19
- "extends": [
20
- "@quilted/eslint-config/project",
21
- "@quilted/eslint-config/react"
22
- ]
23
- }
18
+ "defaults",
19
+ "not ie 11"
20
+ ]
24
21
  }
@@ -0,0 +1,3 @@
1
+ import {quiltModule} from '@quilted/rollup';
2
+
3
+ export default quiltModule();
@@ -4,6 +4,6 @@
4
4
  "outDir": "build/typescript"
5
5
  },
6
6
  "include": ["**/*"],
7
- "exclude": ["build", "quilt.project.ts", "**/*.test.ts", "**/*.test.tsx"],
7
+ "exclude": ["build"],
8
8
  "references": []
9
9
  }
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "version": "0.0.0",
11
11
  "engines": {
12
- "node": ">=14.0.0"
12
+ "node": ">=18.0.0"
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
@@ -20,12 +20,14 @@
20
20
  "types": "./build/typescript/index.d.ts",
21
21
  "quilt:source": "./source/index.ts",
22
22
  "quilt:esnext": "./build/esnext/index.esnext",
23
- "import": "./build/esm/index.mjs",
24
- "require": "./build/cjs/index.cjs"
23
+ "import": "./build/esm/index.mjs"
25
24
  }
26
25
  },
27
26
  "types": "./build/typescript/index.d.ts",
28
27
  "sideEffects": false,
28
+ "scripts": {
29
+ "build": "rollup --config rollup.config.js"
30
+ },
29
31
  "dependencies": {
30
32
  "@types/react": "^17.0.0 || ^18.0.0"
31
33
  },
@@ -38,16 +40,10 @@
38
40
  }
39
41
  },
40
42
  "devDependencies": {
41
- "@quilted/testing": "^0.1.0",
42
43
  "react": "npm:@quilted/react@^18.2.0"
43
44
  },
44
- "eslintConfig": {
45
- "extends": [
46
- "@quilted/eslint-config/project",
47
- "@quilted/eslint-config/react"
48
- ]
49
- },
50
45
  "browserslist": [
51
- "extends @quilted/browserslist-config/defaults"
46
+ "defaults and fully supports es6-module",
47
+ "maintained node versions"
52
48
  ]
53
49
  }
@@ -5,6 +5,6 @@
5
5
  "outDir": "build/typescript"
6
6
  },
7
7
  "include": ["source"],
8
- "exclude": ["quilt.project.ts", "**/*.test.ts", "**/*.test.tsx"],
8
+ "exclude": [],
9
9
  "references": []
10
10
  }
@@ -1,5 +0,0 @@
1
- import {createProject, quiltModule} from '@quilted/craft';
2
-
3
- export default createProject((project) => {
4
- project.use(quiltModule());
5
- });
@@ -1,5 +0,0 @@
1
- import {createProject, quiltPackage} from '@quilted/craft';
2
-
3
- export default createProject((project) => {
4
- project.use(quiltPackage());
5
- });
@@ -1,8 +0,0 @@
1
- import {describe, it, expect} from '@quilted/testing';
2
- import {run} from '..';
3
-
4
- describe('package', () => {
5
- it('returns something fun', () => {
6
- expect(run()).toContain('fun');
7
- });
8
- });
@@ -1 +0,0 @@
1
- # `{{name}}`
@@ -1,49 +0,0 @@
1
- {
2
- "name": "template-package-simple",
3
- "description": "<YOUR DESCRIPTION HERE>",
4
- "type": "module",
5
- "license": "MIT",
6
- "private": true,
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "version": "0.0.0",
11
- "engines": {
12
- "node": ">=18.0.0"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/<USER>/<REPOSITORY>"
17
- },
18
- "exports": {
19
- ".": {
20
- "types": "./build/typescript/index.d.ts",
21
- "quilt:source": "./source/index.ts",
22
- "quilt:esnext": "./build/esnext/index.esnext",
23
- "import": "./build/esm/index.mjs"
24
- }
25
- },
26
- "types": "./build/typescript/index.d.ts",
27
- "sideEffects": false,
28
- "scripts": {
29
- "build": "rollup --config rollup.config.js"
30
- },
31
- "dependencies": {
32
- "@types/react": "^17.0.0 || ^18.0.0"
33
- },
34
- "peerDependencies": {
35
- "react": "^17.0.0 || ^18.0.0"
36
- },
37
- "peerDependenciesMeta": {
38
- "react": {
39
- "optional": true
40
- }
41
- },
42
- "devDependencies": {
43
- "react": "npm:@quilted/react@^18.2.0"
44
- },
45
- "browserslist": [
46
- "defaults and fully supports es6-module",
47
- "maintained node versions"
48
- ]
49
- }
@@ -1,3 +0,0 @@
1
- export function run() {
2
- return 'Have fun building!';
3
- }
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "@quilted/typescript/project.json",
3
- "compilerOptions": {
4
- "rootDir": "source",
5
- "outDir": "build/typescript"
6
- },
7
- "include": ["source"],
8
- "exclude": [],
9
- "references": []
10
- }