|
@@ -1,6 +1,6 @@
|
|
|
//plugins\buildPlugin.ts
|
|
|
import path from "path";
|
|
|
-import fs from "fs";
|
|
|
+import fs from "fs-extra";
|
|
|
|
|
|
class BuildObj {
|
|
|
//编译主进程代码
|
|
@@ -11,9 +11,55 @@ class BuildObj {
|
|
|
platform: "node",
|
|
|
minify: true,
|
|
|
outfile: "./dist/mainEntry.js",
|
|
|
- external: ["electron"],
|
|
|
+ external: ["electron", "pg", "tedious", "mysql", "mysql2", "oracledb", "pg-query-stream", "sqlite3"],
|
|
|
});
|
|
|
}
|
|
|
+ async prepareSqlite() {
|
|
|
+ //拷贝better-sqlite3
|
|
|
+ let srcDir = path.join(process.cwd(), `node_modules/better-sqlite3`);
|
|
|
+ let destDir = path.join(process.cwd(), `dist/node_modules/better-sqlite3`);
|
|
|
+ fs.ensureDirSync(destDir);
|
|
|
+ fs.copySync(srcDir, destDir, {
|
|
|
+ filter: (src) => {
|
|
|
+ if (src.endsWith("better-sqlite3") || src.endsWith("build") || src.endsWith("Release") || src.endsWith("better_sqlite3.node")) return true;
|
|
|
+ else if (src.includes("node_modules\\better-sqlite3\\lib")) return true;
|
|
|
+ else return false;
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ let pkgJson = `{"name": "better-sqlite3","main": "lib/index.js"}`;
|
|
|
+ let pkgJsonPath = path.join(process.cwd(), `dist/node_modules/better-sqlite3/package.json`);
|
|
|
+ fs.writeFileSync(pkgJsonPath, pkgJson);
|
|
|
+ //制作bindings模块
|
|
|
+ let bindingPath = path.join(process.cwd(), `dist/node_modules/bindings/index.js`);
|
|
|
+ fs.ensureFileSync(bindingPath);
|
|
|
+ let bindingsContent = `module.exports = () => {
|
|
|
+ let addonPath = require("path").join(__dirname, '../better-sqlite3/build/Release/better_sqlite3.node');
|
|
|
+ return require(addonPath);
|
|
|
+ };`;
|
|
|
+ fs.writeFileSync(bindingPath, bindingsContent);
|
|
|
+
|
|
|
+ pkgJson = `{"name": "bindings","main": "index.js"}`;
|
|
|
+ pkgJsonPath = path.join(process.cwd(), `dist/node_modules/bindings/package.json`);
|
|
|
+ fs.writeFileSync(pkgJsonPath, pkgJson);
|
|
|
+ }
|
|
|
+ prepareKnexjs() {
|
|
|
+ let pkgJsonPath = path.join(process.cwd(), `dist/node_modules/knex`);
|
|
|
+ fs.ensureDirSync(pkgJsonPath);
|
|
|
+ require("esbuild").buildSync({
|
|
|
+ entryPoints: ["./node_modules/knex/knex.js"],
|
|
|
+ bundle: true,
|
|
|
+ platform: "node",
|
|
|
+ format: "cjs",
|
|
|
+ minify: true,
|
|
|
+ outfile: "./dist/node_modules/knex/index.js",
|
|
|
+ external: ["oracledb", "pg-query-stream", "pg", "sqlite3", "tedious", "mysql", "mysql2", "better-sqlite3"],
|
|
|
+ });
|
|
|
+ let pkgJson = `{"name": "bindings","main": "index.js"}`;
|
|
|
+ pkgJsonPath = path.join(process.cwd(), `dist/node_modules/knex/package.json`);
|
|
|
+ fs.writeFileSync(pkgJsonPath, pkgJson);
|
|
|
+ }
|
|
|
+
|
|
|
//为生产环境准备package.json
|
|
|
preparePackageJson() {
|
|
|
let pkgJsonPath = path.join(process.cwd(), "package.json");
|
|
@@ -49,6 +95,7 @@ class BuildObj {
|
|
|
shortcutName: "fc-ele",
|
|
|
},
|
|
|
publish: [{ provider: "generic", url: "http://localhost:5500/" }],
|
|
|
+ extraResources: [{ from: `./db.db`, to: `./` }],
|
|
|
},
|
|
|
project: process.cwd(),
|
|
|
};
|
|
@@ -61,9 +108,13 @@ export let buildPlugin = () => {
|
|
|
name: "build-plugin",
|
|
|
closeBundle: () => {
|
|
|
let buildObj = new BuildObj();
|
|
|
+ buildObj.prepareSqlite();
|
|
|
buildObj.buildMain();
|
|
|
buildObj.preparePackageJson();
|
|
|
buildObj.buildInstaller();
|
|
|
+ buildObj.prepareKnexjs();
|
|
|
+
|
|
|
},
|
|
|
+
|
|
|
};
|
|
|
};
|