feat:windows打包
This commit is contained in:
parent
0b87ecae94
commit
f04d3bf636
11
electron/build.sh
Normal file
11
electron/build.sh
Normal file
@ -0,0 +1,11 @@
|
||||
cd ../openRenamerFront
|
||||
yarn
|
||||
npm run build
|
||||
cd ../openRenamerBackend
|
||||
yarn
|
||||
tsc
|
||||
rm -rf ./static/js
|
||||
rm -rf ./static/css
|
||||
cp -r ../openRenamerFront/dist/* ./static
|
||||
cd ../electron
|
||||
npm run build
|
@ -4,6 +4,7 @@ const {app, BrowserWindow, Menu} = require('electron')
|
||||
const path = require('path')
|
||||
const {spawn} = require('child_process');
|
||||
const net = require('net');
|
||||
const log = require('electron-log');
|
||||
|
||||
async function createWindow() {
|
||||
// 隐藏菜单栏
|
||||
@ -22,7 +23,7 @@ async function createWindow() {
|
||||
// 下面这两行代码配合上面 new BrowserWindow 里面的 show: false,可以实现打开时窗口最大化
|
||||
win.maximize()
|
||||
win.show()
|
||||
console.log(__dirname);
|
||||
log.info(__dirname);
|
||||
let port = await startBackend()
|
||||
// 并且为你的应用加载index.html
|
||||
// win.loadFile('./dist/index.html')
|
||||
@ -62,18 +63,25 @@ async function startBackend() {
|
||||
}
|
||||
port = port + 1;
|
||||
}
|
||||
const childProcess = spawn('node', ['openRenamerBackend/dist/index.js'], {env: {"PORT": port}});
|
||||
let userHome = process.env.HOME || process.env.USERPROFILE;
|
||||
let dataPath = path.join(userHome, "openRenamer");
|
||||
const childProcess = spawn('node', ['openRenamerBackend/dist/index.js'], {
|
||||
env: {
|
||||
"PORT": port,
|
||||
"DATA_PATH": dataPath
|
||||
}
|
||||
});
|
||||
|
||||
childProcess.stdout.on('data', (data) => {
|
||||
console.log(`stdout: ${data}`);
|
||||
log.info(`stdout: ${data}`);
|
||||
});
|
||||
|
||||
childProcess.stderr.on('data', (data) => {
|
||||
console.error(`stderr: ${data}`);
|
||||
log.error(`stderr: ${data}`);
|
||||
});
|
||||
|
||||
childProcess.on('close', (code) => {
|
||||
console.log(`child process exited with code ${code}`);
|
||||
log.info(`child process exited with code ${code}`);
|
||||
});
|
||||
return port;
|
||||
}
|
||||
|
@ -20,7 +20,17 @@
|
||||
"directories": {
|
||||
"output": "build"
|
||||
},
|
||||
"copyright": "xxxx",
|
||||
"files": [
|
||||
"main.js",
|
||||
"preload.js"
|
||||
],
|
||||
"extraFiles": [
|
||||
{
|
||||
"from": "../openRenamerBackend",
|
||||
"to": "openRenamerBackend"
|
||||
}
|
||||
],
|
||||
"copyright": "open-renamer",
|
||||
"nsis": {
|
||||
"oneClick": false,
|
||||
"allowElevation": true,
|
||||
@ -33,7 +43,6 @@
|
||||
"shortcutName": "openRenamer"
|
||||
},
|
||||
"win": {
|
||||
"icon": "./openRenamerBackend/static/favicon.ico",
|
||||
"target": [
|
||||
"nsis",
|
||||
"zip"
|
||||
@ -48,5 +57,8 @@
|
||||
"linux": {
|
||||
"icon": "build/icons"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"electron-log": "^5.0.1"
|
||||
}
|
||||
}
|
||||
|
1615
electron/pnpm-lock.yaml
generated
Normal file
1615
electron/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,12 @@
|
||||
import * as path from 'path';
|
||||
import * as process from "process";
|
||||
|
||||
//后台所在绝对路径
|
||||
const rootPath = path.resolve(__dirname, '..');
|
||||
|
||||
let config = {
|
||||
rootPath,
|
||||
dataPath: process.env.DATA_PATH ? process.env.DATA_PATH : path.join(rootPath, 'data'),
|
||||
port: process.env.PORT ? parseInt(process.env.PORT) : 8089,
|
||||
token: process.env.TOKEN ? process.env.TOKEN : null,
|
||||
urlPrefix: '/openRenamer/api',
|
||||
|
@ -21,10 +21,8 @@
|
||||
"koa2-cors": "2.0.6",
|
||||
"log4js": "6.3.0",
|
||||
"moment": "2.22.2",
|
||||
"mysql2": "2.2.5",
|
||||
"sqlite": "4.0.23",
|
||||
"sqlite3": "5.0.2",
|
||||
"uuid": "3.3.2",
|
||||
"winston": "3.1.0"
|
||||
"uuid": "3.3.2"
|
||||
}
|
||||
}
|
||||
|
@ -1,108 +0,0 @@
|
||||
import mysql from "mysql2/promise";
|
||||
import config from '../config';
|
||||
import * as fs from "fs-extra";
|
||||
import * as path from 'path';
|
||||
import log from '../util/LogUtil';
|
||||
|
||||
const HISTORY_NAME = "history.json";
|
||||
|
||||
interface Res {
|
||||
rows: any;
|
||||
fields: mysql.FieldPacket;
|
||||
}
|
||||
|
||||
class MysqlUtil {
|
||||
public static pool: mysql.Pool = null;
|
||||
|
||||
static async createPool(mysqlConfig: any) {
|
||||
MysqlUtil.pool = await mysql.createPool(mysqlConfig);
|
||||
let basePath = path.join(config.rootPath, "sqls");
|
||||
let hisPath = path.join(basePath, HISTORY_NAME);
|
||||
let history: Array<string>;
|
||||
if (fs.existsSync(hisPath)) {
|
||||
history = JSON.parse(await fs.readFile(hisPath, "utf-8"));
|
||||
} else {
|
||||
history = new Array();
|
||||
}
|
||||
//执行数据库
|
||||
let files = (await fs.readdir(basePath)).sort((a, b) => a.localeCompare(b)).filter(item => !(item === HISTORY_NAME));
|
||||
let error = null;
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
if (history.indexOf(files[i]) > -1) {
|
||||
log.info("sql无需重复执行:", files[i]);
|
||||
continue;
|
||||
}
|
||||
let sqlLines = (await fs.readFile(path.join(basePath, files[i]), 'utf-8')).split(/[\r\n]/g);
|
||||
try {
|
||||
let sql = "";
|
||||
for (let j = 0; j < sqlLines.length; j++) {
|
||||
sql = sql + sqlLines[j];
|
||||
if (sqlLines[j].endsWith(";")) {
|
||||
await MysqlUtil.pool.execute(sql);
|
||||
sql = "";
|
||||
}
|
||||
}
|
||||
log.info("sql执行成功:", files[i]);
|
||||
history.push(files[i]);
|
||||
} catch (err) {
|
||||
error = err;
|
||||
break;
|
||||
}
|
||||
}
|
||||
await fs.writeFile(hisPath, JSON.stringify(history));
|
||||
if (error != null) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
static async getRows(sql: string, params: Array<any>, connection: mysql.PoolConnection = null): Promise<Array<any>> {
|
||||
return (await MysqlUtil.execute(sql, params, connection)).rows;
|
||||
}
|
||||
|
||||
|
||||
static async getRow(sql: string, params: Array<any>, connection: mysql.PoolConnection = null): Promise<any> {
|
||||
let rows = (await MysqlUtil.execute(sql, params, connection)).rows;
|
||||
return rows.length > 0 ? rows[0] : null;
|
||||
}
|
||||
|
||||
static async getSingle(sql: string, params: Array<any>, connection: mysql.PoolConnection = null): Promise<any> {
|
||||
let rows = (await MysqlUtil.execute(sql, params, connection)).rows;
|
||||
if (rows.length == 0) {
|
||||
return null;
|
||||
}
|
||||
let row = rows[0];
|
||||
return row[Object.keys(row)[0]];
|
||||
}
|
||||
|
||||
|
||||
|
||||
static async execute(sql: string, params: Array<any>, connection: mysql.PoolConnection = null): Promise<Res> {
|
||||
let res: any = {};
|
||||
if (connection == null) {
|
||||
let [rows, fields] = await MysqlUtil.pool.query(sql, params);
|
||||
res['rows'] = fields === undefined ? null : rows;
|
||||
res['fields'] = fields === undefined ? rows : fields;
|
||||
} else {
|
||||
let [rows, fields] = await connection.query(sql, params);
|
||||
res['rows'] = rows;
|
||||
res['fields'] = fields;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static async test() {
|
||||
let connection = await MysqlUtil.pool.getConnection();
|
||||
connection.beginTransaction();
|
||||
connection.query(`insert into url value(6,"GET","asd","public")`);
|
||||
connection.query(`insert into url value(7,"GET","asd","public")`);
|
||||
await connection.commit();
|
||||
connection.release();
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
MysqlUtil,
|
||||
Res,
|
||||
mysql
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import sqlite3 from 'sqlite3';
|
||||
import { open, Database } from 'sqlite';
|
||||
import {open, Database} from 'sqlite';
|
||||
import config from '../config';
|
||||
import * as fs from "fs-extra";
|
||||
import * as path from 'path';
|
||||
@ -12,9 +12,9 @@ class SqliteHelper {
|
||||
public static pool: Database = null;
|
||||
|
||||
static async createPool() {
|
||||
let dataFolder = path.join(config.rootPath, "data");
|
||||
let dataFolder = config.dataPath;
|
||||
if (!fs.existsSync(dataFolder)) {
|
||||
fs.mkdir(dataFolder);
|
||||
await fs.mkdir(dataFolder);
|
||||
}
|
||||
SqliteHelper.pool = await open({
|
||||
filename: path.join(dataFolder, "database.db"),
|
||||
@ -26,7 +26,7 @@ class SqliteHelper {
|
||||
if (fs.existsSync(hisPath)) {
|
||||
history = JSON.parse(await fs.readFile(hisPath, "utf-8"));
|
||||
} else {
|
||||
history = new Array();
|
||||
history = [];
|
||||
}
|
||||
//执行数据库
|
||||
let files = (await fs.readdir(basePath)).sort((a, b) => a.localeCompare(b)).filter(item => !(item === HISTORY_NAME));
|
||||
|
Loading…
x
Reference in New Issue
Block a user