|
1 | 1 | import { writeFile } from "botasaurus/output" |
2 | 2 | import { exec } from 'child_process' |
3 | 3 | import * as path from 'path' |
| 4 | +import * as fs from 'fs' |
| 5 | + |
| 6 | +function ensureDllDirExists(): void { |
| 7 | + const dllDir = path.join(__dirname, "../dll/") |
| 8 | + if (!fs.existsSync(dllDir)) { |
| 9 | + fs.mkdirSync(dllDir, { recursive: true }) |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +function getTempPath(): string { |
| 14 | + return path.join(__dirname, "../dll/", "temp.js") |
| 15 | +} |
| 16 | + |
| 17 | + |
4 | 18 |
|
5 | 19 | function runCode(contents) { |
6 | | - writeFile(contents, path.join(__dirname, "../../", "temp.js"), false) |
7 | | - // Execute temp.js using Node.js |
8 | | - exec('node temp.js', (error, stdout, stderr) => { |
| 20 | + ensureDllDirExists() |
| 21 | + writeFile(contents, getTempPath(), false) |
| 22 | + |
| 23 | + exec('node ./.erb/dll/temp.js', (error, stdout, stderr) => { |
9 | 24 | if (error) { |
10 | 25 | console.error(`Error executing temp.js: ${error}`) |
11 | 26 | return |
12 | 27 | } |
13 | 28 | if (stderr) { |
14 | 29 | console.error(`stderr: ${stderr}`) |
| 30 | + process.exit(1) |
15 | 31 | } |
16 | 32 | }) |
17 | 33 | } |
18 | 34 |
|
19 | | -function getAssetNames(assets) { |
20 | | - const ls:any[] = [] |
21 | | - for (const assetName in assets) { |
22 | | - ls.push(assetName) |
23 | | - } |
24 | | - return ls |
25 | | -} |
26 | | - |
27 | | -export class LogContentsPlugin { |
| 35 | +export class GenerateApiPropsPlugin { |
28 | 36 | apply(compiler) { |
29 | | - compiler.hooks.emit.tapAsync('LogContentsPlugin', async (compilation, callback) => { |
| 37 | + compiler.hooks.emit.tapAsync('GenerateApiPropsPlugin', async (compilation, callback) => { |
30 | 38 | const compAssets = compilation.assets |
31 | | - // console.log(getAssetNames(compAssets)) |
32 | 39 | for (const assetName in compAssets) { |
33 | | - const targetFiles = ["main.bundle.dev.js", |
34 | | - // "main.js", |
35 | | - ] |
| 40 | + const targetFiles = ["main.bundle.dev.js"] |
36 | 41 | if (targetFiles.includes( assetName ) ){ |
37 | 42 | const asset = compAssets[assetName] |
38 | 43 | const source:string = asset.source() |
39 | | - // make dev, and also fix resolve errors of bota server |
40 | | - let contents = source.replace("process.env.CREATE_API_CONFIG", "true") |
41 | | - // fix native modules imports |
| 44 | + let contents = source.replace("main() {", "main() {(0,_utils_generate_app_props__WEBPACK_IMPORTED_MODULE_1__.generateAppProps)();return;") |
| 45 | + |
| 46 | + |
| 47 | + // Fixes Input JS and README paths |
| 48 | + contents = contents.replaceAll('if (isElectron) {', 'if (false) {') |
| 49 | + |
| 50 | + // Disable master logging |
| 51 | + contents = contents.replaceAll('static async enableKubernetes({ masterEndpoint, taskTimeout = master_executor_1.DEFAULT_TASK_TIMEOUT }) {', 'static async enableKubernetes({ masterEndpoint, taskTimeout = master_executor_1.DEFAULT_TASK_TIMEOUT }) {return;') |
42 | 52 | contents = contents.replaceAll('factory(require("', 'factory(require("./release/app/node_modules/') |
43 | | - // factory(require(" |
| 53 | + // Sentry FIX |
| 54 | + contents = contents.replace('function __webpack_require__(moduleId) {', 'function __webpack_require__(moduleId) {if (moduleId.includes("sentry")){return {}};') |
44 | 55 | try { |
45 | | - // console.log("Updating index.html") |
46 | 56 | runCode(contents) |
47 | 57 | } catch (error) { |
48 | 58 | console.error(error) |
49 | 59 | } |
50 | 60 | } |
51 | 61 | } |
52 | | - // console.log(JSON.stringify(ls)) |
53 | 62 | callback() |
54 | 63 | }) |
55 | 64 | } |
|
0 commit comments