@simplysm/sd-cli 12.5.21 → 12.5.23
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/{build-tools → entry}/SdCliCordova.d.ts +5 -6
- package/dist/{build-tools → entry}/SdCliCordova.js +117 -99
- package/dist/entry/SdCliCordova.js.map +1 -0
- package/dist/entry/SdCliElectron.d.ts +2 -2
- package/dist/entry/SdCliElectron.js +50 -40
- package/dist/entry/SdCliElectron.js.map +1 -1
- package/dist/entry/SdCliLocalUpdate.d.ts +1 -2
- package/dist/entry/SdCliLocalUpdate.js +26 -27
- package/dist/entry/SdCliLocalUpdate.js.map +1 -1
- package/dist/entry/SdCliProject.d.ts +1 -5
- package/dist/entry/SdCliProject.js +62 -288
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +23 -20
- package/dist/index.js +23 -20
- package/dist/index.js.map +1 -1
- package/dist/pkg-builders/SdMultiBuildRunner.d.ts +21 -0
- package/dist/pkg-builders/SdMultiBuildRunner.js +174 -0
- package/dist/pkg-builders/SdMultiBuildRunner.js.map +1 -0
- package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.d.ts +4 -0
- package/dist/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.js +7 -7
- package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.js.map +1 -0
- package/dist/pkg-builders/client/SdClientBuildRunner.d.ts +20 -0
- package/dist/pkg-builders/client/SdClientBuildRunner.js +135 -0
- package/dist/pkg-builders/client/SdClientBuildRunner.js.map +1 -0
- package/dist/pkg-builders/client/SdNgBundler.d.ts +29 -0
- package/dist/{build-tools → pkg-builders/client}/SdNgBundler.js +107 -151
- package/dist/pkg-builders/client/SdNgBundler.js.map +1 -0
- package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.d.ts +1 -2
- package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.js +19 -45
- package/dist/pkg-builders/client/SdNgBundlerContext.js.map +1 -0
- package/dist/pkg-builders/client/createSdNgPlugin.d.ts +10 -0
- package/dist/{bundle-plugins/sdNgPlugin.js → pkg-builders/client/createSdNgPlugin.js} +32 -33
- package/dist/pkg-builders/client/createSdNgPlugin.js.map +1 -0
- package/dist/pkg-builders/lib/SdCliIndexFileGenerator.d.ts +5 -0
- package/dist/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.js +11 -11
- package/dist/pkg-builders/lib/SdCliIndexFileGenerator.js.map +1 -0
- package/dist/pkg-builders/lib/SdJsLibBuildRunner.d.ts +16 -0
- package/dist/pkg-builders/lib/SdJsLibBuildRunner.js +81 -0
- package/dist/pkg-builders/lib/SdJsLibBuildRunner.js.map +1 -0
- package/dist/pkg-builders/lib/SdTsLibBuildRunner.d.ts +13 -0
- package/dist/pkg-builders/lib/SdTsLibBuildRunner.js +89 -0
- package/dist/pkg-builders/lib/SdTsLibBuildRunner.js.map +1 -0
- package/dist/pkg-builders/lib/SdTsLibBuilder.d.ts +14 -0
- package/dist/pkg-builders/lib/SdTsLibBuilder.js +54 -0
- package/dist/pkg-builders/lib/SdTsLibBuilder.js.map +1 -0
- package/dist/pkg-builders/server/SdServerBuildRunner.d.ts +17 -0
- package/dist/{builders/SdCliServerBuilder.js → pkg-builders/server/SdServerBuildRunner.js} +48 -53
- package/dist/pkg-builders/server/SdServerBuildRunner.js.map +1 -0
- package/dist/pkg-builders/server/SdServerBundler.d.ts +19 -0
- package/dist/{build-tools → pkg-builders/server}/SdServerBundler.js +25 -30
- package/dist/pkg-builders/server/SdServerBundler.js.map +1 -0
- package/dist/pkg-builders/server/createSdServerPlugin.d.ts +10 -0
- package/dist/pkg-builders/server/createSdServerPlugin.js +53 -0
- package/dist/pkg-builders/server/createSdServerPlugin.js.map +1 -0
- package/dist/sd-cli.js +61 -54
- package/dist/sd-cli.js.map +1 -1
- package/dist/ts-builder/SdTsCompileWorker.d.ts +9 -0
- package/dist/ts-builder/SdTsCompileWorker.js +16 -0
- package/dist/ts-builder/SdTsCompileWorker.js.map +1 -0
- package/dist/ts-builder/SdTsCompiler.d.ts +7 -0
- package/dist/ts-builder/SdTsCompiler.js +557 -0
- package/dist/ts-builder/SdTsCompiler.js.map +1 -0
- package/dist/types/build-plugin.type.d.ts +14 -0
- package/dist/types/build-plugin.type.js +2 -0
- package/dist/types/build-plugin.type.js.map +1 -0
- package/dist/types/build.type.d.ts +15 -0
- package/dist/types/build.type.js +2 -0
- package/dist/types/build.type.js.map +1 -0
- package/dist/types/common-configs.type.d.ts +22 -0
- package/dist/types/common-configs.type.js +2 -0
- package/dist/types/common-configs.type.js.map +1 -0
- package/dist/types/sd-configs.type.d.ts +99 -0
- package/dist/types/sd-configs.type.js +2 -0
- package/dist/types/sd-configs.type.js.map +1 -0
- package/dist/types/ts-compiler.type.d.ts +29 -0
- package/dist/types/ts-compiler.type.js +2 -0
- package/dist/types/ts-compiler.type.js.map +1 -0
- package/dist/types/workers.type.d.ts +49 -0
- package/dist/types/workers.type.js +2 -0
- package/dist/types/workers.type.js.map +1 -0
- package/dist/utils/SdCliConvertMessageUtil.d.ts +21 -0
- package/dist/utils/SdCliConvertMessageUtil.js +137 -0
- package/dist/utils/SdCliConvertMessageUtil.js.map +1 -0
- package/dist/workers/compile-worker.js +27 -0
- package/dist/workers/compile-worker.js.map +1 -0
- package/dist/workers/lint-worker.js +36 -0
- package/dist/workers/lint-worker.js.map +1 -0
- package/dist/workers/server-worker.d.ts +1 -0
- package/dist/workers/server-worker.js +49 -0
- package/dist/workers/server-worker.js.map +1 -0
- package/package.json +8 -11
- package/src/entry/SdCliCordova.ts +363 -0
- package/src/entry/SdCliElectron.ts +96 -69
- package/src/entry/SdCliLocalUpdate.ts +43 -44
- package/src/entry/SdCliProject.ts +72 -417
- package/src/index.ts +23 -20
- package/src/pkg-builders/SdMultiBuildRunner.ts +250 -0
- package/src/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.ts +7 -7
- package/src/pkg-builders/client/SdClientBuildRunner.ts +191 -0
- package/src/{build-tools → pkg-builders/client}/SdNgBundler.ts +135 -190
- package/src/pkg-builders/client/SdNgBundlerContext.ts +111 -0
- package/src/{bundle-plugins/sdNgPlugin.ts → pkg-builders/client/createSdNgPlugin.ts} +43 -46
- package/src/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.ts +11 -11
- package/src/pkg-builders/lib/SdJsLibBuildRunner.ts +105 -0
- package/src/pkg-builders/lib/SdTsLibBuildRunner.ts +128 -0
- package/src/pkg-builders/lib/SdTsLibBuilder.ts +69 -0
- package/src/{builders/SdCliServerBuilder.ts → pkg-builders/server/SdServerBuildRunner.ts} +66 -78
- package/src/{build-tools → pkg-builders/server}/SdServerBundler.ts +40 -41
- package/src/pkg-builders/server/createSdServerPlugin.ts +77 -0
- package/src/sd-cli.ts +197 -211
- package/src/ts-builder/SdTsCompileWorker.ts +21 -0
- package/src/ts-builder/SdTsCompiler.ts +775 -0
- package/src/types/build-plugin.type.ts +16 -0
- package/src/types/build.type.ts +17 -0
- package/src/types/common-configs.type.ts +27 -0
- package/src/types/sd-configs.type.ts +114 -0
- package/src/types/ts-compiler.type.ts +29 -0
- package/src/types/workers.type.ts +27 -0
- package/src/utils/SdCliConvertMessageUtil.ts +177 -0
- package/src/workers/compile-worker.ts +31 -0
- package/src/workers/lint-worker.ts +44 -0
- package/src/workers/server-worker.ts +52 -0
- package/tsconfig.json +7 -1
- package/dist/build-cluster.js +0 -201
- package/dist/build-cluster.js.map +0 -1
- package/dist/build-tools/SdCliCordova.js.map +0 -1
- package/dist/build-tools/SdCliIndexFileGenerator.d.ts +0 -5
- package/dist/build-tools/SdCliIndexFileGenerator.js.map +0 -1
- package/dist/build-tools/SdCliNgRoutesFileGenerator.d.ts +0 -4
- package/dist/build-tools/SdCliNgRoutesFileGenerator.js.map +0 -1
- package/dist/build-tools/SdLinter.d.ts +0 -5
- package/dist/build-tools/SdLinter.js +0 -49
- package/dist/build-tools/SdLinter.js.map +0 -1
- package/dist/build-tools/SdNgBundler.d.ts +0 -29
- package/dist/build-tools/SdNgBundler.js.map +0 -1
- package/dist/build-tools/SdNgBundlerContext.js.map +0 -1
- package/dist/build-tools/SdReactBundler.d.ts +0 -25
- package/dist/build-tools/SdReactBundler.js +0 -295
- package/dist/build-tools/SdReactBundler.js.map +0 -1
- package/dist/build-tools/SdReactBundlerContext.d.ts +0 -14
- package/dist/build-tools/SdReactBundlerContext.js +0 -59
- package/dist/build-tools/SdReactBundlerContext.js.map +0 -1
- package/dist/build-tools/SdServerBundler.d.ts +0 -20
- package/dist/build-tools/SdServerBundler.js.map +0 -1
- package/dist/build-tools/SdTsCompiler.d.ts +0 -34
- package/dist/build-tools/SdTsCompiler.js +0 -534
- package/dist/build-tools/SdTsCompiler.js.map +0 -1
- package/dist/build-tools/SdTsLibBundler.d.ts +0 -13
- package/dist/build-tools/SdTsLibBundler.js +0 -58
- package/dist/build-tools/SdTsLibBundler.js.map +0 -1
- package/dist/builders/SdCliClientBuilder.d.ts +0 -18
- package/dist/builders/SdCliClientBuilder.js +0 -172
- package/dist/builders/SdCliClientBuilder.js.map +0 -1
- package/dist/builders/SdCliJsLibLinter.d.ts +0 -13
- package/dist/builders/SdCliJsLibLinter.js +0 -60
- package/dist/builders/SdCliJsLibLinter.js.map +0 -1
- package/dist/builders/SdCliServerBuilder.d.ts +0 -15
- package/dist/builders/SdCliServerBuilder.js.map +0 -1
- package/dist/builders/SdCliTsLibBuilder.d.ts +0 -12
- package/dist/builders/SdCliTsLibBuilder.js +0 -90
- package/dist/builders/SdCliTsLibBuilder.js.map +0 -1
- package/dist/bundle-plugins/sdNgPlugin.d.ts +0 -16
- package/dist/bundle-plugins/sdNgPlugin.js.map +0 -1
- package/dist/bundle-plugins/sdReactPlugin.d.ts +0 -16
- package/dist/bundle-plugins/sdReactPlugin.js +0 -117
- package/dist/bundle-plugins/sdReactPlugin.js.map +0 -1
- package/dist/bundle-plugins/sdServerPlugin.d.ts +0 -16
- package/dist/bundle-plugins/sdServerPlugin.js +0 -63
- package/dist/bundle-plugins/sdServerPlugin.js.map +0 -1
- package/dist/commons.d.ts +0 -145
- package/dist/commons.js +0 -2
- package/dist/commons.js.map +0 -1
- package/dist/server-worker.js +0 -57
- package/dist/server-worker.js.map +0 -1
- package/dist/utils/SdCliBuildResultUtil.d.ts +0 -16
- package/dist/utils/SdCliBuildResultUtil.js +0 -54
- package/dist/utils/SdCliBuildResultUtil.js.map +0 -1
- package/src/build-cluster.ts +0 -212
- package/src/build-tools/SdCliCordova.ts +0 -340
- package/src/build-tools/SdLinter.ts +0 -65
- package/src/build-tools/SdNgBundlerContext.ts +0 -137
- package/src/build-tools/SdReactBundler.ts +0 -372
- package/src/build-tools/SdReactBundlerContext.ts +0 -71
- package/src/build-tools/SdTsCompiler.ts +0 -754
- package/src/build-tools/SdTsLibBundler.ts +0 -72
- package/src/builders/SdCliClientBuilder.ts +0 -233
- package/src/builders/SdCliJsLibLinter.ts +0 -72
- package/src/builders/SdCliTsLibBuilder.ts +0 -126
- package/src/bundle-plugins/sdReactPlugin.ts +0 -164
- package/src/bundle-plugins/sdServerPlugin.ts +0 -94
- package/src/commons.ts +0 -171
- package/src/server-worker.ts +0 -65
- package/src/utils/SdCliBuildResultUtil.ts +0 -63
- /package/dist/{build-cluster.d.ts → workers/compile-worker.d.ts} +0 -0
- /package/dist/{server-worker.d.ts → workers/lint-worker.d.ts} +0 -0
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
|
-
import nodeStdLibBrowser from "node-stdlib-browser";
|
|
5
|
-
import nodeStdLibBrowserPlugin from "node-stdlib-browser/helpers/esbuild/plugin";
|
|
6
|
-
import { INpmConfig, ISdCliClientBuilderCordovaConfig, ISdCliPackageBuildResult } from "../commons";
|
|
7
|
-
import ts from "typescript";
|
|
8
|
-
import { SdReactBundlerContext } from "./SdReactBundlerContext";
|
|
9
|
-
import { IReactPluginResultCache, sdReactPlugin } from "../bundle-plugins/sdReactPlugin";
|
|
10
|
-
import { transformSupportedBrowsersToTargets } from "@angular/build/src/tools/esbuild/utils";
|
|
11
|
-
import browserslist from "browserslist";
|
|
12
|
-
import { glob } from "glob";
|
|
13
|
-
import { generateSW } from "workbox-build";
|
|
14
|
-
|
|
15
|
-
export class SdReactBundler {
|
|
16
|
-
readonly #logger = Logger.get(["simplysm", "sd-cli", "SdNgBundler"]);
|
|
17
|
-
|
|
18
|
-
readonly #modifiedFileSet = new Set<string>();
|
|
19
|
-
readonly #compileResultCache: IReactPluginResultCache = {
|
|
20
|
-
affectedFileSet: new Set<string>(),
|
|
21
|
-
watchFileSet: new Set<string>()
|
|
22
|
-
};
|
|
23
|
-
#contexts: SdReactBundlerContext[] | undefined;
|
|
24
|
-
|
|
25
|
-
readonly #outputCache = new Map<string, string | number>();
|
|
26
|
-
|
|
27
|
-
readonly #opt: IOptions;
|
|
28
|
-
|
|
29
|
-
readonly #pkgNpmConf: INpmConfig;
|
|
30
|
-
readonly #indexFilePath: string;
|
|
31
|
-
readonly #tsConfigFilePath: string;
|
|
32
|
-
readonly #browserTarget: string[];
|
|
33
|
-
|
|
34
|
-
public constructor(opt: IOptions) {
|
|
35
|
-
this.#opt = opt;
|
|
36
|
-
this.#pkgNpmConf = FsUtil.readJson(path.resolve(opt.pkgPath, "package.json"));
|
|
37
|
-
this.#indexFilePath = path.resolve(opt.pkgPath, "src/index.tsx");
|
|
38
|
-
this.#tsConfigFilePath = path.resolve(opt.pkgPath, "tsconfig.json");
|
|
39
|
-
this.#browserTarget = transformSupportedBrowsersToTargets(browserslist(["Chrome > 78"]));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public markForChanges(filePaths: string[]): void {
|
|
43
|
-
for (const filePath of filePaths) {
|
|
44
|
-
this.#modifiedFileSet.add(path.normalize(filePath));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public async bundleAsync(): Promise<{
|
|
49
|
-
program?: ts.Program;
|
|
50
|
-
watchFileSet: Set<string>;
|
|
51
|
-
affectedFileSet: Set<string>;
|
|
52
|
-
results: ISdCliPackageBuildResult[];
|
|
53
|
-
}> {
|
|
54
|
-
this.#debug(`get contexts...`);
|
|
55
|
-
|
|
56
|
-
if (!this.#contexts) {
|
|
57
|
-
this.#contexts = [
|
|
58
|
-
this._getAppContext(),
|
|
59
|
-
...(this.#opt.builderType === "electron" ? [this._getElectronMainContext()] : [])
|
|
60
|
-
];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this.#debug(`build...`);
|
|
64
|
-
|
|
65
|
-
const bundlingResults = await this.#contexts.mapAsync(async (ctx, i) => await ctx.bundleAsync());
|
|
66
|
-
|
|
67
|
-
//-- results
|
|
68
|
-
const results = bundlingResults.mapMany((bundlingResult) => bundlingResult.results);
|
|
69
|
-
|
|
70
|
-
this.#debug(`convert result...`);
|
|
71
|
-
|
|
72
|
-
const outputFiles: IReactOutputFile[] = bundlingResults
|
|
73
|
-
.mapMany((item) => item.outputFiles ?? [])
|
|
74
|
-
.map((item) => ({
|
|
75
|
-
relPath: path.relative(this.#opt.pkgPath, item.path),
|
|
76
|
-
contents: item.contents
|
|
77
|
-
}));
|
|
78
|
-
|
|
79
|
-
// cordova empty
|
|
80
|
-
if (this.#opt.builderType === "cordova" && this.#opt.cordovaConfig?.plugins) {
|
|
81
|
-
outputFiles.push({ relPath: "cordova-empty.js", contents: "export default {};" });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// index.html
|
|
85
|
-
let indexHtml = await FsUtil.readFileAsync(path.resolve(this.#opt.pkgPath, "src/index.html"));
|
|
86
|
-
indexHtml = indexHtml.replace(/<\/head>/, "<script type=\"module\" src=\"index.js\"></script></head>");
|
|
87
|
-
if (!this.#opt.dev) {
|
|
88
|
-
indexHtml = indexHtml.replace(/<\/head>/, "<script src=\"registerSW.js\"></script></head>");
|
|
89
|
-
}
|
|
90
|
-
if (this.#opt.builderType === "cordova") {
|
|
91
|
-
indexHtml = indexHtml.replace(
|
|
92
|
-
/(.*)<\/head>/,
|
|
93
|
-
"<script type=\"module\" src=\"cordova-entry.js\"></script>\n$1</head>"
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
if (outputFiles.some((item) => item.relPath === "index.css")) {
|
|
97
|
-
indexHtml = indexHtml.replace(/(.*)<\/head>/, "<link rel=\"stylesheet\" href=\"index.css\">\n$1</head>");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
outputFiles.push({
|
|
101
|
-
relPath: "index.html",
|
|
102
|
-
contents: indexHtml
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// copy assets
|
|
106
|
-
outputFiles.push(
|
|
107
|
-
...this.#copyAssets("src", "favicon.ico"),
|
|
108
|
-
...this.#copyAssets("src", "manifest.webmanifest"),
|
|
109
|
-
...this.#copyAssets("src/assets", "**/*", "assets"),
|
|
110
|
-
...(this.#opt.dev && this.#opt.builderType === "cordova"
|
|
111
|
-
? Object.keys(this.#opt.cordovaConfig?.platform ?? { browser: {} }).mapMany((platform) => [
|
|
112
|
-
...this.#copyAssets(
|
|
113
|
-
`.cordova/platforms/${platform}/platform_www/plugins`,
|
|
114
|
-
"**/*",
|
|
115
|
-
`cordova-${platform}/plugins`
|
|
116
|
-
),
|
|
117
|
-
...this.#copyAssets(`.cordova/platforms/${platform}/platform_www`, "cordova.js", `cordova-${platform}`),
|
|
118
|
-
...this.#copyAssets(
|
|
119
|
-
`.cordova/platforms/${platform}/platform_www`,
|
|
120
|
-
"cordova_plugins.js",
|
|
121
|
-
`cordova-${platform}`
|
|
122
|
-
),
|
|
123
|
-
...this.#copyAssets(`.cordova/platforms/${platform}/www`, "config.xml", `cordova-${platform}`)
|
|
124
|
-
])
|
|
125
|
-
: [])
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
// TODO: extract 3rdpartylicenses
|
|
129
|
-
|
|
130
|
-
//-- write
|
|
131
|
-
this.#debug(`write output files...(${outputFiles.length})`);
|
|
132
|
-
|
|
133
|
-
for (const outputFile of outputFiles) {
|
|
134
|
-
const distFilePath = path.resolve(this.#opt.outputPath, outputFile.relPath);
|
|
135
|
-
const prev = this.#outputCache.get(distFilePath);
|
|
136
|
-
if (prev !== Buffer.from(outputFile.contents).toString("base64")) {
|
|
137
|
-
await FsUtil.writeFileAsync(distFilePath, outputFile.contents);
|
|
138
|
-
this.#outputCache.set(distFilePath, Buffer.from(outputFile.contents).toString("base64"));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// service worker
|
|
143
|
-
if (!this.#opt.dev) {
|
|
144
|
-
try {
|
|
145
|
-
const swResult = await generateSW({
|
|
146
|
-
globDirectory: path.resolve(this.#opt.pkgPath, "dist"),
|
|
147
|
-
globPatterns: ["**/*"],
|
|
148
|
-
globIgnores: ["3rdpartylicenses.txt", "*.js.map"],
|
|
149
|
-
globStrict: true,
|
|
150
|
-
swDest: path.resolve(this.#opt.pkgPath, "dist", "sw.js")
|
|
151
|
-
});
|
|
152
|
-
swResult.warnings.map((msg) => {
|
|
153
|
-
results.push({
|
|
154
|
-
filePath: undefined,
|
|
155
|
-
line: undefined,
|
|
156
|
-
char: undefined,
|
|
157
|
-
code: undefined,
|
|
158
|
-
severity: "warning",
|
|
159
|
-
message: `(gen-sw) ${msg}`,
|
|
160
|
-
type: "build"
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
await FsUtil.writeFileAsync(
|
|
165
|
-
path.resolve(this.#opt.pkgPath, "dist", "registerSW.js"),
|
|
166
|
-
`
|
|
167
|
-
if ('serviceWorker' in navigator) {
|
|
168
|
-
window.addEventListener('load', () => {
|
|
169
|
-
navigator.serviceWorker.register('sw.js')
|
|
170
|
-
})
|
|
171
|
-
}`.trim()
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
catch (err) {
|
|
175
|
-
results.push({
|
|
176
|
-
filePath: undefined,
|
|
177
|
-
line: undefined,
|
|
178
|
-
char: undefined,
|
|
179
|
-
code: undefined,
|
|
180
|
-
severity: "error",
|
|
181
|
-
message: `(gen-sw) ${err.toString()}`,
|
|
182
|
-
type: "build"
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
this.#debug(`번들링중 영향받은 파일`, Array.from(this.#compileResultCache.affectedFileSet!));
|
|
188
|
-
|
|
189
|
-
return {
|
|
190
|
-
program: this.#compileResultCache.program,
|
|
191
|
-
watchFileSet: new Set(this.#compileResultCache.watchFileSet),
|
|
192
|
-
affectedFileSet: this.#compileResultCache.affectedFileSet!,
|
|
193
|
-
results
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
#copyAssets(srcDir: string, globPath: string, distDir?: string): IReactOutputFile[] {
|
|
198
|
-
const result: IReactOutputFile[] = [];
|
|
199
|
-
const srcGlobPath = path.resolve(this.#opt.pkgPath, srcDir, globPath);
|
|
200
|
-
const srcPaths = glob.sync(srcGlobPath);
|
|
201
|
-
for (const srcPath of srcPaths) {
|
|
202
|
-
if (!FsUtil.exists(srcPath)) continue;
|
|
203
|
-
result.push({
|
|
204
|
-
relPath: path.join(
|
|
205
|
-
...[distDir, path.relative(path.resolve(this.#opt.pkgPath, srcDir), srcPath)].filterExists()
|
|
206
|
-
),
|
|
207
|
-
contents: FsUtil.readFile(srcPath)
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return result;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
private _getAppContext() {
|
|
215
|
-
return new SdReactBundlerContext(this.#opt.pkgPath, {
|
|
216
|
-
absWorkingDir: this.#opt.pkgPath,
|
|
217
|
-
bundle: true,
|
|
218
|
-
keepNames: true,
|
|
219
|
-
format: "esm",
|
|
220
|
-
assetNames: "media/[name]",
|
|
221
|
-
conditions: ["es2020", "es2015", "module"],
|
|
222
|
-
resolveExtensions: [".js", ".mjs", ".cjs", ".ts", ".tsx"],
|
|
223
|
-
metafile: true,
|
|
224
|
-
legalComments: this.#opt.dev ? "eof" : "none",
|
|
225
|
-
logLevel: "silent",
|
|
226
|
-
minifyIdentifiers: !this.#opt.dev,
|
|
227
|
-
minifySyntax: !this.#opt.dev,
|
|
228
|
-
minifyWhitespace: !this.#opt.dev,
|
|
229
|
-
pure: ["forwardRef"],
|
|
230
|
-
outdir: this.#opt.pkgPath,
|
|
231
|
-
outExtension: undefined,
|
|
232
|
-
sourcemap: true, //this.#opt.dev,
|
|
233
|
-
splitting: true,
|
|
234
|
-
chunkNames: "[name]-[hash]",
|
|
235
|
-
tsconfig: this.#tsConfigFilePath,
|
|
236
|
-
write: false,
|
|
237
|
-
preserveSymlinks: false,
|
|
238
|
-
define: {
|
|
239
|
-
...(!this.#opt.dev ? { ngDevMode: "false" } : {}),
|
|
240
|
-
"ngJitMode": "false",
|
|
241
|
-
"global": "global",
|
|
242
|
-
"process": "process",
|
|
243
|
-
"Buffer": "Buffer",
|
|
244
|
-
"process.env.SD_VERSION": JSON.stringify(this.#pkgNpmConf.version),
|
|
245
|
-
"process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
|
|
246
|
-
...(this.#opt.env
|
|
247
|
-
? Object.keys(this.#opt.env).toObject(
|
|
248
|
-
(key) => `process.env.${key}`,
|
|
249
|
-
(key) => JSON.stringify(this.#opt.env![key])
|
|
250
|
-
)
|
|
251
|
-
: {})
|
|
252
|
-
},
|
|
253
|
-
platform: "browser",
|
|
254
|
-
mainFields: ["es2020", "es2015", "browser", "module", "main"],
|
|
255
|
-
entryNames: "[name]",
|
|
256
|
-
entryPoints: {
|
|
257
|
-
index: this.#indexFilePath
|
|
258
|
-
},
|
|
259
|
-
external: ["electron"],
|
|
260
|
-
target: this.#browserTarget,
|
|
261
|
-
supported: { "async-await": false, "object-rest-spread": false },
|
|
262
|
-
loader: {
|
|
263
|
-
".png": "file",
|
|
264
|
-
".jpeg": "file",
|
|
265
|
-
".jpg": "file",
|
|
266
|
-
".jfif": "file",
|
|
267
|
-
".gif": "file",
|
|
268
|
-
".svg": "file",
|
|
269
|
-
".woff": "file",
|
|
270
|
-
".woff2": "file",
|
|
271
|
-
".ttf": "file",
|
|
272
|
-
".ttc": "file",
|
|
273
|
-
".eot": "file",
|
|
274
|
-
".ico": "file",
|
|
275
|
-
".otf": "file",
|
|
276
|
-
".csv": "file",
|
|
277
|
-
".xlsx": "file",
|
|
278
|
-
".xls": "file",
|
|
279
|
-
".pptx": "file",
|
|
280
|
-
".ppt": "file",
|
|
281
|
-
".docx": "file",
|
|
282
|
-
".doc": "file",
|
|
283
|
-
".zip": "file",
|
|
284
|
-
".pfx": "file",
|
|
285
|
-
".pkl": "file",
|
|
286
|
-
".mp3": "file",
|
|
287
|
-
".ogg": "file"
|
|
288
|
-
},
|
|
289
|
-
inject: [PathUtil.posix(fileURLToPath(import.meta.resolve("node-stdlib-browser/helpers/esbuild/shim")))],
|
|
290
|
-
plugins: [
|
|
291
|
-
...(this.#opt.builderType === "cordova" && this.#opt.cordovaConfig?.plugins
|
|
292
|
-
? [
|
|
293
|
-
{
|
|
294
|
-
name: "cordova:plugin-empty",
|
|
295
|
-
setup: ({ onResolve }) => {
|
|
296
|
-
onResolve({ filter: new RegExp("(" + this.#opt.cordovaConfig!.plugins!.join("|") + ")") }, () => {
|
|
297
|
-
return {
|
|
298
|
-
path: `./cordova-empty.js`,
|
|
299
|
-
external: true
|
|
300
|
-
};
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
]
|
|
305
|
-
: []),
|
|
306
|
-
sdReactPlugin({
|
|
307
|
-
modifiedFileSet: this.#modifiedFileSet,
|
|
308
|
-
dev: this.#opt.dev,
|
|
309
|
-
pkgPath: this.#opt.pkgPath,
|
|
310
|
-
result: this.#compileResultCache,
|
|
311
|
-
watchScopePaths: this.#opt.watchScopePaths,
|
|
312
|
-
}),
|
|
313
|
-
nodeStdLibBrowserPlugin(nodeStdLibBrowser)
|
|
314
|
-
]
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
private _getElectronMainContext() {
|
|
319
|
-
return new SdReactBundlerContext(this.#opt.pkgPath, {
|
|
320
|
-
absWorkingDir: this.#opt.pkgPath,
|
|
321
|
-
bundle: true,
|
|
322
|
-
entryNames: "[name]",
|
|
323
|
-
assetNames: "media/[name]",
|
|
324
|
-
conditions: ["es2020", "es2015", "module"],
|
|
325
|
-
resolveExtensions: [".js", ".mjs", ".cjs", ".ts"],
|
|
326
|
-
metafile: true,
|
|
327
|
-
legalComments: this.#opt.dev ? "eof" : "none",
|
|
328
|
-
logLevel: "silent",
|
|
329
|
-
minify: !this.#opt.dev,
|
|
330
|
-
outdir: this.#opt.pkgPath,
|
|
331
|
-
sourcemap: true, //this.#opt.dev,
|
|
332
|
-
tsconfig: this.#tsConfigFilePath,
|
|
333
|
-
write: false,
|
|
334
|
-
preserveSymlinks: false,
|
|
335
|
-
external: ["electron"],
|
|
336
|
-
define: {
|
|
337
|
-
...(!this.#opt.dev ? { ngDevMode: "false" } : {}),
|
|
338
|
-
"process.env.SD_VERSION": JSON.stringify(this.#pkgNpmConf.version),
|
|
339
|
-
"process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
|
|
340
|
-
...(this.#opt.env
|
|
341
|
-
? Object.keys(this.#opt.env).toObject(
|
|
342
|
-
(key) => `process.env.${key}`,
|
|
343
|
-
(key) => JSON.stringify(this.#opt.env![key])
|
|
344
|
-
)
|
|
345
|
-
: {})
|
|
346
|
-
},
|
|
347
|
-
platform: "node",
|
|
348
|
-
entryPoints: {
|
|
349
|
-
"electron-main": path.resolve(this.#opt.pkgPath, "src/electron-main.ts")
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
#debug(...msg: any[]): void {
|
|
355
|
-
this.#logger.debug(`[${path.basename(this.#opt.pkgPath)}]`, ...msg);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
interface IOptions {
|
|
360
|
-
dev: boolean;
|
|
361
|
-
outputPath: string;
|
|
362
|
-
pkgPath: string;
|
|
363
|
-
builderType: string;
|
|
364
|
-
env: Record<string, string> | undefined;
|
|
365
|
-
cordovaConfig: ISdCliClientBuilderCordovaConfig | undefined;
|
|
366
|
-
watchScopePaths: string[];
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
interface IReactOutputFile {
|
|
370
|
-
relPath: string;
|
|
371
|
-
contents: Uint8Array | string;
|
|
372
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import esbuild from "esbuild";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { ISdCliPackageBuildResult } from "../commons";
|
|
4
|
-
import { Logger } from "@simplysm/sd-core-node";
|
|
5
|
-
|
|
6
|
-
export class SdReactBundlerContext {
|
|
7
|
-
readonly #logger = Logger.get(["simplysm", "sd-cli", "SdReactBundlerContext"]);
|
|
8
|
-
|
|
9
|
-
private _context?: esbuild.BuildContext;
|
|
10
|
-
|
|
11
|
-
public constructor(
|
|
12
|
-
private readonly _pkgPath: string,
|
|
13
|
-
private readonly _esbuildOptions: esbuild.BuildOptions,
|
|
14
|
-
) {}
|
|
15
|
-
|
|
16
|
-
public async bundleAsync() {
|
|
17
|
-
if (this._context == null) {
|
|
18
|
-
this._context = await esbuild.context(this._esbuildOptions);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let buildResult: esbuild.BuildResult;
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
this.#debug(`rebuild...`);
|
|
25
|
-
buildResult = await this._context.rebuild();
|
|
26
|
-
this.#debug(`rebuild completed`);
|
|
27
|
-
} catch (err) {
|
|
28
|
-
if ("warnings" in err || "errors" in err) {
|
|
29
|
-
buildResult = err;
|
|
30
|
-
} else {
|
|
31
|
-
throw err;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this.#debug(`convert results...`);
|
|
36
|
-
|
|
37
|
-
const results = [
|
|
38
|
-
...buildResult.warnings.map((warn) => ({
|
|
39
|
-
filePath: warn.location?.file !== undefined ? path.resolve(this._pkgPath, warn.location.file) : undefined,
|
|
40
|
-
line: warn.location?.line,
|
|
41
|
-
char: warn.location?.column,
|
|
42
|
-
code: warn.text.slice(0, warn.text.indexOf(":")),
|
|
43
|
-
severity: "warning",
|
|
44
|
-
message: `${warn.pluginName ? `(${warn.pluginName}) ` : ""} ${warn.text.slice(warn.text.indexOf(":") + 1)}`,
|
|
45
|
-
type: "build",
|
|
46
|
-
})),
|
|
47
|
-
...buildResult.errors.map((err) => ({
|
|
48
|
-
filePath: err.location?.file !== undefined ? path.resolve(this._pkgPath, err.location.file) : undefined,
|
|
49
|
-
line: err.location?.line,
|
|
50
|
-
char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
|
|
51
|
-
code: err.text.slice(0, err.text.indexOf(":")),
|
|
52
|
-
severity: "error",
|
|
53
|
-
message: `${err.pluginName ? `(${err.pluginName}) ` : ""} ${err.text.slice(err.text.indexOf(":") + 1)}`,
|
|
54
|
-
type: "build",
|
|
55
|
-
})),
|
|
56
|
-
] as ISdCliPackageBuildResult[];
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
results,
|
|
60
|
-
outputFiles: buildResult.outputFiles,
|
|
61
|
-
metafile: buildResult.metafile,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
#debug(...msg: any[]): void {
|
|
66
|
-
this.#logger.debug(
|
|
67
|
-
`[${path.basename(this._pkgPath)}] (${Object.keys(this._esbuildOptions.entryPoints as Record<string, any>).join(", ")})`,
|
|
68
|
-
...msg,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
}
|