@steambrew/ttc 1.2.1 → 1.2.2
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/Compiler.ts +232 -200
- package/dist/index.js +69 -53
- package/package.json +1 -1
package/Compiler.ts
CHANGED
|
@@ -1,259 +1,291 @@
|
|
|
1
1
|
import { OutputOptions, RollupOptions, rollup } from "rollup";
|
|
2
|
-
import json from
|
|
3
|
-
import commonjs from
|
|
4
|
-
import replace from
|
|
5
|
-
import typescript from
|
|
6
|
-
import resolve from
|
|
7
|
-
import terser from
|
|
8
|
-
import babel from
|
|
9
|
-
|
|
10
|
-
import chalk from
|
|
2
|
+
import json from "@rollup/plugin-json";
|
|
3
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
4
|
+
import replace from "@rollup/plugin-replace";
|
|
5
|
+
import typescript from "@rollup/plugin-typescript";
|
|
6
|
+
import resolve from "@rollup/plugin-node-resolve";
|
|
7
|
+
import terser from "@rollup/plugin-terser";
|
|
8
|
+
import babel from "@rollup/plugin-babel";
|
|
9
|
+
|
|
10
|
+
import chalk from "chalk";
|
|
11
11
|
import { Logger } from "./Logger";
|
|
12
|
-
import fs from
|
|
12
|
+
import fs from "fs";
|
|
13
13
|
|
|
14
|
-
import injectProcessEnv from
|
|
15
|
-
import dotenv from
|
|
14
|
+
import injectProcessEnv from "rollup-plugin-inject-process-env";
|
|
15
|
+
import dotenv from "dotenv";
|
|
16
16
|
|
|
17
17
|
const envConfig = dotenv.config().parsed || {};
|
|
18
18
|
|
|
19
19
|
if (envConfig) {
|
|
20
|
-
|
|
20
|
+
Logger.Info("Injecting environment variables...");
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const envVars = Object.keys(envConfig).reduce((acc: any, key) => {
|
|
24
|
-
acc[
|
|
24
|
+
acc[key] = envConfig[key];
|
|
25
25
|
return acc;
|
|
26
26
|
}, {});
|
|
27
27
|
|
|
28
28
|
declare global {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
interface Window {
|
|
30
|
+
PLUGIN_LIST: any;
|
|
31
|
+
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
declare const pluginName: string,
|
|
34
|
+
declare const pluginName: string,
|
|
35
|
+
millennium_main: any,
|
|
36
|
+
MILLENNIUM_BACKEND_IPC: any;
|
|
35
37
|
|
|
36
38
|
export interface TranspilerProps {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
bTersePlugin?: boolean;
|
|
40
|
+
strPluginInternalName: string;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
const WrappedCallServerMethod =
|
|
42
|
-
|
|
43
|
+
const WrappedCallServerMethod =
|
|
44
|
+
"const __call_server_method__ = (methodName, kwargs) => Millennium.callServerMethod(pluginName, methodName, kwargs)";
|
|
45
|
+
const WrappedCallable =
|
|
46
|
+
"const __wrapped_callable__ = (route) => MILLENNIUM_API.callable(__call_server_method__, route)";
|
|
43
47
|
|
|
44
48
|
/**
|
|
45
|
-
* @description Append the active plugin to the global plugin
|
|
49
|
+
* @description Append the active plugin to the global plugin
|
|
46
50
|
* list and notify that the frontend Loaded.
|
|
47
51
|
*/
|
|
48
52
|
function ExecutePluginModule() {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
// Assign the plugin on plugin list.
|
|
54
|
+
Object.assign(window.PLUGIN_LIST[pluginName], millennium_main);
|
|
55
|
+
// Run the rolled up plugins default exported function
|
|
56
|
+
millennium_main["default"]();
|
|
57
|
+
MILLENNIUM_BACKEND_IPC.postMessage(1, { pluginName: pluginName });
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
/**
|
|
57
|
-
* @description Append the active plugin to the global plugin
|
|
61
|
+
* @description Append the active plugin to the global plugin
|
|
58
62
|
* list and notify that the frontend Loaded.
|
|
59
63
|
*/
|
|
60
64
|
function ExecuteWebkitModule() {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
// Assign the plugin on plugin list.
|
|
66
|
+
Object.assign(window.PLUGIN_LIST[pluginName], millennium_main);
|
|
67
|
+
// Run the rolled up plugins default exported function
|
|
68
|
+
millennium_main["default"]();
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
/**
|
|
68
|
-
* @description Simple bootstrap function that initializes PLUGIN_LIST
|
|
69
|
-
* for current plugin given that is doesnt exist.
|
|
72
|
+
* @description Simple bootstrap function that initializes PLUGIN_LIST
|
|
73
|
+
* for current plugin given that is doesnt exist.
|
|
70
74
|
*/
|
|
71
75
|
function InitializePlugins() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
/**
|
|
77
|
+
* This function is called n times depending on n plugin count,
|
|
78
|
+
* Create the plugin list if it wasn't already created
|
|
79
|
+
*/
|
|
80
|
+
!window.PLUGIN_LIST && (window.PLUGIN_LIST = {});
|
|
81
|
+
|
|
82
|
+
// initialize a container for the plugin
|
|
83
|
+
if (!window.PLUGIN_LIST[pluginName]) {
|
|
84
|
+
window.PLUGIN_LIST[pluginName] = {};
|
|
85
|
+
}
|
|
82
86
|
}
|
|
83
87
|
|
|
84
|
-
const ContructFunctions = (parts: any) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
88
|
+
const ContructFunctions = (parts: any) => {
|
|
89
|
+
return parts.join("\n");
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
function InsertMillennium(props: TranspilerProps) {
|
|
93
|
+
const generateBundle = (_: unknown, bundle: any) => {
|
|
94
|
+
for (const fileName in bundle) {
|
|
95
|
+
if (bundle[fileName].type != "chunk") continue;
|
|
96
|
+
|
|
97
|
+
Logger.Info(
|
|
98
|
+
"Injecting Millennium shims into module... " + chalk.green.bold("okay")
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
bundle[fileName].code = ContructFunctions([
|
|
102
|
+
`const pluginName = "${props.strPluginInternalName}";`,
|
|
103
|
+
InitializePlugins.toString(),
|
|
104
|
+
InitializePlugins.name + "()",
|
|
105
|
+
WrappedCallServerMethod,
|
|
106
|
+
WrappedCallable,
|
|
107
|
+
bundle[fileName].code,
|
|
108
|
+
ExecutePluginModule.toString(),
|
|
109
|
+
ExecutePluginModule.name + "()",
|
|
110
|
+
]);
|
|
101
111
|
}
|
|
112
|
+
};
|
|
102
113
|
|
|
103
|
-
|
|
114
|
+
return { name: String(), generateBundle };
|
|
104
115
|
}
|
|
105
116
|
|
|
106
|
-
function InsertWebkitMillennium(props: TranspilerProps)
|
|
107
|
-
{
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
function InsertWebkitMillennium(props: TranspilerProps) {
|
|
118
|
+
const generateBundle = (_: unknown, bundle: any) => {
|
|
119
|
+
for (const fileName in bundle) {
|
|
120
|
+
if (bundle[fileName].type != "chunk") continue;
|
|
121
|
+
|
|
122
|
+
Logger.Info(
|
|
123
|
+
"Injecting Millennium shims into webkit module... " +
|
|
124
|
+
chalk.green.bold("okay")
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
bundle[fileName].code = ContructFunctions([
|
|
128
|
+
`const pluginName = "${props.strPluginInternalName}";`,
|
|
129
|
+
InitializePlugins.toString(),
|
|
130
|
+
InitializePlugins.name + "()",
|
|
131
|
+
WrappedCallServerMethod,
|
|
132
|
+
WrappedCallable,
|
|
133
|
+
bundle[fileName].code,
|
|
134
|
+
ExecuteWebkitModule.toString(),
|
|
135
|
+
ExecuteWebkitModule.name + "()",
|
|
136
|
+
]);
|
|
121
137
|
}
|
|
138
|
+
};
|
|
122
139
|
|
|
123
|
-
|
|
140
|
+
return { name: String(), generateBundle };
|
|
124
141
|
}
|
|
125
142
|
|
|
126
143
|
function GetPluginComponents(props: TranspilerProps) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
144
|
+
let tsConfigPath = `./${GetFrontEndDirectory()}/tsconfig.json`;
|
|
145
|
+
|
|
146
|
+
if (!fs.existsSync(tsConfigPath)) {
|
|
147
|
+
tsConfigPath = "./tsconfig.json";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const pluginList = [
|
|
151
|
+
InsertMillennium(props),
|
|
152
|
+
typescript({
|
|
153
|
+
tsconfig: tsConfigPath,
|
|
154
|
+
}),
|
|
155
|
+
resolve(),
|
|
156
|
+
commonjs(),
|
|
157
|
+
json(),
|
|
158
|
+
injectProcessEnv(envVars),
|
|
159
|
+
replace({
|
|
160
|
+
delimiters: ["", ""],
|
|
161
|
+
preventAssignment: true,
|
|
162
|
+
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
163
|
+
"Millennium.callServerMethod": `__call_server_method__`,
|
|
164
|
+
"client.callable": `__wrapped_callable__`,
|
|
165
|
+
"client.pluginSelf": "window.PLUGIN_LIST[pluginName]",
|
|
166
|
+
"client.Millennium.exposeObj(": "client.Millennium.exposeObj(exports, ",
|
|
167
|
+
}),
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
if (props.bTersePlugin) {
|
|
171
|
+
pluginList.push(terser());
|
|
172
|
+
}
|
|
173
|
+
return pluginList;
|
|
156
174
|
}
|
|
157
175
|
|
|
158
176
|
function GetWebkitPluginComponents(props: TranspilerProps) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
const pluginList = [
|
|
178
|
+
InsertWebkitMillennium(props),
|
|
179
|
+
typescript({
|
|
180
|
+
tsconfig: "./webkit/tsconfig.json",
|
|
181
|
+
}),
|
|
182
|
+
resolve(),
|
|
183
|
+
commonjs(),
|
|
184
|
+
json(),
|
|
185
|
+
injectProcessEnv(envVars),
|
|
186
|
+
replace({
|
|
187
|
+
delimiters: ["", ""],
|
|
188
|
+
preventAssignment: true,
|
|
189
|
+
"Millennium.callServerMethod": `__call_server_method__`,
|
|
190
|
+
"webkit.callable": `__wrapped_callable__`,
|
|
191
|
+
}),
|
|
192
|
+
babel({
|
|
193
|
+
presets: ["@babel/preset-env", "@babel/preset-react"],
|
|
194
|
+
babelHelpers: "bundled",
|
|
195
|
+
}),
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
props.bTersePlugin && pluginList.push(terser());
|
|
199
|
+
return pluginList;
|
|
180
200
|
}
|
|
181
201
|
|
|
182
202
|
const GetFrontEndDirectory = () => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
203
|
+
const pluginJsonPath = "./plugin.json";
|
|
204
|
+
try {
|
|
205
|
+
return (
|
|
206
|
+
JSON.parse(fs.readFileSync(pluginJsonPath, "utf8"))?.frontend ??
|
|
207
|
+
"frontend"
|
|
208
|
+
);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
return "frontend";
|
|
211
|
+
}
|
|
212
|
+
};
|
|
191
213
|
|
|
192
214
|
export const TranspilerPluginComponent = async (props: TranspilerProps) => {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
215
|
+
const frontendRollupConfig: RollupOptions = {
|
|
216
|
+
input: `./${GetFrontEndDirectory()}/index.tsx`,
|
|
217
|
+
plugins: GetPluginComponents(props),
|
|
218
|
+
context: "window",
|
|
219
|
+
external: (id) => {
|
|
220
|
+
if (id === "@steambrew/webkit") {
|
|
221
|
+
Logger.Error(
|
|
222
|
+
"The @steambrew/webkit module should not be included in the frontend module, use @steambrew/client instead. Please remove it from the frontend module and try again."
|
|
223
|
+
);
|
|
224
|
+
process.exit(1);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return id === "@steambrew/client" || id === "react" || id === "react-dom";
|
|
228
|
+
},
|
|
229
|
+
output: {
|
|
230
|
+
name: "millennium_main",
|
|
231
|
+
file: ".millennium/Dist/index.js",
|
|
232
|
+
globals: {
|
|
233
|
+
react: "window.SP_REACT",
|
|
234
|
+
"react-dom": "window.SP_REACTDOM",
|
|
235
|
+
"@steambrew/client": "window.MILLENNIUM_API",
|
|
236
|
+
},
|
|
237
|
+
exports: "named",
|
|
238
|
+
format: "iife",
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
Logger.Info("Starting build; this may take a few moments...");
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
await (
|
|
246
|
+
await rollup(frontendRollupConfig)
|
|
247
|
+
).write(frontendRollupConfig.output as OutputOptions);
|
|
248
|
+
|
|
249
|
+
if (fs.existsSync(`./webkit/index.tsx`)) {
|
|
250
|
+
Logger.Info("Compiling webkit module...");
|
|
251
|
+
|
|
252
|
+
const webkitRollupConfig: RollupOptions = {
|
|
253
|
+
input: `./webkit/index.tsx`,
|
|
254
|
+
plugins: GetWebkitPluginComponents(props),
|
|
255
|
+
context: "window",
|
|
256
|
+
external: (id) => {
|
|
257
|
+
if (id === "@steambrew/client") {
|
|
258
|
+
Logger.Error(
|
|
259
|
+
"The @steambrew/client module should not be included in the webkit module, use @steambrew/webkit instead. Please remove it from the webkit module and try again."
|
|
260
|
+
);
|
|
261
|
+
process.exit(1);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return id === "@steambrew/webkit";
|
|
205
265
|
},
|
|
206
266
|
output: {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
}
|
|
267
|
+
name: "millennium_main",
|
|
268
|
+
file: ".millennium/Dist/webkit.js",
|
|
269
|
+
exports: "named",
|
|
270
|
+
format: "iife",
|
|
271
|
+
globals: {
|
|
272
|
+
"@steambrew/webkit": "window.MILLENNIUM_API",
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
};
|
|
218
276
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
await (await rollup(frontendRollupConfig)).write(frontendRollupConfig.output as OutputOptions);
|
|
223
|
-
|
|
224
|
-
if (fs.existsSync(`./webkit/index.tsx`)) {
|
|
225
|
-
Logger.Info("Compiling webkit module...")
|
|
226
|
-
|
|
227
|
-
const webkitRollupConfig: RollupOptions = {
|
|
228
|
-
input: `./webkit/index.tsx`,
|
|
229
|
-
plugins: GetWebkitPluginComponents(props),
|
|
230
|
-
context: 'window',
|
|
231
|
-
external: (id) => {
|
|
232
|
-
if (id === '@steambrew/client') {
|
|
233
|
-
Logger.Error('The @steambrew/client module should not be included in the webkit module, use @steambrew/webkit instead. Please remove it from the webkit module and try again.')
|
|
234
|
-
process.exit(1)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return id === '@steambrew/webkit'
|
|
238
|
-
},
|
|
239
|
-
output: {
|
|
240
|
-
name: "millennium_main",
|
|
241
|
-
file: ".millennium/Dist/webkit.js",
|
|
242
|
-
exports: 'named',
|
|
243
|
-
format: 'iife',
|
|
244
|
-
globals: {
|
|
245
|
-
"@steambrew/webkit": "window.MILLENNIUM_API"
|
|
246
|
-
},
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
await (await rollup(webkitRollupConfig)).write(webkitRollupConfig.output as OutputOptions);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
Logger.Info('Build succeeded!', Number((performance.now() - global.PerfStartTime).toFixed(3)), 'ms elapsed.')
|
|
277
|
+
await (
|
|
278
|
+
await rollup(webkitRollupConfig)
|
|
279
|
+
).write(webkitRollupConfig.output as OutputOptions);
|
|
254
280
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
281
|
+
|
|
282
|
+
Logger.Info(
|
|
283
|
+
"Build succeeded!",
|
|
284
|
+
Number((performance.now() - global.PerfStartTime).toFixed(3)),
|
|
285
|
+
"ms elapsed."
|
|
286
|
+
);
|
|
287
|
+
} catch (exception) {
|
|
288
|
+
Logger.Error("Build failed!", exception);
|
|
289
|
+
process.exit(1);
|
|
290
|
+
}
|
|
291
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -171,7 +171,7 @@ if (envConfig) {
|
|
|
171
171
|
Logger.Info("Injecting environment variables...");
|
|
172
172
|
}
|
|
173
173
|
const envVars = Object.keys(envConfig).reduce((acc, key) => {
|
|
174
|
-
acc[
|
|
174
|
+
acc[key] = envConfig[key];
|
|
175
175
|
return acc;
|
|
176
176
|
}, {});
|
|
177
177
|
const WrappedCallServerMethod = "const __call_server_method__ = (methodName, kwargs) => Millennium.callServerMethod(pluginName, methodName, kwargs)";
|
|
@@ -181,9 +181,9 @@ const WrappedCallable = "const __wrapped_callable__ = (route) => MILLENNIUM_API.
|
|
|
181
181
|
* list and notify that the frontend Loaded.
|
|
182
182
|
*/
|
|
183
183
|
function ExecutePluginModule() {
|
|
184
|
-
// Assign the plugin on plugin list.
|
|
184
|
+
// Assign the plugin on plugin list.
|
|
185
185
|
Object.assign(window.PLUGIN_LIST[pluginName], millennium_main);
|
|
186
|
-
// Run the rolled up plugins default exported function
|
|
186
|
+
// Run the rolled up plugins default exported function
|
|
187
187
|
millennium_main["default"]();
|
|
188
188
|
MILLENNIUM_BACKEND_IPC.postMessage(1, { pluginName: pluginName });
|
|
189
189
|
}
|
|
@@ -192,9 +192,9 @@ function ExecutePluginModule() {
|
|
|
192
192
|
* list and notify that the frontend Loaded.
|
|
193
193
|
*/
|
|
194
194
|
function ExecuteWebkitModule() {
|
|
195
|
-
// Assign the plugin on plugin list.
|
|
195
|
+
// Assign the plugin on plugin list.
|
|
196
196
|
Object.assign(window.PLUGIN_LIST[pluginName], millennium_main);
|
|
197
|
-
// Run the rolled up plugins default exported function
|
|
197
|
+
// Run the rolled up plugins default exported function
|
|
198
198
|
millennium_main["default"]();
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
@@ -212,18 +212,24 @@ function InitializePlugins() {
|
|
|
212
212
|
window.PLUGIN_LIST[pluginName] = {};
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
const ContructFunctions = (parts) => {
|
|
215
|
+
const ContructFunctions = (parts) => {
|
|
216
|
+
return parts.join("\n");
|
|
217
|
+
};
|
|
216
218
|
function InsertMillennium(props) {
|
|
217
219
|
const generateBundle = (_, bundle) => {
|
|
218
220
|
for (const fileName in bundle) {
|
|
219
|
-
if (bundle[fileName].type !=
|
|
221
|
+
if (bundle[fileName].type != "chunk")
|
|
220
222
|
continue;
|
|
221
223
|
Logger.Info("Injecting Millennium shims into module... " + chalk.green.bold("okay"));
|
|
222
224
|
bundle[fileName].code = ContructFunctions([
|
|
223
225
|
`const pluginName = "${props.strPluginInternalName}";`,
|
|
224
|
-
InitializePlugins.toString(),
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
InitializePlugins.toString(),
|
|
227
|
+
InitializePlugins.name + "()",
|
|
228
|
+
WrappedCallServerMethod,
|
|
229
|
+
WrappedCallable,
|
|
230
|
+
bundle[fileName].code,
|
|
231
|
+
ExecutePluginModule.toString(),
|
|
232
|
+
ExecutePluginModule.name + "()",
|
|
227
233
|
]);
|
|
228
234
|
}
|
|
229
235
|
};
|
|
@@ -232,14 +238,19 @@ function InsertMillennium(props) {
|
|
|
232
238
|
function InsertWebkitMillennium(props) {
|
|
233
239
|
const generateBundle = (_, bundle) => {
|
|
234
240
|
for (const fileName in bundle) {
|
|
235
|
-
if (bundle[fileName].type !=
|
|
241
|
+
if (bundle[fileName].type != "chunk")
|
|
236
242
|
continue;
|
|
237
|
-
Logger.Info("Injecting Millennium shims into webkit module... " +
|
|
243
|
+
Logger.Info("Injecting Millennium shims into webkit module... " +
|
|
244
|
+
chalk.green.bold("okay"));
|
|
238
245
|
bundle[fileName].code = ContructFunctions([
|
|
239
246
|
`const pluginName = "${props.strPluginInternalName}";`,
|
|
240
|
-
InitializePlugins.toString(),
|
|
241
|
-
|
|
242
|
-
|
|
247
|
+
InitializePlugins.toString(),
|
|
248
|
+
InitializePlugins.name + "()",
|
|
249
|
+
WrappedCallServerMethod,
|
|
250
|
+
WrappedCallable,
|
|
251
|
+
bundle[fileName].code,
|
|
252
|
+
ExecuteWebkitModule.toString(),
|
|
253
|
+
ExecuteWebkitModule.name + "()",
|
|
243
254
|
]);
|
|
244
255
|
}
|
|
245
256
|
};
|
|
@@ -248,23 +259,25 @@ function InsertWebkitMillennium(props) {
|
|
|
248
259
|
function GetPluginComponents(props) {
|
|
249
260
|
let tsConfigPath = `./${GetFrontEndDirectory()}/tsconfig.json`;
|
|
250
261
|
if (!fs.existsSync(tsConfigPath)) {
|
|
251
|
-
tsConfigPath =
|
|
262
|
+
tsConfigPath = "./tsconfig.json";
|
|
252
263
|
}
|
|
253
264
|
const pluginList = [
|
|
254
265
|
InsertMillennium(props),
|
|
255
266
|
typescript({
|
|
256
|
-
tsconfig: tsConfigPath
|
|
267
|
+
tsconfig: tsConfigPath,
|
|
257
268
|
}),
|
|
258
|
-
resolve(),
|
|
269
|
+
resolve(),
|
|
270
|
+
commonjs(),
|
|
271
|
+
json(),
|
|
259
272
|
injectProcessEnv(envVars),
|
|
260
273
|
replace({
|
|
261
|
-
delimiters: [
|
|
274
|
+
delimiters: ["", ""],
|
|
262
275
|
preventAssignment: true,
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
276
|
+
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
277
|
+
"Millennium.callServerMethod": `__call_server_method__`,
|
|
278
|
+
"client.callable": `__wrapped_callable__`,
|
|
279
|
+
"client.pluginSelf": "window.PLUGIN_LIST[pluginName]",
|
|
280
|
+
"client.Millennium.exposeObj(": "client.Millennium.exposeObj(exports, ",
|
|
268
281
|
}),
|
|
269
282
|
];
|
|
270
283
|
if (props.bTersePlugin) {
|
|
@@ -276,28 +289,31 @@ function GetWebkitPluginComponents(props) {
|
|
|
276
289
|
const pluginList = [
|
|
277
290
|
InsertWebkitMillennium(props),
|
|
278
291
|
typescript({
|
|
279
|
-
tsconfig:
|
|
292
|
+
tsconfig: "./webkit/tsconfig.json",
|
|
280
293
|
}),
|
|
281
|
-
resolve(),
|
|
294
|
+
resolve(),
|
|
295
|
+
commonjs(),
|
|
296
|
+
json(),
|
|
282
297
|
injectProcessEnv(envVars),
|
|
283
298
|
replace({
|
|
284
|
-
delimiters: [
|
|
299
|
+
delimiters: ["", ""],
|
|
285
300
|
preventAssignment: true,
|
|
286
|
-
|
|
287
|
-
|
|
301
|
+
"Millennium.callServerMethod": `__call_server_method__`,
|
|
302
|
+
"webkit.callable": `__wrapped_callable__`,
|
|
288
303
|
}),
|
|
289
304
|
babel({
|
|
290
|
-
presets: [
|
|
291
|
-
babelHelpers:
|
|
292
|
-
})
|
|
305
|
+
presets: ["@babel/preset-env", "@babel/preset-react"],
|
|
306
|
+
babelHelpers: "bundled",
|
|
307
|
+
}),
|
|
293
308
|
];
|
|
294
309
|
props.bTersePlugin && pluginList.push(terser());
|
|
295
310
|
return pluginList;
|
|
296
311
|
}
|
|
297
312
|
const GetFrontEndDirectory = () => {
|
|
298
|
-
const pluginJsonPath =
|
|
313
|
+
const pluginJsonPath = "./plugin.json";
|
|
299
314
|
try {
|
|
300
|
-
return JSON.parse(fs.readFileSync(pluginJsonPath,
|
|
315
|
+
return (JSON.parse(fs.readFileSync(pluginJsonPath, "utf8"))?.frontend ??
|
|
316
|
+
"frontend");
|
|
301
317
|
}
|
|
302
318
|
catch (error) {
|
|
303
319
|
return "frontend";
|
|
@@ -307,25 +323,25 @@ const TranspilerPluginComponent = async (props) => {
|
|
|
307
323
|
const frontendRollupConfig = {
|
|
308
324
|
input: `./${GetFrontEndDirectory()}/index.tsx`,
|
|
309
325
|
plugins: GetPluginComponents(props),
|
|
310
|
-
context:
|
|
326
|
+
context: "window",
|
|
311
327
|
external: (id) => {
|
|
312
|
-
if (id ===
|
|
313
|
-
Logger.Error(
|
|
328
|
+
if (id === "@steambrew/webkit") {
|
|
329
|
+
Logger.Error("The @steambrew/webkit module should not be included in the frontend module, use @steambrew/client instead. Please remove it from the frontend module and try again.");
|
|
314
330
|
process.exit(1);
|
|
315
331
|
}
|
|
316
|
-
return id ===
|
|
332
|
+
return id === "@steambrew/client" || id === "react" || id === "react-dom";
|
|
317
333
|
},
|
|
318
334
|
output: {
|
|
319
335
|
name: "millennium_main",
|
|
320
336
|
file: ".millennium/Dist/index.js",
|
|
321
337
|
globals: {
|
|
322
|
-
|
|
338
|
+
react: "window.SP_REACT",
|
|
323
339
|
"react-dom": "window.SP_REACTDOM",
|
|
324
|
-
"@steambrew/client": "window.MILLENNIUM_API"
|
|
340
|
+
"@steambrew/client": "window.MILLENNIUM_API",
|
|
325
341
|
},
|
|
326
|
-
exports:
|
|
327
|
-
format:
|
|
328
|
-
}
|
|
342
|
+
exports: "named",
|
|
343
|
+
format: "iife",
|
|
344
|
+
},
|
|
329
345
|
};
|
|
330
346
|
Logger.Info("Starting build; this may take a few moments...");
|
|
331
347
|
try {
|
|
@@ -335,30 +351,30 @@ const TranspilerPluginComponent = async (props) => {
|
|
|
335
351
|
const webkitRollupConfig = {
|
|
336
352
|
input: `./webkit/index.tsx`,
|
|
337
353
|
plugins: GetWebkitPluginComponents(props),
|
|
338
|
-
context:
|
|
354
|
+
context: "window",
|
|
339
355
|
external: (id) => {
|
|
340
|
-
if (id ===
|
|
341
|
-
Logger.Error(
|
|
356
|
+
if (id === "@steambrew/client") {
|
|
357
|
+
Logger.Error("The @steambrew/client module should not be included in the webkit module, use @steambrew/webkit instead. Please remove it from the webkit module and try again.");
|
|
342
358
|
process.exit(1);
|
|
343
359
|
}
|
|
344
|
-
return id ===
|
|
360
|
+
return id === "@steambrew/webkit";
|
|
345
361
|
},
|
|
346
362
|
output: {
|
|
347
363
|
name: "millennium_main",
|
|
348
364
|
file: ".millennium/Dist/webkit.js",
|
|
349
|
-
exports:
|
|
350
|
-
format:
|
|
365
|
+
exports: "named",
|
|
366
|
+
format: "iife",
|
|
351
367
|
globals: {
|
|
352
|
-
"@steambrew/webkit": "window.MILLENNIUM_API"
|
|
368
|
+
"@steambrew/webkit": "window.MILLENNIUM_API",
|
|
353
369
|
},
|
|
354
|
-
}
|
|
370
|
+
},
|
|
355
371
|
};
|
|
356
372
|
await (await rollup(webkitRollupConfig)).write(webkitRollupConfig.output);
|
|
357
373
|
}
|
|
358
|
-
Logger.Info(
|
|
374
|
+
Logger.Info("Build succeeded!", Number((performance.now() - global.PerfStartTime).toFixed(3)), "ms elapsed.");
|
|
359
375
|
}
|
|
360
376
|
catch (exception) {
|
|
361
|
-
Logger.Error(
|
|
377
|
+
Logger.Error("Build failed!", exception);
|
|
362
378
|
process.exit(1);
|
|
363
379
|
}
|
|
364
380
|
};
|