@quilted/create 0.1.50 → 0.1.51
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 +6 -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 +302 -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 +280 -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 +412 -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 +21 -0
- package/templates/module/quilt.project.ts +5 -0
- package/templates/module/tsconfig.json +9 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('node:fs');
|
|
4
|
+
var path = require('node:path');
|
|
5
|
+
var index$1 = require('./index2.cjs');
|
|
6
|
+
var packageManager = require('./shared/package-manager.cjs');
|
|
7
|
+
var index = require('./index.cjs');
|
|
8
|
+
require('node:tty');
|
|
9
|
+
require('node:child_process');
|
|
10
|
+
require('node:url');
|
|
11
|
+
require('node:readline');
|
|
12
|
+
require('node:events');
|
|
13
|
+
|
|
14
|
+
function _interopNamespaceDefault(e) {
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n["default"] = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
32
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
33
|
+
|
|
34
|
+
async function createModule() {
|
|
35
|
+
const argv = getArgv();
|
|
36
|
+
if (argv['--help']) {
|
|
37
|
+
index.printHelp({
|
|
38
|
+
kind: 'module',
|
|
39
|
+
packageManager: argv['--package-manager']?.toLowerCase()
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const inWorkspace = await packageManager.getInWorkspace(argv);
|
|
44
|
+
const name = await getName(argv);
|
|
45
|
+
const directory = await getDirectory(argv, {
|
|
46
|
+
name
|
|
47
|
+
});
|
|
48
|
+
const useReact = await getReact(argv);
|
|
49
|
+
const entry = `${packageManager.toValidPackageName(name)}.${useReact ? 'tsx' : 'ts'}`;
|
|
50
|
+
const createAsMonorepo = !inWorkspace && (await packageManager.getCreateAsMonorepo(argv, {
|
|
51
|
+
type: 'module',
|
|
52
|
+
default: false
|
|
53
|
+
}));
|
|
54
|
+
const setupExtras = await packageManager.getExtrasToSetup(argv, {
|
|
55
|
+
inWorkspace
|
|
56
|
+
});
|
|
57
|
+
const shouldInstall = await packageManager.getShouldInstall(argv, {
|
|
58
|
+
type: 'module'
|
|
59
|
+
});
|
|
60
|
+
const packageManager$1 = await packageManager.getPackageManager(argv, {
|
|
61
|
+
root: directory
|
|
62
|
+
});
|
|
63
|
+
const partOfMonorepo = inWorkspace || createAsMonorepo;
|
|
64
|
+
const moduleDirectory = createAsMonorepo ? path__namespace.join(directory, 'app') : directory;
|
|
65
|
+
if (fs__namespace.existsSync(directory)) {
|
|
66
|
+
await packageManager.emptyDirectory(directory);
|
|
67
|
+
if (moduleDirectory !== directory) {
|
|
68
|
+
fs__namespace.mkdirSync(moduleDirectory, {
|
|
69
|
+
recursive: true
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
fs__namespace.mkdirSync(moduleDirectory, {
|
|
74
|
+
recursive: true
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const rootDirectory = inWorkspace ? process.cwd() : directory;
|
|
78
|
+
const outputRoot = packageManager.createOutputTarget(rootDirectory);
|
|
79
|
+
const moduleTemplate = packageManager.loadTemplate('module');
|
|
80
|
+
const workspaceTemplate = packageManager.loadTemplate('workspace');
|
|
81
|
+
|
|
82
|
+
// If we aren’t already in a workspace, copy the workspace files over, which
|
|
83
|
+
// are needed if we are making a monorepo or not.
|
|
84
|
+
if (!inWorkspace) {
|
|
85
|
+
await workspaceTemplate.copy(directory, file => {
|
|
86
|
+
// When this is a single project, we use the project’s Quilt configuration as the base.
|
|
87
|
+
if (file === 'quilt.workspace.ts') return createAsMonorepo;
|
|
88
|
+
|
|
89
|
+
// We need to make some adjustments to the root package.json
|
|
90
|
+
if (file === 'package.json') return false;
|
|
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 = packageManager.relativeDirectoryForDisplay(path__namespace.relative(directory, moduleDirectory));
|
|
98
|
+
const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
|
|
99
|
+
workspacePackageJson.name = packageManager.toValidPackageName(name);
|
|
100
|
+
workspacePackageJson.workspaces = [moduleRelativeToRoot, './packages/*'];
|
|
101
|
+
if (packageManager$1.type === 'pnpm') {
|
|
102
|
+
await outputRoot.write('pnpm-workspace.yaml', await packageManager.format(`
|
|
103
|
+
packages:
|
|
104
|
+
- '${moduleRelativeToRoot}'
|
|
105
|
+
- './packages/*'
|
|
106
|
+
`, {
|
|
107
|
+
as: 'yaml'
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
await outputRoot.write('package.json', await packageManager.format(JSON.stringify(workspacePackageJson), {
|
|
111
|
+
as: 'json-stringify'
|
|
112
|
+
}));
|
|
113
|
+
} else {
|
|
114
|
+
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))]);
|
|
115
|
+
const combinedPackageJson = packageManager.mergeWorkspaceAndProjectPackageJsons(projectPackageJson, workspacePackageJson);
|
|
116
|
+
adjustPackageJson(combinedPackageJson, {
|
|
117
|
+
name,
|
|
118
|
+
entry,
|
|
119
|
+
react: useReact
|
|
120
|
+
});
|
|
121
|
+
delete combinedPackageJson.workspaces;
|
|
122
|
+
let quiltProject = await moduleTemplate.read('quilt.project.ts');
|
|
123
|
+
quiltProject = quiltProject.replace('quiltModule', 'quiltWorkspace, quiltModule').replace('quiltModule(', 'quiltWorkspace(), quiltModule(');
|
|
124
|
+
if (!useReact) {
|
|
125
|
+
quiltProject = quiltProject.replace('quiltPackage()', 'quiltPackage({react: false})');
|
|
126
|
+
}
|
|
127
|
+
await outputRoot.write('quilt.project.ts', await packageManager.format(quiltProject, {
|
|
128
|
+
as: 'typescript'
|
|
129
|
+
}));
|
|
130
|
+
await outputRoot.write('package.json', await packageManager.format(JSON.stringify(combinedPackageJson), {
|
|
131
|
+
as: 'json-stringify'
|
|
132
|
+
}));
|
|
133
|
+
await outputRoot.write('tsconfig.json', await packageManager.format(JSON.stringify(projectTSConfig), {
|
|
134
|
+
as: 'json'
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
if (setupExtras.has('github')) {
|
|
138
|
+
await packageManager.loadTemplate('github').copy(directory);
|
|
139
|
+
}
|
|
140
|
+
if (setupExtras.has('vscode')) {
|
|
141
|
+
await packageManager.loadTemplate('vscode').copy(directory);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
await moduleTemplate.copy(moduleDirectory, file => {
|
|
145
|
+
// If we are in a monorepo, we can use all the template files as they are
|
|
146
|
+
if (file === 'quilt.project.ts' || file === 'tsconfig.json') {
|
|
147
|
+
return partOfMonorepo;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// We will adjust the entry file
|
|
151
|
+
if (file === 'module.ts') {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// We need to make some adjustments the project’s package.json
|
|
156
|
+
return file !== 'package.json';
|
|
157
|
+
});
|
|
158
|
+
await outputRoot.write(path__namespace.join(moduleDirectory, entry), await moduleTemplate.read('module.ts'));
|
|
159
|
+
if (partOfMonorepo) {
|
|
160
|
+
// Write the app’s package.json (the root one was already created)
|
|
161
|
+
const projectPackageJson = JSON.parse(await moduleTemplate.read('package.json'));
|
|
162
|
+
adjustPackageJson(projectPackageJson, {
|
|
163
|
+
name,
|
|
164
|
+
entry,
|
|
165
|
+
react: useReact
|
|
166
|
+
});
|
|
167
|
+
await outputRoot.write(path__namespace.join(moduleDirectory, 'package.json'), await packageManager.format(JSON.stringify(projectPackageJson), {
|
|
168
|
+
as: 'json-stringify'
|
|
169
|
+
}));
|
|
170
|
+
await Promise.all([packageManager.addToTsConfig(moduleDirectory, outputRoot), packageManager.addToPackageManagerWorkspaces(moduleDirectory, outputRoot, packageManager$1.type)]);
|
|
171
|
+
}
|
|
172
|
+
if (shouldInstall) {
|
|
173
|
+
console.log();
|
|
174
|
+
// TODO: better loading, handle errors
|
|
175
|
+
await packageManager$1.install();
|
|
176
|
+
}
|
|
177
|
+
const commands = [];
|
|
178
|
+
if (!inWorkspace && directory !== process.cwd()) {
|
|
179
|
+
commands.push(`cd ${packageManager.cyan_1(packageManager.relativeDirectoryForDisplay(path__namespace.relative(process.cwd(), directory)))} ${packageManager.dim_1('# Move into your new module’s directory')}`);
|
|
180
|
+
}
|
|
181
|
+
if (!shouldInstall) {
|
|
182
|
+
commands.push(`${packageManager$1.commands.install()} ${packageManager.dim_1('# Install all your dependencies')}`);
|
|
183
|
+
}
|
|
184
|
+
if (commands.length === 0) {
|
|
185
|
+
console.log();
|
|
186
|
+
console.log('Your new module is ready to go!');
|
|
187
|
+
} else {
|
|
188
|
+
const whatsNext = index.stripIndent`
|
|
189
|
+
Your new module is ready to go! There’s just ${commands.length > 1 ? 'a few more steps' : 'one more step'} you’ll need to take
|
|
190
|
+
in order to start developing:
|
|
191
|
+
`;
|
|
192
|
+
console.log();
|
|
193
|
+
console.log(whatsNext);
|
|
194
|
+
console.log();
|
|
195
|
+
console.log(commands.map(command => ` ${command}`).join('\n'));
|
|
196
|
+
}
|
|
197
|
+
const followUp = index.stripIndent`
|
|
198
|
+
Quilt can also help you build, test, lint, and type-check your new module.
|
|
199
|
+
You can learn more about building modules with Quilt by reading the documentation:
|
|
200
|
+
${packageManager.underline_1(packageManager.magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation'))}
|
|
201
|
+
|
|
202
|
+
Have fun! 🎉
|
|
203
|
+
`;
|
|
204
|
+
console.log();
|
|
205
|
+
console.log(followUp);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Argument handling
|
|
209
|
+
|
|
210
|
+
function getArgv() {
|
|
211
|
+
const argv = index$1.arg_1({
|
|
212
|
+
'--yes': Boolean,
|
|
213
|
+
'-y': '--yes',
|
|
214
|
+
'--name': String,
|
|
215
|
+
'--directory': String,
|
|
216
|
+
'--install': Boolean,
|
|
217
|
+
'--no-install': Boolean,
|
|
218
|
+
'--monorepo': Boolean,
|
|
219
|
+
'--no-monorepo': Boolean,
|
|
220
|
+
'--package-manager': String,
|
|
221
|
+
'--extras': [String],
|
|
222
|
+
'--no-extras': Boolean,
|
|
223
|
+
'--react': Boolean,
|
|
224
|
+
'--no-react': Boolean,
|
|
225
|
+
'--help': Boolean,
|
|
226
|
+
'-h': '--help'
|
|
227
|
+
}, {
|
|
228
|
+
permissive: true
|
|
229
|
+
});
|
|
230
|
+
return argv;
|
|
231
|
+
}
|
|
232
|
+
async function getName(argv) {
|
|
233
|
+
let {
|
|
234
|
+
'--name': name
|
|
235
|
+
} = argv;
|
|
236
|
+
if (name == null) {
|
|
237
|
+
name = await index.prompt({
|
|
238
|
+
type: 'text',
|
|
239
|
+
message: 'What would you like to name your new module?',
|
|
240
|
+
initial: 'my-module'
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
return name;
|
|
244
|
+
}
|
|
245
|
+
async function getDirectory(argv, {
|
|
246
|
+
name
|
|
247
|
+
}) {
|
|
248
|
+
let directory = path__namespace.resolve(argv['--directory'] ?? packageManager.toValidPackageName(name));
|
|
249
|
+
while (!argv['--yes']) {
|
|
250
|
+
if (fs__namespace.existsSync(directory) && !(await packageManager.isEmpty(directory))) {
|
|
251
|
+
const relativeDirectory = path__namespace.relative(process.cwd(), directory);
|
|
252
|
+
const empty = await index.prompt({
|
|
253
|
+
type: 'confirm',
|
|
254
|
+
message: `Directory ${packageManager.bold_1(packageManager.relativeDirectoryForDisplay(relativeDirectory))} is not empty, is it safe to empty it?`,
|
|
255
|
+
initial: true
|
|
256
|
+
});
|
|
257
|
+
if (empty) break;
|
|
258
|
+
const promptDirectory = await index.prompt({
|
|
259
|
+
type: 'text',
|
|
260
|
+
message: 'What directory do you want to create your new module in?'
|
|
261
|
+
});
|
|
262
|
+
directory = path__namespace.resolve(promptDirectory);
|
|
263
|
+
} else {
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return directory;
|
|
268
|
+
}
|
|
269
|
+
async function getReact(args) {
|
|
270
|
+
let useReact;
|
|
271
|
+
if (args['--react'] || args['--yes']) {
|
|
272
|
+
useReact = true;
|
|
273
|
+
} else if (args['--no-react']) {
|
|
274
|
+
useReact = false;
|
|
275
|
+
} else {
|
|
276
|
+
useReact = await index.prompt({
|
|
277
|
+
type: 'confirm',
|
|
278
|
+
message: 'Will this module depend on React?',
|
|
279
|
+
initial: false
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
return useReact;
|
|
283
|
+
}
|
|
284
|
+
function adjustPackageJson(packageJson, {
|
|
285
|
+
name,
|
|
286
|
+
entry,
|
|
287
|
+
react
|
|
288
|
+
}) {
|
|
289
|
+
packageJson.name = name;
|
|
290
|
+
packageJson.main = `./${entry}`;
|
|
291
|
+
if (!react) {
|
|
292
|
+
delete packageJson.devDependencies['@types/react'];
|
|
293
|
+
delete packageJson.devDependencies['@types/react-dom'];
|
|
294
|
+
delete packageJson.devDependencies['preact'];
|
|
295
|
+
delete packageJson.devDependencies['react'];
|
|
296
|
+
delete packageJson.devDependencies['react-dom'];
|
|
297
|
+
packageJson.eslintConfig.extends = packageJson.eslintConfig.extends.filter(extend => !extend.includes('react'));
|
|
298
|
+
}
|
|
299
|
+
return packageJson;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
exports.createModule = createModule;
|
package/build/cjs/package.cjs
CHANGED
|
@@ -376,7 +376,7 @@ async function getRepository(args, {
|
|
|
376
376
|
if (!inWorkspace) return;
|
|
377
377
|
const {
|
|
378
378
|
globby
|
|
379
|
-
} = await Promise.resolve().then(function () { return require('./
|
|
379
|
+
} = await Promise.resolve().then(function () { return require('./index5.cjs'); });
|
|
380
380
|
const files = await globby('**/package.json', {
|
|
381
381
|
ignore: ['**/node_modules']
|
|
382
382
|
});
|
|
@@ -122,7 +122,7 @@ async function getPackageRoot() {
|
|
|
122
122
|
packageRootPromise = (async () => {
|
|
123
123
|
const {
|
|
124
124
|
packageDirectory
|
|
125
|
-
} = await Promise.resolve().then(function () { return require('../
|
|
125
|
+
} = await Promise.resolve().then(function () { return require('../index3.cjs'); });
|
|
126
126
|
return packageDirectory({
|
|
127
127
|
cwd: path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('shared/package-manager.cjs', document.baseURI).href))))
|
|
128
128
|
});
|
|
@@ -603,7 +603,7 @@ async function addToPackageManagerWorkspaces(directory, output, packageManager)
|
|
|
603
603
|
const {
|
|
604
604
|
parse,
|
|
605
605
|
stringify
|
|
606
|
-
} = await Promise.resolve().then(function () { return require('../
|
|
606
|
+
} = await Promise.resolve().then(function () { return require('../index4.cjs'); }).then(function (n) { return n.index; });
|
|
607
607
|
const workspaceYaml = parse(await output.read('pnpm-workspace.yaml'));
|
|
608
608
|
workspaceYaml.packages = await addToWorkspaces(path.relative(output.root, directory), workspaceYaml.packages ?? []);
|
|
609
609
|
await output.write('pnpm-workspace.yaml', await format(stringify(workspaceYaml), {
|
package/build/esm/app.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
+
import { a as arg_1 } from './index2.mjs';
|
|
3
4
|
import { c as cyan_1, b as bold_1, g as getInWorkspace, a as getCreateAsMonorepo, d as getExtrasToSetup, e as getShouldInstall, f as getPackageManager, h as emptyDirectory, r as relativeDirectoryForDisplay, t as toValidPackageName, i as format, m as mergeWorkspaceAndProjectPackageJsons, l as loadTemplate, j as addToTsConfig, k as addToPackageManagerWorkspaces, n as dim_1, u as underline_1, o as magenta_1, p as isEmpty, q as createOutputTarget } from './shared/package-manager.mjs';
|
|
4
5
|
import { s as stripIndent, p as printHelp, a as prompt } from './index.mjs';
|
|
5
6
|
import 'node:tty';
|
|
@@ -8,202 +9,6 @@ import 'node:url';
|
|
|
8
9
|
import 'node:readline';
|
|
9
10
|
import 'node:events';
|
|
10
11
|
|
|
11
|
-
const flagSymbol = Symbol('arg flag');
|
|
12
|
-
|
|
13
|
-
class ArgError extends Error {
|
|
14
|
-
constructor(msg, code) {
|
|
15
|
-
super(msg);
|
|
16
|
-
this.name = 'ArgError';
|
|
17
|
-
this.code = code;
|
|
18
|
-
|
|
19
|
-
Object.setPrototypeOf(this, ArgError.prototype);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function arg(
|
|
24
|
-
opts,
|
|
25
|
-
{
|
|
26
|
-
argv = process.argv.slice(2),
|
|
27
|
-
permissive = false,
|
|
28
|
-
stopAtPositional = false
|
|
29
|
-
} = {}
|
|
30
|
-
) {
|
|
31
|
-
if (!opts) {
|
|
32
|
-
throw new ArgError(
|
|
33
|
-
'argument specification object is required',
|
|
34
|
-
'ARG_CONFIG_NO_SPEC'
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const result = { _: [] };
|
|
39
|
-
|
|
40
|
-
const aliases = {};
|
|
41
|
-
const handlers = {};
|
|
42
|
-
|
|
43
|
-
for (const key of Object.keys(opts)) {
|
|
44
|
-
if (!key) {
|
|
45
|
-
throw new ArgError(
|
|
46
|
-
'argument key cannot be an empty string',
|
|
47
|
-
'ARG_CONFIG_EMPTY_KEY'
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (key[0] !== '-') {
|
|
52
|
-
throw new ArgError(
|
|
53
|
-
`argument key must start with '-' but found: '${key}'`,
|
|
54
|
-
'ARG_CONFIG_NONOPT_KEY'
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (key.length === 1) {
|
|
59
|
-
throw new ArgError(
|
|
60
|
-
`argument key must have a name; singular '-' keys are not allowed: ${key}`,
|
|
61
|
-
'ARG_CONFIG_NONAME_KEY'
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (typeof opts[key] === 'string') {
|
|
66
|
-
aliases[key] = opts[key];
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
let type = opts[key];
|
|
71
|
-
let isFlag = false;
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
Array.isArray(type) &&
|
|
75
|
-
type.length === 1 &&
|
|
76
|
-
typeof type[0] === 'function'
|
|
77
|
-
) {
|
|
78
|
-
const [fn] = type;
|
|
79
|
-
type = (value, name, prev = []) => {
|
|
80
|
-
prev.push(fn(value, name, prev[prev.length - 1]));
|
|
81
|
-
return prev;
|
|
82
|
-
};
|
|
83
|
-
isFlag = fn === Boolean || fn[flagSymbol] === true;
|
|
84
|
-
} else if (typeof type === 'function') {
|
|
85
|
-
isFlag = type === Boolean || type[flagSymbol] === true;
|
|
86
|
-
} else {
|
|
87
|
-
throw new ArgError(
|
|
88
|
-
`type missing or not a function or valid array type: ${key}`,
|
|
89
|
-
'ARG_CONFIG_VAD_TYPE'
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (key[1] !== '-' && key.length > 2) {
|
|
94
|
-
throw new ArgError(
|
|
95
|
-
`short argument keys (with a single hyphen) must have only one character: ${key}`,
|
|
96
|
-
'ARG_CONFIG_SHORTOPT_TOOLONG'
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
handlers[key] = [type, isFlag];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
for (let i = 0, len = argv.length; i < len; i++) {
|
|
104
|
-
const wholeArg = argv[i];
|
|
105
|
-
|
|
106
|
-
if (stopAtPositional && result._.length > 0) {
|
|
107
|
-
result._ = result._.concat(argv.slice(i));
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (wholeArg === '--') {
|
|
112
|
-
result._ = result._.concat(argv.slice(i + 1));
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (wholeArg.length > 1 && wholeArg[0] === '-') {
|
|
117
|
-
/* eslint-disable operator-linebreak */
|
|
118
|
-
const separatedArguments =
|
|
119
|
-
wholeArg[1] === '-' || wholeArg.length === 2
|
|
120
|
-
? [wholeArg]
|
|
121
|
-
: wholeArg
|
|
122
|
-
.slice(1)
|
|
123
|
-
.split('')
|
|
124
|
-
.map((a) => `-${a}`);
|
|
125
|
-
/* eslint-enable operator-linebreak */
|
|
126
|
-
|
|
127
|
-
for (let j = 0; j < separatedArguments.length; j++) {
|
|
128
|
-
const arg = separatedArguments[j];
|
|
129
|
-
const [originalArgName, argStr] =
|
|
130
|
-
arg[1] === '-' ? arg.split(/=(.*)/, 2) : [arg, undefined];
|
|
131
|
-
|
|
132
|
-
let argName = originalArgName;
|
|
133
|
-
while (argName in aliases) {
|
|
134
|
-
argName = aliases[argName];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (!(argName in handlers)) {
|
|
138
|
-
if (permissive) {
|
|
139
|
-
result._.push(arg);
|
|
140
|
-
continue;
|
|
141
|
-
} else {
|
|
142
|
-
throw new ArgError(
|
|
143
|
-
`unknown or unexpected option: ${originalArgName}`,
|
|
144
|
-
'ARG_UNKNOWN_OPTION'
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const [type, isFlag] = handlers[argName];
|
|
150
|
-
|
|
151
|
-
if (!isFlag && j + 1 < separatedArguments.length) {
|
|
152
|
-
throw new ArgError(
|
|
153
|
-
`option requires argument (but was followed by another short argument): ${originalArgName}`,
|
|
154
|
-
'ARG_MISSING_REQUIRED_SHORTARG'
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (isFlag) {
|
|
159
|
-
result[argName] = type(true, argName, result[argName]);
|
|
160
|
-
} else if (argStr === undefined) {
|
|
161
|
-
if (
|
|
162
|
-
argv.length < i + 2 ||
|
|
163
|
-
(argv[i + 1].length > 1 &&
|
|
164
|
-
argv[i + 1][0] === '-' &&
|
|
165
|
-
!(
|
|
166
|
-
argv[i + 1].match(/^-?\d*(\.(?=\d))?\d*$/) &&
|
|
167
|
-
(type === Number ||
|
|
168
|
-
// eslint-disable-next-line no-undef
|
|
169
|
-
(typeof BigInt !== 'undefined' && type === BigInt))
|
|
170
|
-
))
|
|
171
|
-
) {
|
|
172
|
-
const extended =
|
|
173
|
-
originalArgName === argName ? '' : ` (alias for ${argName})`;
|
|
174
|
-
throw new ArgError(
|
|
175
|
-
`option requires argument: ${originalArgName}${extended}`,
|
|
176
|
-
'ARG_MISSING_REQUIRED_LONGARG'
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
result[argName] = type(argv[i + 1], argName, result[argName]);
|
|
181
|
-
++i;
|
|
182
|
-
} else {
|
|
183
|
-
result[argName] = type(argStr, argName, result[argName]);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
} else {
|
|
187
|
-
result._.push(wholeArg);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return result;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
arg.flag = (fn) => {
|
|
195
|
-
fn[flagSymbol] = true;
|
|
196
|
-
return fn;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
// Utility types
|
|
200
|
-
arg.COUNT = arg.flag((v, name, existingCount) => (existingCount || 0) + 1);
|
|
201
|
-
|
|
202
|
-
// Expose error class
|
|
203
|
-
arg.ArgError = ArgError;
|
|
204
|
-
|
|
205
|
-
var arg_1 = arg;
|
|
206
|
-
|
|
207
12
|
async function createApp() {
|
|
208
13
|
const argv = getArgv();
|
|
209
14
|
if (argv['--help']) {
|
package/build/esm/index.mjs
CHANGED
|
@@ -7122,6 +7122,7 @@ function printHelp({
|
|
|
7122
7122
|
|
|
7123
7123
|
- ${magenta_1('app')}, a web application
|
|
7124
7124
|
- ${magenta_1('package')}, a shared library of code
|
|
7125
|
+
- ${magenta_1('module')}, a standalone JavaScript module for a browser
|
|
7125
7126
|
|
|
7126
7127
|
You’ll be asked a few additional questions based on the kind you choose.
|
|
7127
7128
|
`;
|
|
@@ -7194,7 +7195,7 @@ function createCommand(explicitPackageManager) {
|
|
|
7194
7195
|
}
|
|
7195
7196
|
|
|
7196
7197
|
/* eslint no-console: off */
|
|
7197
|
-
const VALID_PROJECT_KINDS = new Set(['app', 'package']);
|
|
7198
|
+
const VALID_PROJECT_KINDS = new Set(['app', 'package', 'module']);
|
|
7198
7199
|
run().catch(error => {
|
|
7199
7200
|
if (AbortError.test(error)) return;
|
|
7200
7201
|
console.error(error);
|
|
@@ -7233,6 +7234,9 @@ async function run() {
|
|
|
7233
7234
|
choices: [{
|
|
7234
7235
|
title: 'App',
|
|
7235
7236
|
value: 'app'
|
|
7237
|
+
}, {
|
|
7238
|
+
title: 'Module',
|
|
7239
|
+
value: 'module'
|
|
7236
7240
|
}, {
|
|
7237
7241
|
title: 'Package',
|
|
7238
7242
|
value: 'package'
|
|
@@ -7248,6 +7252,14 @@ async function run() {
|
|
|
7248
7252
|
await createApp();
|
|
7249
7253
|
break;
|
|
7250
7254
|
}
|
|
7255
|
+
case 'module':
|
|
7256
|
+
{
|
|
7257
|
+
const {
|
|
7258
|
+
createModule
|
|
7259
|
+
} = await import('./module.mjs');
|
|
7260
|
+
await createModule();
|
|
7261
|
+
break;
|
|
7262
|
+
}
|
|
7251
7263
|
case 'package':
|
|
7252
7264
|
{
|
|
7253
7265
|
const {
|