@quilted/create 0.1.83 → 0.1.85

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 (36) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/build/cjs/app.cjs +7 -1
  3. package/build/cjs/package.cjs +50 -93
  4. package/build/cjs/shared/prompts.cjs +1 -1
  5. package/build/cjs/shared.cjs +5 -0
  6. package/build/esm/app.mjs +7 -1
  7. package/build/esm/package.mjs +51 -94
  8. package/build/esm/shared/prompts.mjs +1 -1
  9. package/build/esm/shared.mjs +5 -0
  10. package/build/esnext/app.esnext +7 -1
  11. package/build/esnext/package.esnext +51 -94
  12. package/build/esnext/shared/prompts.esnext +1 -1
  13. package/build/esnext/shared.esnext +5 -0
  14. package/build/tsconfig.tsbuildinfo +1 -1
  15. package/build/typescript/app.d.ts.map +1 -1
  16. package/build/typescript/package.d.ts.map +1 -1
  17. package/build/typescript/shared.d.ts +2 -1
  18. package/build/typescript/shared.d.ts.map +1 -1
  19. package/package.json +1 -1
  20. package/source/app.ts +13 -1
  21. package/source/package.ts +89 -157
  22. package/source/shared/prompts.ts +1 -1
  23. package/source/shared.ts +10 -0
  24. package/templates/app-graphql/tests/graphql.ts +1 -0
  25. package/templates/github/_github/workflows/ci.yml +4 -4
  26. package/templates/package-simple/README.md +1 -0
  27. package/templates/package-simple/package.json +51 -0
  28. package/templates/package-simple/rollup.config.js +3 -0
  29. package/templates/package-simple/source/index.test.ts +9 -0
  30. package/templates/package-simple/source/index.ts +3 -0
  31. package/templates/package-simple/tsconfig.json +10 -0
  32. package/templates/workspace-simple/_gitignore +13 -0
  33. package/templates/workspace-simple/_nvmrc +1 -0
  34. package/templates/workspace-simple/_prettierignore +8 -0
  35. package/templates/workspace-simple/package.json +26 -0
  36. package/templates/workspace-simple/tsconfig.json +8 -0
package/source/package.ts CHANGED
@@ -31,17 +31,15 @@ export async function createProject() {
31
31
 
32
32
  if (args['--help']) {
33
33
  const additionalOptions = stripIndent`
34
- ${color.cyan(`--description`)}, ${color.cyan(`--no-description`)}
34
+ ${color.cyan(`--description [description]`)}, ${color.cyan(
35
+ `--no-description`,
36
+ )}
35
37
  A short description of the package. If you don’t provide this option, the command will ask
36
38
  you for a description later.
37
39
  ${color.dim(
38
40
  `@see https://docs.npmjs.com/cli/v9/configuring-npm/package-json#description`,
39
41
  )}
40
42
 
41
- ${color.cyan(`--react`)}, ${color.cyan(`--no-react`)}
42
- Whether this package will use React. If you don’t provide this option, the command
43
- will ask you about it later.
44
-
45
43
  ${color.cyan(`--public`)}, ${color.cyan(`--private`)}
46
44
  Whether this package will be published for other projects to install. If you do not
47
45
  provide this option, the command will ask you about it later.
@@ -53,9 +51,12 @@ export async function createProject() {
53
51
  `@see https://docs.npmjs.com/cli/v9/configuring-npm/package-json#repository`,
54
52
  )}
55
53
 
56
- ${color.cyan(`--registry`)}
54
+ ${color.cyan(`--registry [registry]`)}
57
55
  The package registry to publish this package to. This option only applies if you create
58
56
  a public package. If you do not provide this option, it will use the default NPM registry.
