weapp-vite 5.6.3 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-routes.cjs +2 -2
- package/dist/auto-routes.mjs +1 -1
- package/dist/{chunk-LE4PAGI5.mjs → chunk-AKJEW44F.mjs} +647 -405
- package/dist/{chunk-OQYESMEY.cjs → chunk-FUJ4D6IR.cjs} +757 -515
- package/dist/{chunk-7EOV7C3M.mjs → chunk-GU7U5762.mjs} +1 -1
- package/dist/{chunk-WYNGNSLK.cjs → chunk-VRKZFXIZ.cjs} +4 -4
- package/dist/cli.cjs +879 -280
- package/dist/cli.mjs +880 -281
- package/dist/{config-BuTlQpli.d.cts → config-C-oMiscN.d.cts} +10 -0
- package/dist/{config-BB6bSUwe.d.ts → config-CbKHc1kT.d.ts} +10 -0
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/json.d.cts +1 -1
- package/dist/json.d.ts +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createCompilerContext
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GU7U5762.mjs";
|
|
4
4
|
import {
|
|
5
5
|
DEFAULT_MP_PLATFORM,
|
|
6
|
+
SHARED_CHUNK_VIRTUAL_PREFIX,
|
|
6
7
|
VERSION,
|
|
7
8
|
checkRuntime,
|
|
9
|
+
createSharedBuildConfig,
|
|
8
10
|
logger_default,
|
|
9
11
|
normalizeMiniPlatform,
|
|
10
12
|
resolveMiniPlatform,
|
|
11
13
|
resolveWeappConfigFile
|
|
12
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-AKJEW44F.mjs";
|
|
13
15
|
import {
|
|
14
16
|
init_esm_shims
|
|
15
17
|
} from "./chunk-SSQGJIB5.mjs";
|
|
16
18
|
|
|
17
19
|
// src/cli.ts
|
|
18
20
|
init_esm_shims();
|
|
19
|
-
import process3 from "process";
|
|
20
|
-
import { createProject, initConfig } from "@weapp-core/init";
|
|
21
|
-
import { defu as defu2 } from "@weapp-core/shared";
|
|
22
21
|
|
|
23
22
|
// ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
|
|
24
23
|
init_esm_shims();
|
|
@@ -123,7 +122,7 @@ var findAllBrackets = (v) => {
|
|
|
123
122
|
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
124
123
|
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
125
124
|
const res = [];
|
|
126
|
-
const
|
|
125
|
+
const parse3 = (match) => {
|
|
127
126
|
let variadic = false;
|
|
128
127
|
let value = match[1];
|
|
129
128
|
if (value.startsWith("...")) {
|
|
@@ -138,11 +137,11 @@ var findAllBrackets = (v) => {
|
|
|
138
137
|
};
|
|
139
138
|
let angledMatch;
|
|
140
139
|
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
|
|
141
|
-
res.push(
|
|
140
|
+
res.push(parse3(angledMatch));
|
|
142
141
|
}
|
|
143
142
|
let squareMatch;
|
|
144
143
|
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
|
|
145
|
-
res.push(
|
|
144
|
+
res.push(parse3(squareMatch));
|
|
146
145
|
}
|
|
147
146
|
return res;
|
|
148
147
|
};
|
|
@@ -606,6 +605,627 @@ var CAC = class extends EventEmitter {
|
|
|
606
605
|
};
|
|
607
606
|
var cac = (name = "") => new CAC(name);
|
|
608
607
|
|
|
608
|
+
// src/cli/commands/analyze.ts
|
|
609
|
+
init_esm_shims();
|
|
610
|
+
import process2 from "process";
|
|
611
|
+
import fs from "fs-extra";
|
|
612
|
+
import path2 from "pathe";
|
|
613
|
+
|
|
614
|
+
// src/analyze/subpackages.ts
|
|
615
|
+
init_esm_shims();
|
|
616
|
+
import { Buffer } from "buffer";
|
|
617
|
+
import { posix as path } from "pathe";
|
|
618
|
+
import { build } from "vite";
|
|
619
|
+
var VIRTUAL_MODULE_INDICATOR = "\0";
|
|
620
|
+
var VIRTUAL_PREFIX = `${SHARED_CHUNK_VIRTUAL_PREFIX}/`;
|
|
621
|
+
function isPathInside(parent, candidate) {
|
|
622
|
+
if (!parent) {
|
|
623
|
+
return false;
|
|
624
|
+
}
|
|
625
|
+
const relative = path.relative(parent, candidate);
|
|
626
|
+
return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
627
|
+
}
|
|
628
|
+
function ensurePackage(packages, classification) {
|
|
629
|
+
const existing = packages.get(classification.id);
|
|
630
|
+
if (existing) {
|
|
631
|
+
return existing;
|
|
632
|
+
}
|
|
633
|
+
const created = {
|
|
634
|
+
...classification,
|
|
635
|
+
files: /* @__PURE__ */ new Map()
|
|
636
|
+
};
|
|
637
|
+
packages.set(classification.id, created);
|
|
638
|
+
return created;
|
|
639
|
+
}
|
|
640
|
+
function ensureModule(modules, id, source, sourceType) {
|
|
641
|
+
const existing = modules.get(id);
|
|
642
|
+
if (existing) {
|
|
643
|
+
return existing;
|
|
644
|
+
}
|
|
645
|
+
const created = {
|
|
646
|
+
id,
|
|
647
|
+
source,
|
|
648
|
+
sourceType,
|
|
649
|
+
packages: /* @__PURE__ */ new Map()
|
|
650
|
+
};
|
|
651
|
+
modules.set(id, created);
|
|
652
|
+
return created;
|
|
653
|
+
}
|
|
654
|
+
function registerModuleInPackage(modules, moduleId, source, sourceType, packageId, fileName) {
|
|
655
|
+
const moduleEntry = ensureModule(modules, moduleId, source, sourceType);
|
|
656
|
+
const files = moduleEntry.packages.get(packageId) ?? /* @__PURE__ */ new Set();
|
|
657
|
+
files.add(fileName);
|
|
658
|
+
moduleEntry.packages.set(packageId, files);
|
|
659
|
+
}
|
|
660
|
+
function classifyPackage(fileName, origin, context) {
|
|
661
|
+
if (fileName.startsWith(VIRTUAL_PREFIX)) {
|
|
662
|
+
const combination = fileName.slice(VIRTUAL_PREFIX.length).split("/")[0] || "shared";
|
|
663
|
+
return {
|
|
664
|
+
id: `virtual:${combination}`,
|
|
665
|
+
label: `\u5171\u4EAB\u865A\u62DF\u5305 ${combination}`,
|
|
666
|
+
type: "virtual"
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
const segments = fileName.split("/");
|
|
670
|
+
const rootCandidate = segments[0] ?? "";
|
|
671
|
+
if (rootCandidate && context.subPackageRoots.has(rootCandidate)) {
|
|
672
|
+
const isIndependent = context.independentRoots.has(rootCandidate);
|
|
673
|
+
return {
|
|
674
|
+
id: rootCandidate,
|
|
675
|
+
label: `${isIndependent ? "\u72EC\u7ACB\u5206\u5305" : "\u5206\u5305"} ${rootCandidate}`,
|
|
676
|
+
type: isIndependent || origin === "independent" ? "independent" : "subPackage"
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
return {
|
|
680
|
+
id: "__main__",
|
|
681
|
+
label: "\u4E3B\u5305",
|
|
682
|
+
type: "main"
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
function normalizeModuleId(id) {
|
|
686
|
+
if (!id || id.includes(VIRTUAL_MODULE_INDICATOR)) {
|
|
687
|
+
return void 0;
|
|
688
|
+
}
|
|
689
|
+
if (!path.isAbsolute(id)) {
|
|
690
|
+
return void 0;
|
|
691
|
+
}
|
|
692
|
+
return path.normalize(id);
|
|
693
|
+
}
|
|
694
|
+
function resolveModuleSourceType(absoluteId, ctx) {
|
|
695
|
+
const { configService } = ctx;
|
|
696
|
+
const isNodeModule = absoluteId.includes("/node_modules/") || absoluteId.includes("\\node_modules\\");
|
|
697
|
+
const pluginRoot = configService.absolutePluginRoot;
|
|
698
|
+
const srcRoot = configService.absoluteSrcRoot;
|
|
699
|
+
const inSrc = isPathInside(srcRoot, absoluteId);
|
|
700
|
+
const inPlugin = pluginRoot ? isPathInside(pluginRoot, absoluteId) : false;
|
|
701
|
+
let sourceType;
|
|
702
|
+
if (isNodeModule) {
|
|
703
|
+
sourceType = "node_modules";
|
|
704
|
+
} else if (inSrc) {
|
|
705
|
+
sourceType = "src";
|
|
706
|
+
} else if (inPlugin) {
|
|
707
|
+
sourceType = "plugin";
|
|
708
|
+
} else {
|
|
709
|
+
sourceType = "workspace";
|
|
710
|
+
}
|
|
711
|
+
return {
|
|
712
|
+
source: configService.relativeAbsoluteSrcRoot(absoluteId),
|
|
713
|
+
sourceType
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
function resolveAssetSource(fileName, ctx) {
|
|
717
|
+
const { configService } = ctx;
|
|
718
|
+
const normalized = path.normalize(fileName);
|
|
719
|
+
const srcCandidate = path.resolve(configService.absoluteSrcRoot, normalized);
|
|
720
|
+
if (isPathInside(configService.absoluteSrcRoot, srcCandidate)) {
|
|
721
|
+
return {
|
|
722
|
+
absolute: srcCandidate,
|
|
723
|
+
source: configService.relativeAbsoluteSrcRoot(srcCandidate),
|
|
724
|
+
sourceType: "src"
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
const pluginRoot = configService.absolutePluginRoot;
|
|
728
|
+
if (pluginRoot) {
|
|
729
|
+
const pluginBase = path.basename(pluginRoot);
|
|
730
|
+
if (normalized === pluginBase || normalized.startsWith(`${pluginBase}/`)) {
|
|
731
|
+
const relative = normalized === pluginBase ? "" : normalized.slice(pluginBase.length + 1);
|
|
732
|
+
const absolute = path.resolve(pluginRoot, relative);
|
|
733
|
+
if (isPathInside(pluginRoot, absolute)) {
|
|
734
|
+
return {
|
|
735
|
+
absolute,
|
|
736
|
+
source: configService.relativeAbsoluteSrcRoot(absolute),
|
|
737
|
+
sourceType: "plugin"
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
function toArray(value) {
|
|
744
|
+
return Array.from(value);
|
|
745
|
+
}
|
|
746
|
+
function getAssetSize(asset) {
|
|
747
|
+
if (typeof asset.source === "string") {
|
|
748
|
+
return Buffer.byteLength(asset.source, "utf8");
|
|
749
|
+
}
|
|
750
|
+
if (asset.source instanceof Uint8Array) {
|
|
751
|
+
return asset.source.byteLength;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
function processChunk(chunk, origin, ctx, classifierContext, packages, modules) {
|
|
755
|
+
const classification = classifyPackage(chunk.fileName, origin, classifierContext);
|
|
756
|
+
const packageEntry = ensurePackage(packages, classification);
|
|
757
|
+
const chunkEntry = {
|
|
758
|
+
file: chunk.fileName,
|
|
759
|
+
type: "chunk",
|
|
760
|
+
from: origin,
|
|
761
|
+
size: typeof chunk.code === "string" ? Buffer.byteLength(chunk.code, "utf8") : void 0,
|
|
762
|
+
isEntry: chunk.isEntry,
|
|
763
|
+
modules: []
|
|
764
|
+
};
|
|
765
|
+
const moduleEntries = Object.entries(chunk.modules ?? {});
|
|
766
|
+
for (const [rawModuleId, info] of moduleEntries) {
|
|
767
|
+
const absoluteId = normalizeModuleId(rawModuleId);
|
|
768
|
+
if (!absoluteId) {
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
const { source, sourceType } = resolveModuleSourceType(absoluteId, ctx);
|
|
772
|
+
const moduleEntry = {
|
|
773
|
+
id: absoluteId,
|
|
774
|
+
source,
|
|
775
|
+
sourceType,
|
|
776
|
+
bytes: info?.renderedLength
|
|
777
|
+
};
|
|
778
|
+
if (typeof info?.code === "string") {
|
|
779
|
+
moduleEntry.originalBytes = Buffer.byteLength(info.code, "utf8");
|
|
780
|
+
}
|
|
781
|
+
chunkEntry.modules.push(moduleEntry);
|
|
782
|
+
registerModuleInPackage(
|
|
783
|
+
modules,
|
|
784
|
+
absoluteId,
|
|
785
|
+
source,
|
|
786
|
+
sourceType,
|
|
787
|
+
classification.id,
|
|
788
|
+
chunk.fileName
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
if (chunkEntry.modules) {
|
|
792
|
+
chunkEntry.modules.sort((a, b) => a.source.localeCompare(b.source));
|
|
793
|
+
}
|
|
794
|
+
packageEntry.files.set(chunk.fileName, chunkEntry);
|
|
795
|
+
}
|
|
796
|
+
function processAsset(asset, origin, ctx, classifierContext, packages, modules) {
|
|
797
|
+
const classification = classifyPackage(asset.fileName, origin, classifierContext);
|
|
798
|
+
const packageEntry = ensurePackage(packages, classification);
|
|
799
|
+
const entry = {
|
|
800
|
+
file: asset.fileName,
|
|
801
|
+
type: "asset",
|
|
802
|
+
from: origin,
|
|
803
|
+
size: getAssetSize(asset)
|
|
804
|
+
};
|
|
805
|
+
const assetSource = resolveAssetSource(asset.fileName, ctx);
|
|
806
|
+
if (assetSource) {
|
|
807
|
+
entry.source = assetSource.source;
|
|
808
|
+
registerModuleInPackage(
|
|
809
|
+
modules,
|
|
810
|
+
assetSource.absolute,
|
|
811
|
+
assetSource.source,
|
|
812
|
+
assetSource.sourceType,
|
|
813
|
+
classification.id,
|
|
814
|
+
asset.fileName
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
packageEntry.files.set(asset.fileName, entry);
|
|
818
|
+
}
|
|
819
|
+
function processOutput(output, origin, ctx, classifierContext, packages, modules) {
|
|
820
|
+
if (!output) {
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
for (const item of output.output ?? []) {
|
|
824
|
+
if (item.type === "chunk") {
|
|
825
|
+
processChunk(item, origin, ctx, classifierContext, packages, modules);
|
|
826
|
+
} else if (item.type === "asset") {
|
|
827
|
+
processAsset(item, origin, ctx, classifierContext, packages, modules);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
function summarizePackages(packages) {
|
|
832
|
+
const order = {
|
|
833
|
+
main: 0,
|
|
834
|
+
subPackage: 1,
|
|
835
|
+
independent: 2,
|
|
836
|
+
virtual: 3
|
|
837
|
+
};
|
|
838
|
+
const reports = toArray(packages.values()).map((pkg) => {
|
|
839
|
+
const files = toArray(pkg.files.values());
|
|
840
|
+
files.sort((a, b) => a.file.localeCompare(b.file));
|
|
841
|
+
return {
|
|
842
|
+
id: pkg.id,
|
|
843
|
+
label: pkg.label,
|
|
844
|
+
type: pkg.type,
|
|
845
|
+
files
|
|
846
|
+
};
|
|
847
|
+
});
|
|
848
|
+
reports.sort((a, b) => {
|
|
849
|
+
const delta = order[a.type] - order[b.type];
|
|
850
|
+
if (delta !== 0) {
|
|
851
|
+
return delta;
|
|
852
|
+
}
|
|
853
|
+
if (a.id === "__main__") {
|
|
854
|
+
return -1;
|
|
855
|
+
}
|
|
856
|
+
if (b.id === "__main__") {
|
|
857
|
+
return 1;
|
|
858
|
+
}
|
|
859
|
+
return a.id.localeCompare(b.id);
|
|
860
|
+
});
|
|
861
|
+
return reports;
|
|
862
|
+
}
|
|
863
|
+
function summarizeModules(modules) {
|
|
864
|
+
const usage = toArray(modules.values()).map((module) => {
|
|
865
|
+
const packages = toArray(module.packages.entries()).map(([packageId, files]) => {
|
|
866
|
+
const sortedFiles = toArray(files).sort((a, b) => a.localeCompare(b));
|
|
867
|
+
return {
|
|
868
|
+
packageId,
|
|
869
|
+
files: sortedFiles
|
|
870
|
+
};
|
|
871
|
+
}).sort((a, b) => {
|
|
872
|
+
if (a.packageId === b.packageId) {
|
|
873
|
+
return 0;
|
|
874
|
+
}
|
|
875
|
+
if (a.packageId === "__main__") {
|
|
876
|
+
return -1;
|
|
877
|
+
}
|
|
878
|
+
if (b.packageId === "__main__") {
|
|
879
|
+
return 1;
|
|
880
|
+
}
|
|
881
|
+
return a.packageId.localeCompare(b.packageId);
|
|
882
|
+
});
|
|
883
|
+
return {
|
|
884
|
+
id: module.id,
|
|
885
|
+
source: module.source,
|
|
886
|
+
sourceType: module.sourceType,
|
|
887
|
+
packages
|
|
888
|
+
};
|
|
889
|
+
});
|
|
890
|
+
usage.sort((a, b) => a.source.localeCompare(b.source));
|
|
891
|
+
return usage;
|
|
892
|
+
}
|
|
893
|
+
function expandVirtualModulePlacements(modules, packages, context) {
|
|
894
|
+
for (const moduleEntry of modules.values()) {
|
|
895
|
+
const virtualEntries = Array.from(moduleEntry.packages.entries()).filter(([packageId]) => packageId.startsWith("virtual:"));
|
|
896
|
+
if (!virtualEntries.length) {
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
const virtualFileBases = /* @__PURE__ */ new Map();
|
|
900
|
+
for (const [virtualPackageId, files] of virtualEntries) {
|
|
901
|
+
const combination = virtualPackageId.slice("virtual:".length);
|
|
902
|
+
if (!combination) {
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
const segments = combination.split(/[_+]/).map((segment) => segment.trim()).filter(Boolean);
|
|
906
|
+
if (!segments.length) {
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
let matchingBases = virtualFileBases.get(virtualPackageId);
|
|
910
|
+
if (!matchingBases) {
|
|
911
|
+
matchingBases = Array.from(files).map((file) => path.basename(file));
|
|
912
|
+
virtualFileBases.set(virtualPackageId, matchingBases);
|
|
913
|
+
}
|
|
914
|
+
for (const root of segments) {
|
|
915
|
+
if (!context.subPackageRoots.has(root)) {
|
|
916
|
+
continue;
|
|
917
|
+
}
|
|
918
|
+
const targetPackage = packages.get(root);
|
|
919
|
+
if (!targetPackage) {
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
const moduleFiles = moduleEntry.packages.get(root) ?? /* @__PURE__ */ new Set();
|
|
923
|
+
const targetFiles = Array.from(targetPackage.files.values()).filter((fileEntry) => {
|
|
924
|
+
if (!matchingBases?.length) {
|
|
925
|
+
return true;
|
|
926
|
+
}
|
|
927
|
+
const base = path.basename(fileEntry.file);
|
|
928
|
+
return matchingBases.includes(base);
|
|
929
|
+
}).map((fileEntry) => fileEntry.file);
|
|
930
|
+
if (targetFiles.length === 0) {
|
|
931
|
+
const fallback = targetPackage.files.values().next().value;
|
|
932
|
+
if (fallback) {
|
|
933
|
+
moduleFiles.add(fallback.file);
|
|
934
|
+
}
|
|
935
|
+
} else {
|
|
936
|
+
for (const fileName of targetFiles) {
|
|
937
|
+
moduleFiles.add(fileName);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
if (moduleFiles.size > 0) {
|
|
941
|
+
moduleEntry.packages.set(root, moduleFiles);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
function summarizeSubPackages(metas) {
|
|
948
|
+
const descriptors = metas.map((meta) => {
|
|
949
|
+
const root = meta.subPackage.root ?? "";
|
|
950
|
+
return {
|
|
951
|
+
root,
|
|
952
|
+
independent: Boolean(meta.subPackage.independent),
|
|
953
|
+
name: meta.subPackage.name
|
|
954
|
+
};
|
|
955
|
+
}).filter((descriptor) => descriptor.root);
|
|
956
|
+
descriptors.sort((a, b) => a.root.localeCompare(b.root));
|
|
957
|
+
return descriptors;
|
|
958
|
+
}
|
|
959
|
+
async function analyzeSubpackages(ctx) {
|
|
960
|
+
const { configService, scanService, buildService } = ctx;
|
|
961
|
+
if (!configService || !scanService || !buildService) {
|
|
962
|
+
throw new Error("analyzeSubpackages requires configService, scanService and buildService to be initialized");
|
|
963
|
+
}
|
|
964
|
+
await scanService.loadAppEntry();
|
|
965
|
+
const subPackageMetas = scanService.loadSubPackages();
|
|
966
|
+
const subPackageRoots = /* @__PURE__ */ new Set();
|
|
967
|
+
const independentRoots = /* @__PURE__ */ new Set();
|
|
968
|
+
for (const meta of subPackageMetas) {
|
|
969
|
+
const root = meta.subPackage.root;
|
|
970
|
+
if (root) {
|
|
971
|
+
subPackageRoots.add(root);
|
|
972
|
+
if (meta.subPackage.independent) {
|
|
973
|
+
independentRoots.add(root);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
const classifierContext = {
|
|
978
|
+
subPackageRoots,
|
|
979
|
+
independentRoots
|
|
980
|
+
};
|
|
981
|
+
const analysisConfig = configService.merge(
|
|
982
|
+
void 0,
|
|
983
|
+
createSharedBuildConfig(configService, scanService),
|
|
984
|
+
{
|
|
985
|
+
build: {
|
|
986
|
+
write: false,
|
|
987
|
+
watch: null
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
);
|
|
991
|
+
const mainResult = await build(analysisConfig);
|
|
992
|
+
const mainOutputs = Array.isArray(mainResult) ? mainResult : [mainResult];
|
|
993
|
+
const packages = /* @__PURE__ */ new Map();
|
|
994
|
+
const modules = /* @__PURE__ */ new Map();
|
|
995
|
+
for (const output of mainOutputs) {
|
|
996
|
+
processOutput(output, "main", ctx, classifierContext, packages, modules);
|
|
997
|
+
}
|
|
998
|
+
for (const root of independentRoots) {
|
|
999
|
+
const output = buildService.getIndependentOutput(root);
|
|
1000
|
+
processOutput(output, "independent", ctx, classifierContext, packages, modules);
|
|
1001
|
+
}
|
|
1002
|
+
expandVirtualModulePlacements(modules, packages, classifierContext);
|
|
1003
|
+
return {
|
|
1004
|
+
packages: summarizePackages(packages),
|
|
1005
|
+
modules: summarizeModules(modules),
|
|
1006
|
+
subPackages: summarizeSubPackages(subPackageMetas)
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// src/cli/options.ts
|
|
1011
|
+
init_esm_shims();
|
|
1012
|
+
function filterDuplicateOptions(options) {
|
|
1013
|
+
for (const [key, value] of Object.entries(options)) {
|
|
1014
|
+
if (Array.isArray(value)) {
|
|
1015
|
+
options[key] = value[value.length - 1];
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
function resolveConfigFile(options) {
|
|
1020
|
+
if (typeof options.config === "string") {
|
|
1021
|
+
return options.config;
|
|
1022
|
+
}
|
|
1023
|
+
if (typeof options.c === "string") {
|
|
1024
|
+
return options.c;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
function convertBase(value) {
|
|
1028
|
+
if (value === 0) {
|
|
1029
|
+
return "";
|
|
1030
|
+
}
|
|
1031
|
+
return value;
|
|
1032
|
+
}
|
|
1033
|
+
function coerceBooleanOption(value) {
|
|
1034
|
+
if (value === void 0) {
|
|
1035
|
+
return void 0;
|
|
1036
|
+
}
|
|
1037
|
+
if (typeof value === "boolean") {
|
|
1038
|
+
return value;
|
|
1039
|
+
}
|
|
1040
|
+
if (typeof value === "string") {
|
|
1041
|
+
const normalized = value.trim().toLowerCase();
|
|
1042
|
+
if (normalized === "") {
|
|
1043
|
+
return true;
|
|
1044
|
+
}
|
|
1045
|
+
if (normalized === "false" || normalized === "0" || normalized === "off" || normalized === "no") {
|
|
1046
|
+
return false;
|
|
1047
|
+
}
|
|
1048
|
+
if (normalized === "true" || normalized === "1" || normalized === "on" || normalized === "yes") {
|
|
1049
|
+
return true;
|
|
1050
|
+
}
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
1053
|
+
if (typeof value === "number") {
|
|
1054
|
+
return value !== 0;
|
|
1055
|
+
}
|
|
1056
|
+
return Boolean(value);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
// src/cli/runtime.ts
|
|
1060
|
+
init_esm_shims();
|
|
1061
|
+
function logRuntimeTarget(targets) {
|
|
1062
|
+
logger_default.info(`\u76EE\u6807\u5E73\u53F0\uFF1A${targets.label}`);
|
|
1063
|
+
}
|
|
1064
|
+
function resolveRuntimeTargets(options) {
|
|
1065
|
+
const rawPlatform = typeof options.platform === "string" ? options.platform : typeof options.p === "string" ? options.p : void 0;
|
|
1066
|
+
if (!rawPlatform) {
|
|
1067
|
+
return {
|
|
1068
|
+
runMini: true,
|
|
1069
|
+
runWeb: false,
|
|
1070
|
+
mpPlatform: DEFAULT_MP_PLATFORM,
|
|
1071
|
+
label: DEFAULT_MP_PLATFORM
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
const normalized = normalizeMiniPlatform(rawPlatform);
|
|
1075
|
+
if (!normalized) {
|
|
1076
|
+
return {
|
|
1077
|
+
runMini: true,
|
|
1078
|
+
runWeb: false,
|
|
1079
|
+
mpPlatform: DEFAULT_MP_PLATFORM,
|
|
1080
|
+
label: DEFAULT_MP_PLATFORM
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
if (normalized === "h5" || normalized === "web") {
|
|
1084
|
+
return {
|
|
1085
|
+
runMini: false,
|
|
1086
|
+
runWeb: true,
|
|
1087
|
+
mpPlatform: void 0,
|
|
1088
|
+
label: normalized === "h5" ? "h5" : "web"
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
const mpPlatform = resolveMiniPlatform(normalized);
|
|
1092
|
+
if (mpPlatform) {
|
|
1093
|
+
return {
|
|
1094
|
+
runMini: true,
|
|
1095
|
+
runWeb: false,
|
|
1096
|
+
mpPlatform,
|
|
1097
|
+
label: mpPlatform
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${DEFAULT_MP_PLATFORM}`);
|
|
1101
|
+
return {
|
|
1102
|
+
runMini: true,
|
|
1103
|
+
runWeb: false,
|
|
1104
|
+
mpPlatform: DEFAULT_MP_PLATFORM,
|
|
1105
|
+
label: DEFAULT_MP_PLATFORM
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
function createInlineConfig(mpPlatform) {
|
|
1109
|
+
if (!mpPlatform) {
|
|
1110
|
+
return void 0;
|
|
1111
|
+
}
|
|
1112
|
+
return {
|
|
1113
|
+
weapp: {
|
|
1114
|
+
platform: mpPlatform
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// src/cli/commands/analyze.ts
|
|
1120
|
+
function printAnalysisSummary(result) {
|
|
1121
|
+
const packageLabelMap = /* @__PURE__ */ new Map();
|
|
1122
|
+
const packageModuleSet = /* @__PURE__ */ new Map();
|
|
1123
|
+
for (const pkg of result.packages) {
|
|
1124
|
+
packageLabelMap.set(pkg.id, pkg.label);
|
|
1125
|
+
}
|
|
1126
|
+
for (const module of result.modules) {
|
|
1127
|
+
for (const pkgRef of module.packages) {
|
|
1128
|
+
const set = packageModuleSet.get(pkgRef.packageId) ?? /* @__PURE__ */ new Set();
|
|
1129
|
+
set.add(module.id);
|
|
1130
|
+
packageModuleSet.set(pkgRef.packageId, set);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
logger_default.success("\u5206\u5305\u5206\u6790\u5B8C\u6210");
|
|
1134
|
+
for (const pkg of result.packages) {
|
|
1135
|
+
const chunkCount = pkg.files.filter((file) => file.type === "chunk").length;
|
|
1136
|
+
const assetCount = pkg.files.length - chunkCount;
|
|
1137
|
+
const moduleCount = packageModuleSet.get(pkg.id)?.size ?? 0;
|
|
1138
|
+
logger_default.info(`- ${pkg.label}\uFF1A${chunkCount} \u4E2A\u6A21\u5757\u4EA7\u7269\uFF0C${assetCount} \u4E2A\u8D44\u6E90\uFF0C\u8986\u76D6 ${moduleCount} \u4E2A\u6E90\u7801\u6A21\u5757`);
|
|
1139
|
+
}
|
|
1140
|
+
if (result.subPackages.length > 0) {
|
|
1141
|
+
logger_default.info("\u5206\u5305\u914D\u7F6E\uFF1A");
|
|
1142
|
+
for (const descriptor of result.subPackages) {
|
|
1143
|
+
const segments = [descriptor.root];
|
|
1144
|
+
if (descriptor.name) {
|
|
1145
|
+
segments.push(`\u522B\u540D\uFF1A${descriptor.name}`);
|
|
1146
|
+
}
|
|
1147
|
+
if (descriptor.independent) {
|
|
1148
|
+
segments.push("\u72EC\u7ACB\u6784\u5EFA");
|
|
1149
|
+
}
|
|
1150
|
+
logger_default.info(`- ${segments.join("\uFF0C")}`);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
const duplicates = result.modules.filter((module) => module.packages.length > 1);
|
|
1154
|
+
if (duplicates.length === 0) {
|
|
1155
|
+
logger_default.info("\u672A\u68C0\u6D4B\u5230\u8DE8\u5305\u590D\u7528\u7684\u6E90\u7801\u6A21\u5757\u3002");
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
logger_default.info(`\u8DE8\u5305\u590D\u7528/\u590D\u5236\u6E90\u7801\u5171 ${duplicates.length} \u9879\uFF1A`);
|
|
1159
|
+
const limit = 10;
|
|
1160
|
+
const entries = duplicates.slice(0, limit);
|
|
1161
|
+
for (const module of entries) {
|
|
1162
|
+
const placements = module.packages.map((pkgRef) => {
|
|
1163
|
+
const label = packageLabelMap.get(pkgRef.packageId) ?? pkgRef.packageId;
|
|
1164
|
+
return `${label} \u2192 ${pkgRef.files.join(", ")}`;
|
|
1165
|
+
}).join("\uFF1B");
|
|
1166
|
+
logger_default.info(`- ${module.source} (${module.sourceType})\uFF1A${placements}`);
|
|
1167
|
+
}
|
|
1168
|
+
if (duplicates.length > limit) {
|
|
1169
|
+
logger_default.info(`- \u2026\u5176\u4F59 ${duplicates.length - limit} \u9879\u8BF7\u4F7F\u7528 \`weapp-vite analyze --json\` \u67E5\u770B`);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
function registerAnalyzeCommand(cli2) {
|
|
1173
|
+
cli2.command("analyze [root]", "analyze \u4E24\u7AEF\u5305\u4F53\u4E0E\u6E90\u7801\u6620\u5C04").option("--json", `[boolean] \u8F93\u51FA JSON \u7ED3\u679C`).option("--output <file>", `[string] \u5C06\u5206\u6790\u7ED3\u679C\u5199\u5165\u6307\u5B9A\u6587\u4EF6\uFF08JSON\uFF09`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).action(async (root, options) => {
|
|
1174
|
+
filterDuplicateOptions(options);
|
|
1175
|
+
const configFile = resolveConfigFile(options);
|
|
1176
|
+
const targets = resolveRuntimeTargets(options);
|
|
1177
|
+
logRuntimeTarget(targets);
|
|
1178
|
+
if (!targets.runMini) {
|
|
1179
|
+
logger_default.warn("\u5F53\u524D\u547D\u4EE4\u4EC5\u652F\u6301\u5C0F\u7A0B\u5E8F\u5E73\u53F0\uFF0C\u8BF7\u901A\u8FC7 --platform weapp \u6307\u5B9A\u76EE\u6807\u3002");
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
if (targets.runWeb) {
|
|
1183
|
+
logger_default.warn("\u5206\u6790\u547D\u4EE4\u6682\u4E0D\u652F\u6301 Web \u5E73\u53F0\uFF0C\u5C06\u5FFD\u7565\u76F8\u5173\u914D\u7F6E\u3002");
|
|
1184
|
+
}
|
|
1185
|
+
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1186
|
+
try {
|
|
1187
|
+
const ctx = await createCompilerContext({
|
|
1188
|
+
cwd: root,
|
|
1189
|
+
mode: options.mode ?? "production",
|
|
1190
|
+
configFile,
|
|
1191
|
+
inlineConfig
|
|
1192
|
+
});
|
|
1193
|
+
const result = await analyzeSubpackages(ctx);
|
|
1194
|
+
const outputJson = coerceBooleanOption(options.json);
|
|
1195
|
+
const outputOption = typeof options.output === "string" ? options.output.trim() : "";
|
|
1196
|
+
let writtenPath;
|
|
1197
|
+
if (outputOption) {
|
|
1198
|
+
const configService = ctx.configService;
|
|
1199
|
+
const baseDir = configService?.cwd ?? process2.cwd();
|
|
1200
|
+
const resolvedOutputPath = path2.isAbsolute(outputOption) ? outputOption : path2.resolve(baseDir, outputOption);
|
|
1201
|
+
await fs.ensureDir(path2.dirname(resolvedOutputPath));
|
|
1202
|
+
await fs.writeFile(resolvedOutputPath, `${JSON.stringify(result, null, 2)}
|
|
1203
|
+
`, "utf8");
|
|
1204
|
+
const relativeOutput = configService ? configService.relativeCwd(resolvedOutputPath) : resolvedOutputPath;
|
|
1205
|
+
logger_default.success(`\u5206\u6790\u7ED3\u679C\u5DF2\u5199\u5165 ${relativeOutput}`);
|
|
1206
|
+
writtenPath = resolvedOutputPath;
|
|
1207
|
+
}
|
|
1208
|
+
if (outputJson) {
|
|
1209
|
+
if (!writtenPath) {
|
|
1210
|
+
process2.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
1211
|
+
`);
|
|
1212
|
+
}
|
|
1213
|
+
} else {
|
|
1214
|
+
printAnalysisSummary(result);
|
|
1215
|
+
}
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
logger_default.error(error);
|
|
1218
|
+
process2.exitCode = 1;
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
// src/cli/commands/build.ts
|
|
1224
|
+
init_esm_shims();
|
|
1225
|
+
|
|
1226
|
+
// src/cli/logBuildAppFinish.ts
|
|
1227
|
+
init_esm_shims();
|
|
1228
|
+
|
|
609
1229
|
// ../../node_modules/.pnpm/package-manager-detector@1.5.0/node_modules/package-manager-detector/dist/commands.mjs
|
|
610
1230
|
init_esm_shims();
|
|
611
1231
|
function dashDashArg(agent, agentCommand) {
|
|
@@ -740,18 +1360,134 @@ function constructCommand(value, args) {
|
|
|
740
1360
|
};
|
|
741
1361
|
}
|
|
742
1362
|
|
|
743
|
-
// src/cli.ts
|
|
744
|
-
|
|
745
|
-
|
|
1363
|
+
// src/cli/logBuildAppFinish.ts
|
|
1364
|
+
var logBuildAppFinishOnlyShowOnce = false;
|
|
1365
|
+
function logBuildAppFinish(configService, webServer, options = {}) {
|
|
1366
|
+
if (logBuildAppFinishOnlyShowOnce) {
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1369
|
+
const { skipMini = false, skipWeb = false } = options;
|
|
1370
|
+
if (skipMini) {
|
|
1371
|
+
if (webServer) {
|
|
1372
|
+
const urls = webServer.resolvedUrls;
|
|
1373
|
+
const candidates = urls ? [...urls.local ?? [], ...urls.network ?? []] : [];
|
|
1374
|
+
if (candidates.length > 0) {
|
|
1375
|
+
logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
|
|
1376
|
+
for (const url of candidates) {
|
|
1377
|
+
logger_default.info(` \u279C ${url}`);
|
|
1378
|
+
}
|
|
1379
|
+
} else {
|
|
1380
|
+
logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
1381
|
+
}
|
|
1382
|
+
} else {
|
|
1383
|
+
logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
1384
|
+
}
|
|
1385
|
+
logBuildAppFinishOnlyShowOnce = true;
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
const { command, args } = resolveCommand(
|
|
1389
|
+
configService.packageManager.agent,
|
|
1390
|
+
"run",
|
|
1391
|
+
["open"]
|
|
1392
|
+
) ?? {
|
|
1393
|
+
command: "npm",
|
|
1394
|
+
args: ["run", "open"]
|
|
1395
|
+
};
|
|
1396
|
+
const devCommand = `${command} ${args.join(" ")}`;
|
|
1397
|
+
logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
|
|
1398
|
+
logger_default.info(`\u6267\u884C \`${devCommand}\` \u53EF\u4EE5\u76F4\u63A5\u5728 \`\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\` \u91CC\u6253\u5F00\u5F53\u524D\u5E94\u7528`);
|
|
1399
|
+
logger_default.info("\u6216\u624B\u52A8\u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u5BFC\u5165\u6839\u76EE\u5F55(`project.config.json` \u6587\u4EF6\u6240\u5728\u7684\u76EE\u5F55)\uFF0C\u5373\u53EF\u9884\u89C8\u6548\u679C");
|
|
1400
|
+
if (!skipWeb && webServer) {
|
|
1401
|
+
const urls = webServer.resolvedUrls;
|
|
1402
|
+
const candidates = urls ? [...urls.local ?? [], ...urls.network ?? []] : [];
|
|
1403
|
+
if (candidates.length > 0) {
|
|
1404
|
+
logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
|
|
1405
|
+
for (const url of candidates) {
|
|
1406
|
+
logger_default.info(` \u279C ${url}`);
|
|
1407
|
+
}
|
|
1408
|
+
} else {
|
|
1409
|
+
logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
logBuildAppFinishOnlyShowOnce = true;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
// src/cli/openIde.ts
|
|
1416
|
+
init_esm_shims();
|
|
746
1417
|
import { parse } from "weapp-ide-cli";
|
|
1418
|
+
async function openIde() {
|
|
1419
|
+
try {
|
|
1420
|
+
await parse(["open", "-p"]);
|
|
1421
|
+
} catch (error) {
|
|
1422
|
+
logger_default.error(error);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
// src/cli/commands/build.ts
|
|
1427
|
+
function registerBuildCommand(cli2) {
|
|
1428
|
+
cli2.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option(
|
|
1429
|
+
"--sourcemap [output]",
|
|
1430
|
+
`[boolean | "inline" | "hidden"] output source maps for build (default: false)`
|
|
1431
|
+
).option(
|
|
1432
|
+
"--minify [minifier]",
|
|
1433
|
+
`[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`
|
|
1434
|
+
).option(
|
|
1435
|
+
"--emptyOutDir",
|
|
1436
|
+
`[boolean] force empty outDir when it's outside of root`
|
|
1437
|
+
).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
|
|
1438
|
+
filterDuplicateOptions(options);
|
|
1439
|
+
const configFile = resolveConfigFile(options);
|
|
1440
|
+
const targets = resolveRuntimeTargets(options);
|
|
1441
|
+
logRuntimeTarget(targets);
|
|
1442
|
+
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1443
|
+
const { buildService, configService, webService } = await createCompilerContext({
|
|
1444
|
+
cwd: root,
|
|
1445
|
+
mode: options.mode ?? "production",
|
|
1446
|
+
configFile,
|
|
1447
|
+
inlineConfig
|
|
1448
|
+
});
|
|
1449
|
+
if (targets.runMini) {
|
|
1450
|
+
await buildService.build(options);
|
|
1451
|
+
}
|
|
1452
|
+
const webConfig = configService.weappWebConfig;
|
|
1453
|
+
if (targets.runWeb && webConfig?.enabled) {
|
|
1454
|
+
try {
|
|
1455
|
+
await webService?.build();
|
|
1456
|
+
logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
|
|
1457
|
+
} catch (error) {
|
|
1458
|
+
logger_default.error(error);
|
|
1459
|
+
throw error;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
if (targets.runMini) {
|
|
1463
|
+
logBuildAppFinish(configService, void 0, { skipWeb: !targets.runWeb });
|
|
1464
|
+
}
|
|
1465
|
+
if (options.open && targets.runMini) {
|
|
1466
|
+
await openIde();
|
|
1467
|
+
}
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
// src/cli/commands/create.ts
|
|
1472
|
+
init_esm_shims();
|
|
1473
|
+
import { createProject } from "@weapp-core/init";
|
|
1474
|
+
function registerCreateCommand(cli2) {
|
|
1475
|
+
cli2.command("create [outDir]", "create project").option("-t, --template <type>", "template type").action(async (outDir, options) => {
|
|
1476
|
+
await createProject(outDir, options.template);
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
// src/cli/commands/generate.ts
|
|
1481
|
+
init_esm_shims();
|
|
1482
|
+
import path5 from "pathe";
|
|
747
1483
|
|
|
748
1484
|
// src/schematics.ts
|
|
749
1485
|
init_esm_shims();
|
|
750
|
-
import
|
|
1486
|
+
import process3 from "process";
|
|
751
1487
|
import { generateJs, generateJson, generateWxml, generateWxss } from "@weapp-core/schematics";
|
|
752
1488
|
import { defu } from "@weapp-core/shared";
|
|
753
|
-
import
|
|
754
|
-
import
|
|
1489
|
+
import fs2 from "fs-extra";
|
|
1490
|
+
import path3 from "pathe";
|
|
755
1491
|
function composePath(outDir, filename) {
|
|
756
1492
|
return `${outDir}${outDir ? "/" : ""}${filename}`;
|
|
757
1493
|
}
|
|
@@ -765,8 +1501,8 @@ function resolveExtension(extension) {
|
|
|
765
1501
|
return extension ? extension.startsWith(".") ? extension : `.${extension}` : "";
|
|
766
1502
|
}
|
|
767
1503
|
async function readTemplateFile(templatePath, context) {
|
|
768
|
-
const absolutePath =
|
|
769
|
-
return
|
|
1504
|
+
const absolutePath = path3.isAbsolute(templatePath) ? templatePath : path3.resolve(context.cwd, templatePath);
|
|
1505
|
+
return fs2.readFile(absolutePath, "utf8");
|
|
770
1506
|
}
|
|
771
1507
|
async function loadTemplate(template, context) {
|
|
772
1508
|
if (template === void 0) {
|
|
@@ -800,13 +1536,13 @@ async function generate(options) {
|
|
|
800
1536
|
extensions: {
|
|
801
1537
|
...defaultExtensions
|
|
802
1538
|
},
|
|
803
|
-
cwd:
|
|
1539
|
+
cwd: process3.cwd(),
|
|
804
1540
|
templates: void 0
|
|
805
1541
|
});
|
|
806
1542
|
if (fileName === void 0) {
|
|
807
|
-
fileName =
|
|
1543
|
+
fileName = path3.basename(outDir);
|
|
808
1544
|
}
|
|
809
|
-
const basepath =
|
|
1545
|
+
const basepath = path3.resolve(cwd, outDir);
|
|
810
1546
|
const targetFileTypes = type === "app" ? ["js", "wxss", "json"] : ["js", "wxss", "json", "wxml"];
|
|
811
1547
|
const files = [];
|
|
812
1548
|
for (const fileType of targetFileTypes) {
|
|
@@ -818,7 +1554,7 @@ async function generate(options) {
|
|
|
818
1554
|
} else if (fileType === "wxss") {
|
|
819
1555
|
defaultCode = generateWxss();
|
|
820
1556
|
} else if (fileType === "wxml") {
|
|
821
|
-
defaultCode = generateWxml(
|
|
1557
|
+
defaultCode = generateWxml(path3.join(outDir, fileName));
|
|
822
1558
|
} else if (fileType === "json") {
|
|
823
1559
|
defaultCode = generateJson(type, configuredExt);
|
|
824
1560
|
if (configuredExt === "js" || configuredExt === "ts") {
|
|
@@ -846,27 +1582,23 @@ async function generate(options) {
|
|
|
846
1582
|
}
|
|
847
1583
|
for (const { code, fileName: fileName2 } of files) {
|
|
848
1584
|
if (code !== void 0) {
|
|
849
|
-
await
|
|
1585
|
+
await fs2.outputFile(path3.resolve(basepath, fileName2), code, "utf8");
|
|
850
1586
|
logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
|
|
851
1587
|
}
|
|
852
1588
|
}
|
|
853
1589
|
}
|
|
854
1590
|
|
|
855
|
-
// src/cli.ts
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
node: "20.19.0"
|
|
862
|
-
});
|
|
863
|
-
} catch {
|
|
864
|
-
}
|
|
1591
|
+
// src/cli/loadConfig.ts
|
|
1592
|
+
init_esm_shims();
|
|
1593
|
+
import process4 from "process";
|
|
1594
|
+
import { defu as defu2 } from "@weapp-core/shared";
|
|
1595
|
+
import path4 from "pathe";
|
|
1596
|
+
import { loadConfigFromFile } from "vite";
|
|
865
1597
|
async function loadConfig(configFile) {
|
|
866
|
-
const cwd =
|
|
1598
|
+
const cwd = process4.cwd();
|
|
867
1599
|
let resolvedConfigFile = configFile;
|
|
868
|
-
if (resolvedConfigFile && !
|
|
869
|
-
resolvedConfigFile =
|
|
1600
|
+
if (resolvedConfigFile && !path4.isAbsolute(resolvedConfigFile)) {
|
|
1601
|
+
resolvedConfigFile = path4.resolve(cwd, resolvedConfigFile);
|
|
870
1602
|
}
|
|
871
1603
|
const configEnv = {
|
|
872
1604
|
command: "serve",
|
|
@@ -879,8 +1611,8 @@ async function loadConfig(configFile) {
|
|
|
879
1611
|
});
|
|
880
1612
|
let weappLoaded;
|
|
881
1613
|
if (weappConfigFilePath) {
|
|
882
|
-
const normalizedWeappPath =
|
|
883
|
-
const normalizedLoadedPath = loaded?.path ?
|
|
1614
|
+
const normalizedWeappPath = path4.resolve(weappConfigFilePath);
|
|
1615
|
+
const normalizedLoadedPath = loaded?.path ? path4.resolve(loaded.path) : void 0;
|
|
884
1616
|
if (normalizedLoadedPath && normalizedLoadedPath === normalizedWeappPath) {
|
|
885
1617
|
weappLoaded = loaded;
|
|
886
1618
|
} else {
|
|
@@ -910,269 +1642,136 @@ async function loadConfig(configFile) {
|
|
|
910
1642
|
dependencies: Array.from(dependencySet)
|
|
911
1643
|
};
|
|
912
1644
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
if (
|
|
924
|
-
|
|
925
|
-
for (const url of candidates) {
|
|
926
|
-
logger_default.info(` \u279C ${url}`);
|
|
927
|
-
}
|
|
928
|
-
} else {
|
|
929
|
-
logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
930
|
-
}
|
|
931
|
-
} else {
|
|
932
|
-
logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
933
|
-
}
|
|
934
|
-
logBuildAppFinishOnlyShowOnce = true;
|
|
935
|
-
return;
|
|
936
|
-
}
|
|
937
|
-
const { command, args } = resolveCommand(
|
|
938
|
-
configService.packageManager.agent,
|
|
939
|
-
"run",
|
|
940
|
-
["open"]
|
|
941
|
-
) ?? {
|
|
942
|
-
command: "npm",
|
|
943
|
-
args: ["run", "open"]
|
|
944
|
-
};
|
|
945
|
-
const devCommand = `${command} ${args.join(" ")}`;
|
|
946
|
-
logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
|
|
947
|
-
logger_default.info(`\u6267\u884C \`${devCommand}\` \u53EF\u4EE5\u76F4\u63A5\u5728 \`\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\` \u91CC\u6253\u5F00\u5F53\u524D\u5E94\u7528`);
|
|
948
|
-
logger_default.info("\u6216\u624B\u52A8\u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u5BFC\u5165\u6839\u76EE\u5F55(`project.config.json` \u6587\u4EF6\u6240\u5728\u7684\u76EE\u5F55)\uFF0C\u5373\u53EF\u9884\u89C8\u6548\u679C");
|
|
949
|
-
if (!skipWeb && webServer) {
|
|
950
|
-
const urls = webServer.resolvedUrls;
|
|
951
|
-
const candidates = urls ? [...urls.local ?? [], ...urls.network ?? []] : [];
|
|
952
|
-
if (candidates.length > 0) {
|
|
953
|
-
logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
|
|
954
|
-
for (const url of candidates) {
|
|
955
|
-
logger_default.info(` \u279C ${url}`);
|
|
1645
|
+
|
|
1646
|
+
// src/cli/commands/generate.ts
|
|
1647
|
+
function registerGenerateCommand(cli2) {
|
|
1648
|
+
cli2.command("g [filepath]", "generate component").alias("generate").option("-a, --app", "type app").option("-p, --page", "type app").option("-n, --name <name>", "filename").action(async (filepath, options) => {
|
|
1649
|
+
filterDuplicateOptions(options);
|
|
1650
|
+
const config = await loadConfig(resolveConfigFile(options));
|
|
1651
|
+
let type = "component";
|
|
1652
|
+
let fileName = options.name;
|
|
1653
|
+
if (options.app) {
|
|
1654
|
+
type = "app";
|
|
1655
|
+
if (filepath === void 0) {
|
|
1656
|
+
filepath = "";
|
|
956
1657
|
}
|
|
957
|
-
|
|
958
|
-
logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
|
|
1658
|
+
fileName = "app";
|
|
959
1659
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
function filterDuplicateOptions(options) {
|
|
964
|
-
for (const [key, value] of Object.entries(options)) {
|
|
965
|
-
if (Array.isArray(value)) {
|
|
966
|
-
options[key] = value[value.length - 1];
|
|
1660
|
+
if (filepath === void 0) {
|
|
1661
|
+
logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
|
|
1662
|
+
return;
|
|
967
1663
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
function resolveConfigFile(options) {
|
|
971
|
-
if (typeof options.config === "string") {
|
|
972
|
-
return options.config;
|
|
973
|
-
}
|
|
974
|
-
if (typeof options.c === "string") {
|
|
975
|
-
return options.c;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
function convertBase(v) {
|
|
979
|
-
if (v === 0) {
|
|
980
|
-
return "";
|
|
981
|
-
}
|
|
982
|
-
return v;
|
|
983
|
-
}
|
|
984
|
-
async function openIde() {
|
|
985
|
-
try {
|
|
986
|
-
await parse(["open", "-p"]);
|
|
987
|
-
} catch (error) {
|
|
988
|
-
logger_default.error(error);
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
function logRuntimeTarget(targets) {
|
|
992
|
-
logger_default.info(`\u76EE\u6807\u5E73\u53F0\uFF1A${targets.label}`);
|
|
993
|
-
}
|
|
994
|
-
function resolveRuntimeTargets(options) {
|
|
995
|
-
const rawPlatform = typeof options.platform === "string" ? options.platform : typeof options.p === "string" ? options.p : void 0;
|
|
996
|
-
if (!rawPlatform) {
|
|
997
|
-
return {
|
|
998
|
-
runMini: true,
|
|
999
|
-
runWeb: false,
|
|
1000
|
-
mpPlatform: DEFAULT_MP_PLATFORM,
|
|
1001
|
-
label: DEFAULT_MP_PLATFORM
|
|
1002
|
-
};
|
|
1003
|
-
}
|
|
1004
|
-
const normalized = normalizeMiniPlatform(rawPlatform);
|
|
1005
|
-
if (!normalized) {
|
|
1006
|
-
return {
|
|
1007
|
-
runMini: true,
|
|
1008
|
-
runWeb: false,
|
|
1009
|
-
mpPlatform: DEFAULT_MP_PLATFORM,
|
|
1010
|
-
label: DEFAULT_MP_PLATFORM
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
if (normalized === "h5" || normalized === "web") {
|
|
1014
|
-
return {
|
|
1015
|
-
runMini: false,
|
|
1016
|
-
runWeb: true,
|
|
1017
|
-
mpPlatform: void 0,
|
|
1018
|
-
label: normalized === "h5" ? "h5" : "web"
|
|
1019
|
-
};
|
|
1020
|
-
}
|
|
1021
|
-
const mpPlatform = resolveMiniPlatform(normalized);
|
|
1022
|
-
if (mpPlatform) {
|
|
1023
|
-
return {
|
|
1024
|
-
runMini: true,
|
|
1025
|
-
runWeb: false,
|
|
1026
|
-
mpPlatform,
|
|
1027
|
-
label: mpPlatform
|
|
1028
|
-
};
|
|
1029
|
-
}
|
|
1030
|
-
logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${DEFAULT_MP_PLATFORM}`);
|
|
1031
|
-
return {
|
|
1032
|
-
runMini: true,
|
|
1033
|
-
runWeb: false,
|
|
1034
|
-
mpPlatform: DEFAULT_MP_PLATFORM,
|
|
1035
|
-
label: DEFAULT_MP_PLATFORM
|
|
1036
|
-
};
|
|
1037
|
-
}
|
|
1038
|
-
function createInlineConfig(mpPlatform) {
|
|
1039
|
-
if (!mpPlatform) {
|
|
1040
|
-
return void 0;
|
|
1041
|
-
}
|
|
1042
|
-
return {
|
|
1043
|
-
weapp: {
|
|
1044
|
-
platform: mpPlatform
|
|
1664
|
+
if (options.page) {
|
|
1665
|
+
type = "page";
|
|
1045
1666
|
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
logRuntimeTarget(targets);
|
|
1056
|
-
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1057
|
-
const { buildService, configService, webService } = await createCompilerContext({
|
|
1058
|
-
cwd: root,
|
|
1059
|
-
mode: options.mode ?? "development",
|
|
1060
|
-
isDev: true,
|
|
1061
|
-
configFile,
|
|
1062
|
-
inlineConfig
|
|
1667
|
+
const generateOptions = config?.config.weapp?.generate;
|
|
1668
|
+
fileName = generateOptions?.filenames?.[type] ?? fileName;
|
|
1669
|
+
await generate({
|
|
1670
|
+
outDir: path5.join(generateOptions?.dirs?.[type] ?? "", filepath),
|
|
1671
|
+
type,
|
|
1672
|
+
fileName,
|
|
1673
|
+
extensions: generateOptions?.extensions,
|
|
1674
|
+
templates: generateOptions?.templates
|
|
1675
|
+
});
|
|
1063
1676
|
});
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
// src/cli/commands/init.ts
|
|
1680
|
+
init_esm_shims();
|
|
1681
|
+
import { initConfig } from "@weapp-core/init";
|
|
1682
|
+
function registerInitCommand(cli2) {
|
|
1683
|
+
cli2.command("init").action(async () => {
|
|
1069
1684
|
try {
|
|
1070
|
-
|
|
1685
|
+
await initConfig({
|
|
1686
|
+
command: "weapp-vite"
|
|
1687
|
+
});
|
|
1071
1688
|
} catch (error) {
|
|
1072
1689
|
logger_default.error(error);
|
|
1073
|
-
throw error;
|
|
1074
1690
|
}
|
|
1075
|
-
}
|
|
1076
|
-
if (targets.runMini) {
|
|
1077
|
-
logBuildAppFinish(configService, webServer, { skipWeb: !targets.runWeb });
|
|
1078
|
-
} else if (targets.runWeb) {
|
|
1079
|
-
logBuildAppFinish(configService, webServer, { skipMini: true });
|
|
1080
|
-
}
|
|
1081
|
-
if (options.open && targets.runMini) {
|
|
1082
|
-
await openIde();
|
|
1083
|
-
}
|
|
1084
|
-
});
|
|
1085
|
-
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option(
|
|
1086
|
-
"--sourcemap [output]",
|
|
1087
|
-
`[boolean | "inline" | "hidden"] output source maps for build (default: false)`
|
|
1088
|
-
).option(
|
|
1089
|
-
"--minify [minifier]",
|
|
1090
|
-
`[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`
|
|
1091
|
-
).option(
|
|
1092
|
-
"--emptyOutDir",
|
|
1093
|
-
`[boolean] force empty outDir when it's outside of root`
|
|
1094
|
-
).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
|
|
1095
|
-
filterDuplicateOptions(options);
|
|
1096
|
-
const configFile = resolveConfigFile(options);
|
|
1097
|
-
const targets = resolveRuntimeTargets(options);
|
|
1098
|
-
logRuntimeTarget(targets);
|
|
1099
|
-
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1100
|
-
const { buildService, configService, webService } = await createCompilerContext({
|
|
1101
|
-
cwd: root,
|
|
1102
|
-
mode: options.mode ?? "production",
|
|
1103
|
-
configFile,
|
|
1104
|
-
inlineConfig
|
|
1105
1691
|
});
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
// src/cli/commands/npm.ts
|
|
1695
|
+
init_esm_shims();
|
|
1696
|
+
import { parse as parse2 } from "weapp-ide-cli";
|
|
1697
|
+
function registerNpmCommand(cli2) {
|
|
1698
|
+
cli2.command("npm").alias("build:npm").alias("build-npm").action(async () => {
|
|
1111
1699
|
try {
|
|
1112
|
-
await
|
|
1113
|
-
logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
|
|
1700
|
+
await parse2(["build-npm", "-p"]);
|
|
1114
1701
|
} catch (error) {
|
|
1115
1702
|
logger_default.error(error);
|
|
1116
|
-
throw error;
|
|
1117
1703
|
}
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
// src/cli/commands/open.ts
|
|
1708
|
+
init_esm_shims();
|
|
1709
|
+
function registerOpenCommand(cli2) {
|
|
1710
|
+
cli2.command("open").action(async () => {
|
|
1123
1711
|
await openIde();
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
// src/cli/commands/serve.ts
|
|
1716
|
+
init_esm_shims();
|
|
1717
|
+
function registerServeCommand(cli2) {
|
|
1718
|
+
cli2.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).action(async (root, options) => {
|
|
1719
|
+
filterDuplicateOptions(options);
|
|
1720
|
+
const configFile = resolveConfigFile(options);
|
|
1721
|
+
const targets = resolveRuntimeTargets(options);
|
|
1722
|
+
logRuntimeTarget(targets);
|
|
1723
|
+
const inlineConfig = createInlineConfig(targets.mpPlatform);
|
|
1724
|
+
const { buildService, configService, webService } = await createCompilerContext({
|
|
1725
|
+
cwd: root,
|
|
1726
|
+
mode: options.mode ?? "development",
|
|
1727
|
+
isDev: true,
|
|
1728
|
+
configFile,
|
|
1729
|
+
inlineConfig
|
|
1130
1730
|
});
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
});
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
type = "app";
|
|
1151
|
-
if (filepath === void 0) {
|
|
1152
|
-
filepath = "";
|
|
1731
|
+
if (targets.runMini) {
|
|
1732
|
+
await buildService.build(options);
|
|
1733
|
+
}
|
|
1734
|
+
let webServer;
|
|
1735
|
+
if (targets.runWeb) {
|
|
1736
|
+
try {
|
|
1737
|
+
webServer = await webService?.startDevServer();
|
|
1738
|
+
} catch (error) {
|
|
1739
|
+
logger_default.error(error);
|
|
1740
|
+
throw error;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
if (targets.runMini) {
|
|
1744
|
+
logBuildAppFinish(configService, webServer, { skipWeb: !targets.runWeb });
|
|
1745
|
+
} else if (targets.runWeb) {
|
|
1746
|
+
logBuildAppFinish(configService, webServer, { skipMini: true });
|
|
1747
|
+
}
|
|
1748
|
+
if (options.open && targets.runMini) {
|
|
1749
|
+
await openIde();
|
|
1153
1750
|
}
|
|
1154
|
-
fileName = "app";
|
|
1155
|
-
}
|
|
1156
|
-
if (filepath === void 0) {
|
|
1157
|
-
logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
|
|
1158
|
-
return;
|
|
1159
|
-
}
|
|
1160
|
-
if (options.page) {
|
|
1161
|
-
type = "page";
|
|
1162
|
-
}
|
|
1163
|
-
const generateOptions = config?.config.weapp?.generate;
|
|
1164
|
-
fileName = generateOptions?.filenames?.[type] ?? fileName;
|
|
1165
|
-
await generate({
|
|
1166
|
-
outDir: path2.join(generateOptions?.dirs?.[type] ?? "", filepath),
|
|
1167
|
-
type,
|
|
1168
|
-
fileName,
|
|
1169
|
-
extensions: generateOptions?.extensions,
|
|
1170
|
-
templates: generateOptions?.templates
|
|
1171
1751
|
});
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
// src/cli.ts
|
|
1755
|
+
var cli = cac("weapp-vite");
|
|
1756
|
+
try {
|
|
1757
|
+
checkRuntime({
|
|
1758
|
+
bun: "0.0.0",
|
|
1759
|
+
deno: "0.0.0",
|
|
1760
|
+
node: "20.19.0"
|
|
1761
|
+
});
|
|
1762
|
+
} catch {
|
|
1763
|
+
}
|
|
1764
|
+
cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
|
|
1765
|
+
type: [convertBase]
|
|
1766
|
+
}).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
|
|
1767
|
+
registerServeCommand(cli);
|
|
1768
|
+
registerBuildCommand(cli);
|
|
1769
|
+
registerAnalyzeCommand(cli);
|
|
1770
|
+
registerInitCommand(cli);
|
|
1771
|
+
registerOpenCommand(cli);
|
|
1772
|
+
registerNpmCommand(cli);
|
|
1773
|
+
registerGenerateCommand(cli);
|
|
1774
|
+
registerCreateCommand(cli);
|
|
1176
1775
|
cli.help();
|
|
1177
1776
|
cli.version(VERSION);
|
|
1178
1777
|
cli.parse();
|