@stencil/cli 5.0.0-alpha.16 → 5.0.0-alpha.17
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 +76 -0
- package/dist/index.d.mts +166 -1
- package/dist/index.mjs +166 -6
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
# Run tests
|
|
21
|
+
npx stencil test --spec
|
|
22
|
+
npx stencil test --e2e
|
|
23
|
+
|
|
24
|
+
# Generate a new component
|
|
25
|
+
npx stencil generate my-component
|
|
26
|
+
|
|
27
|
+
# Start dev server
|
|
28
|
+
npx stencil build --dev --watch --serve
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Programmatic API
|
|
32
|
+
|
|
33
|
+
### `run(init)` — invoke the CLI from code
|
|
34
|
+
|
|
35
|
+
Mirrors running `stencil <task>` in the terminal. Parse your own `args` array and Stencil handles the rest.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { run } from '@stencil/cli';
|
|
39
|
+
import { createNodeLogger, createNodeSys } from '@stencil/core/sys/node';
|
|
40
|
+
|
|
41
|
+
await run({
|
|
42
|
+
args: ['build', '--dev', '--watch'],
|
|
43
|
+
logger: createNodeLogger(),
|
|
44
|
+
sys: createNodeSys(),
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### `runTask(coreCompiler, config, task, sys, flags?)` — lower-level task execution
|
|
49
|
+
|
|
50
|
+
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.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import * as coreCompiler from '@stencil/core/compiler';
|
|
54
|
+
import { runTask, createConfigFlags } from '@stencil/cli';
|
|
55
|
+
import { createNodeLogger, createNodeSys } from '@stencil/core/sys/node';
|
|
56
|
+
|
|
57
|
+
const logger = createNodeLogger();
|
|
58
|
+
const sys = createNodeSys();
|
|
59
|
+
|
|
60
|
+
// Load and validate stencil.config.ts
|
|
61
|
+
const { config, diagnostics } = await coreCompiler.loadConfig({
|
|
62
|
+
configPath: './stencil.config.ts',
|
|
63
|
+
logger,
|
|
64
|
+
sys,
|
|
65
|
+
});
|
|
66
|
+
if (diagnostics.length) logger.printDiagnostics(diagnostics);
|
|
67
|
+
|
|
68
|
+
// Optional: override config flags (e.g. force dev mode)
|
|
69
|
+
const flags = createConfigFlags({ task: 'build', dev: true });
|
|
70
|
+
|
|
71
|
+
await runTask(coreCompiler, config, 'build', sys, flags);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Valid `task` values: `'build'` | `'docs'` | `'generate'` | `'serve'` | `'prerender'` | `'test'` | `'info'` | `'migrate'` | `'init'` | `'add'` | `'telemetry'`
|
|
75
|
+
|
|
76
|
+
`flags` is optional — if omitted, defaults are derived from the task.
|
package/dist/index.d.mts
CHANGED
|
@@ -176,6 +176,157 @@ interface ProjectConfig {
|
|
|
176
176
|
/** Enable signal-based reactivity backing (top-level in stencil.config.ts). */
|
|
177
177
|
signalBacking?: boolean;
|
|
178
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Structured editor for `stencil.config.ts`, backed by the TypeScript compiler API.
|
|
181
|
+
* Obtain one via {@link WizardContext.openStencilConfig}.
|
|
182
|
+
*
|
|
183
|
+
* All mutation methods accumulate edits in memory. Call {@link save} once to
|
|
184
|
+
* write them all back to disk in a single pass.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* const editor = await ctx.openStencilConfig();
|
|
188
|
+
* editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
|
|
189
|
+
* editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
|
|
190
|
+
* await editor.save();
|
|
191
|
+
*/
|
|
192
|
+
interface StencilConfigEditor {
|
|
193
|
+
/**
|
|
194
|
+
* Returns `true` if any import from `moduleSpecifier` already exists in the file.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* if (!editor.hasImport('@stencil/vue-output-target')) {
|
|
198
|
+
* editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
|
|
199
|
+
* }
|
|
200
|
+
*/
|
|
201
|
+
hasImport(moduleSpecifier: string): boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Adds `import { ...namedImports } from 'moduleSpecifier'` after the last
|
|
204
|
+
* existing import in the file. No-op if any import from `moduleSpecifier`
|
|
205
|
+
* already exists.
|
|
206
|
+
*
|
|
207
|
+
* @param moduleSpecifier - The module to import from, e.g. `'@stencil/sass'`.
|
|
208
|
+
* @param namedImports - At least one named export to import.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
|
|
212
|
+
* // > import { vueOutputTarget } from '@stencil/vue-output-target';
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* editor.addImport('@stencil/sass', ['sass']);
|
|
216
|
+
* // > import { sass } from '@stencil/sass';
|
|
217
|
+
*/
|
|
218
|
+
addImport(moduleSpecifier: string, namedImports: [string, ...string[]]): void;
|
|
219
|
+
/**
|
|
220
|
+
* Returns `true` if `substring` appears anywhere in the text of the
|
|
221
|
+
* `outputTargets` array. Use this to guard against adding the same target twice.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* if (!editor.outputTargetsContains('vueOutputTarget(')) {
|
|
225
|
+
* editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
|
|
226
|
+
* }
|
|
227
|
+
*/
|
|
228
|
+
outputTargetsContains(substring: string): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Appends `expression` as a new element in the `outputTargets` array,
|
|
231
|
+
* creating the `outputTargets` property if it is absent from the config.
|
|
232
|
+
*
|
|
233
|
+
* `expression` is a TypeScript expression that is inserted verbatim into
|
|
234
|
+
* the source file. It must evaluate to a value assignable to {@link OutputTarget}
|
|
235
|
+
* - built-in targets use object literal syntax (e.g. `"{ type: 'standalone' }"`),
|
|
236
|
+
* while third-party targets are function calls that return `OutputTargetCustom`
|
|
237
|
+
* (e.g. `"vueOutputTarget({...})"`). Call {@link addImport} first to bring the
|
|
238
|
+
* factory function into scope.
|
|
239
|
+
*
|
|
240
|
+
* @param expression - A TypeScript expression, e.g. `"{ type: 'standalone' }"`
|
|
241
|
+
* or `"vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })"`.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* // Built-in target (object literal):
|
|
245
|
+
* editor.addOutputTarget("{ type: 'standalone' }");
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* // Third-party target (OutputTargetCustom - add the import first):
|
|
249
|
+
* editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
|
|
250
|
+
* editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
|
|
251
|
+
*/
|
|
252
|
+
addOutputTarget(expression: string): void;
|
|
253
|
+
/**
|
|
254
|
+
* Replaces the first element in the `outputTargets` array whose text contains
|
|
255
|
+
* `substring` with `expression` in-place. Returns `true` if a match was found
|
|
256
|
+
* and replaced, `false` if no element contained `substring`.
|
|
257
|
+
*
|
|
258
|
+
* Useful for the reconfigure flow — the replaced target stays at the same
|
|
259
|
+
* position in the array rather than being moved to the end.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* // Replace if already configured, otherwise append:
|
|
263
|
+
* if (!editor.replaceOutputTarget('vueOutputTarget(', newExpression)) {
|
|
264
|
+
* editor.addOutputTarget(newExpression);
|
|
265
|
+
* }
|
|
266
|
+
*/
|
|
267
|
+
replaceOutputTarget(substring: string, expression: string): boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Removes the first element in the `outputTargets` array whose text contains
|
|
270
|
+
* `substring`. Returns `true` if an element was removed, `false` if no match
|
|
271
|
+
* was found.
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* editor.removeOutputTarget('vueOutputTarget(');
|
|
275
|
+
*/
|
|
276
|
+
removeOutputTarget(substring: string): boolean;
|
|
277
|
+
/**
|
|
278
|
+
* Returns `true` if `substring` appears anywhere in the text of the
|
|
279
|
+
* `plugins` array. Use this to guard against adding the same plugin twice.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* if (!editor.pluginsContains('sass(')) {
|
|
283
|
+
* editor.addPlugin('sass()');
|
|
284
|
+
* }
|
|
285
|
+
*/
|
|
286
|
+
pluginsContains(substring: string): boolean;
|
|
287
|
+
/**
|
|
288
|
+
* Appends `expression` as a new element in the `plugins` array,
|
|
289
|
+
* creating the `plugins` property if it is absent from the config.
|
|
290
|
+
*
|
|
291
|
+
* `expression` is a TypeScript expression that is inserted verbatim into
|
|
292
|
+
* the source file. Call {@link addImport} first to bring the plugin factory
|
|
293
|
+
* into scope.
|
|
294
|
+
*
|
|
295
|
+
* @param expression - A TypeScript expression, e.g. `'sass()'` or
|
|
296
|
+
* `"sass({ injectGlobalPaths: ['src/global/variables.scss'] })"`.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* editor.addImport('@stencil/sass', ['sass']);
|
|
300
|
+
* editor.addPlugin('sass()');
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* editor.addImport('@stencil/sass', ['sass']);
|
|
304
|
+
* editor.addPlugin("sass({ injectGlobalPaths: ['src/global/variables.scss'] })");
|
|
305
|
+
*/
|
|
306
|
+
addPlugin(expression: string): void;
|
|
307
|
+
/**
|
|
308
|
+
* Replaces the first element in the `plugins` array whose text contains
|
|
309
|
+
* `substring` with `expression` in-place. Returns `true` if a match was found
|
|
310
|
+
* and replaced, `false` if no element contained `substring`.
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* if (!editor.replacePlugin('sass(', newSassCall)) {
|
|
314
|
+
* editor.addPlugin(newSassCall);
|
|
315
|
+
* }
|
|
316
|
+
*/
|
|
317
|
+
replacePlugin(substring: string, expression: string): boolean;
|
|
318
|
+
/**
|
|
319
|
+
* Removes the first element in the `plugins` array whose text contains
|
|
320
|
+
* `substring`. Returns `true` if an element was removed, `false` if no match
|
|
321
|
+
* was found.
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* editor.removePlugin('sass(');
|
|
325
|
+
*/
|
|
326
|
+
removePlugin(substring: string): boolean;
|
|
327
|
+
/** Write all accumulated edits back to disk. */
|
|
328
|
+
save(): Promise<void>;
|
|
329
|
+
}
|
|
179
330
|
/**
|
|
180
331
|
* Context passed to wizard steps at runtime.
|
|
181
332
|
*/
|
|
@@ -197,6 +348,20 @@ interface WizardContext {
|
|
|
197
348
|
* where in the workspace it wants to live and for creating that directory.
|
|
198
349
|
*/
|
|
199
350
|
workspaceRoot?: string;
|
|
351
|
+
/**
|
|
352
|
+
* Open the project's `stencil.config.ts` for structured editing.
|
|
353
|
+
* Use the returned {@link StencilConfigEditor} to add imports, output targets,
|
|
354
|
+
* and plugins, then call `save()` to persist.
|
|
355
|
+
*
|
|
356
|
+
* Use {@link ts} directly when you need to manipulate other files or perform
|
|
357
|
+
* operations the editor does not cover.
|
|
358
|
+
*/
|
|
359
|
+
openStencilConfig: () => Promise<StencilConfigEditor>;
|
|
360
|
+
/**
|
|
361
|
+
* TypeScript compiler API. Available for advanced AST manipulation beyond
|
|
362
|
+
* what {@link openStencilConfig} covers.
|
|
363
|
+
*/
|
|
364
|
+
ts: typeof import('typescript');
|
|
200
365
|
}
|
|
201
366
|
/**
|
|
202
367
|
* A single file a plugin can offer during `stencil generate`.
|
|
@@ -293,4 +458,4 @@ interface StencilWizardPlugin {
|
|
|
293
458
|
init?: WizardInitContribution;
|
|
294
459
|
}
|
|
295
460
|
//#endregion
|
|
296
|
-
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 };
|
|
461
|
+
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -7,11 +7,11 @@ import { cancel, isCancel, select } from "@clack/prompts";
|
|
|
7
7
|
import * as nypm from "nypm";
|
|
8
8
|
import { addDevDependency, detectPackageManager, installDependencies } from "nypm";
|
|
9
9
|
import { isCI } from "std-env";
|
|
10
|
+
import ts from "typescript";
|
|
10
11
|
import { pathToFileURL } from "node:url";
|
|
11
12
|
import { existsSync } from "node:fs";
|
|
12
13
|
import { homedir } from "node:os";
|
|
13
14
|
import { dirname as dirname$1, isAbsolute, join as join$1, relative as relative$1 } from "path";
|
|
14
|
-
import ts from "typescript";
|
|
15
15
|
import { generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getStyleBoilerplate, getTemplatePath, toPascalCase } from "@stencil/templates";
|
|
16
16
|
import { start } from "@stencil/dev-server";
|
|
17
17
|
//#region src/config-flags.ts
|
|
@@ -602,6 +602,159 @@ const mergeFlags = (config, flags) => {
|
|
|
602
602
|
return merged;
|
|
603
603
|
};
|
|
604
604
|
//#endregion
|
|
605
|
+
//#region src/wizard/config-editor.ts
|
|
606
|
+
async function openStencilConfig(configPath) {
|
|
607
|
+
let text = await readFile(configPath, "utf8");
|
|
608
|
+
const parse = () => ts.createSourceFile(configPath, text, ts.ScriptTarget.Latest, true);
|
|
609
|
+
function findArray(sf, propName) {
|
|
610
|
+
let found;
|
|
611
|
+
const visit = (node) => {
|
|
612
|
+
if (!found && ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === propName && ts.isArrayLiteralExpression(node.initializer)) found = node.initializer;
|
|
613
|
+
else ts.forEachChild(node, visit);
|
|
614
|
+
};
|
|
615
|
+
visit(sf);
|
|
616
|
+
return found;
|
|
617
|
+
}
|
|
618
|
+
function findConfigObject(sf) {
|
|
619
|
+
for (const stmt of sf.statements) if (ts.isVariableStatement(stmt)) {
|
|
620
|
+
for (const decl of stmt.declarationList.declarations) if (ts.isIdentifier(decl.name) && decl.name.text === "config" && decl.initializer && ts.isObjectLiteralExpression(decl.initializer)) return decl.initializer;
|
|
621
|
+
}
|
|
622
|
+
let found;
|
|
623
|
+
const visit = (node) => {
|
|
624
|
+
if (found) return;
|
|
625
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
626
|
+
if (node.properties.some((p) => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === "namespace")) {
|
|
627
|
+
found = node;
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
ts.forEachChild(node, visit);
|
|
632
|
+
};
|
|
633
|
+
visit(sf);
|
|
634
|
+
return found;
|
|
635
|
+
}
|
|
636
|
+
function replaceInArray(arr, substring, expression) {
|
|
637
|
+
for (const element of arr.elements) if (text.slice(element.getStart(), element.getEnd()).includes(substring)) {
|
|
638
|
+
text = text.slice(0, element.getStart()) + expression + text.slice(element.getEnd());
|
|
639
|
+
return true;
|
|
640
|
+
}
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
function removeFromArray(arr, substring) {
|
|
644
|
+
const idx = arr.elements.findIndex((element) => text.slice(element.getStart(), element.getEnd()).includes(substring));
|
|
645
|
+
if (idx === -1) return false;
|
|
646
|
+
const element = arr.elements[idx];
|
|
647
|
+
if (arr.elements.length > 0 && text.slice(arr.getStart(), arr.elements[0].getStart()).includes("\n")) {
|
|
648
|
+
const lineStart = text.lastIndexOf("\n", element.getStart());
|
|
649
|
+
let end = element.getEnd();
|
|
650
|
+
const trailingComma = text.slice(end).match(/^\s*,/);
|
|
651
|
+
if (trailingComma) end += trailingComma[0].length;
|
|
652
|
+
text = text.slice(0, lineStart) + text.slice(end);
|
|
653
|
+
} else {
|
|
654
|
+
let start = element.getStart();
|
|
655
|
+
let end = element.getEnd();
|
|
656
|
+
if (idx < arr.elements.length - 1) {
|
|
657
|
+
const trailingMatch = text.slice(end).match(/^,\s*/);
|
|
658
|
+
if (trailingMatch) end += trailingMatch[0].length;
|
|
659
|
+
} else if (idx > 0) {
|
|
660
|
+
const precedingMatch = text.slice(0, start).match(/,\s*$/);
|
|
661
|
+
if (precedingMatch) start -= precedingMatch[0].length;
|
|
662
|
+
}
|
|
663
|
+
text = text.slice(0, start) + text.slice(end);
|
|
664
|
+
}
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
function appendToArray(arr, code) {
|
|
668
|
+
if (arr.elements.length === 0) {
|
|
669
|
+
const insertPos = arr.getEnd() - 1;
|
|
670
|
+
text = text.slice(0, insertPos) + code + text.slice(insertPos);
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
let insertPos = arr.elements[arr.elements.length - 1].getEnd();
|
|
674
|
+
const trailingComma = text.slice(insertPos).match(/^\s*,/);
|
|
675
|
+
if (trailingComma) insertPos += trailingComma[0].length;
|
|
676
|
+
const firstElemStart = arr.elements[0].getStart();
|
|
677
|
+
if (text.slice(arr.getStart(), firstElemStart).includes("\n")) {
|
|
678
|
+
const lineStart = text.lastIndexOf("\n", firstElemStart) + 1;
|
|
679
|
+
const indent = text.slice(lineStart, firstElemStart).match(/^\s+/)?.[0] ?? " ";
|
|
680
|
+
text = `${text.slice(0, insertPos)},\n${indent}${code}${text.slice(insertPos)}`;
|
|
681
|
+
} else text = `${text.slice(0, insertPos)}, ${code}${text.slice(insertPos)}`;
|
|
682
|
+
}
|
|
683
|
+
function addArrayProp(sf, propName, code) {
|
|
684
|
+
const configObj = findConfigObject(sf);
|
|
685
|
+
if (!configObj) throw new Error("Could not find Stencil config object in stencil.config.ts");
|
|
686
|
+
let propIndent = " ";
|
|
687
|
+
if (configObj.properties.length > 0) {
|
|
688
|
+
const firstPropStart = configObj.properties[0].getStart();
|
|
689
|
+
const lineStart = text.lastIndexOf("\n", firstPropStart) + 1;
|
|
690
|
+
propIndent = text.slice(lineStart, firstPropStart).match(/^\s+/)?.[0] ?? " ";
|
|
691
|
+
}
|
|
692
|
+
const newProp = `${propName}: [\n${propIndent + " "}${code},\n${propIndent}]`;
|
|
693
|
+
const lastProp = configObj.properties[configObj.properties.length - 1];
|
|
694
|
+
if (lastProp) {
|
|
695
|
+
let insertPos = lastProp.getEnd();
|
|
696
|
+
const trailingComma = text.slice(insertPos).match(/^\s*,/);
|
|
697
|
+
if (trailingComma) insertPos += trailingComma[0].length;
|
|
698
|
+
text = `${text.slice(0, insertPos)},\n${propIndent}${newProp}${text.slice(insertPos)}`;
|
|
699
|
+
} else {
|
|
700
|
+
const insertPos = configObj.getEnd() - 1;
|
|
701
|
+
text = `${text.slice(0, insertPos)}\n${propIndent}${newProp},\n${text.slice(insertPos)}`;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return {
|
|
705
|
+
hasImport(moduleSpecifier) {
|
|
706
|
+
return parse().statements.some((s) => ts.isImportDeclaration(s) && ts.isStringLiteral(s.moduleSpecifier) && s.moduleSpecifier.text === moduleSpecifier);
|
|
707
|
+
},
|
|
708
|
+
addImport(moduleSpecifier, namedImports) {
|
|
709
|
+
const sf = parse();
|
|
710
|
+
if (sf.statements.some((s) => ts.isImportDeclaration(s) && ts.isStringLiteral(s.moduleSpecifier) && s.moduleSpecifier.text === moduleSpecifier)) return;
|
|
711
|
+
let insertPos = 0;
|
|
712
|
+
for (const s of sf.statements) if (ts.isImportDeclaration(s)) insertPos = s.getEnd();
|
|
713
|
+
const decl = `\nimport { ${namedImports.join(", ")} } from '${moduleSpecifier}';`;
|
|
714
|
+
text = insertPos > 0 ? text.slice(0, insertPos) + decl + text.slice(insertPos) : decl + "\n" + text;
|
|
715
|
+
},
|
|
716
|
+
outputTargetsContains(substring) {
|
|
717
|
+
const arr = findArray(parse(), "outputTargets");
|
|
718
|
+
return arr ? text.slice(arr.getStart(), arr.getEnd()).includes(substring) : false;
|
|
719
|
+
},
|
|
720
|
+
addOutputTarget(expression) {
|
|
721
|
+
const sf = parse();
|
|
722
|
+
const arr = findArray(sf, "outputTargets");
|
|
723
|
+
if (arr) appendToArray(arr, expression);
|
|
724
|
+
else addArrayProp(sf, "outputTargets", expression);
|
|
725
|
+
},
|
|
726
|
+
replaceOutputTarget(substring, expression) {
|
|
727
|
+
const arr = findArray(parse(), "outputTargets");
|
|
728
|
+
return arr ? replaceInArray(arr, substring, expression) : false;
|
|
729
|
+
},
|
|
730
|
+
removeOutputTarget(substring) {
|
|
731
|
+
const arr = findArray(parse(), "outputTargets");
|
|
732
|
+
return arr ? removeFromArray(arr, substring) : false;
|
|
733
|
+
},
|
|
734
|
+
pluginsContains(substring) {
|
|
735
|
+
const arr = findArray(parse(), "plugins");
|
|
736
|
+
return arr ? text.slice(arr.getStart(), arr.getEnd()).includes(substring) : false;
|
|
737
|
+
},
|
|
738
|
+
addPlugin(expression) {
|
|
739
|
+
const sf = parse();
|
|
740
|
+
const arr = findArray(sf, "plugins");
|
|
741
|
+
if (arr) appendToArray(arr, expression);
|
|
742
|
+
else addArrayProp(sf, "plugins", expression);
|
|
743
|
+
},
|
|
744
|
+
replacePlugin(substring, expression) {
|
|
745
|
+
const arr = findArray(parse(), "plugins");
|
|
746
|
+
return arr ? replaceInArray(arr, substring, expression) : false;
|
|
747
|
+
},
|
|
748
|
+
removePlugin(substring) {
|
|
749
|
+
const arr = findArray(parse(), "plugins");
|
|
750
|
+
return arr ? removeFromArray(arr, substring) : false;
|
|
751
|
+
},
|
|
752
|
+
async save() {
|
|
753
|
+
await writeFile(configPath, text, "utf8");
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
//#endregion
|
|
605
758
|
//#region src/wizard/discover.ts
|
|
606
759
|
function toStringRecord(val) {
|
|
607
760
|
return val !== null && typeof val === "object" ? val : {};
|
|
@@ -1032,7 +1185,7 @@ async function isExistingStencilProject(dir) {
|
|
|
1032
1185
|
}
|
|
1033
1186
|
//#endregion
|
|
1034
1187
|
//#region src/wizard/splash.ts
|
|
1035
|
-
const CLI_VERSION = "5.0.0-alpha.
|
|
1188
|
+
const CLI_VERSION = "5.0.0-alpha.17";
|
|
1036
1189
|
const isTTY = process.stdout.isTTY;
|
|
1037
1190
|
const noColor = !isTTY || "NO_COLOR" in process.env;
|
|
1038
1191
|
const RESET = noColor ? "" : "\x1B[0m";
|
|
@@ -1138,12 +1291,15 @@ async function taskAdd(packages, strictConfig) {
|
|
|
1138
1291
|
});
|
|
1139
1292
|
s.stop("Installed");
|
|
1140
1293
|
}
|
|
1294
|
+
const config = strictConfig ? toProjectConfig(strictConfig) : defaultProjectConfig(cwd);
|
|
1141
1295
|
const context = {
|
|
1142
1296
|
isNewProject: false,
|
|
1143
1297
|
prompts: p,
|
|
1144
1298
|
nypm,
|
|
1145
|
-
config
|
|
1146
|
-
workspaceRoot: await detectWorkspaceRoot(cwd)
|
|
1299
|
+
config,
|
|
1300
|
+
workspaceRoot: await detectWorkspaceRoot(cwd),
|
|
1301
|
+
ts,
|
|
1302
|
+
openStencilConfig: () => openStencilConfig(join(config.rootDir, "stencil.config.ts"))
|
|
1147
1303
|
};
|
|
1148
1304
|
if (packagesToInstall.length > 0) {
|
|
1149
1305
|
const discovered = await discoverPlugins(cwd);
|
|
@@ -3871,7 +4027,9 @@ async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
|
3871
4027
|
prompts: p,
|
|
3872
4028
|
nypm,
|
|
3873
4029
|
config: projectConfig,
|
|
3874
|
-
workspaceRoot: monorepo ? cwd : void 0
|
|
4030
|
+
workspaceRoot: monorepo ? cwd : void 0,
|
|
4031
|
+
ts,
|
|
4032
|
+
openStencilConfig: () => openStencilConfig(join(projectConfig.rootDir, "stencil.config.ts"))
|
|
3875
4033
|
});
|
|
3876
4034
|
}
|
|
3877
4035
|
const pm = (await nypm.detectPackageManager(cwd))?.name ?? "npm";
|
|
@@ -3925,7 +4083,9 @@ async function addCapabilities(cwd, strictConfig) {
|
|
|
3925
4083
|
prompts: p,
|
|
3926
4084
|
nypm,
|
|
3927
4085
|
config: projectConfig,
|
|
3928
|
-
workspaceRoot
|
|
4086
|
+
workspaceRoot,
|
|
4087
|
+
ts,
|
|
4088
|
+
openStencilConfig: () => openStencilConfig(join(projectConfig.rootDir, "stencil.config.ts"))
|
|
3929
4089
|
});
|
|
3930
4090
|
p.outro("Done! Run pnpm run dev to continue.");
|
|
3931
4091
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stencil/cli",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.17",
|
|
4
4
|
"description": "CLI for Stencil - Web component compiler",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"nypm": "^0.3.12",
|
|
42
42
|
"std-env": "^3.8.0",
|
|
43
43
|
"typescript": ">4.0.0 <7.0.0",
|
|
44
|
-
"@stencil/
|
|
45
|
-
"@stencil/
|
|
44
|
+
"@stencil/dev-server": "5.0.0-alpha.17",
|
|
45
|
+
"@stencil/templates": "5.0.0-alpha.17"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"tsdown": ">=0.21.0 <1.0.0",
|
|
49
49
|
"vitest": "^4.1.7",
|
|
50
|
-
"@stencil/core": "5.0.0-alpha.
|
|
50
|
+
"@stencil/core": "5.0.0-alpha.17"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@stencil/core": "^5.0.0-0"
|