feat: 破坏性更新 cjs to es

This commit is contained in:
手瓜一十雪 2024-05-22 19:58:45 +08:00
parent 08976624cd
commit 4e0cdbcb91
17 changed files with 75 additions and 13 deletions

View File

@ -15,4 +15,4 @@ for %%a in ("!RetString!") do (
set "QQPath=!pathWithoutUninstall!QQ.exe"
set ELECTRON_RUN_AS_NODE=1
echo !QQPath!
"!QQPath!" ./napcat.cjs %*
"!QQPath!" ./napcat.mjs %*

View File

@ -37,7 +37,7 @@ if (!(Test-Path $QQpath)) {
throw "provided QQ path is invalid: $QQpath"
}
$Bootfile = Join-Path $PSScriptRoot "napcat.cjs"
$Bootfile = Join-Path $PSScriptRoot "napcat.mjs"
$env:ELECTRON_RUN_AS_NODE = 1
$commandInfo = Get-Command $QQpath -ErrorAction Stop
Start-Process powershell -ArgumentList "-noexit", "-noprofile", "-command &{& chcp 65001;& '$($commandInfo.Path)' $Bootfile $params}"

View File

@ -14,4 +14,4 @@ for %%a in ("!RetString!") do (
set "QQPath=!pathWithoutUninstall!QQ.exe"
set ELECTRON_RUN_AS_NODE=1
echo !QQPath!
"!QQPath!" ./napcat.cjs %*
"!QQPath!" ./napcat.mjs %*

View File

@ -37,7 +37,7 @@ if (!(Test-Path $QQpath)) {
throw "provided QQ path is invalid: $QQpath"
}
$Bootfile = Join-Path $PSScriptRoot "napcat.cjs"
$Bootfile = Join-Path $PSScriptRoot "napcat.mjs"
$env:ELECTRON_RUN_AS_NODE = 1
$commandInfo = Get-Command $QQpath -ErrorAction Stop
Start-Process powershell -ArgumentList "-noexit", "-noprofile", "-command &{& '$($commandInfo.Path)' $Bootfile $params}"

View File

@ -18,4 +18,4 @@ if ! [ -x /opt/QQ/qq ]; then
exit 1
fi
/opt/QQ/qq "${SCRIPT_DIR}/napcat.cjs" "$@"
/opt/QQ/qq "${SCRIPT_DIR}/napcat.mjs" "$@"

View File

@ -1,6 +1,12 @@
import path from 'node:path';
import fs from 'node:fs';
import { log, logDebug, logError } from '@/common/utils/log';
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const configDir = path.resolve(__dirname, 'config');
fs.mkdirSync(configDir, { recursive: true });

View File

@ -55,7 +55,7 @@ if (fs.existsSync(configVersionInfoPath)) {
export const qqVersionConfigInfo: QQVersionConfigInfo = _qqVersionConfigInfo;
export const qqPkgInfo: QQPkgInfo = require(pkgInfoPath);
export const qqPkgInfo: QQPkgInfo = JSON.parse(fs.readFileSync(pkgInfoPath).toString());
// platform_type: 3,
// app_type: 4,
// app_version: '9.9.9-23159',

View File

@ -1,7 +1,12 @@
import * as os from 'os';
import path from 'node:path';
import fs from 'fs';
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export function getModuleWithArchName(moduleName: string) {
const systemPlatform = os.platform();
const cpuArch = os.arch();

View File

@ -2,6 +2,12 @@ import crypto from 'node:crypto';
import path from 'node:path';
import fs from 'fs/promises';
import { log, logDebug } from './log';
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export function sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}

View File

@ -2,6 +2,12 @@ import log4js, { Configuration } from 'log4js';
import { truncateString } from '@/common/utils/helper';
import path from 'node:path';
import { SelfInfo } from '@/core';
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export enum LogLevel {
DEBUG = 'debug',

View File

@ -1,6 +1,13 @@
import { resolve } from "node:path";
import { spawn } from "node:child_process";
import { pid, ppid, exit } from 'node:process';
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export async function rebootWithQuickLogin(uin: string) {
let batScript = resolve(__dirname, './napcat.bat');
let batUtf8Script = resolve(__dirname, './napcat-utf8.bat');

View File

@ -2,6 +2,7 @@ import { napCatCore } from '@/core';
import { program } from 'commander';
import qrcode from 'qrcode-terminal';
import fs from 'fs/promises';
import fsSync from 'fs';
import path from 'node:path';
import { checkVersion } from '@/common/utils/version';
import { log, logDebug, logError, LogLevel, setLogLevel } from '@/common/utils/log';
@ -9,6 +10,13 @@ import { NapCatOnebot11 } from '@/onebot11/main';
import { InitWebUi } from './webui/index';
import { WebUiDataRuntime } from './webui/src/helper/Data';
import { UpdateConfig } from './common/utils/helper';
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
program
.option('-q, --qq <type>', 'QQ号')
.parse(process.argv);
@ -19,10 +27,8 @@ UpdateConfig().catch(logError);
InitWebUi();
const cmdOptions = program.opts();
// console.log(process.argv);
checkVersion().then((remoteVersion: string) => {
const localVersion = require('./package.json').version;
checkVersion().then(async (remoteVersion: string) => {
const localVersion = JSON.parse(fsSync.readFileSync(path.join(__dirname, 'package.json')).toString());
const localVersionList = localVersion.split('.');
const remoteVersionList = remoteVersion.split('.');
log('[NapCat] 当前版本:', localVersion);

View File

@ -5,6 +5,13 @@ import { resolve } from 'node:path';
import { ALLRouter } from './src/router';
import { WebUiConfig } from './src/helper/config';
const app = express();
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
/**
* WebUI服务
* Express服务器以支持JSON解析和静态文件服务6099

View File

@ -2,6 +2,12 @@ import { RequestHandler } from "express";
import { resolve } from "path";
import { readdir, stat } from "fs/promises";
import { existsSync } from "fs";
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export const GetLogFileListHandler: RequestHandler = async (req, res) => {
try {
let LogsPath = resolve(__dirname, "./logs/");

View File

@ -3,6 +3,13 @@ import { WebUiDataRuntime } from "../helper/Data";
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
import { OB11Config } from "@/webui/ui/components/WebUiApiOB11Config";
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const isEmpty = (data: any) =>
data === undefined || data === null || data === "";
export const OB11GetConfigHandler: RequestHandler = async (req, res) => {

View File

@ -1,6 +1,12 @@
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
const net = require('net');
import * as net from "node:net";
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// 限制尝试端口的次数,避免死循环
const MAX_PORT_TRY = 100;

View File

@ -83,8 +83,8 @@ const baseConfig = (mode: string = 'development') => defineConfig({
minify: false,
lib: {
entry: 'src/index.ts',
formats: ['cjs'],
fileName: () => 'napcat.cjs',
formats: ['es'],
fileName: () => 'napcat.mjs',
},
rollupOptions: {
// external: [ /node:*/ ],