@quilted/create 0.1.50 → 0.1.52
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.
- package/CHANGELOG.md +12 -0
- package/build/cjs/app.cjs +16 -211
- package/build/cjs/index.cjs +13 -1
- package/build/cjs/index2.cjs +157 -326
- package/build/cjs/index3.cjs +307 -7793
- package/build/cjs/index4.cjs +7402 -7181
- package/build/cjs/index5.cjs +7633 -0
- package/build/cjs/module.cjs +318 -0
- package/build/cjs/package.cjs +1 -1
- package/build/cjs/shared/package-manager.cjs +2 -2
- package/build/esm/app.mjs +1 -196
- package/build/esm/index.mjs +13 -1
- package/build/esm/index2.mjs +157 -325
- package/build/esm/index3.mjs +306 -7793
- package/build/esm/index4.mjs +7402 -7174
- package/build/esm/index5.mjs +7624 -0
- package/build/esm/module.mjs +296 -0
- package/build/esm/package.mjs +1 -1
- package/build/esm/shared/package-manager.mjs +2 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/help.d.ts +1 -1
- package/build/typescript/help.d.ts.map +1 -1
- package/build/typescript/module.d.ts +2 -0
- package/build/typescript/module.d.ts.map +1 -0
- package/build/typescript/shared/prompts.d.ts +2 -2
- package/build/typescript/shared/prompts.d.ts.map +1 -1
- package/build/typescript/shared.d.ts +1 -1
- package/build/typescript/shared.d.ts.map +1 -1
- package/package.json +1 -1
- package/source/create.ts +7 -1
- package/source/help.ts +6 -1
- package/source/module.ts +426 -0
- package/source/shared/prompts.ts +2 -2
- package/source/shared.ts +2 -0
- package/templates/module/module.ts +3 -0
- package/templates/module/package.json +24 -0
- package/templates/module/quilt.project.ts +5 -0
- package/templates/module/tsconfig.json +9 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuiltInParserName } from 'prettier';
|
|
2
2
|
export { prompt } from '@quilted/cli-kit';
|
|
3
|
-
export declare function loadTemplate(name: 'package' | 'app-basic' | 'app-single-file' | 'app-empty' | 'app-graphql' | 'workspace' | 'github' | 'vscode'): {
|
|
3
|
+
export declare function loadTemplate(name: 'package' | 'app-basic' | 'app-single-file' | 'app-empty' | 'app-graphql' | 'module' | 'workspace' | 'github' | 'vscode'): {
|
|
4
4
|
copy(to: string, handleFile?: ((file: string) => boolean) | undefined): Promise<void>;
|
|
5
5
|
read(file: string): Promise<string>;
|
|
6
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../source/shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,UAAU,CAAC;AAChD,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAExC,wBAAgB,YAAY,CAC1B,IAAI,EACA,SAAS,GACT,WAAW,GACX,iBAAiB,GACjB,WAAW,GACX,aAAa,GACb,WAAW,GACX,QAAQ,GACR,QAAQ;aAKK,MAAM,uBAAsB,MAAM,KAAK,OAAO;eAwB5C,MAAM;EAO1B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACpC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrD;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAY/D;
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../source/shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,UAAU,CAAC;AAChD,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAExC,wBAAgB,YAAY,CAC1B,IAAI,EACA,SAAS,GACT,WAAW,GACX,iBAAiB,GACjB,WAAW,GACX,aAAa,GACb,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,QAAQ;aAKK,MAAM,uBAAsB,MAAM,KAAK,OAAO;eAwB5C,MAAM;EAO1B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACpC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrD;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAY/D;AAiCD,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,UAOrD;AAoBD,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBAE5D;AAED,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,oBAEzC;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,iBAQ/C;AAED,wBAAgB,2BAA2B,CAAC,iBAAiB,EAAE,MAAM,UAIpE;AAED,wBAAsB,MAAM,CAC1B,OAAO,EAAE,MAAM,EACf,EAAC,EAAE,EAAE,MAAM,EAAC,EAAE;IAAC,EAAE,EAAE,iBAAiB,CAAA;CAAC,mBAyBtC;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EAClC,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,0BAYpC;AAeD,wBAAgB,oCAAoC,CAClD,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3C,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,2BAsC9C"}
|
package/package.json
CHANGED
package/source/create.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {AbortError, stripIndent, color, parseArguments} from '@quilted/cli-kit';
|
|
|
5
5
|
import {printHelp} from './help';
|
|
6
6
|
import {prompt} from './shared';
|
|
7
7
|
|
|
8
|
-
const VALID_PROJECT_KINDS = new Set(['app', 'package']);
|
|
8
|
+
const VALID_PROJECT_KINDS = new Set(['app', 'package', 'module']);
|
|
9
9
|
|
|
10
10
|
run().catch((error) => {
|
|
11
11
|
if (AbortError.test(error)) return;
|
|
@@ -57,6 +57,7 @@ async function run() {
|
|
|
57
57
|
message: 'What kind of project would you like to create?',
|
|
58
58
|
choices: [
|
|
59
59
|
{title: 'App', value: 'app'},
|
|
60
|
+
{title: 'Module', value: 'module'},
|
|
60
61
|
{title: 'Package', value: 'package'},
|
|
61
62
|
],
|
|
62
63
|
});
|
|
@@ -68,6 +69,11 @@ async function run() {
|
|
|
68
69
|
await createApp();
|
|
69
70
|
break;
|
|
70
71
|
}
|
|
72
|
+
case 'module': {
|
|
73
|
+
const {createModule} = await import('./module');
|
|
74
|
+
await createModule();
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
71
77
|
case 'package': {
|
|
72
78
|
const {createProject} = await import('./package');
|
|
73
79
|
await createProject();
|
package/source/help.ts
CHANGED
|
@@ -4,7 +4,11 @@ export function printHelp({
|
|
|
4
4
|
kind,
|
|
5
5
|
options: customOptions,
|
|
6
6
|
packageManager,
|
|
7
|
-
}: {
|
|
7
|
+
}: {
|
|
8
|
+
kind?: 'app' | 'package' | 'module';
|
|
9
|
+
options?: string;
|
|
10
|
+
packageManager?: string;
|
|
11
|
+
} = {}) {
|
|
8
12
|
const command = createCommand(packageManager);
|
|
9
13
|
|
|
10
14
|
const usage = stripIndent`
|
|
@@ -31,6 +35,7 @@ export function printHelp({
|
|
|
31
35
|
|
|
32
36
|
- ${color.magenta('app')}, a web application
|
|
33
37
|
- ${color.magenta('package')}, a shared library of code
|
|
38
|
+
- ${color.magenta('module')}, a standalone JavaScript module for a browser
|
|
34
39
|
|
|
35
40
|
You’ll be asked a few additional questions based on the kind you choose.
|
|
36
41
|
`;
|
package/source/module.ts
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
import arg from 'arg';
|
|
5
|
+
import * as color from 'colorette';
|
|
6
|
+
import {stripIndent} from 'common-tags';
|
|
7
|
+
|
|
8
|
+
import {printHelp} from './help';
|
|
9
|
+
import {
|
|
10
|
+
format,
|
|
11
|
+
loadTemplate,
|
|
12
|
+
createOutputTarget,
|
|
13
|
+
isEmpty,
|
|
14
|
+
emptyDirectory,
|
|
15
|
+
toValidPackageName,
|
|
16
|
+
relativeDirectoryForDisplay,
|
|
17
|
+
mergeWorkspaceAndProjectPackageJsons,
|
|
18
|
+
} from './shared';
|
|
19
|
+
import {
|
|
20
|
+
prompt,
|
|
21
|
+
getInWorkspace,
|
|
22
|
+
getCreateAsMonorepo,
|
|
23
|
+
getExtrasToSetup,
|
|
24
|
+
getPackageManager,
|
|
25
|
+
getShouldInstall,
|
|
26
|
+
} from './shared/prompts';
|
|
27
|
+
import {addToTsConfig} from './shared/tsconfig';
|
|
28
|
+
import {addToPackageManagerWorkspaces} from './shared/package-manager';
|
|
29
|
+
|
|
30
|
+
type Arguments = ReturnType<typeof getArgv>;
|
|
31
|
+
|
|
32
|
+
export async function createModule() {
|
|
33
|
+
const argv = getArgv();
|
|
34
|
+
|
|
35
|
+
if (argv['--help']) {
|
|
36
|
+
printHelp({
|
|
37
|
+
kind: 'module',
|
|
38
|
+
packageManager: argv['--package-manager']?.toLowerCase(),
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const inWorkspace = await getInWorkspace(argv);
|
|
44
|
+
const name = await getName(argv);
|
|
45
|
+
const directory = await getDirectory(argv, {name});
|
|
46
|
+
const entry = await getEntry(argv, {name});
|
|
47
|
+
|
|
48
|
+
const useReact = await getReact(argv);
|
|
49
|
+
|
|
50
|
+
const createAsMonorepo =
|
|
51
|
+
!inWorkspace &&
|
|
52
|
+
(await getCreateAsMonorepo(argv, {
|
|
53
|
+
type: 'module',
|
|
54
|
+
default: false,
|
|
55
|
+
}));
|
|
56
|
+
const setupExtras = await getExtrasToSetup(argv, {inWorkspace});
|
|
57
|
+
const shouldInstall = await getShouldInstall(argv, {type: 'module'});
|
|
58
|
+
const packageManager = await getPackageManager(argv, {root: directory});
|
|
59
|
+
|
|
60
|
+
const partOfMonorepo = inWorkspace || createAsMonorepo;
|
|
61
|
+
|
|
62
|
+
const moduleDirectory = createAsMonorepo
|
|
63
|
+
? path.join(directory, 'app')
|
|
64
|
+
: directory;
|
|
65
|
+
|
|
66
|
+
if (fs.existsSync(directory)) {
|
|
67
|
+
await emptyDirectory(directory);
|
|
68
|
+
|
|
69
|
+
if (moduleDirectory !== directory) {
|
|
70
|
+
fs.mkdirSync(moduleDirectory, {recursive: true});
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
fs.mkdirSync(moduleDirectory, {recursive: true});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const rootDirectory = inWorkspace ? process.cwd() : directory;
|
|
77
|
+
const outputRoot = createOutputTarget(rootDirectory);
|
|
78
|
+
const moduleTemplate = loadTemplate('module');
|
|
79
|
+
const workspaceTemplate = loadTemplate('workspace');
|
|
80
|
+
|
|
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) {
|
|
84
|
+
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;
|
|
92
|
+
});
|
|
93
|
+
|
|
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
|
+
);
|
|
146
|
+
|
|
147
|
+
adjustPackageJson(combinedPackageJson, {name, entry, react: useReact});
|
|
148
|
+
delete combinedPackageJson.workspaces;
|
|
149
|
+
|
|
150
|
+
let quiltProject = await moduleTemplate.read('quilt.project.ts');
|
|
151
|
+
quiltProject = quiltProject
|
|
152
|
+
.replace('quiltModule', 'quiltWorkspace, quiltModule')
|
|
153
|
+
.replace('quiltModule(', 'quiltWorkspace(), quiltModule(');
|
|
154
|
+
|
|
155
|
+
if (!useReact) {
|
|
156
|
+
quiltProject = quiltProject.replace(
|
|
157
|
+
'quiltPackage()',
|
|
158
|
+
'quiltPackage({react: false})',
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
await outputRoot.write(
|
|
163
|
+
'quilt.project.ts',
|
|
164
|
+
await format(quiltProject, {as: 'typescript'}),
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
await outputRoot.write(
|
|
168
|
+
'package.json',
|
|
169
|
+
await format(JSON.stringify(combinedPackageJson), {
|
|
170
|
+
as: 'json-stringify',
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
await outputRoot.write(
|
|
175
|
+
'tsconfig.json',
|
|
176
|
+
await format(JSON.stringify(projectTSConfig), {as: 'json'}),
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (setupExtras.has('github')) {
|
|
181
|
+
await loadTemplate('github').copy(directory);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (setupExtras.has('vscode')) {
|
|
185
|
+
await loadTemplate('vscode').copy(directory);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
await moduleTemplate.copy(moduleDirectory, (file) => {
|
|
190
|
+
// If we are in a monorepo, we can use all the template files as they are
|
|
191
|
+
if (file === 'quilt.project.ts' || file === 'tsconfig.json') {
|
|
192
|
+
return partOfMonorepo;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// We will adjust the entry file
|
|
196
|
+
if (file === 'module.ts') {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// We need to make some adjustments the project’s package.json
|
|
201
|
+
return file !== 'package.json';
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
await outputRoot.write(
|
|
205
|
+
path.join(moduleDirectory, entry),
|
|
206
|
+
await moduleTemplate.read('module.ts'),
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
if (partOfMonorepo) {
|
|
210
|
+
// Write the app’s package.json (the root one was already created)
|
|
211
|
+
const projectPackageJson = JSON.parse(
|
|
212
|
+
await moduleTemplate.read('package.json'),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
adjustPackageJson(projectPackageJson, {name, entry, react: useReact});
|
|
216
|
+
|
|
217
|
+
await outputRoot.write(
|
|
218
|
+
path.join(moduleDirectory, 'package.json'),
|
|
219
|
+
await format(JSON.stringify(projectPackageJson), {
|
|
220
|
+
as: 'json-stringify',
|
|
221
|
+
}),
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
await Promise.all([
|
|
225
|
+
addToTsConfig(moduleDirectory, outputRoot),
|
|
226
|
+
addToPackageManagerWorkspaces(
|
|
227
|
+
moduleDirectory,
|
|
228
|
+
outputRoot,
|
|
229
|
+
packageManager.type,
|
|
230
|
+
),
|
|
231
|
+
]);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (shouldInstall) {
|
|
235
|
+
console.log();
|
|
236
|
+
// TODO: better loading, handle errors
|
|
237
|
+
await packageManager.install();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const commands: string[] = [];
|
|
241
|
+
|
|
242
|
+
if (!inWorkspace && directory !== process.cwd()) {
|
|
243
|
+
commands.push(
|
|
244
|
+
`cd ${color.cyan(
|
|
245
|
+
relativeDirectoryForDisplay(path.relative(process.cwd(), directory)),
|
|
246
|
+
)} ${color.dim('# Move into your new module’s directory')}`,
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (!shouldInstall) {
|
|
251
|
+
commands.push(
|
|
252
|
+
`${packageManager.commands.install()} ${color.dim(
|
|
253
|
+
'# Install all your dependencies',
|
|
254
|
+
)}`,
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (commands.length === 0) {
|
|
259
|
+
console.log();
|
|
260
|
+
console.log('Your new module is ready to go!');
|
|
261
|
+
} else {
|
|
262
|
+
const whatsNext = stripIndent`
|
|
263
|
+
Your new module is ready to go! There’s just ${
|
|
264
|
+
commands.length > 1 ? 'a few more steps' : 'one more step'
|
|
265
|
+
} you’ll need to take
|
|
266
|
+
in order to start developing:
|
|
267
|
+
`;
|
|
268
|
+
|
|
269
|
+
console.log();
|
|
270
|
+
console.log(whatsNext);
|
|
271
|
+
console.log();
|
|
272
|
+
console.log(commands.map((command) => ` ${command}`).join('\n'));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const followUp = stripIndent`
|
|
276
|
+
Quilt can also help you build, test, lint, and type-check your new module.
|
|
277
|
+
You can learn more about building modules with Quilt by reading the documentation:
|
|
278
|
+
${color.underline(
|
|
279
|
+
color.magenta(
|
|
280
|
+
'https://github.com/lemonmade/quilt/tree/main/documentation',
|
|
281
|
+
),
|
|
282
|
+
)}
|
|
283
|
+
|
|
284
|
+
Have fun! 🎉
|
|
285
|
+
`;
|
|
286
|
+
|
|
287
|
+
console.log();
|
|
288
|
+
console.log(followUp);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Argument handling
|
|
292
|
+
|
|
293
|
+
function getArgv() {
|
|
294
|
+
const argv = arg(
|
|
295
|
+
{
|
|
296
|
+
'--yes': Boolean,
|
|
297
|
+
'-y': '--yes',
|
|
298
|
+
'--name': String,
|
|
299
|
+
'--directory': String,
|
|
300
|
+
'--entry': String,
|
|
301
|
+
'--install': Boolean,
|
|
302
|
+
'--no-install': Boolean,
|
|
303
|
+
'--monorepo': Boolean,
|
|
304
|
+
'--no-monorepo': Boolean,
|
|
305
|
+
'--package-manager': String,
|
|
306
|
+
'--extras': [String],
|
|
307
|
+
'--no-extras': Boolean,
|
|
308
|
+
'--react': Boolean,
|
|
309
|
+
'--no-react': Boolean,
|
|
310
|
+
'--help': Boolean,
|
|
311
|
+
'-h': '--help',
|
|
312
|
+
},
|
|
313
|
+
{permissive: true},
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
return argv;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
async function getName(argv: Arguments) {
|
|
320
|
+
let {'--name': name} = argv;
|
|
321
|
+
|
|
322
|
+
if (name == null) {
|
|
323
|
+
name = await prompt({
|
|
324
|
+
type: 'text',
|
|
325
|
+
message: 'What would you like to name your new module?',
|
|
326
|
+
initial: 'my-module',
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return name!;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async function getEntry(argv: Arguments, {name}: {name: string}) {
|
|
334
|
+
if (argv['--entry']) {
|
|
335
|
+
return argv['--entry'];
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const entry = await prompt({
|
|
339
|
+
type: 'text',
|
|
340
|
+
message: 'What do you want to name your entry file?',
|
|
341
|
+
initial: `${toValidPackageName(name)}.ts`,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
return entry;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async function getDirectory(argv: Arguments, {name}: {name: string}) {
|
|
348
|
+
let directory = path.resolve(
|
|
349
|
+
argv['--directory'] ?? toValidPackageName(name!),
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
while (!argv['--yes']) {
|
|
353
|
+
if (fs.existsSync(directory) && !(await isEmpty(directory))) {
|
|
354
|
+
const relativeDirectory = path.relative(process.cwd(), directory);
|
|
355
|
+
|
|
356
|
+
const empty = await prompt({
|
|
357
|
+
type: 'confirm',
|
|
358
|
+
message: `Directory ${color.bold(
|
|
359
|
+
relativeDirectoryForDisplay(relativeDirectory),
|
|
360
|
+
)} is not empty, is it safe to empty it?`,
|
|
361
|
+
initial: true,
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
if (empty) break;
|
|
365
|
+
|
|
366
|
+
const promptDirectory = await prompt({
|
|
367
|
+
type: 'text',
|
|
368
|
+
message: 'What directory do you want to create your new module in?',
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
directory = path.resolve(promptDirectory);
|
|
372
|
+
} else {
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
return directory;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async function getReact(args: Arguments) {
|
|
381
|
+
let useReact: boolean;
|
|
382
|
+
|
|
383
|
+
if (args['--react'] || args['--yes']) {
|
|
384
|
+
useReact = true;
|
|
385
|
+
} else if (args['--no-react']) {
|
|
386
|
+
useReact = false;
|
|
387
|
+
} else {
|
|
388
|
+
useReact = await prompt({
|
|
389
|
+
type: 'confirm',
|
|
390
|
+
message: 'Will this module depend on React?',
|
|
391
|
+
initial: false,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return useReact;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function adjustPackageJson(
|
|
399
|
+
packageJson: Record<string, any>,
|
|
400
|
+
{
|
|
401
|
+
name,
|
|
402
|
+
entry,
|
|
403
|
+
react,
|
|
404
|
+
}: {
|
|
405
|
+
name: string;
|
|
406
|
+
entry: string;
|
|
407
|
+
react: boolean;
|
|
408
|
+
},
|
|
409
|
+
) {
|
|
410
|
+
packageJson.name = name;
|
|
411
|
+
packageJson.main = `./${entry}`;
|
|
412
|
+
|
|
413
|
+
if (!react) {
|
|
414
|
+
delete packageJson.devDependencies['@types/react'];
|
|
415
|
+
delete packageJson.devDependencies['@types/react-dom'];
|
|
416
|
+
delete packageJson.devDependencies['preact'];
|
|
417
|
+
delete packageJson.devDependencies['react'];
|
|
418
|
+
delete packageJson.devDependencies['react-dom'];
|
|
419
|
+
|
|
420
|
+
packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(
|
|
421
|
+
(extend: string) => !extend.includes('react'),
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return packageJson;
|
|
426
|
+
}
|
package/source/shared/prompts.ts
CHANGED
|
@@ -35,7 +35,7 @@ export async function getCreateAsMonorepo(
|
|
|
35
35
|
{
|
|
36
36
|
type,
|
|
37
37
|
default: defaultCreateAsMonorepo = true,
|
|
38
|
-
}: {type: 'app' | 'package'; default?: boolean},
|
|
38
|
+
}: {type: 'app' | 'package' | 'module'; default?: boolean},
|
|
39
39
|
) {
|
|
40
40
|
let createAsMonorepo: boolean;
|
|
41
41
|
|
|
@@ -56,7 +56,7 @@ export async function getCreateAsMonorepo(
|
|
|
56
56
|
|
|
57
57
|
export async function getShouldInstall(
|
|
58
58
|
argv: BaseArguments,
|
|
59
|
-
{type}: {type: 'app' | 'package'},
|
|
59
|
+
{type}: {type: 'app' | 'package' | 'module'},
|
|
60
60
|
) {
|
|
61
61
|
let shouldInstall: boolean;
|
|
62
62
|
|
package/source/shared.ts
CHANGED
|
@@ -11,6 +11,7 @@ export function loadTemplate(
|
|
|
11
11
|
| 'app-single-file'
|
|
12
12
|
| 'app-empty'
|
|
13
13
|
| 'app-graphql'
|
|
14
|
+
| 'module'
|
|
14
15
|
| 'workspace'
|
|
15
16
|
| 'github'
|
|
16
17
|
| 'vscode',
|
|
@@ -80,6 +81,7 @@ async function templateDirectory(
|
|
|
80
81
|
| 'app-single-file'
|
|
81
82
|
| 'app-empty'
|
|
82
83
|
| 'app-graphql'
|
|
84
|
+
| 'module'
|
|
83
85
|
| 'workspace'
|
|
84
86
|
| 'github'
|
|
85
87
|
| 'vscode',
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "template-module",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"main": "./module.ts",
|
|
5
|
+
"version": "0.0.0",
|
|
6
|
+
"private": true,
|
|
7
|
+
"dependencies": {},
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@types/react": "^18.0.0",
|
|
10
|
+
"@types/react-dom": "^18.0.0",
|
|
11
|
+
"preact": "^10.11.0",
|
|
12
|
+
"react": "npm:@quilted/react@^18.2.0",
|
|
13
|
+
"react-dom": "npm:@quilted/react-dom@^18.2.0"
|
|
14
|
+
},
|
|
15
|
+
"browserslist": [
|
|
16
|
+
"extends @quilted/browserslist-config/modules"
|
|
17
|
+
],
|
|
18
|
+
"eslintConfig": {
|
|
19
|
+
"extends": [
|
|
20
|
+
"@quilted/eslint-config/project",
|
|
21
|
+
"@quilted/eslint-config/react"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
}
|