57
+
58
+ ${color.cyan(`--react`)}
59
+ Whether this package will use React. Defaults to false.
59
60
  `;
60
61
 
61
62
  printHelp({
@@ -101,143 +102,47 @@ export async function createProject() {
101
102
 
102
103
  const rootDirectory = inWorkspace ? process.cwd() : directory;
103
104
  const outputRoot = createOutputTarget(rootDirectory);
104
- const packageTemplate = loadTemplate('package');
105
- const workspaceTemplate = loadTemplate('workspace');
105
+ const packageTemplate = loadTemplate('package-simple');
106
+ const workspaceTemplate = loadTemplate('workspace-simple');
106
107
 
107
- // If we aren’t already in a workspace, copy the workspace files over, which
108
- // are needed if we are making a monorepo or not.
109
- if (!inWorkspace) {
108
+ if (createAsMonorepo) {
110
109
  await workspaceTemplate.copy(directory, (file) => {
111
- // When this is a single project, we use the project’s Quilt configuration as the base.
112
- if (file === 'quilt.workspace.ts') return createAsMonorepo;
113
-
114
- // We need to make some adjustments to the root package.json
115
- if (file === 'package.json') return false;
116
-
117
- return true;
110
+ // We will adjust the package.json before writing it
111
+ return file !== 'package.json';
118
112
  });
119
113
 
120
- // If we are creating a monorepo, we need to add the root package.json and
121
- // package manager workspace configuration.
122
- if (createAsMonorepo) {
123
- const packageRelativeToRoot = path.relative(
124
- rootDirectory,
125
- packageDirectory,
126
- );
127
- const packageGlobRelativeToRoot = relativeDirectoryForDisplay(
128
- path.join(packageRelativeToRoot, '*'),
129
- );
130
- const workspacePackageJson = JSON.parse(
131
- await workspaceTemplate.read('package.json'),
132
- );
133
-
134
- workspacePackageJson.name = toValidPackageName(name!);
135
- workspacePackageJson.workspaces = [packageGlobRelativeToRoot];
136
-
137
- if (packageManager.type === 'pnpm') {
138
- await outputRoot.write(
139
- 'pnpm-workspace.yaml',
140
- await format(
141
- `
142
- packages:
143
- - '${packageGlobRelativeToRoot}'
144
- `,
145
- {as: 'yaml'},
146
- ),
147
- );
148
- }
149
-
150
- await outputRoot.write(
151
- 'package.json',
152
- await format(JSON.stringify(workspacePackageJson), {
153
- as: 'json-stringify',
154
- }),
155
- );
156
- } else {
157
- const [projectPackageJson, projectTSConfig, workspacePackageJson] =
158
- await Promise.all([
159
- packageTemplate
160
- .read('package.json')
161
- .then((content) => JSON.parse(content)),
162
- packageTemplate
163
- .read('tsconfig.json')
164
- .then((content) => JSON.parse(content)),
165
- workspaceTemplate
166
- .read('package.json')
167
- .then((content) => JSON.parse(content)),
168
- ]);
169
-
170
- const mergedPackageJson = mergeWorkspaceAndProjectPackageJsons(
171
- projectPackageJson,
172
- workspacePackageJson,
173
- );
174
-
175
- delete mergedPackageJson.workspaces;
176
-
177
- adjustPackageJson(mergedPackageJson, {
178
- name: toValidPackageName(name!),
179
- description,
180
- react: useReact,
181
- isPublic,
182
- registry: args['--registry'],
183
- });
114
+ const workspacePackageJson = JSON.parse(
115
+ await workspaceTemplate.read('package.json'),
116
+ );
184
117
 
185
- await outputRoot.write(
186
- 'package.json',
187
- await format(JSON.stringify(mergedPackageJson), {
188
- as: 'json-stringify',
189
- }),
190
- );
118
+ workspacePackageJson.name = toValidPackageName(name!);
191
119
 
120
+ if (packageManager.type === 'pnpm') {
192
121
  await outputRoot.write(
193
- 'tsconfig.json',
194
- await format(JSON.stringify(projectTSConfig), {as: 'json'}),
122
+ 'pnpm-workspace.yaml',
123
+ await format(
124
+ `
125
+ packages:
126
+ - './packages/*'
127
+ `,
128
+ {as: 'yaml'},
129
+ ),
195
130
  );
196
131
  }
197
132
 
198
- if (setupExtras.has('github')) {
199
- await loadTemplate('github').copy(directory);
200
- }
201
-
202
- if (setupExtras.has('vscode')) {
203
- await loadTemplate('vscode').copy(directory);
204
- }
133
+ await outputRoot.write(
134
+ 'package.json',
135
+ await format(JSON.stringify(workspacePackageJson), {
136
+ as: 'json-stringify',
137
+ }),
138
+ );
205
139
  }
206
140
 
207
141
  await packageTemplate.copy(packageDirectory, (file) => {
208
- // If we are in a monorepo, we can use all the template files as they are
209
- if (file === 'tsconfig.json') {
210
- return partOfMonorepo;
211
- }
212
-
213
- // We need to make some adjustments the project’s package.json, README, and Quilt config
214
- return (
215
- file !== 'package.json' &&
216
- file !== 'quilt.project.ts' &&
217
- file !== 'README.md'
218
- );
142
+ // We will adjust the package.json and README.md before writing them
143
+ return file !== 'package.json' && file !== 'README.md';
219
144
  });
220
145
 
221
- let quiltProject = await packageTemplate.read('quilt.project.ts');
222
-
223
- if (!partOfMonorepo) {
224
- quiltProject = quiltProject
225
- .replace('quiltPackage', 'quiltWorkspace, quiltPackage')
226
- .replace('quiltPackage(', 'quiltWorkspace(), quiltPackage(');
227
- }
228
-
229
- if (!useReact) {
230
- quiltProject = quiltProject.replace(
231
- 'quiltPackage()',
232
- 'quiltPackage({react: false})',
233
- );
234
- }
235
-
236
- await outputRoot.write(
237
- path.join(packageDirectory, 'quilt.project.ts'),
238
- await format(quiltProject, {as: 'typescript'}),
239
- );
240
-
241
146
  await outputRoot.write(
242
147
  path.join(packageDirectory, 'README.md'),
243
148
  (await packageTemplate.read('README.md')).replaceAll(
@@ -247,6 +152,16 @@ export async function createProject() {
247
152
  );
248
153
 
249
154
  if (partOfMonorepo) {
155
+ // Add the package to the workspace configuration files
156
+ await Promise.all([
157
+ addToTsConfig(packageDirectory, outputRoot),
158
+ addToPackageManagerWorkspaces(
159
+ packageDirectory,
160
+ outputRoot,
161
+ packageManager.type,
162
+ ),
163
+ ]);
164
+
250
165
  // Write the package’s package.json (the root one was already created)
251
166
  const projectPackageJson = JSON.parse(
252
167
  await packageTemplate.read('package.json'),
@@ -264,7 +179,11 @@ export async function createProject() {
264
179
  directory,
265
180
  };
266
181
  } else if (repository != null) {
267
- projectPackageJson.repository = {type: 'git', ...repository, directory};
182
+ projectPackageJson.repository = {
183
+ type: 'git',
184
+ ...repository,
185
+ directory,
186
+ };
268
187
  } else {
269
188
  projectPackageJson.repository.directory = directory;
270
189
  }
@@ -284,15 +203,47 @@ export async function createProject() {
284
203
  as: 'json-stringify',
285
204
  }),
286
205
  );
287
-
288
- await Promise.all([
289
- addToTsConfig(packageDirectory, outputRoot),
290
- addToPackageManagerWorkspaces(
291
- packageDirectory,
292
- outputRoot,
293
- packageManager.type,
294
- ),
206
+ } else {
207
+ // Write the package’s package.json by combining elements of the root and
208
+ // package templates
209
+ const [projectPackageJson, workspacePackageJson] = await Promise.all([
210
+ packageTemplate
211
+ .read('package.json')
212
+ .then((content) => JSON.parse(content)),
213
+ workspaceTemplate
214
+ .read('package.json')
215
+ .then((content) => JSON.parse(content)),
295
216
  ]);
217
+
218
+ const mergedPackageJson = mergeWorkspaceAndProjectPackageJsons(
219
+ projectPackageJson,
220
+ workspacePackageJson,
221
+ );
222
+
223
+ adjustPackageJson(mergedPackageJson, {
224
+ name: toValidPackageName(name!),
225
+ description,
226
+ react: useReact,
227
+ isPublic,
228
+ registry: args['--registry'],
229
+ });
230
+
231
+ await outputRoot.write(
232
+ 'package.json',
233
+ await format(JSON.stringify(mergedPackageJson), {
234
+ as: 'json-stringify',
235
+ }),
236
+ );
237
+ }
238
+
239
+ if (!inWorkspace) {
240
+ if (setupExtras.has('github')) {
241
+ await loadTemplate('github').copy(directory);
242
+ }
243
+
244
+ if (setupExtras.has('vscode')) {
245
+ await loadTemplate('vscode').copy(directory);
246
+ }
296
247
  }
297
248
 
298
249
  if (shouldInstall) {
@@ -441,7 +392,6 @@ function getArguments() {
441
392
  '--extras': [String],
442
393
  '--no-extras': Boolean,
443
394
  '--react': Boolean,
444
- '--no-react': Boolean,
445
395
  '--public': Boolean,
446
396
  '--private': Boolean,
447
397
  '--registry': String,
@@ -570,21 +520,7 @@ async function getPublic(args: Arguments) {
570
520
  }
571
521
 
572
522
  async function getReact(args: Arguments) {
573
- let useReact: boolean;
574
-
575
- if (args['--react'] || args['--yes']) {
576
- useReact = true;
577
- } else if (args['--no-react']) {
578
- useReact = false;
579
- } else {
580
- useReact = await prompt({
581
- type: 'confirm',
582
- message: 'Will this package depend on React?',
583
- initial: true,
584
- });
585
- }
586
-
587
- return useReact;
523
+ return Boolean(args['--react']);
588
524
  }
589
525
 
590
526
  function adjustPackageJson(
@@ -651,10 +587,6 @@ function adjustPackageJson(
651
587
  delete packageJson.devDependencies['react'];
652
588
  delete packageJson.peerDependencies['react'];
653
589
  delete packageJson.peerDependenciesMeta['react'];
654
-
655
- packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(
656
- (extend: string) => !extend.includes('react'),
657
- );
658
590
  }
659
591
 
660
592
  return packageJson;
@@ -63,7 +63,7 @@ export async function getPackageManager(
63
63
  options?: Parameters<typeof createPackageManagerRunner>[1],
64
64
  ) {
65
65
  const packageManager = await baseGetPackageManager(argv['--package-manager']);
66
- return createPackageManagerRunner(packageManager ?? 'npm', options);
66
+ return createPackageManagerRunner(packageManager ?? 'pnpm', options);
67
67
  }
68
68
 
69
69
  type Extra = 'github' | 'vscode';
package/source/shared.ts CHANGED
@@ -7,6 +7,7 @@ export {prompt} from '@quilted/cli-kit';
7
7
  export function loadTemplate(
8
8
  name:
9
9
  | 'package'
10
+ | 'package-simple'
10
11
  | 'app-basic'
11
12
  | 'app-empty'
12
13
  | 'app-graphql'
@@ -14,6 +15,7 @@ export function loadTemplate(
14
15
  | 'module'
15
16
  | 'service-basic'
16
17
  | 'workspace'
18
+ | 'workspace-simple'
17
19
  | 'github'
18
20
  | 'vscode',
19
21
  ) {
@@ -50,6 +52,12 @@ export function loadTemplate(
50
52
 
51
53
  return fs.readFileSync(path.join(templateRoot, file), {encoding: 'utf8'});
52
54
  },
55
+ async has(file: string) {
56
+ templateRootPromise ??= templateDirectory(name);
57
+ const templateRoot = await templateRootPromise;
58
+
59
+ return fs.existsSync(path.join(templateRoot, file));
60
+ },
53
61
  };
54
62
  }
55
63
 
@@ -78,6 +86,7 @@ let packageRootPromise: Promise<string> | undefined;
78
86
  async function templateDirectory(
79
87
  name:
80
88
  | 'package'
89
+ | 'package-simple'
81
90
  | 'app-basic'
82
91
  | 'app-empty'
83
92
  | 'app-graphql'
@@ -85,6 +94,7 @@ async function templateDirectory(
85
94
  | 'module'
86
95
  | 'service-basic'
87
96
  | 'workspace'
97
+ | 'workspace-simple'
88
98
  | 'github'
89
99
  | 'vscode',
90
100
  ) {
@@ -1,3 +1,4 @@
1
+ import '@quilted/quilt/polyfills/fetch';
1
2
  import {
2
3
  GraphQLTesting,
3
4
  GraphQLController,
@@ -19,7 +19,7 @@ jobs:
19
19
  steps:
20
20
  - uses: actions/checkout@v3
21
21
  - uses: ./.github/workflows/actions/prepare
22
- - uses: quilt-framework/action-lint@v2
22
+ - run: pnpm run lint
23
23
 
24
24
  type-check:
25
25
  name: Type check 🧮
@@ -27,7 +27,7 @@ jobs:
27
27
  steps:
28
28
  - uses: actions/checkout@v3
29
29
  - uses: ./.github/workflows/actions/prepare
30
- - uses: quilt-framework/action-type-check@v2
30
+ - run: pnpm run type-check
31
31
 
32
32
  unit-tests:
33
33
  name: Unit tests 🧪
@@ -35,7 +35,7 @@ jobs:
35
35
  steps:
36
36
  - uses: actions/checkout@v3
37
37
  - uses: ./.github/workflows/actions/prepare
38
- - uses: quilt-framework/action-test@v2
38
+ - run: pnpm run test
39
39
 
40
40
  build:
41
41
  name: Build 🏗
@@ -44,4 +44,4 @@ jobs:
44
44
  steps:
45
45
  - uses: actions/checkout@v3
46
46
  - uses: ./.github/workflows/actions/prepare
47
- - uses: quilt-framework/action-build@v2
47
+ - run: pnpm run build
@@ -0,0 +1 @@
1
+ # `{{name}}`
@@ -0,0 +1,51 @@
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
+ "require": "./build/cjs/index.cjs"
25
+ }
26
+ },
27
+ "types": "./build/typescript/index.d.ts",
28
+ "sideEffects": false,
29
+ "scripts": {
30
+ "build": "rollup --config rollup.config.js"
31
+ },
32
+ "dependencies": {
33
+ "@types/react": "^17.0.0 || ^18.0.0"
34
+ },
35
+ "peerDependencies": {
36
+ "react": "^17.0.0 || ^18.0.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "react": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "devDependencies": {
44
+ "@quilted/testing": "^0.1.0",
45
+ "react": "npm:@quilted/react@^18.2.0"
46
+ },
47
+ "browserslist": [
48
+ "defaults and fully supports es6-module",
49
+ "maintained node versions"
50
+ ]
51
+ }
@@ -0,0 +1,3 @@
1
+ import {quiltPackageESModules} from '@quilted/rollup';
2
+
3
+ export default quiltPackageESModules();
@@ -0,0 +1,9 @@
1
+ import {describe, it, expect} from 'vitest';
2
+
3
+ import {run} from './index.ts';
4
+
5
+ describe('package', () => {
6
+ it('returns something fun', () => {
7
+ expect(run()).toContain('fun');
8
+ });
9
+ });
@@ -0,0 +1,3 @@
1
+ export function run() {
2
+ return 'Have fun building!';
3
+ }
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,13 @@
1
+ # Dependencies
2
+ node_modules/
3
+
4
+ # Build outputs
5
+ .quilt/
6
+ build/
7
+ bin/
8
+
9
+ # Special operating system files
10
+ .DS_STORE
11
+
12
+ # Temporary files
13
+ *.log
@@ -0,0 +1 @@
1
+ 18.17.0
@@ -0,0 +1,8 @@
1
+ # Dependencies
2
+ node_modules/
3
+ pnpm-lock.yaml
4
+
5
+ # Build outputs
6
+ .quilt/
7
+ build/
8
+ bin/
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "template-workspace-simple",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "private": true,
6
+ "scripts": {
7
+ "build": "pnpm -r run build",
8
+ "lint": "prettier --write --cache .",
9
+ "test": "vitest",
10
+ "type-check": "tsc --build --pretty"
11
+ },
12
+ "devDependencies": {
13
+ "@quilted/rollup": "^0.1.11",
14
+ "@quilted/typescript": "^0.2.0",
15
+ "rollup": "^4.1.0",
16
+ "prettier": "^3.0.0",
17
+ "typescript": "^5.2.0",
18
+ "vitest": "^0.34.0"
19
+ },
20
+ "prettier": {
21
+ "arrowParens": "always",
22
+ "bracketSpacing": false,
23
+ "singleQuote": true,
24
+ "trailingComma": "all"
25
+ }
26
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "@quilted/typescript/workspace.json",
3
+ "compilerOptions": {
4
+ "outDir": "build/typescript"
5
+ },
6
+ "include": [],
7
+ "references": []
8
+ }