@stencil/cli 5.0.0-alpha.7 → 5.0.0-alpha.8
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/dist/index.d.mts +52 -9
- package/dist/index.mjs +954 -552
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { LOG_LEVELS } from "@stencil/core/compiler";
|
|
2
2
|
import { buildError, catchError, hasError, isFunction, isOutputTargetDocs, isOutputTargetSsr, isOutputTargetWww, isString, normalizePath, readOnlyArrayHasStringMember, result, shouldIgnoreError, toCamelCase, validateComponentTag } from "@stencil/core/compiler/utils";
|
|
3
|
-
import {
|
|
3
|
+
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
4
|
+
import { basename, dirname, join, parse, relative, resolve } from "node:path";
|
|
4
5
|
import * as p from "@clack/prompts";
|
|
5
6
|
import { cancel, isCancel, select } from "@clack/prompts";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
7
|
+
import * as nypm from "nypm";
|
|
8
|
+
import { addDevDependency, installDependencies } from "nypm";
|
|
9
|
+
import { isCI } from "std-env";
|
|
10
10
|
import { pathToFileURL } from "node:url";
|
|
11
11
|
import { existsSync } from "node:fs";
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
12
|
+
import { dirname as dirname$1, isAbsolute, join as join$1, relative as relative$1 } from "path";
|
|
13
|
+
import ts from "typescript";
|
|
14
|
+
import { generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getStyleBoilerplate, getTemplatePath, toPascalCase } from "@stencil/templates";
|
|
14
15
|
import { start } from "@stencil/dev-server";
|
|
15
16
|
//#region src/config-flags.ts
|
|
16
17
|
/**
|
|
@@ -600,191 +601,688 @@ const mergeFlags = (config, flags) => {
|
|
|
600
601
|
return merged;
|
|
601
602
|
};
|
|
602
603
|
//#endregion
|
|
603
|
-
//#region src/
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
if (config.devMode && !flags.ci && !currentVersion.includes("-dev.") && isFunction(config.sys.checkVersion)) return config.sys.checkVersion(config.logger, currentVersion);
|
|
613
|
-
return null;
|
|
614
|
-
};
|
|
615
|
-
/**
|
|
616
|
-
* Print the results of running the provided `versionChecker`.
|
|
617
|
-
*
|
|
618
|
-
* Does not print if no `versionChecker` is provided.
|
|
619
|
-
*
|
|
620
|
-
* @param versionChecker the function to invoke.
|
|
621
|
-
*/
|
|
622
|
-
const printCheckVersionResults = async (versionChecker) => {
|
|
623
|
-
if (versionChecker) {
|
|
624
|
-
const checkVersionResults = await versionChecker;
|
|
625
|
-
if (isFunction(checkVersionResults)) checkVersionResults();
|
|
604
|
+
//#region src/wizard/discover.ts
|
|
605
|
+
function toStringRecord(val) {
|
|
606
|
+
return val !== null && typeof val === "object" ? val : {};
|
|
607
|
+
}
|
|
608
|
+
async function readJson$1(filePath) {
|
|
609
|
+
try {
|
|
610
|
+
return JSON.parse(await readFile(filePath, "utf8"));
|
|
611
|
+
} catch {
|
|
612
|
+
return null;
|
|
626
613
|
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
|
|
614
|
+
}
|
|
615
|
+
async function loadOne(rootDir, packageName, loader) {
|
|
616
|
+
const wizardEntry = ((await readJson$1(join(rootDir, "node_modules", packageName, "package.json")))?.stencil)?.wizard;
|
|
617
|
+
if (!wizardEntry) return null;
|
|
618
|
+
const wizardPath = join(rootDir, "node_modules", packageName, wizardEntry);
|
|
619
|
+
let mod;
|
|
620
|
+
try {
|
|
621
|
+
mod = await loader(pathToFileURL(wizardPath).href);
|
|
622
|
+
} catch {
|
|
623
|
+
console.warn(`[stencil] ${packageName} declares stencil.wizard but the module failed to load: ${wizardPath}`);
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
const plugin = mod.wizard;
|
|
627
|
+
if (!plugin || typeof plugin !== "object") {
|
|
628
|
+
console.warn(`[stencil] ${packageName} declares stencil.wizard but does not export a 'wizard' object`);
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
return {
|
|
632
|
+
packageName,
|
|
633
|
+
plugin
|
|
634
|
+
};
|
|
635
|
+
}
|
|
630
636
|
/**
|
|
631
|
-
*
|
|
637
|
+
* Scans the project's declared dependencies for packages that expose a
|
|
638
|
+
* `stencil.wizard` entry in their `package.json` and dynamically imports
|
|
639
|
+
* each matching module.
|
|
632
640
|
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
* - Removes the property
|
|
637
|
-
* - For `buildDist: true` or `buildDocs: true`, adds `skipInDev: false` to relevant output targets
|
|
641
|
+
* @param rootDir - Absolute path to the project root (where `package.json` lives).
|
|
642
|
+
* @param loader - Module loader; injectable for testing. Defaults to `import()`.
|
|
643
|
+
* @returns Array of successfully loaded plugins, in dependency declaration order.
|
|
638
644
|
*/
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
652
|
-
const isTrue = node.initializer.kind === ts.SyntaxKind.TrueKeyword;
|
|
653
|
-
matches.push({
|
|
654
|
-
node,
|
|
655
|
-
message: `Deprecated '${propName}' found${isTrue ? " (set to true)" : ""} - will be removed and skipInDev added to output targets`,
|
|
656
|
-
line: line + 1,
|
|
657
|
-
column: character + 1
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
ts.forEachChild(node, visit);
|
|
662
|
-
};
|
|
663
|
-
visit(sourceFile);
|
|
664
|
-
return matches;
|
|
665
|
-
},
|
|
666
|
-
transform(sourceFile, matches) {
|
|
667
|
-
if (matches.length === 0) return sourceFile.getFullText();
|
|
668
|
-
let text = sourceFile.getFullText();
|
|
669
|
-
const targetTypesNeedingSkipInDev = [];
|
|
670
|
-
for (const match of matches) {
|
|
671
|
-
const prop = match.node;
|
|
672
|
-
const propName = prop.name.text;
|
|
673
|
-
if (prop.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
674
|
-
if (propName === "buildDist") targetTypesNeedingSkipInDev.push("dist", "dist-custom-elements", "dist-hydrate-script", "loader-bundle", "standalone", "ssr");
|
|
675
|
-
else if (propName === "buildDocs") targetTypesNeedingSkipInDev.push("docs-readme", "docs-json", "docs-custom", "docs-vscode", "docs-custom-elements-manifest");
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
const outputTargetsToModify = [];
|
|
679
|
-
const findOutputTargets = (node) => {
|
|
680
|
-
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === "outputTargets" && ts.isArrayLiteralExpression(node.initializer)) {
|
|
681
|
-
for (const element of node.initializer.elements) if (ts.isObjectLiteralExpression(element)) {
|
|
682
|
-
const typeProp = element.properties.find((p) => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === "type");
|
|
683
|
-
if (typeProp && ts.isStringLiteral(typeProp.initializer)) {
|
|
684
|
-
const targetType = typeProp.initializer.text;
|
|
685
|
-
if (targetTypesNeedingSkipInDev.includes(targetType)) {
|
|
686
|
-
if (!element.properties.some((p) => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === "skipInDev")) outputTargetsToModify.push(element);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
ts.forEachChild(node, findOutputTargets);
|
|
692
|
-
};
|
|
693
|
-
findOutputTargets(sourceFile);
|
|
694
|
-
const allModifications = [];
|
|
695
|
-
for (const match of matches) {
|
|
696
|
-
const prop = match.node;
|
|
697
|
-
const start = prop.getStart();
|
|
698
|
-
let end = prop.getEnd();
|
|
699
|
-
const afterProp = text.slice(end).match(/^\s*,/);
|
|
700
|
-
if (afterProp) end = end + afterProp[0].length;
|
|
701
|
-
allModifications.push({
|
|
702
|
-
type: "remove",
|
|
703
|
-
start,
|
|
704
|
-
end,
|
|
705
|
-
node: prop
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
for (const target of outputTargetsToModify) {
|
|
709
|
-
const lastProp = target.properties[target.properties.length - 1];
|
|
710
|
-
if (lastProp) allModifications.push({
|
|
711
|
-
type: "addSkipInDev",
|
|
712
|
-
start: lastProp.getEnd(),
|
|
713
|
-
end: lastProp.getEnd(),
|
|
714
|
-
node: target
|
|
715
|
-
});
|
|
716
|
-
}
|
|
717
|
-
allModifications.sort((a, b) => b.start - a.start);
|
|
718
|
-
for (const mod of allModifications) if (mod.type === "remove") text = text.slice(0, mod.start) + text.slice(mod.end);
|
|
719
|
-
else if (mod.type === "addSkipInDev") {
|
|
720
|
-
const firstProp = mod.node.properties[0];
|
|
721
|
-
let indent = " ";
|
|
722
|
-
if (firstProp) {
|
|
723
|
-
const propStart = firstProp.getStart();
|
|
724
|
-
const lineStart = text.lastIndexOf("\n", propStart) + 1;
|
|
725
|
-
const leadingWhitespace = text.slice(lineStart, propStart);
|
|
726
|
-
if (/^\s+$/.test(leadingWhitespace)) indent = leadingWhitespace;
|
|
727
|
-
}
|
|
728
|
-
const afterLastProp = text.slice(mod.start).match(/^(\s*,)?/);
|
|
729
|
-
const skipLength = afterLastProp && afterLastProp[1] ? afterLastProp[0].length : 0;
|
|
730
|
-
text = text.slice(0, mod.start) + `,\n${indent}skipInDev: false,` + text.slice(mod.start + skipLength);
|
|
645
|
+
async function discoverPlugins(rootDir, loader = (url) => import(url)) {
|
|
646
|
+
const pkg = await readJson$1(join(rootDir, "package.json"));
|
|
647
|
+
if (!pkg) return [];
|
|
648
|
+
const depNames = [...new Set([...Object.keys(toStringRecord(pkg.dependencies)), ...Object.keys(toStringRecord(pkg.devDependencies))])];
|
|
649
|
+
const plugins = (await Promise.allSettled(depNames.map((name) => loadOne(rootDir, name, loader)))).filter((r) => r.status === "fulfilled" && r.value !== null).map((r) => r.value);
|
|
650
|
+
const devPath = process.env.STENCIL_WIZARD_DEV;
|
|
651
|
+
if (devPath) {
|
|
652
|
+
const devPlugin = await loadDevPlugin(resolve(rootDir, devPath), loader);
|
|
653
|
+
if (devPlugin) {
|
|
654
|
+
const deduped = plugins.filter((p) => p.packageName !== devPlugin.packageName);
|
|
655
|
+
plugins.length = 0;
|
|
656
|
+
plugins.push(devPlugin, ...deduped);
|
|
731
657
|
}
|
|
732
|
-
text = text.replace(/,\s*\n\s*\n/g, ",\n");
|
|
733
|
-
text = text.replace(/{\s*\n\s*\n/g, "{\n");
|
|
734
|
-
return text;
|
|
735
658
|
}
|
|
736
|
-
|
|
659
|
+
return plugins;
|
|
660
|
+
}
|
|
661
|
+
async function findDevPackageName(wizardPath) {
|
|
662
|
+
const dir = dirname(wizardPath);
|
|
663
|
+
for (const candidate of [dir, resolve(dir, "..")]) {
|
|
664
|
+
const pkg = await readJson$1(join(candidate, "package.json"));
|
|
665
|
+
if (typeof pkg?.name === "string") return pkg.name;
|
|
666
|
+
}
|
|
667
|
+
return basename(dir);
|
|
668
|
+
}
|
|
669
|
+
async function loadDevPlugin(wizardPath, loader) {
|
|
670
|
+
const packageName = await findDevPackageName(wizardPath);
|
|
671
|
+
let mod;
|
|
672
|
+
try {
|
|
673
|
+
mod = await loader(pathToFileURL(wizardPath).href);
|
|
674
|
+
} catch {
|
|
675
|
+
console.warn(`[stencil] STENCIL_WIZARD_DEV: failed to load ${wizardPath}`);
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
const plugin = mod.wizard;
|
|
679
|
+
if (!plugin || typeof plugin !== "object") {
|
|
680
|
+
console.warn(`[stencil] STENCIL_WIZARD_DEV: ${wizardPath} does not export a 'wizard' object`);
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
683
|
+
return {
|
|
684
|
+
packageName,
|
|
685
|
+
plugin
|
|
686
|
+
};
|
|
687
|
+
}
|
|
737
688
|
//#endregion
|
|
738
|
-
//#region src/
|
|
689
|
+
//#region src/wizard/clack.ts
|
|
739
690
|
/**
|
|
740
|
-
*
|
|
691
|
+
* Exits cleanly if the user cancelled a prompt (Ctrl+C).
|
|
692
|
+
* Narrows the type from `T | symbol` to `T` for callers.
|
|
741
693
|
*
|
|
742
|
-
*
|
|
743
|
-
* Build mode is controlled exclusively by the `--dev` CLI flag (default is production).
|
|
744
|
-
* This migration removes `devMode` from the config object.
|
|
694
|
+
* @param value - Return value from a `@clack/prompts` prompt call.
|
|
745
695
|
*/
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
fromVersion: "4.x",
|
|
751
|
-
toVersion: "5.x",
|
|
752
|
-
detect(sourceFile) {
|
|
753
|
-
const matches = [];
|
|
754
|
-
const visit = (node) => {
|
|
755
|
-
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
|
|
756
|
-
if (node.name.text === "devMode") {
|
|
757
|
-
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
758
|
-
matches.push({
|
|
759
|
-
node,
|
|
760
|
-
message: `Deprecated 'devMode' config option found - build mode is now set via the --dev CLI flag (production is the default)`,
|
|
761
|
-
line: line + 1,
|
|
762
|
-
column: character + 1
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
ts.forEachChild(node, visit);
|
|
767
|
-
};
|
|
768
|
-
visit(sourceFile);
|
|
769
|
-
return matches;
|
|
770
|
-
},
|
|
771
|
-
transform(sourceFile, matches) {
|
|
772
|
-
if (matches.length === 0) return sourceFile.getFullText();
|
|
773
|
-
let text = sourceFile.getFullText();
|
|
774
|
-
for (const match of [...matches].reverse()) {
|
|
775
|
-
const node = match.node;
|
|
776
|
-
const start = node.getFullStart();
|
|
777
|
-
const end = node.getEnd();
|
|
778
|
-
let removeEnd = end;
|
|
779
|
-
const trailingComma = text.slice(end).match(/^\s*,/);
|
|
780
|
-
if (trailingComma) removeEnd = end + trailingComma[0].length;
|
|
781
|
-
text = text.slice(0, start) + text.slice(removeEnd);
|
|
782
|
-
}
|
|
783
|
-
return text;
|
|
696
|
+
function cancelIfAborted(value) {
|
|
697
|
+
if (isCancel(value)) {
|
|
698
|
+
cancel("Cancelled.");
|
|
699
|
+
process.exit(0);
|
|
784
700
|
}
|
|
785
|
-
}
|
|
701
|
+
}
|
|
786
702
|
//#endregion
|
|
787
|
-
//#region src/
|
|
703
|
+
//#region src/wizard/init/steps.ts
|
|
704
|
+
/** Well-known integrations the CLI can offer before any packages are installed. */
|
|
705
|
+
const KNOWN_INTEGRATIONS = [
|
|
706
|
+
{
|
|
707
|
+
package: "@stencil/vitest",
|
|
708
|
+
displayName: "Vitest",
|
|
709
|
+
description: "Unit / Spec / Integration / Browser testing",
|
|
710
|
+
group: "Testing"
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
package: "@stencil/playwright",
|
|
714
|
+
displayName: "Playwright",
|
|
715
|
+
description: "E2E testing",
|
|
716
|
+
group: "Testing"
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
package: "@stencil/sass",
|
|
720
|
+
displayName: "Sass",
|
|
721
|
+
description: "Sass/SCSS styles",
|
|
722
|
+
group: "Styling"
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
package: "@stencil/eslint-plugin",
|
|
726
|
+
displayName: "ESLint Plugin",
|
|
727
|
+
description: "Stencil-aware lint rules (ESLint, oxlint, Biome)",
|
|
728
|
+
group: "Linting"
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
package: "@stencil/storybook-plugin",
|
|
732
|
+
displayName: "Storybook",
|
|
733
|
+
description: "Component development & documentation",
|
|
734
|
+
group: "Tooling"
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
package: "@stencil/types-output-target",
|
|
738
|
+
displayName: "Types",
|
|
739
|
+
description: "TypeScript types for React, Vue, Solid, Svelte, Preact",
|
|
740
|
+
group: "Framework integrations"
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
package: "@stencil/react-output-target",
|
|
744
|
+
displayName: "React",
|
|
745
|
+
description: "React component wrappers",
|
|
746
|
+
group: "Framework integrations"
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
package: "@stencil/angular-output-target",
|
|
750
|
+
displayName: "Angular",
|
|
751
|
+
description: "Angular component wrappers",
|
|
752
|
+
group: "Framework integrations"
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
package: "@stencil/vue-output-target",
|
|
756
|
+
displayName: "Vue",
|
|
757
|
+
description: "Vue component wrappers",
|
|
758
|
+
group: "Framework integrations"
|
|
759
|
+
}
|
|
760
|
+
];
|
|
761
|
+
async function promptOutputs() {
|
|
762
|
+
const picks = await p.multiselect({
|
|
763
|
+
message: "Outputs:",
|
|
764
|
+
options: [
|
|
765
|
+
{
|
|
766
|
+
value: "loader",
|
|
767
|
+
label: "Loader",
|
|
768
|
+
hint: "performant lazy-loader; browser & bundler ready"
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
value: "standalone",
|
|
772
|
+
label: "Standalone",
|
|
773
|
+
hint: "per-component modules, import only what you need"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
value: "ssr",
|
|
777
|
+
label: "SSR",
|
|
778
|
+
hint: "pre-render components in any JS server environment"
|
|
779
|
+
},
|
|
780
|
+
{
|
|
781
|
+
value: "ssr-wasm",
|
|
782
|
+
label: "SSR WASM",
|
|
783
|
+
hint: "experimental: compile SSR to a portable WASM binary"
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
value: "www",
|
|
787
|
+
label: "WWW",
|
|
788
|
+
hint: "app mode with dev server and optional PWA support"
|
|
789
|
+
}
|
|
790
|
+
],
|
|
791
|
+
required: false
|
|
792
|
+
});
|
|
793
|
+
cancelIfAborted(picks);
|
|
794
|
+
return picks;
|
|
795
|
+
}
|
|
796
|
+
async function promptFeatures() {
|
|
797
|
+
const picks = await p.multiselect({
|
|
798
|
+
message: "Features:",
|
|
799
|
+
options: [
|
|
800
|
+
{
|
|
801
|
+
value: "signals",
|
|
802
|
+
label: "Signals",
|
|
803
|
+
hint: "signal-backed @Prop/@State for cross-framework reactive interop"
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
value: "globalStyle",
|
|
807
|
+
label: "Global style",
|
|
808
|
+
hint: "Global stylesheet for font definitions, CSS variables, pre-load styles etc"
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
value: "globalScript",
|
|
812
|
+
label: "Global script",
|
|
813
|
+
hint: "Global script for initializing application-wide logic before components load"
|
|
814
|
+
}
|
|
815
|
+
],
|
|
816
|
+
required: false
|
|
817
|
+
});
|
|
818
|
+
cancelIfAborted(picks);
|
|
819
|
+
const set = new Set(picks);
|
|
820
|
+
return {
|
|
821
|
+
signals: set.has("signals"),
|
|
822
|
+
globalStyle: set.has("globalStyle"),
|
|
823
|
+
globalScript: set.has("globalScript")
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
async function promptDocs() {
|
|
827
|
+
const picks = await p.multiselect({
|
|
828
|
+
message: "Docs:",
|
|
829
|
+
options: [
|
|
830
|
+
{
|
|
831
|
+
value: "cem",
|
|
832
|
+
label: "CEM",
|
|
833
|
+
hint: "custom-elements.json - preferred format for interop with tools like Storybook, Styleguidist, etc"
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
value: "json",
|
|
837
|
+
label: "JSON",
|
|
838
|
+
hint: "docs.json - Stencil / Ionic centric schema"
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
value: "vscode",
|
|
842
|
+
label: "VS Code",
|
|
843
|
+
hint: "vscode-data.json - editor autocomplete for your components"
|
|
844
|
+
}
|
|
845
|
+
],
|
|
846
|
+
initialValues: ["cem"],
|
|
847
|
+
required: false
|
|
848
|
+
});
|
|
849
|
+
cancelIfAborted(picks);
|
|
850
|
+
return picks;
|
|
851
|
+
}
|
|
852
|
+
async function promptProjectName() {
|
|
853
|
+
const name = await p.text({
|
|
854
|
+
message: "Project name:",
|
|
855
|
+
defaultValue: "my-stencil-library",
|
|
856
|
+
validate: (v) => {
|
|
857
|
+
if (!v?.trim()) return "Project name is required";
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
cancelIfAborted(name);
|
|
861
|
+
return name;
|
|
862
|
+
}
|
|
863
|
+
function buildGroupedOptions(integrations) {
|
|
864
|
+
const groups = {};
|
|
865
|
+
for (const i of integrations) (groups[i.group] ??= []).push({
|
|
866
|
+
value: i.package,
|
|
867
|
+
label: i.displayName,
|
|
868
|
+
hint: i.description
|
|
869
|
+
});
|
|
870
|
+
return groups;
|
|
871
|
+
}
|
|
872
|
+
async function promptCustomPackages() {
|
|
873
|
+
const input = await p.text({
|
|
874
|
+
message: "Additional packages to install:",
|
|
875
|
+
placeholder: "e.g. my-plugin another-package (leave blank to skip)"
|
|
876
|
+
});
|
|
877
|
+
cancelIfAborted(input);
|
|
878
|
+
if (typeof input !== "string" || !input.trim()) return [];
|
|
879
|
+
return input.split(/[\s,]+/).map((s) => s.trim()).filter(Boolean);
|
|
880
|
+
}
|
|
881
|
+
async function promptIntegrations() {
|
|
882
|
+
const picks = await p.groupMultiselect({
|
|
883
|
+
message: "Add integrations (optional):",
|
|
884
|
+
options: buildGroupedOptions(KNOWN_INTEGRATIONS),
|
|
885
|
+
required: false
|
|
886
|
+
});
|
|
887
|
+
cancelIfAborted(picks);
|
|
888
|
+
return KNOWN_INTEGRATIONS.filter((i) => picks.includes(i.package));
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Prompt for actions on an existing project: install new integrations and/or
|
|
892
|
+
* run init wizards for already-installed packages with wizard contributions.
|
|
893
|
+
*
|
|
894
|
+
* @param installable - KNOWN_INTEGRATIONS not yet present in the project.
|
|
895
|
+
* @param configurable - Already-installed plugins that declare an `init` contribution.
|
|
896
|
+
* @returns Selected integrations to install and plugins to configure.
|
|
897
|
+
*/
|
|
898
|
+
async function promptAddCapabilities(installable, configurable) {
|
|
899
|
+
const options = {};
|
|
900
|
+
if (installable.length > 0) options["Install new integrations"] = installable.map((i) => ({
|
|
901
|
+
value: `install:${i.package}`,
|
|
902
|
+
label: i.displayName,
|
|
903
|
+
hint: i.description
|
|
904
|
+
}));
|
|
905
|
+
if (configurable.length > 0) options["Configure existing integrations"] = configurable.map((d) => ({
|
|
906
|
+
value: `configure:${d.packageName}`,
|
|
907
|
+
label: d.plugin.init.displayName,
|
|
908
|
+
hint: d.plugin.init.description
|
|
909
|
+
}));
|
|
910
|
+
const picks = await p.groupMultiselect({
|
|
911
|
+
message: "What would you like to do?",
|
|
912
|
+
options,
|
|
913
|
+
required: false
|
|
914
|
+
});
|
|
915
|
+
cancelIfAborted(picks);
|
|
916
|
+
const pickedSet = new Set(picks);
|
|
917
|
+
return {
|
|
918
|
+
toInstall: installable.filter((i) => pickedSet.has(`install:${i.package}`)),
|
|
919
|
+
toConfigure: configurable.filter((d) => pickedSet.has(`configure:${d.packageName}`))
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
//#endregion
|
|
923
|
+
//#region src/wizard/project.ts
|
|
924
|
+
/**
|
|
925
|
+
* Extracts the stable, plugin-relevant fields from a fully-resolved compiler config.
|
|
926
|
+
* @param validated The fully-resolved compiler config.
|
|
927
|
+
* @returns A ProjectConfig with only the fields relevant to plugins and the wizard.
|
|
928
|
+
* This is a stable subset of the compiler config that won't change between versions.
|
|
929
|
+
*/
|
|
930
|
+
function toProjectConfig(validated) {
|
|
931
|
+
return {
|
|
932
|
+
rootDir: validated.rootDir,
|
|
933
|
+
srcDir: validated.srcDir,
|
|
934
|
+
namespace: validated.namespace,
|
|
935
|
+
fsNamespace: validated.fsNamespace,
|
|
936
|
+
outputTargets: validated.outputTargets ?? [],
|
|
937
|
+
globalScript: validated.globalScript,
|
|
938
|
+
globalStyle: validated.globalStyle,
|
|
939
|
+
compat: validated.compat,
|
|
940
|
+
signalBacking: validated.signalBacking
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Builds a minimal ProjectConfig when no validated config is available (e.g. new project, no compiler).
|
|
945
|
+
* @param rootDir The root directory of the project.
|
|
946
|
+
* @param overrides Optional fields to override the defaults.
|
|
947
|
+
* @returns A ProjectConfig with reasonable defaults for a new project.
|
|
948
|
+
* */
|
|
949
|
+
function defaultProjectConfig(rootDir, overrides) {
|
|
950
|
+
const namespace = overrides?.namespace ?? "";
|
|
951
|
+
return {
|
|
952
|
+
rootDir,
|
|
953
|
+
srcDir: join(rootDir, "src"),
|
|
954
|
+
namespace,
|
|
955
|
+
fsNamespace: overrides?.fsNamespace ?? namespace.toLowerCase(),
|
|
956
|
+
outputTargets: [],
|
|
957
|
+
...overrides
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Returns true if the directory looks like an existing Stencil project:
|
|
962
|
+
* - has an explicit `stencil.config.ts`, OR
|
|
963
|
+
* - has `.tsx` files under `src/` (zero-config project).
|
|
964
|
+
* @param dir The directory to check for an existing Stencil project.
|
|
965
|
+
* @returns A promise that resolves to true if the directory looks like an existing Stencil project, false otherwise.
|
|
966
|
+
*/
|
|
967
|
+
async function isExistingStencilProject(dir) {
|
|
968
|
+
if (existsSync(join(dir, "stencil.config.ts"))) return true;
|
|
969
|
+
try {
|
|
970
|
+
return (await readdir(join(dir, "src"), {
|
|
971
|
+
recursive: true,
|
|
972
|
+
withFileTypes: true
|
|
973
|
+
})).some((e) => e.isFile() && e.name.endsWith(".tsx"));
|
|
974
|
+
} catch {
|
|
975
|
+
return false;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
//#endregion
|
|
979
|
+
//#region src/wizard/splash.ts
|
|
980
|
+
const CLI_VERSION = "5.0.0-alpha.8";
|
|
981
|
+
const isTTY = process.stdout.isTTY;
|
|
982
|
+
const noColor = !isTTY || "NO_COLOR" in process.env;
|
|
983
|
+
const RESET = noColor ? "" : "\x1B[0m";
|
|
984
|
+
const BOLD = noColor ? "" : "\x1B[1m";
|
|
985
|
+
const DIM = noColor ? "" : "\x1B[2m";
|
|
986
|
+
const BLUE = noColor ? "" : "\x1B[38;2;60;44;255m";
|
|
987
|
+
const RAW = `\
|
|
988
|
+
.............
|
|
989
|
+
...................
|
|
990
|
+
.........................
|
|
991
|
+
..............................
|
|
992
|
+
.................................
|
|
993
|
+
..............████████████.........
|
|
994
|
+
.............████████████............
|
|
995
|
+
............████████████...............
|
|
996
|
+
...........*************.................
|
|
997
|
+
.........████████████████████████████....
|
|
998
|
+
.......████████████████████████████......
|
|
999
|
+
.....████████████████████████████........
|
|
1000
|
+
...████████████████████████████..........
|
|
1001
|
+
................*************............
|
|
1002
|
+
..............████████████.............
|
|
1003
|
+
............████████████..............
|
|
1004
|
+
.........████████████...............
|
|
1005
|
+
.................................
|
|
1006
|
+
..............................
|
|
1007
|
+
..........................
|
|
1008
|
+
......................
|
|
1009
|
+
................`;
|
|
1010
|
+
function colorize(raw) {
|
|
1011
|
+
if (noColor) return raw;
|
|
1012
|
+
let out = "";
|
|
1013
|
+
let style = "";
|
|
1014
|
+
for (const ch of raw) {
|
|
1015
|
+
const next = ".*".includes(ch) ? BLUE : "";
|
|
1016
|
+
if (next !== style) {
|
|
1017
|
+
if (style) out += RESET;
|
|
1018
|
+
if (next) out += next;
|
|
1019
|
+
style = next;
|
|
1020
|
+
}
|
|
1021
|
+
out += ch;
|
|
1022
|
+
}
|
|
1023
|
+
return style ? out + RESET : out;
|
|
1024
|
+
}
|
|
1025
|
+
const SPLASH = colorize(RAW);
|
|
1026
|
+
function printSplash() {
|
|
1027
|
+
if (!isTTY) return;
|
|
1028
|
+
const header = ` ${BOLD}Stencil${RESET} ${BLUE}v${CLI_VERSION}${RESET}`;
|
|
1029
|
+
const tagline = ` ${DIM}The Custom Element Compiler${RESET}`;
|
|
1030
|
+
process.stdout.write(`\n${SPLASH}\n\n${header}\n${tagline}\n\n`);
|
|
1031
|
+
}
|
|
1032
|
+
//#endregion
|
|
1033
|
+
//#region src/task-add.ts
|
|
1034
|
+
async function getInstalledPackageNames(rootDir) {
|
|
1035
|
+
try {
|
|
1036
|
+
const pkg = JSON.parse(await readFile(join(rootDir, "package.json"), "utf8"));
|
|
1037
|
+
const keys = (v) => Object.keys(v !== null && typeof v === "object" ? v : {});
|
|
1038
|
+
return new Set([...keys(pkg.dependencies), ...keys(pkg.devDependencies)]);
|
|
1039
|
+
} catch {
|
|
1040
|
+
return /* @__PURE__ */ new Set();
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
async function selectInteractive(cwd) {
|
|
1044
|
+
const discovered = await discoverPlugins(cwd);
|
|
1045
|
+
const installed = await getInstalledPackageNames(cwd);
|
|
1046
|
+
const installable = KNOWN_INTEGRATIONS.filter((i) => !installed.has(i.package));
|
|
1047
|
+
const configurable = discovered.filter((d) => d.plugin.init != null);
|
|
1048
|
+
let toInstall = [];
|
|
1049
|
+
let toConfigure = [];
|
|
1050
|
+
if (installable.length > 0 || configurable.length > 0) {
|
|
1051
|
+
const result = await promptAddCapabilities(installable, configurable);
|
|
1052
|
+
toInstall = result.toInstall;
|
|
1053
|
+
toConfigure = result.toConfigure;
|
|
1054
|
+
} else p.log.info("All known integrations are already installed.");
|
|
1055
|
+
const customPackages = await promptCustomPackages();
|
|
1056
|
+
return {
|
|
1057
|
+
packagesToInstall: [...toInstall.map((i) => i.package), ...customPackages],
|
|
1058
|
+
pluginsToReconfigure: toConfigure
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
async function taskAdd(packages, strictConfig) {
|
|
1062
|
+
const cwd = process.cwd();
|
|
1063
|
+
printSplash();
|
|
1064
|
+
p.intro("stencil add");
|
|
1065
|
+
if (isCI) {
|
|
1066
|
+
p.log.warn("Running in CI - non-interactive mode is not yet supported for `stencil add`.");
|
|
1067
|
+
process.exit(1);
|
|
1068
|
+
}
|
|
1069
|
+
let packagesToInstall = packages;
|
|
1070
|
+
let pluginsToReconfigure = [];
|
|
1071
|
+
if (packages.length === 0) ({packagesToInstall, pluginsToReconfigure} = await selectInteractive(cwd));
|
|
1072
|
+
if (packagesToInstall.length === 0 && pluginsToReconfigure.length === 0) {
|
|
1073
|
+
p.outro("Nothing to do.");
|
|
1074
|
+
return;
|
|
1075
|
+
}
|
|
1076
|
+
if (packagesToInstall.length > 0) if (process.env.STENCIL_WIZARD_DEV) p.log.warn(`Dev mode: skipping install, loading wizard from ${process.env.STENCIL_WIZARD_DEV}`);
|
|
1077
|
+
else {
|
|
1078
|
+
const s = p.spinner();
|
|
1079
|
+
s.start(`Installing ${packagesToInstall.join(", ")}`);
|
|
1080
|
+
await addDevDependency(packagesToInstall, {
|
|
1081
|
+
cwd,
|
|
1082
|
+
silent: true
|
|
1083
|
+
});
|
|
1084
|
+
s.stop("Installed");
|
|
1085
|
+
}
|
|
1086
|
+
const context = {
|
|
1087
|
+
isNewProject: false,
|
|
1088
|
+
prompts: p,
|
|
1089
|
+
nypm,
|
|
1090
|
+
config: strictConfig ? toProjectConfig(strictConfig) : defaultProjectConfig(cwd)
|
|
1091
|
+
};
|
|
1092
|
+
if (packagesToInstall.length > 0) {
|
|
1093
|
+
const discovered = await discoverPlugins(cwd);
|
|
1094
|
+
const installedSet = new Set(packagesToInstall);
|
|
1095
|
+
for (const d of discovered) if (installedSet.has(d.packageName) && d.plugin.init?.run) await d.plugin.init.run(context);
|
|
1096
|
+
}
|
|
1097
|
+
for (const d of pluginsToReconfigure) if (d.plugin.init?.run) await d.plugin.init.run(context);
|
|
1098
|
+
p.outro("Done!");
|
|
1099
|
+
}
|
|
1100
|
+
//#endregion
|
|
1101
|
+
//#region src/check-version.ts
|
|
1102
|
+
/**
|
|
1103
|
+
* Retrieve a reference to the active `CompilerSystem`'s `checkVersion` function
|
|
1104
|
+
* @param config the Stencil configuration associated with the currently compiled project
|
|
1105
|
+
* @param currentVersion the Stencil compiler's version string
|
|
1106
|
+
* @param flags the CLI flags (owned by CLI, not part of core config)
|
|
1107
|
+
* @returns a reference to `checkVersion`, or `null` if one does not exist on the current `CompilerSystem`
|
|
1108
|
+
*/
|
|
1109
|
+
const startCheckVersion = async (config, currentVersion, flags) => {
|
|
1110
|
+
if (config.devMode && !flags.ci && !currentVersion.includes("-dev.") && isFunction(config.sys.checkVersion)) return config.sys.checkVersion(config.logger, currentVersion);
|
|
1111
|
+
return null;
|
|
1112
|
+
};
|
|
1113
|
+
/**
|
|
1114
|
+
* Print the results of running the provided `versionChecker`.
|
|
1115
|
+
*
|
|
1116
|
+
* Does not print if no `versionChecker` is provided.
|
|
1117
|
+
*
|
|
1118
|
+
* @param versionChecker the function to invoke.
|
|
1119
|
+
*/
|
|
1120
|
+
const printCheckVersionResults = async (versionChecker) => {
|
|
1121
|
+
if (versionChecker) {
|
|
1122
|
+
const checkVersionResults = await versionChecker;
|
|
1123
|
+
if (isFunction(checkVersionResults)) checkVersionResults();
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
//#endregion
|
|
1127
|
+
//#region src/migrations/rules/build-dist-docs.ts
|
|
1128
|
+
/**
|
|
1129
|
+
* Migration rule for buildDist and buildDocs removal.
|
|
1130
|
+
*
|
|
1131
|
+
* In Stencil v5, these global config options are replaced with per-output-target
|
|
1132
|
+
* `skipInDev` property. This migration:
|
|
1133
|
+
* - Detects `buildDist` or `buildDocs` in stencil.config.ts
|
|
1134
|
+
* - Removes the property
|
|
1135
|
+
* - For `buildDist: true` or `buildDocs: true`, adds `skipInDev: false` to relevant output targets
|
|
1136
|
+
*/
|
|
1137
|
+
const buildDistDocsRule = {
|
|
1138
|
+
id: "build-dist-docs",
|
|
1139
|
+
name: "buildDist/buildDocs Removal",
|
|
1140
|
+
description: "Remove deprecated buildDist and buildDocs config options",
|
|
1141
|
+
fromVersion: "4.x",
|
|
1142
|
+
toVersion: "5.x",
|
|
1143
|
+
detect(sourceFile) {
|
|
1144
|
+
const matches = [];
|
|
1145
|
+
const visit = (node) => {
|
|
1146
|
+
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
|
|
1147
|
+
const propName = node.name.text;
|
|
1148
|
+
if (propName === "buildDist" || propName === "buildDocs") {
|
|
1149
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
1150
|
+
const isTrue = node.initializer.kind === ts.SyntaxKind.TrueKeyword;
|
|
1151
|
+
matches.push({
|
|
1152
|
+
node,
|
|
1153
|
+
message: `Deprecated '${propName}' found${isTrue ? " (set to true)" : ""} - will be removed and skipInDev added to output targets`,
|
|
1154
|
+
line: line + 1,
|
|
1155
|
+
column: character + 1
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
ts.forEachChild(node, visit);
|
|
1160
|
+
};
|
|
1161
|
+
visit(sourceFile);
|
|
1162
|
+
return matches;
|
|
1163
|
+
},
|
|
1164
|
+
transform(sourceFile, matches) {
|
|
1165
|
+
if (matches.length === 0) return sourceFile.getFullText();
|
|
1166
|
+
let text = sourceFile.getFullText();
|
|
1167
|
+
const targetTypesNeedingSkipInDev = [];
|
|
1168
|
+
for (const match of matches) {
|
|
1169
|
+
const prop = match.node;
|
|
1170
|
+
const propName = prop.name.text;
|
|
1171
|
+
if (prop.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
1172
|
+
if (propName === "buildDist") targetTypesNeedingSkipInDev.push("dist", "dist-custom-elements", "dist-hydrate-script", "loader-bundle", "standalone", "ssr");
|
|
1173
|
+
else if (propName === "buildDocs") targetTypesNeedingSkipInDev.push("docs-readme", "docs-json", "docs-custom", "docs-vscode", "docs-custom-elements-manifest");
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
const outputTargetsToModify = [];
|
|
1177
|
+
const findOutputTargets = (node) => {
|
|
1178
|
+
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === "outputTargets" && ts.isArrayLiteralExpression(node.initializer)) {
|
|
1179
|
+
for (const element of node.initializer.elements) if (ts.isObjectLiteralExpression(element)) {
|
|
1180
|
+
const typeProp = element.properties.find((p) => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === "type");
|
|
1181
|
+
if (typeProp && ts.isStringLiteral(typeProp.initializer)) {
|
|
1182
|
+
const targetType = typeProp.initializer.text;
|
|
1183
|
+
if (targetTypesNeedingSkipInDev.includes(targetType)) {
|
|
1184
|
+
if (!element.properties.some((p) => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === "skipInDev")) outputTargetsToModify.push(element);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
ts.forEachChild(node, findOutputTargets);
|
|
1190
|
+
};
|
|
1191
|
+
findOutputTargets(sourceFile);
|
|
1192
|
+
const allModifications = [];
|
|
1193
|
+
for (const match of matches) {
|
|
1194
|
+
const prop = match.node;
|
|
1195
|
+
const start = prop.getStart();
|
|
1196
|
+
let end = prop.getEnd();
|
|
1197
|
+
const afterProp = text.slice(end).match(/^\s*,/);
|
|
1198
|
+
if (afterProp) end = end + afterProp[0].length;
|
|
1199
|
+
allModifications.push({
|
|
1200
|
+
type: "remove",
|
|
1201
|
+
start,
|
|
1202
|
+
end,
|
|
1203
|
+
node: prop
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
for (const target of outputTargetsToModify) {
|
|
1207
|
+
const lastProp = target.properties[target.properties.length - 1];
|
|
1208
|
+
if (lastProp) allModifications.push({
|
|
1209
|
+
type: "addSkipInDev",
|
|
1210
|
+
start: lastProp.getEnd(),
|
|
1211
|
+
end: lastProp.getEnd(),
|
|
1212
|
+
node: target
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
allModifications.sort((a, b) => b.start - a.start);
|
|
1216
|
+
for (const mod of allModifications) if (mod.type === "remove") text = text.slice(0, mod.start) + text.slice(mod.end);
|
|
1217
|
+
else if (mod.type === "addSkipInDev") {
|
|
1218
|
+
const firstProp = mod.node.properties[0];
|
|
1219
|
+
let indent = " ";
|
|
1220
|
+
if (firstProp) {
|
|
1221
|
+
const propStart = firstProp.getStart();
|
|
1222
|
+
const lineStart = text.lastIndexOf("\n", propStart) + 1;
|
|
1223
|
+
const leadingWhitespace = text.slice(lineStart, propStart);
|
|
1224
|
+
if (/^\s+$/.test(leadingWhitespace)) indent = leadingWhitespace;
|
|
1225
|
+
}
|
|
1226
|
+
const afterLastProp = text.slice(mod.start).match(/^(\s*,)?/);
|
|
1227
|
+
const skipLength = afterLastProp && afterLastProp[1] ? afterLastProp[0].length : 0;
|
|
1228
|
+
text = text.slice(0, mod.start) + `,\n${indent}skipInDev: false,` + text.slice(mod.start + skipLength);
|
|
1229
|
+
}
|
|
1230
|
+
text = text.replace(/,\s*\n\s*\n/g, ",\n");
|
|
1231
|
+
text = text.replace(/{\s*\n\s*\n/g, "{\n");
|
|
1232
|
+
return text;
|
|
1233
|
+
}
|
|
1234
|
+
};
|
|
1235
|
+
//#endregion
|
|
1236
|
+
//#region src/migrations/rules/dev-mode.ts
|
|
1237
|
+
/**
|
|
1238
|
+
* Migration rule for `devMode` config option removal.
|
|
1239
|
+
*
|
|
1240
|
+
* In Stencil v5, `devMode` is no longer a user-settable config option in `stencil.config.ts`.
|
|
1241
|
+
* Build mode is controlled exclusively by the `--dev` CLI flag (default is production).
|
|
1242
|
+
* This migration removes `devMode` from the config object.
|
|
1243
|
+
*/
|
|
1244
|
+
const devModeRule = {
|
|
1245
|
+
id: "dev-mode",
|
|
1246
|
+
name: "devMode Config Removal",
|
|
1247
|
+
description: "Remove deprecated devMode config option - use --dev CLI flag instead",
|
|
1248
|
+
fromVersion: "4.x",
|
|
1249
|
+
toVersion: "5.x",
|
|
1250
|
+
detect(sourceFile) {
|
|
1251
|
+
const matches = [];
|
|
1252
|
+
const visit = (node) => {
|
|
1253
|
+
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
|
|
1254
|
+
if (node.name.text === "devMode") {
|
|
1255
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
1256
|
+
matches.push({
|
|
1257
|
+
node,
|
|
1258
|
+
message: `Deprecated 'devMode' config option found - build mode is now set via the --dev CLI flag (production is the default)`,
|
|
1259
|
+
line: line + 1,
|
|
1260
|
+
column: character + 1
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
ts.forEachChild(node, visit);
|
|
1265
|
+
};
|
|
1266
|
+
visit(sourceFile);
|
|
1267
|
+
return matches;
|
|
1268
|
+
},
|
|
1269
|
+
transform(sourceFile, matches) {
|
|
1270
|
+
if (matches.length === 0) return sourceFile.getFullText();
|
|
1271
|
+
let text = sourceFile.getFullText();
|
|
1272
|
+
for (const match of [...matches].reverse()) {
|
|
1273
|
+
const node = match.node;
|
|
1274
|
+
const start = node.getFullStart();
|
|
1275
|
+
const end = node.getEnd();
|
|
1276
|
+
let removeEnd = end;
|
|
1277
|
+
const trailingComma = text.slice(end).match(/^\s*,/);
|
|
1278
|
+
if (trailingComma) removeEnd = end + trailingComma[0].length;
|
|
1279
|
+
text = text.slice(0, start) + text.slice(removeEnd);
|
|
1280
|
+
}
|
|
1281
|
+
return text;
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
//#endregion
|
|
1285
|
+
//#region src/migrations/rules/encapsulation-api.ts
|
|
788
1286
|
/**
|
|
789
1287
|
* Migration rule for the @Component encapsulation API change.
|
|
790
1288
|
*
|
|
@@ -1984,7 +2482,7 @@ const taskMigrate = async (coreCompiler, config, flags) => {
|
|
|
1984
2482
|
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
|
|
1985
2483
|
const matches = rule.detect(sourceFile);
|
|
1986
2484
|
if (matches.length > 0) {
|
|
1987
|
-
const relPath = relative(config.rootDir, filePath);
|
|
2485
|
+
const relPath = relative$1(config.rootDir, filePath);
|
|
1988
2486
|
logger.info(`\n${logger.cyan(relPath)}`);
|
|
1989
2487
|
logger.info(` ${logger.yellow(`[${rule.id}]`)} ${rule.name}`);
|
|
1990
2488
|
for (const match of matches) logger.info(` Line ${match.line}: ${match.message}`);
|
|
@@ -2096,8 +2594,8 @@ const detectMigrations = async (coreCompiler, config) => {
|
|
|
2096
2594
|
*/
|
|
2097
2595
|
async function getTypeScriptFiles(config, sys, logger) {
|
|
2098
2596
|
let tsconfigPath;
|
|
2099
|
-
if (config.tsconfig) tsconfigPath = isAbsolute(config.tsconfig) ? config.tsconfig : join(config.rootDir, config.tsconfig);
|
|
2100
|
-
else tsconfigPath = join(config.rootDir, "tsconfig.json");
|
|
2597
|
+
if (config.tsconfig) tsconfigPath = isAbsolute(config.tsconfig) ? config.tsconfig : join$1(config.rootDir, config.tsconfig);
|
|
2598
|
+
else tsconfigPath = join$1(config.rootDir, "tsconfig.json");
|
|
2101
2599
|
logger.debug(`Using tsconfig: ${tsconfigPath}`);
|
|
2102
2600
|
const tsconfigContent = await sys.readFile(tsconfigPath);
|
|
2103
2601
|
if (!tsconfigContent) {
|
|
@@ -2127,11 +2625,11 @@ async function getTypeScriptFiles(config, sys, logger) {
|
|
|
2127
2625
|
const configContent = await sys.readFile(configFile);
|
|
2128
2626
|
if (configContent) {
|
|
2129
2627
|
const configSourceFile = ts.createSourceFile(configFile, configContent, ts.ScriptTarget.Latest, true);
|
|
2130
|
-
const configDir = dirname(configFile);
|
|
2628
|
+
const configDir = dirname$1(configFile);
|
|
2131
2629
|
for (const statement of configSourceFile.statements) if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
2132
2630
|
const specifier = statement.moduleSpecifier.text;
|
|
2133
2631
|
if (!specifier.startsWith("./") && !specifier.startsWith("../")) continue;
|
|
2134
|
-
const basePath = join(configDir, specifier);
|
|
2632
|
+
const basePath = join$1(configDir, specifier);
|
|
2135
2633
|
const candidates = basePath.endsWith(".ts") || basePath.endsWith(".tsx") ? [basePath] : [`${basePath}.ts`, `${basePath}.tsx`];
|
|
2136
2634
|
for (const candidate of candidates) if (!candidate.endsWith(".d.ts") && !files.includes(candidate) && candidate.startsWith(config.rootDir)) {
|
|
2137
2635
|
if (await sys.readFile(candidate)) {
|
|
@@ -2245,7 +2743,7 @@ function uuidv4() {
|
|
|
2245
2743
|
* @param path the path on the file system to read and parse
|
|
2246
2744
|
* @returns the parsed JSON
|
|
2247
2745
|
*/
|
|
2248
|
-
async function readJson
|
|
2746
|
+
async function readJson(sys, path) {
|
|
2249
2747
|
const file = await sys.readFile(path);
|
|
2250
2748
|
return file ? JSON.parse(file) : null;
|
|
2251
2749
|
}
|
|
@@ -2277,7 +2775,7 @@ const defaultConfigDirectory = (sys) => sys.resolvePath(`${sys.homeDir()}/.ionic
|
|
|
2277
2775
|
* @returns the config read from disk that has been potentially been updated
|
|
2278
2776
|
*/
|
|
2279
2777
|
async function readConfig(sys) {
|
|
2280
|
-
let config = await readJson
|
|
2778
|
+
let config = await readJson(sys, defaultConfig(sys));
|
|
2281
2779
|
if (!config) {
|
|
2282
2780
|
config = {
|
|
2283
2781
|
"tokens.telemetry": uuidv4(),
|
|
@@ -2515,7 +3013,7 @@ async function getInstalledPackages(sys, flags) {
|
|
|
2515
3013
|
const yarn = isUsingYarn(sys);
|
|
2516
3014
|
try {
|
|
2517
3015
|
const appRootDir = sys.getCurrentDirectory();
|
|
2518
|
-
const packageJson = await tryFn(readJson
|
|
3016
|
+
const packageJson = await tryFn(readJson, sys, sys.resolvePath(appRootDir + "/package.json"));
|
|
2519
3017
|
if (!packageJson) return {
|
|
2520
3018
|
packages,
|
|
2521
3019
|
packagesNoVersions
|
|
@@ -2550,7 +3048,7 @@ async function getInstalledPackages(sys, flags) {
|
|
|
2550
3048
|
*/
|
|
2551
3049
|
async function npmPackages(sys, ionicPackages) {
|
|
2552
3050
|
const appRootDir = sys.getCurrentDirectory();
|
|
2553
|
-
const packageLockJson = await tryFn(readJson
|
|
3051
|
+
const packageLockJson = await tryFn(readJson, sys, sys.resolvePath(appRootDir + "/package-lock.json"));
|
|
2554
3052
|
return ionicPackages.map(([k, v]) => {
|
|
2555
3053
|
let version = packageLockJson?.dependencies[k]?.version ?? packageLockJson?.devDependencies[k]?.version ?? v;
|
|
2556
3054
|
version = version.includes("file:") ? sanitizeDeclaredVersion(v) : version;
|
|
@@ -2744,173 +3242,79 @@ const taskBuild = async (coreCompiler, config, flags) => {
|
|
|
2744
3242
|
config.logger.printDiagnostics(prerenderDiagnostics);
|
|
2745
3243
|
if (prerenderDiagnostics.some((d) => d.level === "error")) exitCode = 1;
|
|
2746
3244
|
}
|
|
2747
|
-
await printCheckVersionResults(versionChecker);
|
|
2748
|
-
} catch (e) {
|
|
2749
|
-
exitCode = 1;
|
|
2750
|
-
config.logger.error(e);
|
|
2751
|
-
}
|
|
2752
|
-
if (exitCode > 0) return config.sys.exit(exitCode);
|
|
2753
|
-
};
|
|
2754
|
-
/**
|
|
2755
|
-
* Prompt the user about available migrations.
|
|
2756
|
-
* Shows what migrations are available and lets them choose to run them.
|
|
2757
|
-
* @param config the Stencil config
|
|
2758
|
-
* @param migrationResult the result of migration detection with available migrations
|
|
2759
|
-
* @param context whether this is a pre-build check or post-error check
|
|
2760
|
-
* @returns the user's chosen action for handling migrations
|
|
2761
|
-
*/
|
|
2762
|
-
async function promptForMigration(config, migrationResult, context) {
|
|
2763
|
-
const logger = config.logger;
|
|
2764
|
-
logger.info("");
|
|
2765
|
-
logger.info(logger.bold(logger.yellow("Migrations Required")));
|
|
2766
|
-
logger.info("─".repeat(40));
|
|
2767
|
-
logger.info(`Found ${migrationResult.totalMatches} item(s) in ${migrationResult.filesAffected} file(s) that need to be migrated for Stencil v5.`);
|
|
2768
|
-
for (const migration of migrationResult.migrations) {
|
|
2769
|
-
const relPath = relative(config.rootDir, migration.filePath);
|
|
2770
|
-
logger.info(` ${logger.cyan(relPath)}: ${migration.matches.length} item(s)`);
|
|
2771
|
-
}
|
|
2772
|
-
logger.info("");
|
|
2773
|
-
if (context === "pre-build") logger.info("Your config contains deprecated options that must be migrated before building.");
|
|
2774
|
-
else logger.info("These migrations may help resolve the build errors above.");
|
|
2775
|
-
const action = await select({
|
|
2776
|
-
message: "What would you like to do?",
|
|
2777
|
-
options: [
|
|
2778
|
-
{
|
|
2779
|
-
value: "run",
|
|
2780
|
-
label: "Run migration",
|
|
2781
|
-
hint: "Apply migrations and re-run build"
|
|
2782
|
-
},
|
|
2783
|
-
{
|
|
2784
|
-
value: "dry-run",
|
|
2785
|
-
label: "Dry run",
|
|
2786
|
-
hint: "Preview changes without modifying files"
|
|
2787
|
-
},
|
|
2788
|
-
{
|
|
2789
|
-
value: "exit",
|
|
2790
|
-
label: "Exit",
|
|
2791
|
-
hint: "Exit without making changes"
|
|
2792
|
-
}
|
|
2793
|
-
]
|
|
2794
|
-
});
|
|
2795
|
-
if (isCancel(action)) return "exit";
|
|
2796
|
-
return action;
|
|
2797
|
-
}
|
|
2798
|
-
//#endregion
|
|
2799
|
-
//#region src/task-docs.ts
|
|
2800
|
-
const taskDocs = async (coreCompiler, config) => {
|
|
2801
|
-
config.devServer = {};
|
|
2802
|
-
config.outputTargets = config.outputTargets.filter(isOutputTargetDocs);
|
|
2803
|
-
config.devMode = true;
|
|
2804
|
-
startupCompilerLog(coreCompiler, config);
|
|
2805
|
-
const compiler = await coreCompiler.createCompiler(config);
|
|
2806
|
-
await compiler.build();
|
|
2807
|
-
await compiler.destroy();
|
|
2808
|
-
};
|
|
2809
|
-
//#endregion
|
|
2810
|
-
//#region src/wizard/clack.ts
|
|
2811
|
-
/**
|
|
2812
|
-
* Exits cleanly if the user cancelled a prompt (Ctrl+C).
|
|
2813
|
-
* Narrows the type from `T | symbol` to `T` for callers.
|
|
2814
|
-
*
|
|
2815
|
-
* @param value - Return value from a `@clack/prompts` prompt call.
|
|
2816
|
-
*/
|
|
2817
|
-
function cancelIfAborted(value) {
|
|
2818
|
-
if (isCancel(value)) {
|
|
2819
|
-
cancel("Cancelled.");
|
|
2820
|
-
process.exit(0);
|
|
2821
|
-
}
|
|
2822
|
-
}
|
|
2823
|
-
//#endregion
|
|
2824
|
-
//#region src/wizard/discover.ts
|
|
2825
|
-
function toStringRecord(val) {
|
|
2826
|
-
return val !== null && typeof val === "object" ? val : {};
|
|
2827
|
-
}
|
|
2828
|
-
async function readJson(filePath) {
|
|
2829
|
-
try {
|
|
2830
|
-
return JSON.parse(await readFile(filePath, "utf8"));
|
|
2831
|
-
} catch {
|
|
2832
|
-
return null;
|
|
2833
|
-
}
|
|
2834
|
-
}
|
|
2835
|
-
async function loadOne(rootDir, packageName, loader) {
|
|
2836
|
-
const wizardEntry = ((await readJson(join$1(rootDir, "node_modules", packageName, "package.json")))?.stencil)?.wizard;
|
|
2837
|
-
if (!wizardEntry) return null;
|
|
2838
|
-
const wizardPath = join$1(rootDir, "node_modules", packageName, wizardEntry);
|
|
2839
|
-
let mod;
|
|
2840
|
-
try {
|
|
2841
|
-
mod = await loader(pathToFileURL(wizardPath).href);
|
|
2842
|
-
} catch {
|
|
2843
|
-
console.warn(`[stencil] ${packageName} declares stencil.wizard but the module failed to load: ${wizardPath}`);
|
|
2844
|
-
return null;
|
|
2845
|
-
}
|
|
2846
|
-
const plugin = mod.wizard;
|
|
2847
|
-
if (!plugin || typeof plugin !== "object") {
|
|
2848
|
-
console.warn(`[stencil] ${packageName} declares stencil.wizard but does not export a 'wizard' object`);
|
|
2849
|
-
return null;
|
|
2850
|
-
}
|
|
2851
|
-
return {
|
|
2852
|
-
packageName,
|
|
2853
|
-
plugin
|
|
2854
|
-
};
|
|
2855
|
-
}
|
|
2856
|
-
/**
|
|
2857
|
-
* Scans the project's declared dependencies for packages that expose a
|
|
2858
|
-
* `stencil.wizard` entry in their `package.json` and dynamically imports
|
|
2859
|
-
* each matching module.
|
|
2860
|
-
*
|
|
2861
|
-
* @param rootDir - Absolute path to the project root (where `package.json` lives).
|
|
2862
|
-
* @param loader - Module loader; injectable for testing. Defaults to `import()`.
|
|
2863
|
-
* @returns Array of successfully loaded plugins, in dependency declaration order.
|
|
2864
|
-
*/
|
|
2865
|
-
async function discoverPlugins(rootDir, loader = (url) => import(url)) {
|
|
2866
|
-
const pkg = await readJson(join$1(rootDir, "package.json"));
|
|
2867
|
-
if (!pkg) return [];
|
|
2868
|
-
const depNames = [...new Set([...Object.keys(toStringRecord(pkg.dependencies)), ...Object.keys(toStringRecord(pkg.devDependencies))])];
|
|
2869
|
-
const plugins = (await Promise.allSettled(depNames.map((name) => loadOne(rootDir, name, loader)))).filter((r) => r.status === "fulfilled" && r.value !== null).map((r) => r.value);
|
|
2870
|
-
const devPath = process.env.STENCIL_WIZARD_DEV;
|
|
2871
|
-
if (devPath) {
|
|
2872
|
-
const devPlugin = await loadDevPlugin(resolve(rootDir, devPath), loader);
|
|
2873
|
-
if (devPlugin) plugins.unshift(devPlugin);
|
|
2874
|
-
}
|
|
2875
|
-
return plugins;
|
|
2876
|
-
}
|
|
2877
|
-
async function findDevPackageName(wizardPath) {
|
|
2878
|
-
const dir = dirname$1(wizardPath);
|
|
2879
|
-
for (const candidate of [dir, resolve(dir, "..")]) {
|
|
2880
|
-
const pkg = await readJson(join$1(candidate, "package.json"));
|
|
2881
|
-
if (typeof pkg?.name === "string") return pkg.name;
|
|
2882
|
-
}
|
|
2883
|
-
return basename(dir);
|
|
2884
|
-
}
|
|
2885
|
-
async function loadDevPlugin(wizardPath, loader) {
|
|
2886
|
-
const packageName = await findDevPackageName(wizardPath);
|
|
2887
|
-
let mod;
|
|
2888
|
-
try {
|
|
2889
|
-
mod = await loader(pathToFileURL(wizardPath).href);
|
|
2890
|
-
} catch {
|
|
2891
|
-
console.warn(`[stencil] STENCIL_WIZARD_DEV: failed to load ${wizardPath}`);
|
|
2892
|
-
return null;
|
|
3245
|
+
await printCheckVersionResults(versionChecker);
|
|
3246
|
+
} catch (e) {
|
|
3247
|
+
exitCode = 1;
|
|
3248
|
+
config.logger.error(e);
|
|
2893
3249
|
}
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
3250
|
+
if (exitCode > 0) return config.sys.exit(exitCode);
|
|
3251
|
+
};
|
|
3252
|
+
/**
|
|
3253
|
+
* Prompt the user about available migrations.
|
|
3254
|
+
* Shows what migrations are available and lets them choose to run them.
|
|
3255
|
+
* @param config the Stencil config
|
|
3256
|
+
* @param migrationResult the result of migration detection with available migrations
|
|
3257
|
+
* @param context whether this is a pre-build check or post-error check
|
|
3258
|
+
* @returns the user's chosen action for handling migrations
|
|
3259
|
+
*/
|
|
3260
|
+
async function promptForMigration(config, migrationResult, context) {
|
|
3261
|
+
const logger = config.logger;
|
|
3262
|
+
logger.info("");
|
|
3263
|
+
logger.info(logger.bold(logger.yellow("Migrations Required")));
|
|
3264
|
+
logger.info("─".repeat(40));
|
|
3265
|
+
logger.info(`Found ${migrationResult.totalMatches} item(s) in ${migrationResult.filesAffected} file(s) that need to be migrated for Stencil v5.`);
|
|
3266
|
+
for (const migration of migrationResult.migrations) {
|
|
3267
|
+
const relPath = relative$1(config.rootDir, migration.filePath);
|
|
3268
|
+
logger.info(` ${logger.cyan(relPath)}: ${migration.matches.length} item(s)`);
|
|
2898
3269
|
}
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
3270
|
+
logger.info("");
|
|
3271
|
+
if (context === "pre-build") logger.info("Your config contains deprecated options that must be migrated before building.");
|
|
3272
|
+
else logger.info("These migrations may help resolve the build errors above.");
|
|
3273
|
+
const action = await select({
|
|
3274
|
+
message: "What would you like to do?",
|
|
3275
|
+
options: [
|
|
3276
|
+
{
|
|
3277
|
+
value: "run",
|
|
3278
|
+
label: "Run migration",
|
|
3279
|
+
hint: "Apply migrations and re-run build"
|
|
3280
|
+
},
|
|
3281
|
+
{
|
|
3282
|
+
value: "dry-run",
|
|
3283
|
+
label: "Dry run",
|
|
3284
|
+
hint: "Preview changes without modifying files"
|
|
3285
|
+
},
|
|
3286
|
+
{
|
|
3287
|
+
value: "exit",
|
|
3288
|
+
label: "Exit",
|
|
3289
|
+
hint: "Exit without making changes"
|
|
3290
|
+
}
|
|
3291
|
+
]
|
|
3292
|
+
});
|
|
3293
|
+
if (isCancel(action)) return "exit";
|
|
3294
|
+
return action;
|
|
2903
3295
|
}
|
|
2904
3296
|
//#endregion
|
|
3297
|
+
//#region src/task-docs.ts
|
|
3298
|
+
const taskDocs = async (coreCompiler, config) => {
|
|
3299
|
+
config.devServer = {};
|
|
3300
|
+
config.outputTargets = config.outputTargets.filter(isOutputTargetDocs);
|
|
3301
|
+
config.devMode = true;
|
|
3302
|
+
startupCompilerLog(coreCompiler, config);
|
|
3303
|
+
const compiler = await coreCompiler.createCompiler(config);
|
|
3304
|
+
await compiler.build();
|
|
3305
|
+
await compiler.destroy();
|
|
3306
|
+
};
|
|
3307
|
+
//#endregion
|
|
2905
3308
|
//#region src/task-generate.ts
|
|
3309
|
+
async function resolveFileTemplates(contrib, ctx) {
|
|
3310
|
+
const { fileTemplates } = contrib;
|
|
3311
|
+
if (!fileTemplates) return [];
|
|
3312
|
+
return typeof fileTemplates === "function" ? fileTemplates(ctx) : fileTemplates;
|
|
3313
|
+
}
|
|
2906
3314
|
const taskGenerate = async (config, flags) => {
|
|
2907
|
-
if (!config.configPath) {
|
|
2908
|
-
config.logger.error("Please run this command in your root directory (i. e. the one containing stencil.config.ts).");
|
|
2909
|
-
return config.sys.exit(1);
|
|
2910
|
-
}
|
|
2911
3315
|
const srcDir = config.srcDir;
|
|
2912
|
-
if (!srcDir) {
|
|
2913
|
-
config.logger.error(
|
|
3316
|
+
if (!srcDir || !existsSync(srcDir)) {
|
|
3317
|
+
config.logger.error("Please run this command in your project root directory.");
|
|
2914
3318
|
return config.sys.exit(1);
|
|
2915
3319
|
}
|
|
2916
3320
|
const generateContribs = (await discoverPlugins(config.rootDir)).flatMap((d) => d.plugin.generate ? [d.plugin.generate] : []);
|
|
@@ -2952,7 +3356,14 @@ const taskGenerate = async (config, flags) => {
|
|
|
2952
3356
|
});
|
|
2953
3357
|
cancelIfAborted(stylePick);
|
|
2954
3358
|
const styleExtension = stylePick || void 0;
|
|
2955
|
-
const
|
|
3359
|
+
const generateCtx = {
|
|
3360
|
+
tagName: componentName,
|
|
3361
|
+
config: toProjectConfig(config),
|
|
3362
|
+
prompts: p,
|
|
3363
|
+
nypm
|
|
3364
|
+
};
|
|
3365
|
+
const allFileTemplates = [];
|
|
3366
|
+
for (const contrib of generateContribs) allFileTemplates.push(...await resolveFileTemplates(contrib, generateCtx));
|
|
2956
3367
|
let pickedExtensions = [];
|
|
2957
3368
|
if (allFileTemplates.length > 0) {
|
|
2958
3369
|
const filePick = await p.multiselect({
|
|
@@ -2967,20 +3378,20 @@ const taskGenerate = async (config, flags) => {
|
|
|
2967
3378
|
cancelIfAborted(filePick);
|
|
2968
3379
|
pickedExtensions = filePick;
|
|
2969
3380
|
}
|
|
2970
|
-
const outDir = join
|
|
3381
|
+
const outDir = join(srcDir, "components", dir, componentName);
|
|
2971
3382
|
const className = toPascalCase(componentName);
|
|
2972
3383
|
const filesToWrite = [];
|
|
2973
3384
|
filesToWrite.push({
|
|
2974
|
-
absPath: normalizePath(join
|
|
3385
|
+
absPath: normalizePath(join(outDir, `${componentName}.tsx`)),
|
|
2975
3386
|
content: getComponentBoilerplate(componentName, styleExtension)
|
|
2976
3387
|
});
|
|
2977
3388
|
if (styleExtension) filesToWrite.push({
|
|
2978
|
-
absPath: normalizePath(join
|
|
3389
|
+
absPath: normalizePath(join(outDir, `${componentName}.${styleExtension}`)),
|
|
2979
3390
|
content: getStyleBoilerplate(styleExtension)
|
|
2980
3391
|
});
|
|
2981
3392
|
for (const ext of pickedExtensions) {
|
|
2982
3393
|
const tmpl = allFileTemplates.find((ft) => ft.extension === ext);
|
|
2983
|
-
const absPath = normalizePath(join
|
|
3394
|
+
const absPath = normalizePath(join(outDir, tmpl.subdirectory ?? "", `${componentName}.${ext}`));
|
|
2984
3395
|
filesToWrite.push({
|
|
2985
3396
|
absPath,
|
|
2986
3397
|
content: tmpl.template(componentName, className)
|
|
@@ -2992,10 +3403,10 @@ const taskGenerate = async (config, flags) => {
|
|
|
2992
3403
|
await config.sys.exit(1);
|
|
2993
3404
|
return;
|
|
2994
3405
|
}
|
|
2995
|
-
const dirs = [...new Set(filesToWrite.map(({ absPath }) => normalizePath(join
|
|
3406
|
+
const dirs = [...new Set(filesToWrite.map(({ absPath }) => normalizePath(join(absPath, ".."))))];
|
|
2996
3407
|
await Promise.all(dirs.map((d) => config.sys.createDir(d, { recursive: true })));
|
|
2997
3408
|
await Promise.all(filesToWrite.map(({ absPath, content }) => config.sys.writeFile(absPath, content)));
|
|
2998
|
-
p.note(filesToWrite.map(({ absPath }) => relative
|
|
3409
|
+
p.note(filesToWrite.map(({ absPath }) => relative(config.rootDir, absPath)).join("\n"), "Generated");
|
|
2999
3410
|
p.outro(`stencil generate ${input}`);
|
|
3000
3411
|
};
|
|
3001
3412
|
//#endregion
|
|
@@ -3127,219 +3538,156 @@ async function copyTemplate(rootDir, projectName, namespace) {
|
|
|
3127
3538
|
});
|
|
3128
3539
|
for (const entry of entries) {
|
|
3129
3540
|
if (!entry.isFile()) continue;
|
|
3130
|
-
const srcPath = join
|
|
3131
|
-
const
|
|
3132
|
-
|
|
3133
|
-
await
|
|
3541
|
+
const srcPath = join(entry.parentPath, entry.name);
|
|
3542
|
+
const relPath = relative(templateDir, srcPath);
|
|
3543
|
+
const destPath = join(rootDir, relPath);
|
|
3544
|
+
await mkdir(dirname(destPath), { recursive: true });
|
|
3545
|
+
const content = (await readFile(srcPath, "utf8")).replace(/\{\{PROJECT_NAME\}\}/g, projectName).replace(/\{\{NAMESPACE\}\}/g, namespace);
|
|
3546
|
+
if (relPath === "package.json") await mergePackageJson(destPath, content);
|
|
3547
|
+
else if (relPath === "tsconfig.json") await mergeTsConfig(destPath, content);
|
|
3548
|
+
else if (relPath === ".gitignore") await mergeGitignore(destPath, content);
|
|
3549
|
+
else await writeIfAbsent(destPath, content);
|
|
3134
3550
|
}
|
|
3135
3551
|
}
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
const pkgPath = join$1(rootDir, "package.json");
|
|
3146
|
-
const pkg = JSON.parse(await readFile(pkgPath, "utf8"));
|
|
3147
|
-
const devDeps = pkg.devDependencies ?? {};
|
|
3148
|
-
for (const name of integrations) devDeps[name] = "latest";
|
|
3149
|
-
pkg.devDependencies = devDeps;
|
|
3150
|
-
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
3552
|
+
async function writeIfAbsent(destPath, content) {
|
|
3553
|
+
try {
|
|
3554
|
+
await writeFile(destPath, content, {
|
|
3555
|
+
encoding: "utf8",
|
|
3556
|
+
flag: "wx"
|
|
3557
|
+
});
|
|
3558
|
+
} catch (e) {
|
|
3559
|
+
if (e.code !== "EEXIST") throw e;
|
|
3560
|
+
}
|
|
3151
3561
|
}
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
group: "Testing"
|
|
3161
|
-
},
|
|
3162
|
-
{
|
|
3163
|
-
package: "@stencil/playwright",
|
|
3164
|
-
displayName: "Playwright",
|
|
3165
|
-
description: "E2E testing",
|
|
3166
|
-
group: "Testing"
|
|
3167
|
-
},
|
|
3168
|
-
{
|
|
3169
|
-
package: "@stencil/sass",
|
|
3170
|
-
displayName: "Sass",
|
|
3171
|
-
description: "Sass/SCSS styles",
|
|
3172
|
-
group: "Styling"
|
|
3173
|
-
},
|
|
3174
|
-
{
|
|
3175
|
-
package: "@stencil/eslint-plugin",
|
|
3176
|
-
displayName: "ESLint Plugin",
|
|
3177
|
-
description: "Stencil-aware lint rules (ESLint, oxlint, Biome)",
|
|
3178
|
-
group: "Linting"
|
|
3179
|
-
},
|
|
3180
|
-
{
|
|
3181
|
-
package: "@stencil/storybook-plugin",
|
|
3182
|
-
displayName: "Storybook",
|
|
3183
|
-
description: "Component development & documentation",
|
|
3184
|
-
group: "Tooling"
|
|
3185
|
-
},
|
|
3186
|
-
{
|
|
3187
|
-
package: "@stencil/types-output-target",
|
|
3188
|
-
displayName: "Types",
|
|
3189
|
-
description: "TypeScript types for React, Vue, Solid, Svelte, Preact",
|
|
3190
|
-
group: "Framework integrations"
|
|
3191
|
-
},
|
|
3192
|
-
{
|
|
3193
|
-
package: "@stencil/react-output-target",
|
|
3194
|
-
displayName: "React",
|
|
3195
|
-
description: "React component wrappers",
|
|
3196
|
-
group: "Framework integrations"
|
|
3197
|
-
},
|
|
3198
|
-
{
|
|
3199
|
-
package: "@stencil/angular-output-target",
|
|
3200
|
-
displayName: "Angular",
|
|
3201
|
-
description: "Angular component wrappers",
|
|
3202
|
-
group: "Framework integrations"
|
|
3203
|
-
},
|
|
3204
|
-
{
|
|
3205
|
-
package: "@stencil/vue-output-target",
|
|
3206
|
-
displayName: "Vue",
|
|
3207
|
-
description: "Vue component wrappers",
|
|
3208
|
-
group: "Framework integrations"
|
|
3562
|
+
async function mergePackageJson(destPath, templateContent) {
|
|
3563
|
+
const template = JSON.parse(templateContent);
|
|
3564
|
+
let existing;
|
|
3565
|
+
try {
|
|
3566
|
+
existing = JSON.parse(await readFile(destPath, "utf8"));
|
|
3567
|
+
} catch {
|
|
3568
|
+
await writeFile(destPath, templateContent, "utf8");
|
|
3569
|
+
return;
|
|
3209
3570
|
}
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
const
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3571
|
+
const dependencies = mergeStringRecord(template.dependencies, existing.dependencies);
|
|
3572
|
+
const devDependencies = mergeStringRecord(template.devDependencies, existing.devDependencies);
|
|
3573
|
+
for (const pkg of Object.keys(devDependencies)) if (pkg in dependencies) delete devDependencies[pkg];
|
|
3574
|
+
const merged = {
|
|
3575
|
+
...template,
|
|
3576
|
+
...existing,
|
|
3577
|
+
scripts: mergeStringRecord(template.scripts, existing.scripts),
|
|
3578
|
+
dependencies,
|
|
3579
|
+
devDependencies
|
|
3580
|
+
};
|
|
3581
|
+
await writeFile(destPath, JSON.stringify(merged, null, 2) + "\n", "utf8");
|
|
3221
3582
|
}
|
|
3222
|
-
function
|
|
3223
|
-
const
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3583
|
+
async function mergeTsConfig(destPath, templateContent) {
|
|
3584
|
+
const template = JSON.parse(templateContent);
|
|
3585
|
+
let existing;
|
|
3586
|
+
try {
|
|
3587
|
+
existing = JSON.parse(await readFile(destPath, "utf8"));
|
|
3588
|
+
} catch {
|
|
3589
|
+
await writeFile(destPath, templateContent, "utf8");
|
|
3590
|
+
return;
|
|
3591
|
+
}
|
|
3592
|
+
const merged = {
|
|
3593
|
+
...template,
|
|
3594
|
+
...existing,
|
|
3595
|
+
compilerOptions: mergeStringRecord(template.compilerOptions, existing.compilerOptions)
|
|
3596
|
+
};
|
|
3597
|
+
await writeFile(destPath, JSON.stringify(merged, null, 2) + "\n", "utf8");
|
|
3230
3598
|
}
|
|
3231
|
-
async function
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3599
|
+
async function mergeGitignore(destPath, templateContent) {
|
|
3600
|
+
let existing;
|
|
3601
|
+
try {
|
|
3602
|
+
existing = await readFile(destPath, "utf8");
|
|
3603
|
+
} catch {
|
|
3604
|
+
await writeFile(destPath, templateContent, "utf8");
|
|
3605
|
+
return;
|
|
3606
|
+
}
|
|
3607
|
+
const existingEntries = new Set(existing.split("\n").map((l) => l.trim()).filter(Boolean));
|
|
3608
|
+
const missing = templateContent.split("\n").filter((line) => line.trim() && !existingEntries.has(line.trim()));
|
|
3609
|
+
if (missing.length === 0) return;
|
|
3610
|
+
const separator = existing.endsWith("\n") ? "" : "\n";
|
|
3611
|
+
await writeFile(destPath, existing + separator + missing.join("\n") + "\n", "utf8");
|
|
3239
3612
|
}
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
* run init wizards for already-installed packages with wizard contributions.
|
|
3243
|
-
*
|
|
3244
|
-
* @param installable - KNOWN_INTEGRATIONS not yet present in the project.
|
|
3245
|
-
* @param configurable - Already-installed plugins that declare an `init` contribution.
|
|
3246
|
-
* @returns Selected integrations to install and plugins to configure.
|
|
3247
|
-
*/
|
|
3248
|
-
async function promptAddCapabilities(installable, configurable) {
|
|
3249
|
-
const options = {};
|
|
3250
|
-
if (installable.length > 0) options["Install new integrations"] = installable.map((i) => ({
|
|
3251
|
-
value: `install:${i.package}`,
|
|
3252
|
-
label: i.displayName,
|
|
3253
|
-
hint: i.description
|
|
3254
|
-
}));
|
|
3255
|
-
if (configurable.length > 0) options["Configure existing integrations"] = configurable.map((d) => ({
|
|
3256
|
-
value: `configure:${d.packageName}`,
|
|
3257
|
-
label: d.plugin.init.displayName,
|
|
3258
|
-
hint: d.plugin.init.description
|
|
3259
|
-
}));
|
|
3260
|
-
const picks = await p.groupMultiselect({
|
|
3261
|
-
message: "What would you like to do?",
|
|
3262
|
-
options,
|
|
3263
|
-
required: false
|
|
3264
|
-
});
|
|
3265
|
-
cancelIfAborted(picks);
|
|
3266
|
-
const pickedSet = new Set(picks);
|
|
3613
|
+
function mergeStringRecord(base, override) {
|
|
3614
|
+
const toObj = (v) => v !== null && typeof v === "object" ? v : {};
|
|
3267
3615
|
return {
|
|
3268
|
-
|
|
3269
|
-
|
|
3616
|
+
...toObj(base),
|
|
3617
|
+
...toObj(override)
|
|
3270
3618
|
};
|
|
3271
3619
|
}
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
const noColor = !process.stdout.isTTY || "NO_COLOR" in process.env;
|
|
3275
|
-
const RESET = noColor ? "" : "\x1B[0m";
|
|
3276
|
-
const BG = noColor ? "" : "\x1B[38;2;60;44;255m";
|
|
3277
|
-
const RAW = `\
|
|
3278
|
-
.............
|
|
3279
|
-
...................
|
|
3280
|
-
.........................
|
|
3281
|
-
..............................
|
|
3282
|
-
.................................
|
|
3283
|
-
..............████████████.........
|
|
3284
|
-
.............████████████............
|
|
3285
|
-
............████████████...............
|
|
3286
|
-
...........***************...............
|
|
3287
|
-
.........████████████████████████████....
|
|
3288
|
-
.......████████████████████████████......
|
|
3289
|
-
.....████████████████████████████........
|
|
3290
|
-
...████████████████████████████..........
|
|
3291
|
-
...............**************............
|
|
3292
|
-
..............████████████.............
|
|
3293
|
-
............████████████..............
|
|
3294
|
-
.........████████████...............
|
|
3295
|
-
.................................
|
|
3296
|
-
..............................
|
|
3297
|
-
..........................
|
|
3298
|
-
......................
|
|
3299
|
-
................`;
|
|
3300
|
-
function colorize(raw) {
|
|
3301
|
-
if (noColor) return raw;
|
|
3302
|
-
let out = "";
|
|
3303
|
-
let style = "";
|
|
3304
|
-
for (const ch of raw) {
|
|
3305
|
-
const next = ".*".includes(ch) ? BG : "";
|
|
3306
|
-
if (next !== style) {
|
|
3307
|
-
if (style) out += RESET;
|
|
3308
|
-
if (next) out += next;
|
|
3309
|
-
style = next;
|
|
3310
|
-
}
|
|
3311
|
-
out += ch;
|
|
3312
|
-
}
|
|
3313
|
-
return style ? out + RESET : out;
|
|
3620
|
+
async function writeStencilConfig(rootDir, content) {
|
|
3621
|
+
await writeFile(join(rootDir, "stencil.config.ts"), content, "utf8");
|
|
3314
3622
|
}
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3623
|
+
async function writeGlobalStyle(rootDir) {
|
|
3624
|
+
const path = join(rootDir, "src", "global.css");
|
|
3625
|
+
await mkdir(dirname(path), { recursive: true });
|
|
3626
|
+
await writeIfAbsent(path, `@import "stencil-globals";\n@import "stencil-hydrate";\n`);
|
|
3627
|
+
}
|
|
3628
|
+
async function writeGlobalScript(rootDir) {
|
|
3629
|
+
const path = join(rootDir, "src", "global.ts");
|
|
3630
|
+
await mkdir(dirname(path), { recursive: true });
|
|
3631
|
+
await writeIfAbsent(path, `export default function (): void {}\n`);
|
|
3632
|
+
}
|
|
3633
|
+
/**
|
|
3634
|
+
* Write output-driven distributable fields (type, module, types) into package.json.
|
|
3635
|
+
* These fields depend on which outputs the user selected, so they cannot be static in the template.
|
|
3636
|
+
* Skips if fields is empty (e.g. www-only project).
|
|
3637
|
+
*
|
|
3638
|
+
* @param rootDir - Absolute path to the project root.
|
|
3639
|
+
* @param fields - Fields to write, from generatePackageJsonFields().
|
|
3640
|
+
*/
|
|
3641
|
+
async function applyPackageJsonFields(rootDir, fields) {
|
|
3642
|
+
if (Object.keys(fields).length === 0) return;
|
|
3643
|
+
const pkgPath = join(rootDir, "package.json");
|
|
3644
|
+
const pkg = JSON.parse(await readFile(pkgPath, "utf8"));
|
|
3645
|
+
Object.assign(pkg, fields);
|
|
3646
|
+
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
3319
3647
|
}
|
|
3320
3648
|
//#endregion
|
|
3321
3649
|
//#region src/task-init.ts
|
|
3322
|
-
|
|
3650
|
+
function outputKeysToTargets(keys) {
|
|
3651
|
+
const map = {
|
|
3652
|
+
loader: "loader-bundle",
|
|
3653
|
+
standalone: "standalone",
|
|
3654
|
+
ssr: "ssr",
|
|
3655
|
+
"ssr-wasm": "ssr-wasm",
|
|
3656
|
+
www: "www"
|
|
3657
|
+
};
|
|
3658
|
+
return keys.length > 0 ? keys.map((k) => ({ type: map[k] })) : [{ type: "loader-bundle" }];
|
|
3659
|
+
}
|
|
3660
|
+
async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
3323
3661
|
const cwd = process.cwd();
|
|
3324
|
-
const isExistingProject =
|
|
3662
|
+
const isExistingProject = await isExistingStencilProject(cwd);
|
|
3325
3663
|
printSplash();
|
|
3326
|
-
p.intro(
|
|
3664
|
+
p.intro(`stencil init`);
|
|
3327
3665
|
if (process.env.STENCIL_WIZARD_DEV) p.log.warn(`Dev mode: loading wizard from ${process.env.STENCIL_WIZARD_DEV}`);
|
|
3328
3666
|
if (isCI) {
|
|
3329
3667
|
p.log.warn("Running in CI - non-interactive mode is not yet supported for `stencil init`.");
|
|
3330
3668
|
process.exit(1);
|
|
3331
3669
|
}
|
|
3332
3670
|
if (isExistingProject) {
|
|
3333
|
-
await addCapabilities(cwd);
|
|
3671
|
+
await addCapabilities(cwd, strictConfig);
|
|
3334
3672
|
return;
|
|
3335
3673
|
}
|
|
3336
3674
|
const projectName = await promptProjectName();
|
|
3337
3675
|
const namespace = toNamespace(projectName);
|
|
3676
|
+
const outputs = await promptOutputs();
|
|
3677
|
+
const features = await promptFeatures();
|
|
3678
|
+
const docs = await promptDocs();
|
|
3338
3679
|
const selectedIntegrations = await promptIntegrations();
|
|
3680
|
+
const configSource = generateStencilConfig({
|
|
3681
|
+
namespace,
|
|
3682
|
+
outputs,
|
|
3683
|
+
signals: features.signals,
|
|
3684
|
+
docs
|
|
3685
|
+
});
|
|
3339
3686
|
const summaryLines = [
|
|
3340
3687
|
`Template: component-starter`,
|
|
3341
3688
|
`Name: ${projectName}`,
|
|
3342
|
-
`Namespace: ${namespace}
|
|
3689
|
+
`Namespace: ${namespace}`,
|
|
3690
|
+
`Config: ${configSource ? "stencil.config.ts" : "zero-config (loader default)"}`
|
|
3343
3691
|
];
|
|
3344
3692
|
if (selectedIntegrations.length > 0) summaryLines.push(`Add: ${selectedIntegrations.map((i) => i.displayName).join(", ")}`);
|
|
3345
3693
|
p.note(summaryLines.join("\n"), "Summary");
|
|
@@ -3352,8 +3700,11 @@ async function taskInit() {
|
|
|
3352
3700
|
const s1 = p.spinner();
|
|
3353
3701
|
s1.start("Scaffolding project files");
|
|
3354
3702
|
await copyTemplate(cwd, projectName, namespace);
|
|
3703
|
+
await applyPackageJsonFields(cwd, generatePackageJsonFields(outputs));
|
|
3704
|
+
if (configSource) await writeStencilConfig(cwd, configSource);
|
|
3705
|
+
if (features.globalStyle) await writeGlobalStyle(cwd);
|
|
3706
|
+
if (features.globalScript) await writeGlobalScript(cwd);
|
|
3355
3707
|
s1.stop("Project files created");
|
|
3356
|
-
if (selectedIntegrations.length > 0) await patchPackageJson(cwd, selectedIntegrations.map((i) => i.package));
|
|
3357
3708
|
const s2 = p.spinner();
|
|
3358
3709
|
s2.start("Installing dependencies");
|
|
3359
3710
|
await installDependencies({
|
|
@@ -3361,19 +3712,36 @@ async function taskInit() {
|
|
|
3361
3712
|
silent: true
|
|
3362
3713
|
});
|
|
3363
3714
|
s2.stop("Dependencies installed");
|
|
3715
|
+
if (selectedIntegrations.length > 0) {
|
|
3716
|
+
const s3 = p.spinner();
|
|
3717
|
+
const pkgs = selectedIntegrations.map((i) => i.package);
|
|
3718
|
+
s3.start(`Installing ${pkgs.join(", ")}`);
|
|
3719
|
+
await addDevDependency(pkgs, {
|
|
3720
|
+
cwd,
|
|
3721
|
+
silent: true
|
|
3722
|
+
});
|
|
3723
|
+
s3.stop("Integrations installed");
|
|
3724
|
+
}
|
|
3364
3725
|
if (selectedIntegrations.length > 0) {
|
|
3365
3726
|
const discovered = await discoverPlugins(cwd);
|
|
3366
3727
|
const selectedPkgs = new Set(selectedIntegrations.map((i) => i.package));
|
|
3367
|
-
const
|
|
3728
|
+
const resolvedValidated = loadProjectConfig ? await loadProjectConfig(configSource ? join(cwd, "stencil.config.ts") : void 0) : coreCompiler ? coreCompiler.validateConfig({
|
|
3368
3729
|
rootDir: cwd,
|
|
3369
|
-
|
|
3730
|
+
outputTargets: outputKeysToTargets(outputs),
|
|
3731
|
+
...configSource ? { namespace } : {}
|
|
3732
|
+
}, {}).config : null;
|
|
3733
|
+
const context = {
|
|
3734
|
+
isNewProject: true,
|
|
3735
|
+
prompts: p,
|
|
3736
|
+
nypm,
|
|
3737
|
+
config: resolvedValidated ? toProjectConfig(resolvedValidated) : defaultProjectConfig(cwd, { namespace })
|
|
3370
3738
|
};
|
|
3371
3739
|
for (const d of discovered) if (selectedPkgs.has(d.packageName) && d.plugin.init?.run) await d.plugin.init.run(context);
|
|
3372
3740
|
}
|
|
3373
3741
|
p.outro("Your project is ready! Run: pnpm run dev");
|
|
3374
3742
|
}
|
|
3375
|
-
async function addCapabilities(cwd) {
|
|
3376
|
-
const raw = JSON.parse(await readFile(join
|
|
3743
|
+
async function addCapabilities(cwd, strictConfig) {
|
|
3744
|
+
const raw = JSON.parse(await readFile(join(cwd, "package.json"), "utf8"));
|
|
3377
3745
|
const installed = new Set([...Object.keys(raw.dependencies ?? {}), ...Object.keys(raw.devDependencies ?? {})]);
|
|
3378
3746
|
const discovered = await discoverPlugins(cwd);
|
|
3379
3747
|
const configurable = discovered.filter((d) => d.plugin.init);
|
|
@@ -3399,10 +3767,10 @@ async function addCapabilities(cwd) {
|
|
|
3399
3767
|
process.exit(0);
|
|
3400
3768
|
}
|
|
3401
3769
|
if (toInstall.length > 0) {
|
|
3402
|
-
await patchPackageJson(cwd, toInstall.map((i) => i.package));
|
|
3403
3770
|
const s = p.spinner();
|
|
3404
|
-
|
|
3405
|
-
|
|
3771
|
+
const pkgs = toInstall.map((i) => i.package);
|
|
3772
|
+
s.start(`Installing ${pkgs.join(", ")}`);
|
|
3773
|
+
await addDevDependency(pkgs, {
|
|
3406
3774
|
cwd,
|
|
3407
3775
|
silent: true
|
|
3408
3776
|
});
|
|
@@ -3412,8 +3780,10 @@ async function addCapabilities(cwd) {
|
|
|
3412
3780
|
const newlyInstalledPkgs = new Set(toInstall.map((i) => i.package));
|
|
3413
3781
|
const toRun = [...allDiscovered.filter((d) => newlyInstalledPkgs.has(d.packageName)), ...toConfigure].filter((d) => d.plugin.init?.run);
|
|
3414
3782
|
const context = {
|
|
3415
|
-
|
|
3416
|
-
|
|
3783
|
+
isNewProject: false,
|
|
3784
|
+
prompts: p,
|
|
3785
|
+
nypm,
|
|
3786
|
+
config: strictConfig ? toProjectConfig(strictConfig) : defaultProjectConfig(cwd)
|
|
3417
3787
|
};
|
|
3418
3788
|
for (const d of toRun) await d.plugin.init.run(context);
|
|
3419
3789
|
p.outro("Done! Run pnpm run dev to continue.");
|
|
@@ -3477,8 +3847,37 @@ const run = async (init) => {
|
|
|
3477
3847
|
}), logger, sys);
|
|
3478
3848
|
return;
|
|
3479
3849
|
}
|
|
3480
|
-
if (task === "init") {
|
|
3481
|
-
await
|
|
3850
|
+
if (task === "add" || task === "init") {
|
|
3851
|
+
const coreCompiler = await loadCoreCompiler(sys);
|
|
3852
|
+
const rootDir = sys.getCurrentDirectory();
|
|
3853
|
+
const findConfigResults = await findConfig({
|
|
3854
|
+
sys,
|
|
3855
|
+
configPath: flags.config
|
|
3856
|
+
});
|
|
3857
|
+
let strictConfig;
|
|
3858
|
+
if (!findConfigResults.isErr) {
|
|
3859
|
+
const foundConfig = result.unwrap(findConfigResults);
|
|
3860
|
+
const loaded = await coreCompiler.loadConfig({
|
|
3861
|
+
config: { rootDir },
|
|
3862
|
+
configPath: foundConfig.configPath ?? void 0,
|
|
3863
|
+
logger,
|
|
3864
|
+
sys
|
|
3865
|
+
});
|
|
3866
|
+
strictConfig = coreCompiler.validateConfig(loaded.config, {}).config;
|
|
3867
|
+
} else strictConfig = coreCompiler.validateConfig({ rootDir }, {}).config;
|
|
3868
|
+
if (task === "add") await taskAdd(flags.unknownArgs, strictConfig);
|
|
3869
|
+
else {
|
|
3870
|
+
const loadProjectConfig = async (configPath) => {
|
|
3871
|
+
const loaded = await coreCompiler.loadConfig({
|
|
3872
|
+
config: { rootDir },
|
|
3873
|
+
configPath,
|
|
3874
|
+
logger,
|
|
3875
|
+
sys
|
|
3876
|
+
});
|
|
3877
|
+
return coreCompiler.validateConfig(loaded.config, {}).config;
|
|
3878
|
+
};
|
|
3879
|
+
await taskInit(coreCompiler, strictConfig, loadProjectConfig);
|
|
3880
|
+
}
|
|
3482
3881
|
return;
|
|
3483
3882
|
}
|
|
3484
3883
|
startupLog(logger, task);
|
|
@@ -3538,6 +3937,9 @@ const runTask = async (coreCompiler, config, task, sys, flags) => {
|
|
|
3538
3937
|
if (!configWithFlags.sys) configWithFlags.sys = sys;
|
|
3539
3938
|
const strictConfig = coreCompiler.validateConfig(configWithFlags, {}).config;
|
|
3540
3939
|
switch (task) {
|
|
3940
|
+
case "add":
|
|
3941
|
+
await taskAdd(resolvedFlags.unknownArgs ?? [], strictConfig);
|
|
3942
|
+
break;
|
|
3541
3943
|
case "build":
|
|
3542
3944
|
await taskBuild(coreCompiler, strictConfig, resolvedFlags);
|
|
3543
3945
|
break;
|
|
@@ -3552,7 +3954,7 @@ const runTask = async (coreCompiler, config, task, sys, flags) => {
|
|
|
3552
3954
|
await taskHelp(resolvedFlags, strictConfig.logger, sys);
|
|
3553
3955
|
break;
|
|
3554
3956
|
case "init":
|
|
3555
|
-
await taskInit();
|
|
3957
|
+
await taskInit(coreCompiler, strictConfig);
|
|
3556
3958
|
break;
|
|
3557
3959
|
case "migrate":
|
|
3558
3960
|
await taskMigrate(coreCompiler, strictConfig, resolvedFlags);
|