@simplysm/sd-cli 12.5.20 → 12.5.21
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/SdReactBundler.d.ts +25 -0
- package/dist/build-tools/SdReactBundler.js +295 -0
- package/dist/build-tools/SdReactBundler.js.map +1 -0
- package/dist/build-tools/SdReactBundlerContext.d.ts +14 -0
- package/dist/build-tools/SdReactBundlerContext.js +59 -0
- package/dist/build-tools/SdReactBundlerContext.js.map +1 -0
- package/dist/builders/SdCliClientBuilder.js +41 -20
- package/dist/builders/SdCliClientBuilder.js.map +1 -1
- package/dist/bundle-plugins/sdReactPlugin.d.ts +16 -0
- package/dist/bundle-plugins/sdReactPlugin.js +117 -0
- package/dist/bundle-plugins/sdReactPlugin.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +8 -5
- package/src/build-tools/SdReactBundler.ts +372 -0
- package/src/build-tools/SdReactBundlerContext.ts +71 -0
- package/src/builders/SdCliClientBuilder.ts +49 -27
- package/src/bundle-plugins/sdReactPlugin.ts +164 -0
- package/src/index.ts +3 -0
|
@@ -14,18 +14,15 @@ import { SdCliCordova } from "../build-tools/SdCliCordova";
|
|
|
14
14
|
import { SdCliNgRoutesFileGenerator } from "../build-tools/SdCliNgRoutesFileGenerator";
|
|
15
15
|
import { SdLinter } from "../build-tools/SdLinter";
|
|
16
16
|
import { SdCliElectron } from "../entry/SdCliElectron";
|
|
17
|
-
|
|
18
|
-
// import ts from "typescript";
|
|
17
|
+
import { SdReactBundler } from "../build-tools/SdReactBundler";
|
|
19
18
|
|
|
20
19
|
export class SdCliClientBuilder extends EventEmitter {
|
|
21
20
|
private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliClientBuilder"]);
|
|
22
21
|
private readonly _pkgConf: ISdCliClientPackageConfig;
|
|
23
22
|
private readonly _npmConf: INpmConfig;
|
|
24
|
-
private _builders?: SdNgBundler[];
|
|
23
|
+
private _builders?: (SdNgBundler | SdReactBundler)[];
|
|
25
24
|
private _cordova?: SdCliCordova;
|
|
26
25
|
|
|
27
|
-
// #program?: ts.Program;
|
|
28
|
-
|
|
29
26
|
public constructor(
|
|
30
27
|
private readonly _projConf: ISdCliConfig,
|
|
31
28
|
private readonly _pkgPath: string,
|
|
@@ -133,28 +130,53 @@ export class SdCliClientBuilder extends EventEmitter {
|
|
|
133
130
|
if (!this._builders) {
|
|
134
131
|
this._debug(`BUILD 준비...`);
|
|
135
132
|
|
|
136
|
-
this.
|
|
137
|
-
(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
133
|
+
if (this._npmConf.dependencies && Object.keys(this._npmConf.dependencies).includes("react")) {
|
|
134
|
+
this._builders = builderTypes.map(
|
|
135
|
+
(builderType) =>
|
|
136
|
+
new SdReactBundler({
|
|
137
|
+
dev: opt.dev,
|
|
138
|
+
builderType: builderType,
|
|
139
|
+
pkgPath: this._pkgPath,
|
|
140
|
+
outputPath:
|
|
141
|
+
builderType === "web"
|
|
142
|
+
? path.resolve(this._pkgPath, "dist")
|
|
143
|
+
: builderType === "electron" && !opt.dev
|
|
144
|
+
? path.resolve(this._pkgPath, ".electron/src")
|
|
145
|
+
: builderType === "cordova" && !opt.dev
|
|
146
|
+
? path.resolve(this._pkgPath, ".cordova/www")
|
|
147
|
+
: path.resolve(this._pkgPath, "dist", builderType),
|
|
148
|
+
env: {
|
|
149
|
+
...this._pkgConf.env,
|
|
150
|
+
...this._pkgConf.builder?.[builderType]?.env,
|
|
151
|
+
},
|
|
152
|
+
cordovaConfig: builderType === "cordova" ? this._pkgConf.builder!.cordova : undefined,
|
|
153
|
+
watchScopePaths: [path.resolve(this._pkgPath, "../"), ...localUpdatePaths],
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
156
|
+
} else {
|
|
157
|
+
this._builders = builderTypes.map(
|
|
158
|
+
(builderType) =>
|
|
159
|
+
new SdNgBundler({
|
|
160
|
+
dev: opt.dev,
|
|
161
|
+
builderType: builderType,
|
|
162
|
+
pkgPath: this._pkgPath,
|
|
163
|
+
outputPath:
|
|
164
|
+
builderType === "web"
|
|
165
|
+
? path.resolve(this._pkgPath, "dist")
|
|
166
|
+
: builderType === "electron" && !opt.dev
|
|
167
|
+
? path.resolve(this._pkgPath, ".electron/src")
|
|
168
|
+
: builderType === "cordova" && !opt.dev
|
|
169
|
+
? path.resolve(this._pkgPath, ".cordova/www")
|
|
170
|
+
: path.resolve(this._pkgPath, "dist", builderType),
|
|
171
|
+
env: {
|
|
172
|
+
...this._pkgConf.env,
|
|
173
|
+
...this._pkgConf.builder?.[builderType]?.env,
|
|
174
|
+
},
|
|
175
|
+
cordovaConfig: builderType === "cordova" ? this._pkgConf.builder!.cordova : undefined,
|
|
176
|
+
watchScopePaths: [path.resolve(this._pkgPath, "../"), ...localUpdatePaths],
|
|
177
|
+
}),
|
|
178
|
+
);
|
|
179
|
+
}
|
|
158
180
|
}
|
|
159
181
|
|
|
160
182
|
this._debug(`BUILD & CHECK...`);
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import esbuild from "esbuild";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { ISdTsCompilerResult, SdTsCompiler } from "../build-tools/SdTsCompiler";
|
|
5
|
+
import { convertTypeScriptDiagnostic } from "@angular/build/src/tools/esbuild/angular/diagnostics";
|
|
6
|
+
import postcss from "postcss";
|
|
7
|
+
import { FsUtil } from "@simplysm/sd-core-node";
|
|
8
|
+
import postcssUrl from "postcss-url";
|
|
9
|
+
import postcssHas from "css-has-pseudo";
|
|
10
|
+
import autoprefixer from "autoprefixer";
|
|
11
|
+
|
|
12
|
+
export function sdReactPlugin(conf: {
|
|
13
|
+
pkgPath: string;
|
|
14
|
+
dev: boolean;
|
|
15
|
+
modifiedFileSet: Set<string>;
|
|
16
|
+
result: IReactPluginResultCache;
|
|
17
|
+
watchScopePaths: string[];
|
|
18
|
+
}): esbuild.Plugin {
|
|
19
|
+
return {
|
|
20
|
+
name: "sd-ng-compiler",
|
|
21
|
+
setup: (build: esbuild.PluginBuild) => {
|
|
22
|
+
const compiler = new SdTsCompiler({
|
|
23
|
+
pkgPath: conf.pkgPath,
|
|
24
|
+
additionalOptions: { declaration: false },
|
|
25
|
+
isDevMode: conf.dev,
|
|
26
|
+
isForBundle: true,
|
|
27
|
+
watchScopePaths: conf.watchScopePaths
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
let buildResult: ISdTsCompilerResult;
|
|
31
|
+
const outputContentsCacheMap = new Map<string, string | Uint8Array | undefined>();
|
|
32
|
+
|
|
33
|
+
//---------------------------
|
|
34
|
+
|
|
35
|
+
build.onStart(async () => {
|
|
36
|
+
compiler.invalidate(conf.modifiedFileSet);
|
|
37
|
+
for (const modifiedFile of conf.modifiedFileSet) {
|
|
38
|
+
outputContentsCacheMap.delete(modifiedFile);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
buildResult = await compiler.buildAsync();
|
|
42
|
+
|
|
43
|
+
conf.result.watchFileSet = buildResult.watchFileSet;
|
|
44
|
+
conf.result.affectedFileSet = buildResult.affectedFileSet;
|
|
45
|
+
conf.result.program = buildResult.program;
|
|
46
|
+
|
|
47
|
+
//-- return err/warn
|
|
48
|
+
return {
|
|
49
|
+
errors: [
|
|
50
|
+
...buildResult.typescriptDiagnostics
|
|
51
|
+
.filter((item) => item.category === ts.DiagnosticCategory.Error)
|
|
52
|
+
.map((item) => convertTypeScriptDiagnostic(ts, item)),
|
|
53
|
+
...Array.from(buildResult.stylesheetBundlingResultMap.values()).flatMap((item) => item.errors),
|
|
54
|
+
].filterExists(),
|
|
55
|
+
warnings: [
|
|
56
|
+
...buildResult.typescriptDiagnostics
|
|
57
|
+
.filter((item) => item.category !== ts.DiagnosticCategory.Error)
|
|
58
|
+
.map((item) => convertTypeScriptDiagnostic(ts, item)),
|
|
59
|
+
// ...Array.from(buildResult.stylesheetResultMap.values()).flatMap(item => item.warnings)
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
build.onLoad({ filter: /\.tsx?$/ }, (args) => {
|
|
65
|
+
const output = outputContentsCacheMap.get(path.normalize(args.path));
|
|
66
|
+
if (output != null) {
|
|
67
|
+
return { contents: output, loader: "js" };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const emittedJsFile = buildResult.emittedFilesCacheMap.get(path.normalize(args.path))?.last();
|
|
71
|
+
if (!emittedJsFile) {
|
|
72
|
+
throw new Error(`ts 빌더 결과 emit 파일이 존재하지 않습니다. ${args.path}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const contents = emittedJsFile.text;
|
|
76
|
+
|
|
77
|
+
outputContentsCacheMap.set(path.normalize(args.path), contents);
|
|
78
|
+
|
|
79
|
+
return { contents, loader: "js" };
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
build.onLoad({ filter: /\.[cm]?jsx?$/ }, (args) => {
|
|
83
|
+
conf.result.watchFileSet!.add(path.normalize(args.path));
|
|
84
|
+
return null;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
build.onLoad({ filter: /\.css$/ }, async (args) => {
|
|
88
|
+
conf.result.watchFileSet!.add(path.normalize(args.path));
|
|
89
|
+
const output = outputContentsCacheMap.get(path.normalize(args.path));
|
|
90
|
+
if (output != null) {
|
|
91
|
+
return {
|
|
92
|
+
contents: output,
|
|
93
|
+
loader: "file",
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const css = await FsUtil.readFileAsync(path.normalize(args.path));
|
|
98
|
+
const result = await postcss()
|
|
99
|
+
.use(
|
|
100
|
+
autoprefixer({
|
|
101
|
+
overrideBrowserslist: ["Chrome > 78"]
|
|
102
|
+
})
|
|
103
|
+
)
|
|
104
|
+
.use(
|
|
105
|
+
postcssUrl({
|
|
106
|
+
url: "copy",
|
|
107
|
+
}),
|
|
108
|
+
)
|
|
109
|
+
.use(
|
|
110
|
+
postcssHas()
|
|
111
|
+
)
|
|
112
|
+
.process(css, {
|
|
113
|
+
from: path.normalize(args.path),
|
|
114
|
+
to: path.resolve(conf.pkgPath, "dist", "media", path.basename(args.path)),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
outputContentsCacheMap.set(path.normalize(args.path), result.css);
|
|
118
|
+
|
|
119
|
+
return { contents: result.css, loader: "file" };
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
build.onLoad(
|
|
123
|
+
{
|
|
124
|
+
filter: new RegExp(
|
|
125
|
+
"(" +
|
|
126
|
+
Object.keys(build.initialOptions.loader!)
|
|
127
|
+
.map((item) => "\\" + item)
|
|
128
|
+
.join("|") +
|
|
129
|
+
")$",
|
|
130
|
+
),
|
|
131
|
+
},
|
|
132
|
+
(args) => {
|
|
133
|
+
conf.result.watchFileSet!.add(path.normalize(args.path));
|
|
134
|
+
return null;
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
build.onEnd((result) => {
|
|
139
|
+
for (const { outputFiles, metafile } of buildResult.stylesheetBundlingResultMap.values()) {
|
|
140
|
+
result.outputFiles = result.outputFiles ?? [];
|
|
141
|
+
result.outputFiles.push(...outputFiles);
|
|
142
|
+
|
|
143
|
+
if (result.metafile && metafile) {
|
|
144
|
+
result.metafile.inputs = { ...result.metafile.inputs, ...metafile.inputs };
|
|
145
|
+
result.metafile.outputs = { ...result.metafile.outputs, ...metafile.outputs };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
conf.result.outputFiles = result.outputFiles;
|
|
150
|
+
conf.result.metafile = result.metafile;
|
|
151
|
+
|
|
152
|
+
conf.modifiedFileSet.clear();
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface IReactPluginResultCache {
|
|
159
|
+
watchFileSet?: Set<string>;
|
|
160
|
+
affectedFileSet?: Set<string>;
|
|
161
|
+
program?: ts.Program;
|
|
162
|
+
outputFiles?: esbuild.OutputFile[];
|
|
163
|
+
metafile?: esbuild.Metafile;
|
|
164
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ export * from "./build-tools/SdCliNgRoutesFileGenerator";
|
|
|
4
4
|
export * from "./build-tools/SdLinter";
|
|
5
5
|
export * from "./build-tools/SdNgBundler";
|
|
6
6
|
export * from "./build-tools/SdNgBundlerContext";
|
|
7
|
+
export * from "./build-tools/SdReactBundler";
|
|
8
|
+
export * from "./build-tools/SdReactBundlerContext";
|
|
7
9
|
export * from "./build-tools/SdServerBundler";
|
|
8
10
|
export * from "./build-tools/SdTsCompiler";
|
|
9
11
|
export * from "./build-tools/SdTsLibBundler";
|
|
@@ -12,6 +14,7 @@ export * from "./builders/SdCliJsLibLinter";
|
|
|
12
14
|
export * from "./builders/SdCliServerBuilder";
|
|
13
15
|
export * from "./builders/SdCliTsLibBuilder";
|
|
14
16
|
export * from "./bundle-plugins/sdNgPlugin";
|
|
17
|
+
export * from "./bundle-plugins/sdReactPlugin";
|
|
15
18
|
export * from "./bundle-plugins/sdServerPlugin";
|
|
16
19
|
export * from "./commons";
|
|
17
20
|
export * from "./entry/SdCliElectron";
|