@stencil/cli 5.0.0-alpha.8 → 5.0.0-beta.0
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 +72 -0
- package/dist/index.d.mts +179 -6
- package/dist/index.mjs +878 -156
- package/package.json +11 -10
- /package/{LICENSE.md → LICENSE} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @stencil/cli
|
|
2
|
+
|
|
3
|
+
CLI for [Stencil](https://stenciljs.com) - build, test, and generate web components.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @stencil/cli @stencil/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Build
|
|
15
|
+
npx stencil build
|
|
16
|
+
|
|
17
|
+
# Build in watch mode
|
|
18
|
+
npx stencil build --watch
|
|
19
|
+
|
|
20
|
+
# Generate a new component
|
|
21
|
+
npx stencil generate my-component
|
|
22
|
+
|
|
23
|
+
# Start dev server
|
|
24
|
+
npx stencil build --dev --watch --serve
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Programmatic API
|
|
28
|
+
|
|
29
|
+
### `run(init)` - invoke the CLI from code
|
|
30
|
+
|
|
31
|
+
Mirrors running `stencil <task>` in the terminal. Parse your own `args` array and Stencil handles the rest.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { run } from '@stencil/cli';
|
|
35
|
+
import { createNodeLogger, createNodeSys } from '@stencil/core/sys/node';
|
|
36
|
+
|
|
37
|
+
await run({
|
|
38
|
+
args: ['build', '--dev', '--watch'],
|
|
39
|
+
logger: createNodeLogger(),
|
|
40
|
+
sys: createNodeSys(),
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### `runTask(coreCompiler, config, task, sys, flags?)` - lower-level task execution
|
|
45
|
+
|
|
46
|
+
Use this when you need control over the compiler instance or config before running a task. You are responsible for loading the compiler and config yourself.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import * as coreCompiler from '@stencil/core/compiler';
|
|
50
|
+
import { runTask, createConfigFlags } from '@stencil/cli';
|
|
51
|
+
import { createNodeLogger, createNodeSys } from '@stencil/core/sys/node';
|
|
52
|
+
|
|
53
|
+
const logger = createNodeLogger();
|
|
54
|
+
const sys = createNodeSys();
|
|
55
|
+
|
|
56
|
+
// Load and validate stencil.config.ts
|
|
57
|
+
const { config, diagnostics } = await coreCompiler.loadConfig({
|
|
58
|
+
configPath: './stencil.config.ts',
|
|
59
|
+
logger,
|
|
60
|
+
sys,
|
|
61
|
+
});
|
|
62
|
+
if (diagnostics.length) logger.printDiagnostics(diagnostics);
|
|
63
|
+
|
|
64
|
+
// Optional: override config flags (e.g. force dev mode)
|
|
65
|
+
const flags = createConfigFlags({ task: 'build', dev: true });
|
|
66
|
+
|
|
67
|
+
await runTask(coreCompiler, config, 'build', sys, flags);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Valid `task` values: `'build'` | `'docs'` | `'generate'` | `'serve'` | `'prerender'` | `'info'` | `'migrate'` | `'init'` | `'add'` | `'telemetry'`
|
|
71
|
+
|
|
72
|
+
`flags` is optional - if omitted, defaults are derived from the task.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import * as d from "@stencil/core/compiler";
|
|
2
2
|
import { ConfigCompat, LogLevel, OutputTarget } from "@stencil/core/compiler";
|
|
3
|
-
|
|
4
3
|
//#region src/types.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Supported CLI task commands
|
|
7
6
|
*/
|
|
8
|
-
type TaskCommand = 'add' | 'build' | 'docs' | 'generate' | 'g' | 'help' | 'info' | 'init' | 'migrate' | 'prerender' | 'serve' | 'telemetry' | '
|
|
7
|
+
type TaskCommand = 'add' | 'build' | 'docs' | 'generate' | 'g' | 'help' | 'info' | 'init' | 'migrate' | 'prerender' | 'serve' | 'telemetry' | 'version';
|
|
9
8
|
//#endregion
|
|
10
9
|
//#region src/config-flags.d.ts
|
|
11
10
|
/**
|
|
12
11
|
* All the Boolean options supported by the Stencil CLI
|
|
13
12
|
*/
|
|
14
|
-
declare const BOOLEAN_CLI_FLAGS: readonly ["build", "cache", "
|
|
13
|
+
declare const BOOLEAN_CLI_FLAGS: readonly ["build", "cache", "ci", "debug", "dev", "docs", "dryRun", "help", "log", "open", "prerender", "profile", "serviceWorker", "serve", "ssr", "verbose", "version", "watch"];
|
|
15
14
|
/**
|
|
16
15
|
* All the Number options supported by the Stencil CLI
|
|
17
16
|
*/
|
|
@@ -19,7 +18,7 @@ declare const NUMBER_CLI_FLAGS: readonly ["port"];
|
|
|
19
18
|
/**
|
|
20
19
|
* All the String options supported by the Stencil CLI
|
|
21
20
|
*/
|
|
22
|
-
declare const STRING_CLI_FLAGS: readonly ["address", "config", "
|
|
21
|
+
declare const STRING_CLI_FLAGS: readonly ["address", "config", "docsJson", "root"];
|
|
23
22
|
declare const STRING_ARRAY_CLI_FLAGS: readonly [];
|
|
24
23
|
/**
|
|
25
24
|
* All the CLI arguments which may have string or number values
|
|
@@ -48,7 +47,7 @@ declare const LOG_LEVEL_CLI_FLAGS: readonly ["logLevel"];
|
|
|
48
47
|
* for which we want optional keys, we make all the properties optional (w/ `'?'`)
|
|
49
48
|
* and possibly null.
|
|
50
49
|
*/
|
|
51
|
-
type ObjectFromKeys<K extends ReadonlyArray<string>, T> = { [key in K[number]]?: T | null };
|
|
50
|
+
type ObjectFromKeys<K extends ReadonlyArray<string>, T> = { [key in K[number]]?: T | null; };
|
|
52
51
|
/**
|
|
53
52
|
* Type containing the possible Boolean configuration flags, to be included
|
|
54
53
|
* in ConfigFlags, below
|
|
@@ -176,6 +175,157 @@ interface ProjectConfig {
|
|
|
176
175
|
/** Enable signal-based reactivity backing (top-level in stencil.config.ts). */
|
|
177
176
|
signalBacking?: boolean;
|
|
178
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Structured editor for `stencil.config.ts`, backed by the TypeScript compiler API.
|
|
180
|
+
* Obtain one via {@link WizardContext.openStencilConfig}.
|
|
181
|
+
*
|
|
182
|
+
* All mutation methods accumulate edits in memory. Call {@link save} once to
|
|
183
|
+
* write them all back to disk in a single pass.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* const editor = await ctx.openStencilConfig();
|
|
187
|
+
* editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
|
|
188
|
+
* editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
|
|
189
|
+
* await editor.save();
|
|
190
|
+
*/
|
|
191
|
+
interface StencilConfigEditor {
|
|
192
|
+
/**
|
|
193
|
+
* Returns `true` if any import from `moduleSpecifier` already exists in the file.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* if (!editor.hasImport('@stencil/vue-output-target')) {
|
|
197
|
+
* editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
|
|
198
|
+
* }
|
|
199
|
+
*/
|
|
200
|
+
hasImport(moduleSpecifier: string): boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Adds `import { ...namedImports } from 'moduleSpecifier'` after the last
|
|
203
|
+
* existing import in the file. No-op if any import from `moduleSpecifier`
|
|
204
|
+
* already exists.
|
|
205
|
+
*
|
|
206
|
+
* @param moduleSpecifier - The module to import from, e.g. `'@stencil/sass'`.
|
|
207
|
+
* @param namedImports - At least one named export to import.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
|
|
211
|
+
* // > import { vueOutputTarget } from '@stencil/vue-output-target';
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* editor.addImport('@stencil/sass', ['sass']);
|
|
215
|
+
* // > import { sass } from '@stencil/sass';
|
|
216
|
+
*/
|
|
217
|
+
addImport(moduleSpecifier: string, namedImports: [string, ...string[]]): void;
|
|
218
|
+
/**
|
|
219
|
+
* Returns `true` if `substring` appears anywhere in the text of the
|
|
220
|
+
* `outputTargets` array. Use this to guard against adding the same target twice.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* if (!editor.outputTargetsContains('vueOutputTarget(')) {
|
|
224
|
+
* editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
|
|
225
|
+
* }
|
|
226
|
+
*/
|
|
227
|
+
outputTargetsContains(substring: string): boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Appends `expression` as a new element in the `outputTargets` array,
|
|
230
|
+
* creating the `outputTargets` property if it is absent from the config.
|
|
231
|
+
*
|
|
232
|
+
* `expression` is a TypeScript expression that is inserted verbatim into
|
|
233
|
+
* the source file. It must evaluate to a value assignable to {@link OutputTarget}
|
|
234
|
+
* - built-in targets use object literal syntax (e.g. `"{ type: 'standalone' }"`),
|
|
235
|
+
* while third-party targets are function calls that return `OutputTargetCustom`
|
|
236
|
+
* (e.g. `"vueOutputTarget({...})"`). Call {@link addImport} first to bring the
|
|
237
|
+
* factory function into scope.
|
|
238
|
+
*
|
|
239
|
+
* @param expression - A TypeScript expression, e.g. `"{ type: 'standalone' }"`
|
|
240
|
+
* or `"vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })"`.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* // Built-in target (object literal):
|
|
244
|
+
* editor.addOutputTarget("{ type: 'standalone' }");
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* // Third-party target (OutputTargetCustom - add the import first):
|
|
248
|
+
* editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
|
|
249
|
+
* editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
|
|
250
|
+
*/
|
|
251
|
+
addOutputTarget(expression: string): void;
|
|
252
|
+
/**
|
|
253
|
+
* Replaces the first element in the `outputTargets` array whose text contains
|
|
254
|
+
* `substring` with `expression` in-place. Returns `true` if a match was found
|
|
255
|
+
* and replaced, `false` if no element contained `substring`.
|
|
256
|
+
*
|
|
257
|
+
* Useful for the reconfigure flow — the replaced target stays at the same
|
|
258
|
+
* position in the array rather than being moved to the end.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* // Replace if already configured, otherwise append:
|
|
262
|
+
* if (!editor.replaceOutputTarget('vueOutputTarget(', newExpression)) {
|
|
263
|
+
* editor.addOutputTarget(newExpression);
|
|
264
|
+
* }
|
|
265
|
+
*/
|
|
266
|
+
replaceOutputTarget(substring: string, expression: string): boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Removes the first element in the `outputTargets` array whose text contains
|
|
269
|
+
* `substring`. Returns `true` if an element was removed, `false` if no match
|
|
270
|
+
* was found.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* editor.removeOutputTarget('vueOutputTarget(');
|
|
274
|
+
*/
|
|
275
|
+
removeOutputTarget(substring: string): boolean;
|
|
276
|
+
/**
|
|
277
|
+
* Returns `true` if `substring` appears anywhere in the text of the
|
|
278
|
+
* `plugins` array. Use this to guard against adding the same plugin twice.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* if (!editor.pluginsContains('sass(')) {
|
|
282
|
+
* editor.addPlugin('sass()');
|
|
283
|
+
* }
|
|
284
|
+
*/
|
|
285
|
+
pluginsContains(substring: string): boolean;
|
|
286
|
+
/**
|
|
287
|
+
* Appends `expression` as a new element in the `plugins` array,
|
|
288
|
+
* creating the `plugins` property if it is absent from the config.
|
|
289
|
+
*
|
|
290
|
+
* `expression` is a TypeScript expression that is inserted verbatim into
|
|
291
|
+
* the source file. Call {@link addImport} first to bring the plugin factory
|
|
292
|
+
* into scope.
|
|
293
|
+
*
|
|
294
|
+
* @param expression - A TypeScript expression, e.g. `'sass()'` or
|
|
295
|
+
* `"sass({ injectGlobalPaths: ['src/global/variables.scss'] })"`.
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* editor.addImport('@stencil/sass', ['sass']);
|
|
299
|
+
* editor.addPlugin('sass()');
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* editor.addImport('@stencil/sass', ['sass']);
|
|
303
|
+
* editor.addPlugin("sass({ injectGlobalPaths: ['src/global/variables.scss'] })");
|
|
304
|
+
*/
|
|
305
|
+
addPlugin(expression: string): void;
|
|
306
|
+
/**
|
|
307
|
+
* Replaces the first element in the `plugins` array whose text contains
|
|
308
|
+
* `substring` with `expression` in-place. Returns `true` if a match was found
|
|
309
|
+
* and replaced, `false` if no element contained `substring`.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* if (!editor.replacePlugin('sass(', newSassCall)) {
|
|
313
|
+
* editor.addPlugin(newSassCall);
|
|
314
|
+
* }
|
|
315
|
+
*/
|
|
316
|
+
replacePlugin(substring: string, expression: string): boolean;
|
|
317
|
+
/**
|
|
318
|
+
* Removes the first element in the `plugins` array whose text contains
|
|
319
|
+
* `substring`. Returns `true` if an element was removed, `false` if no match
|
|
320
|
+
* was found.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* editor.removePlugin('sass(');
|
|
324
|
+
*/
|
|
325
|
+
removePlugin(substring: string): boolean;
|
|
326
|
+
/** Write all accumulated edits back to disk. */
|
|
327
|
+
save(): Promise<void>;
|
|
328
|
+
}
|
|
179
329
|
/**
|
|
180
330
|
* Context passed to wizard steps at runtime.
|
|
181
331
|
*/
|
|
@@ -188,6 +338,29 @@ interface WizardContext {
|
|
|
188
338
|
nypm: typeof import('nypm');
|
|
189
339
|
/** Resolved project config. See {@link ProjectConfig} for available fields. */
|
|
190
340
|
config: ProjectConfig;
|
|
341
|
+
/**
|
|
342
|
+
* Absolute path to the monorepo workspace root when the project is part of a
|
|
343
|
+
* workspace, `undefined` for single-package projects.
|
|
344
|
+
*
|
|
345
|
+
* When present, `config.rootDir` is the core Stencil package (e.g.
|
|
346
|
+
* `<workspaceRoot>/packages/core/`). The plugin is responsible for deciding
|
|
347
|
+
* where in the workspace it wants to live and for creating that directory.
|
|
348
|
+
*/
|
|
349
|
+
workspaceRoot?: string;
|
|
350
|
+
/**
|
|
351
|
+
* Open the project's `stencil.config.ts` for structured editing.
|
|
352
|
+
* Use the returned {@link StencilConfigEditor} to add imports, output targets,
|
|
353
|
+
* and plugins, then call `save()` to persist.
|
|
354
|
+
*
|
|
355
|
+
* Use {@link ts} directly when you need to manipulate other files or perform
|
|
356
|
+
* operations the editor does not cover.
|
|
357
|
+
*/
|
|
358
|
+
openStencilConfig: () => Promise<StencilConfigEditor>;
|
|
359
|
+
/**
|
|
360
|
+
* TypeScript compiler API. Available for advanced AST manipulation beyond
|
|
361
|
+
* what {@link openStencilConfig} covers.
|
|
362
|
+
*/
|
|
363
|
+
ts: typeof import('typescript');
|
|
191
364
|
}
|
|
192
365
|
/**
|
|
193
366
|
* A single file a plugin can offer during `stencil generate`.
|
|
@@ -284,4 +457,4 @@ interface StencilWizardPlugin {
|
|
|
284
457
|
init?: WizardInitContribution;
|
|
285
458
|
}
|
|
286
459
|
//#endregion
|
|
287
|
-
export { BOOLEAN_CLI_FLAGS, type ConfigFlags, type GenerateContext, type ProjectConfig, type StencilWizardPlugin, type TaskCommand, type WizardContext, type WizardFileTemplate, type WizardGenerateContribution, type WizardInitContribution, createConfigFlags, parseFlags, run, runTask };
|
|
460
|
+
export { BOOLEAN_CLI_FLAGS, type ConfigFlags, type GenerateContext, type ProjectConfig, type StencilConfigEditor, type StencilWizardPlugin, type TaskCommand, type WizardContext, type WizardFileTemplate, type WizardGenerateContribution, type WizardInitContribution, createConfigFlags, parseFlags, run, runTask };
|