diff --git a/bin/README.md b/bin/README.md index 39c70be..8d4f99d 100644 --- a/bin/README.md +++ b/bin/README.md @@ -119,4 +119,13 @@ url 为你需要打包的网页链接 🔗或者本地html文件,必须提供 ```shell --system-tray-icon +``` + + +#### [copy-iter-file] + +递归拷贝,当url为本地文件路径时候,若开启该选项,则将url路径文件所在文件夹以及所有子文件都拷贝到pake静态文件夹,默认不开启 + +```shell +--copy-iter-file ``` \ No newline at end of file diff --git a/bin/README_EN.md b/bin/README_EN.md index 331065a..27d5321 100644 --- a/bin/README_EN.md +++ b/bin/README_EN.md @@ -119,3 +119,12 @@ The notification tray icon is only valid when the notification tray is displayed ```shell --system-tray-icon ``` + + +#### [copy-iter-file] + +Recursive copy, when the url is a local file path, if this option is enabled, the folder where the url path file is located and all sub-files are copied to the pake static folder, which is not enabled by default + +```shell +--copy-iter-file +``` diff --git a/bin/builders/common.ts b/bin/builders/common.ts index 5baebd1..bfe58fb 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -2,9 +2,11 @@ import { PakeAppOptions } from '@/types.js'; import prompts from 'prompts'; import path from 'path'; import fs from 'fs/promises'; +import fs2 from 'fs-extra'; import { npmDirectory } from '@/utils/dir.js'; import logger from '@/options/logger.js'; + export async function promptText(message: string, initial?: string) { const response = await prompts({ type: 'text', @@ -31,7 +33,7 @@ export async function mergeTauriConfig( showMenu, showSystemTray, systemTrayIcon, - // iter_copy_file, + iterCopyFile, identifier, name, } = options; @@ -65,16 +67,8 @@ export async function mergeTauriConfig( // logger.warn(JSON.stringify(tauriConf.pake.windows, null, 4)); Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); // 判断一下url类型,是文件还是网站 - // 如果是文件,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下(待做) + // 如果是文件,并且开启了递归拷贝功能,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下,否则只拷贝单个文件。 - // const src_exists = await fs.stat("src") - // .then(() => true) - // .catch(() => false); - // if (!src_exists) { - // fs.mkdir("src") - // } else { - // fs.rm - // } const url_exists = await fs.stat(url) .then(() => true) .catch(() => false); @@ -82,9 +76,23 @@ export async function mergeTauriConfig( logger.warn("you input may a local file"); tauriConf.pake.windows[0].url_type = "local"; const file_name = path.basename(url); - // const dir_name = path.dirname(url); - const url_path = path.join(npmDirectory,"dist/", file_name); - await fs.copyFile(url, url_path); + const dir_name = path.dirname(url); + if (!iterCopyFile) { + const url_path = path.join(npmDirectory,"dist/", file_name); + await fs.copyFile(url, url_path); + } else { + const old_dir = path.join(npmDirectory,"dist/"); + const new_dir = path.join(npmDirectory,"dist_bak/"); + fs.rename(old_dir, new_dir); + fs2.copy(dir_name, old_dir); + // 将dist_bak里面的cli.js和about_pake.html拷贝回去 + const cli_path = path.join(new_dir, "cli.js") + const cli_path_target = path.join(old_dir, "cli.js") + const about_pake_path = path.join(new_dir, "about_pake.html"); + const about_patk_path_target = path.join(new_dir, "about_pake.html") + fs.copyFile(cli_path, cli_path_target); + fs.copyFile(about_pake_path, about_patk_path_target); + } tauriConf.pake.windows[0].url = file_name; tauriConf.pake.windows[0].url_type = "local"; } else { diff --git a/bin/cli.ts b/bin/cli.ts index c50f9fa..294a06b 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -27,13 +27,13 @@ program .option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu) .option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray) .option('--system-tray-icon ', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon) + .option('--iter-copy-file', + 'copy all static file to pake app when url is a local file', + DEFAULT_PAKE_OPTIONS.iterCopyFile) .option( '--targets ', 'only for linux, default is "deb", option "appaimge" or "all"(deb & appimage)', DEFAULT_PAKE_OPTIONS.targets) - // .option('--iter-copy-file', - // 'copy all static file to pake app when url is a static file', - // DEFAULT_PAKE_OPTIONS.iter_copy_file) .option('--debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent) .action(async (url: string, options: PakeCliOptions) => { checkUpdateTips(); diff --git a/bin/defaults.ts b/bin/defaults.ts index 50516eb..4200bb4 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -11,7 +11,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { showMenu: false, showSystemTray: false, targets: 'deb', - // iter_copy_file: false, + iterCopyFile: false, systemTrayIcon: '', debug: false, }; diff --git a/bin/types.ts b/bin/types.ts index 6725079..dbb9672 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -32,8 +32,9 @@ export interface PakeCliOptions { /** 托盘图标, Windows、Linux默认和应用图标共用一样的,MacOS需要提别提供, 格式为png或者ico */ systemTrayIcon: string; - // /** 递归拷贝,当url为本地文件路径时候,将文件所在文件夹下面的所有子文件都拷贝到pake静态文件夹,默认不开启 */ - // iter_copy_file: false; + // /** 递归拷贝,当url为本地文件路径时候,若开启该选项,则将url路径文件所在文件夹以及所有子文件都拷贝到pake静态文件夹,默认不开启 */ + iterCopyFile: false; + // 包输出产物,对linux用户有效,默认为deb,可选appimage, 或者all(即同时输出deb和all); targets: string; diff --git a/dist/cli.js b/dist/cli.js index 2754600..c003df5 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -7,6 +7,7 @@ import fs from 'fs'; import prompts from 'prompts'; import path from 'path'; import fs$1 from 'fs/promises'; +import fs2 from 'fs-extra'; import chalk from 'chalk'; import crypto from 'crypto'; import axios from 'axios'; @@ -52,7 +53,7 @@ const DEFAULT_PAKE_OPTIONS = { showMenu: false, showSystemTray: false, targets: 'deb', - // iter_copy_file: false, + iterCopyFile: false, systemTrayIcon: '', debug: false, }; @@ -1636,9 +1637,7 @@ function promptText(message, initial) { } function mergeTauriConfig(url, options, tauriConf) { return __awaiter(this, void 0, void 0, function* () { - const { width, height, fullscreen, transparent, resizable, userAgent, showMenu, showSystemTray, systemTrayIcon, - // iter_copy_file, - identifier, name, } = options; + const { width, height, fullscreen, transparent, resizable, userAgent, showMenu, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, } = options; const tauriConfWindowOptions = { width, height, @@ -1668,14 +1667,6 @@ function mergeTauriConfig(url, options, tauriConf) { Object.assign(tauriConf.pake.windows[0], Object.assign({ url }, tauriConfWindowOptions)); // 判断一下url类型,是文件还是网站 // 如果是文件,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下(待做) - // const src_exists = await fs.stat("src") - // .then(() => true) - // .catch(() => false); - // if (!src_exists) { - // fs.mkdir("src") - // } else { - // fs.rm - // } const url_exists = yield fs$1.stat(url) .then(() => true) .catch(() => false); @@ -1683,9 +1674,24 @@ function mergeTauriConfig(url, options, tauriConf) { logger.warn("you input may a local file"); tauriConf.pake.windows[0].url_type = "local"; const file_name = path.basename(url); - // const dir_name = path.dirname(url); - const url_path = path.join(npmDirectory, "dist/", file_name); - yield fs$1.copyFile(url, url_path); + const dir_name = path.dirname(url); + if (!iterCopyFile) { + const url_path = path.join(npmDirectory, "dist/", file_name); + yield fs$1.copyFile(url, url_path); + } + else { + const old_dir = path.join(npmDirectory, "dist/"); + const new_dir = path.join(npmDirectory, "dist_bak/"); + fs$1.rename(old_dir, new_dir); + fs2.copy(dir_name, old_dir); + // 将dist_bak里面的cli.js和about_pake.html拷贝回去 + const cli_path = path.join(new_dir, "cli.js"); + const cli_path_target = path.join(old_dir, "cli.js"); + const about_pake_path = path.join(new_dir, "about_pake.html"); + const about_patk_path_target = path.join(new_dir, "about_pake.html"); + fs$1.copyFile(cli_path, cli_path_target); + fs$1.copyFile(about_pake_path, about_patk_path_target); + } tauriConf.pake.windows[0].url = file_name; tauriConf.pake.windows[0].url_type = "local"; } @@ -2454,6 +2460,7 @@ var dependencies = { chalk: "^5.1.2", commander: "^9.4.1", "file-type": "^18.0.0", + "fs-extra": "^11.1.0", "is-url": "^1.2.4", loglevel: "^1.8.1", ora: "^6.1.2", @@ -2468,6 +2475,7 @@ var devDependencies = { "@rollup/plugin-json": "^5.0.1", "@rollup/plugin-terser": "^0.1.0", "@rollup/plugin-typescript": "^9.0.2", + "@types/fs-extra": "^9.0.13", "@types/is-url": "^1.2.30", "@types/page-icon": "^0.3.4", "@types/prompts": "^2.4.1", @@ -2520,10 +2528,8 @@ program .option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu) .option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray) .option('--system-tray-icon ', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon) + .option('--iter-copy-file', 'copy all static file to pake app when url is a local file', DEFAULT_PAKE_OPTIONS.iterCopyFile) .option('--targets ', 'only for linux, default is "deb", option "appaimge" or "all"(deb & appimage)', DEFAULT_PAKE_OPTIONS.targets) - // .option('--iter-copy-file', - // 'copy all static file to pake app when url is a static file', - // DEFAULT_PAKE_OPTIONS.iter_copy_file) .option('--debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent) .action((url, options) => __awaiter(void 0, void 0, void 0, function* () { checkUpdateTips(); diff --git a/dist/index.html b/dist/index.html deleted file mode 100644 index 8a32f1a..0000000 --- a/dist/index.html +++ /dev/null @@ -1,559 +0,0 @@ -AriaNg \ No newline at end of file diff --git a/package.json b/package.json index 0edaf8d..30fc33d 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "chalk": "^5.1.2", "commander": "^9.4.1", "file-type": "^18.0.0", + "fs-extra": "^11.1.0", "is-url": "^1.2.4", "loglevel": "^1.8.1", "ora": "^6.1.2", @@ -66,6 +67,7 @@ "@rollup/plugin-json": "^5.0.1", "@rollup/plugin-terser": "^0.1.0", "@rollup/plugin-typescript": "^9.0.2", + "@types/fs-extra": "^9.0.13", "@types/is-url": "^1.2.30", "@types/page-icon": "^0.3.4", "@types/prompts": "^2.4.1",