@wc-toolkit/cem-generator-cli 0.1.2 → 0.1.3
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/README.md +22 -4
- package/dist/cli.js +36 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ cem init --plugin lit svelte
|
|
|
21
21
|
cem generate
|
|
22
22
|
|
|
23
23
|
# Specify custom tsconfig and output path
|
|
24
|
-
cem generate --
|
|
24
|
+
cem generate --tsconfig ./tsconfig.json --output ./custom-elements.json
|
|
25
25
|
|
|
26
26
|
# Include/exclude specific files
|
|
27
27
|
cem generate --include "src/components/**" --exclude "**/*.test.ts"
|
|
@@ -39,13 +39,27 @@ cem generate --no-inheritance
|
|
|
39
39
|
which parser plugins to use, then presents a multi-select list of integrations:
|
|
40
40
|
`react-wrappers`, `jsx-types`, `vuejs-types`, and `svelte-types`. The type
|
|
41
41
|
integrations use `./types` and strongly typed events by default. The command
|
|
42
|
-
also
|
|
42
|
+
also asks whether to add the generated manifest to `package.json` as the
|
|
43
|
+
`customElements` property. It supports `--plugin <names...>`,
|
|
43
44
|
`--yes`, `--force`, and `--config <path>`.
|
|
44
45
|
|
|
46
|
+
When accepted, the package.json property uses the default manifest path:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"customElements": "custom-elements.json"
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Use `filePath` in the config when the manifest belongs in a build directory.
|
|
55
|
+
|
|
45
56
|
`cem generate` uses source-oriented include/exclude defaults when those flags
|
|
46
57
|
are omitted. Supplying either flag replaces its defaults. The TypeScript
|
|
47
58
|
configuration still controls which files enter the program.
|
|
48
59
|
|
|
60
|
+
The config file may set `filePath` to choose the generated manifest path. The
|
|
61
|
+
`--output` flag takes precedence when supplied.
|
|
62
|
+
|
|
49
63
|
When `cem init` installs dependencies, CLI mode installs
|
|
50
64
|
`@wc-toolkit/cem-generator-cli`, while code mode installs
|
|
51
65
|
`@wc-toolkit/cem-generator` and `tsx`. Selected parser and integration
|
|
@@ -58,7 +72,8 @@ back to comma-separated selection numbers.
|
|
|
58
72
|
|
|
59
73
|
| Option | Description | Default |
|
|
60
74
|
|--------|-------------|---------|
|
|
61
|
-
|
|
|
75
|
+
| `--tsconfig <path>` | Path to tsconfig.json | `./tsconfig.json` |
|
|
76
|
+
| `-c, --config <path>` | Path to the generator config file | auto-detected |
|
|
62
77
|
| `-o, --output <path>` | Output file path | `./custom-elements.json` |
|
|
63
78
|
| `--include <patterns...>` | Glob patterns to include | `src/**/*.{ts,tsx,js,jsx}` when `src/` exists |
|
|
64
79
|
| `--exclude <patterns...>` | Glob patterns to exclude | Tests, specs, stories, `dist/`, and `node_modules/` |
|
|
@@ -66,9 +81,12 @@ back to comma-separated selection numbers.
|
|
|
66
81
|
| `--plugin <paths...>` | Additional plugin paths to load | - |
|
|
67
82
|
| `--conflict-policy <policy>` | Detector conflict policy: `throw` \| `last-wins` | `last-wins` |
|
|
68
83
|
|
|
84
|
+
The config file may set `filePath` for the manifest path. The `--output` flag
|
|
85
|
+
takes precedence over `filePath`.
|
|
86
|
+
|
|
69
87
|
## Example
|
|
70
88
|
|
|
71
89
|
```bash
|
|
72
90
|
# Basic manifest generation
|
|
73
|
-
cem generate --
|
|
91
|
+
cem generate --tsconfig tsconfig.json --output custom-elements.json
|
|
74
92
|
```
|
package/dist/cli.js
CHANGED
|
@@ -46,6 +46,7 @@ const INTEGRATION_CHOICES = [
|
|
|
46
46
|
},
|
|
47
47
|
];
|
|
48
48
|
const DEFAULT_SOURCE_INCLUDE = ["src/**/*.{ts,tsx,js,jsx}"];
|
|
49
|
+
const DEFAULT_MANIFEST_PATH = "./custom-elements.json";
|
|
49
50
|
const DEFAULT_SOURCE_EXCLUDE = [
|
|
50
51
|
"**/*.test.*",
|
|
51
52
|
"**/*.spec.*",
|
|
@@ -63,7 +64,7 @@ program
|
|
|
63
64
|
.description("Generate a Custom Elements Manifest")
|
|
64
65
|
.option("--tsconfig <path>", "Path to tsconfig.json", "./tsconfig.json")
|
|
65
66
|
.option("-c, --config <path>", "Path to cem-generator config file (auto-detected if omitted)")
|
|
66
|
-
.option("-o, --output <path>", "Output file path"
|
|
67
|
+
.option("-o, --output <path>", "Output file path")
|
|
67
68
|
.option("--include <patterns...>", "Glob patterns to include")
|
|
68
69
|
.option("--exclude <patterns...>", "Glob patterns to exclude")
|
|
69
70
|
.option("--no-inheritance", "Disable inheritance materialization")
|
|
@@ -127,7 +128,7 @@ program
|
|
|
127
128
|
console.log(`Using config file: ${configPath}`);
|
|
128
129
|
}
|
|
129
130
|
const manifest = generateCem(mergedOptions);
|
|
130
|
-
const outputPath = path.resolve(options.output);
|
|
131
|
+
const outputPath = path.resolve(options.output ?? mergedOptions.filePath ?? "./custom-elements.json");
|
|
131
132
|
const outputDir = path.dirname(outputPath);
|
|
132
133
|
if (!fs.existsSync(outputDir)) {
|
|
133
134
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
@@ -200,12 +201,16 @@ program
|
|
|
200
201
|
if (shouldInstall) {
|
|
201
202
|
installPluginDependencies(packagesToInstall);
|
|
202
203
|
}
|
|
204
|
+
const addManifestToPackageJson = !options.yes && await promptForPackageManifest(cwd);
|
|
203
205
|
fs.writeFileSync(configPath, createConfigSource(selectedPlugins, selectedIntegrations, getDefaultInclude(cwd), DEFAULT_SOURCE_EXCLUDE), "utf-8");
|
|
204
206
|
console.log(`Created config file at ${configPath}`);
|
|
205
207
|
if (mode === "code") {
|
|
206
208
|
fs.writeFileSync(outputPath, createCodeSource(configPath, outputPath), "utf-8");
|
|
207
209
|
console.log(`Created code file at ${outputPath}`);
|
|
208
210
|
}
|
|
211
|
+
if (addManifestToPackageJson) {
|
|
212
|
+
updatePackageJsonManifestPath(cwd, DEFAULT_MANIFEST_PATH);
|
|
213
|
+
}
|
|
209
214
|
printNextSteps(mode, configPath, outputPath);
|
|
210
215
|
}
|
|
211
216
|
catch (error) {
|
|
@@ -314,6 +319,35 @@ async function promptForInstall() {
|
|
|
314
319
|
prompt.close();
|
|
315
320
|
}
|
|
316
321
|
}
|
|
322
|
+
async function promptForPackageManifest(cwd) {
|
|
323
|
+
const packageJsonPath = path.join(cwd, "package.json");
|
|
324
|
+
if (!fs.existsSync(packageJsonPath))
|
|
325
|
+
return false;
|
|
326
|
+
if (isInteractiveTerminal()) {
|
|
327
|
+
const { addManifest } = await inquirer.prompt({
|
|
328
|
+
type: "confirm",
|
|
329
|
+
name: "addManifest",
|
|
330
|
+
message: `Add \"customElements\": \"${DEFAULT_MANIFEST_PATH.slice(2)}\" to package.json?`,
|
|
331
|
+
default: false,
|
|
332
|
+
});
|
|
333
|
+
return addManifest;
|
|
334
|
+
}
|
|
335
|
+
const prompt = readline.createInterface({ input, output });
|
|
336
|
+
try {
|
|
337
|
+
const answer = await prompt.question(`Add "customElements": "${DEFAULT_MANIFEST_PATH.slice(2)}" to package.json? (y/N): `);
|
|
338
|
+
return /^y(es)?$/i.test(answer.trim());
|
|
339
|
+
}
|
|
340
|
+
finally {
|
|
341
|
+
prompt.close();
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function updatePackageJsonManifestPath(cwd, manifestPath) {
|
|
345
|
+
const packageJsonPath = path.join(cwd, "package.json");
|
|
346
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
347
|
+
packageJson.customElements = manifestPath.replace(/^\.\//, "");
|
|
348
|
+
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`, "utf-8");
|
|
349
|
+
console.log(`Updated package.json with customElements: ${packageJson.customElements}`);
|
|
350
|
+
}
|
|
317
351
|
function installPluginDependencies(packages) {
|
|
318
352
|
const packageManager = detectPackageManager();
|
|
319
353
|
const args = packageManager === "npm"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wc-toolkit/cem-generator-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "CLI for generating Custom Elements Manifests.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"commander": "^12.1.0",
|
|
36
36
|
"custom-elements-manifest": "^2.1.0",
|
|
37
37
|
"inquirer": "^14.2.2",
|
|
38
|
-
"@wc-toolkit/cem-generator": "0.1.
|
|
38
|
+
"@wc-toolkit/cem-generator": "0.1.3",
|
|
39
39
|
"@wc-toolkit/cem-generator-utils": "0.1.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
"build": "tsc",
|
|
47
47
|
"test": "node --test tests/*.test.mjs",
|
|
48
48
|
"dev": "tsx src/cli.ts",
|
|
49
|
-
"demo": "node dist/cli.js generate --
|
|
49
|
+
"demo": "node dist/cli.js generate --tsconfig ../../examples/tsconfig.json --output ../../examples/custom-elements-demo.json --conflict-policy last-wins"
|
|
50
50
|
}
|
|
51
51
|
}
|