update: 完善开发模式
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -37,3 +37,4 @@ dist
|
|||||||
src-tauri/.cargo/config
|
src-tauri/.cargo/config
|
||||||
src-tauri/.cargo/
|
src-tauri/.cargo/
|
||||||
.next
|
.next
|
||||||
|
src-tauri/.pake/
|
||||||
22
bin/helpers/merge.ts
vendored
22
bin/helpers/merge.ts
vendored
@@ -5,6 +5,7 @@ import { npmDirectory } from '@/utils/dir';
|
|||||||
import combineFiles from '@/utils/combine';
|
import combineFiles from '@/utils/combine';
|
||||||
import logger from '@/options/logger';
|
import logger from '@/options/logger';
|
||||||
import { PakeAppOptions, PlatformMap } from '@/types';
|
import { PakeAppOptions, PlatformMap } from '@/types';
|
||||||
|
import { tauriConfigDirectory } from '../utils/dir';
|
||||||
|
|
||||||
export async function mergeConfig(url: string, options: PakeAppOptions, tauriConf: any) {
|
export async function mergeConfig(url: string, options: PakeAppOptions, tauriConf: any) {
|
||||||
const {
|
const {
|
||||||
@@ -200,20 +201,23 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
|||||||
|
|
||||||
// Save config file.
|
// Save config file.
|
||||||
const platformConfigPaths: PlatformMap = {
|
const platformConfigPaths: PlatformMap = {
|
||||||
win32: 'src-tauri/tauri.windows.conf.json',
|
win32: 'tauri.windows.conf.json',
|
||||||
darwin: 'src-tauri/tauri.macos.conf.json',
|
darwin: 'tauri.macos.conf.json',
|
||||||
linux: 'src-tauri/tauri.linux.conf.json',
|
linux: 'tauri.linux.conf.json',
|
||||||
};
|
};
|
||||||
const configPath = path.join(npmDirectory, platformConfigPaths[platform]);
|
const configPath = path.join(tauriConfigDirectory, platformConfigPaths[platform]);
|
||||||
|
|
||||||
const bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
|
const bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
|
||||||
await fsExtra.writeJson(configPath, bundleConf, { spaces: 4 });
|
await fsExtra.outputJSON(configPath, bundleConf, { spaces: 4 });
|
||||||
const pakeConfigPath = path.join(npmDirectory, 'src-tauri/pake.json');
|
const pakeConfigPath = path.join(tauriConfigDirectory, 'pake.json');
|
||||||
await fsExtra.writeJson(pakeConfigPath, tauriConf.pake, { spaces: 4 });
|
await fsExtra.outputJSON(pakeConfigPath, tauriConf.pake, { spaces: 4 });
|
||||||
|
|
||||||
let tauriConf2 = JSON.parse(JSON.stringify(tauriConf));
|
let tauriConf2 = JSON.parse(JSON.stringify(tauriConf));
|
||||||
delete tauriConf2.pake;
|
delete tauriConf2.pake;
|
||||||
delete tauriConf2.tauri.bundle;
|
delete tauriConf2.tauri.bundle;
|
||||||
const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json');
|
if (process.env.NODE_ENV === 'development') {
|
||||||
await fsExtra.writeJson(configJsonPath, tauriConf2, { spaces: 4 });
|
tauriConf2.tauri.bundle = bundleConf.tauri.bundle;
|
||||||
|
}
|
||||||
|
const configJsonPath = path.join(tauriConfigDirectory, 'tauri.conf.json');
|
||||||
|
await fsExtra.outputJSON(configJsonPath, tauriConf2, { spaces: 4 });
|
||||||
}
|
}
|
||||||
|
|||||||
4
bin/utils/dir.ts
vendored
4
bin/utils/dir.ts
vendored
@@ -5,4 +5,6 @@ import { fileURLToPath } from 'url';
|
|||||||
const currentModulePath = fileURLToPath(import.meta.url);
|
const currentModulePath = fileURLToPath(import.meta.url);
|
||||||
|
|
||||||
// Resolve the parent directory of the current module
|
// Resolve the parent directory of the current module
|
||||||
export const npmDirectory = process.env.DEV === 'true' ? process.cwd() : path.join(path.dirname(currentModulePath), '..');
|
export const npmDirectory = path.join(path.dirname(currentModulePath), '..');
|
||||||
|
|
||||||
|
export const tauriConfigDirectory = process.env.NODE_ENV === 'development' ? path.join(npmDirectory, 'src-tauri', '.pake') : path.join(npmDirectory, 'src-tauri');
|
||||||
24
dist/cli.js
vendored
24
dist/cli.js
vendored
@@ -60,7 +60,7 @@ var scripts = {
|
|||||||
analyze: "cd src-tauri && cargo bloat --release --crates",
|
analyze: "cd src-tauri && cargo bloat --release --crates",
|
||||||
tauri: "tauri",
|
tauri: "tauri",
|
||||||
cli: "rollup -c rollup.config.js --watch",
|
cli: "rollup -c rollup.config.js --watch",
|
||||||
"cli:dev": "cross-env DEV=true tsx watch ./bin/dev.ts & npm run dev",
|
"cli:dev": "cross-env NODE_ENV=development rollup -c rollup.config.js -w",
|
||||||
"cli:build": "cross-env NODE_ENV=production rollup -c rollup.config.js",
|
"cli:build": "cross-env NODE_ENV=production rollup -c rollup.config.js",
|
||||||
prepublishOnly: "npm run cli:build"
|
prepublishOnly: "npm run cli:build"
|
||||||
};
|
};
|
||||||
@@ -88,6 +88,7 @@ var devDependencies = {
|
|||||||
"@rollup/plugin-alias": "^4.0.2",
|
"@rollup/plugin-alias": "^4.0.2",
|
||||||
"@rollup/plugin-commonjs": "^23.0.2",
|
"@rollup/plugin-commonjs": "^23.0.2",
|
||||||
"@rollup/plugin-json": "^5.0.2",
|
"@rollup/plugin-json": "^5.0.2",
|
||||||
|
"@rollup/plugin-replace": "^5.0.2",
|
||||||
"@rollup/plugin-terser": "^0.1.0",
|
"@rollup/plugin-terser": "^0.1.0",
|
||||||
"@types/fs-extra": "^9.0.13",
|
"@types/fs-extra": "^9.0.13",
|
||||||
"@types/is-url": "^1.2.30",
|
"@types/is-url": "^1.2.30",
|
||||||
@@ -362,7 +363,8 @@ const IS_LINUX = platform$1 === 'linux';
|
|||||||
// Convert the current module URL to a file path
|
// Convert the current module URL to a file path
|
||||||
const currentModulePath = fileURLToPath(import.meta.url);
|
const currentModulePath = fileURLToPath(import.meta.url);
|
||||||
// Resolve the parent directory of the current module
|
// Resolve the parent directory of the current module
|
||||||
const npmDirectory = process.env.DEV === 'true' ? process.cwd() : path.join(path.dirname(currentModulePath), '..');
|
const npmDirectory = path.join(path.dirname(currentModulePath), '..');
|
||||||
|
const tauriConfigDirectory = path.join(npmDirectory, 'src-tauri');
|
||||||
|
|
||||||
function shellExec(command) {
|
function shellExec(command) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -639,20 +641,20 @@ async function mergeConfig(url, options, tauriConf) {
|
|||||||
}
|
}
|
||||||
// Save config file.
|
// Save config file.
|
||||||
const platformConfigPaths = {
|
const platformConfigPaths = {
|
||||||
win32: 'src-tauri/tauri.windows.conf.json',
|
win32: 'tauri.windows.conf.json',
|
||||||
darwin: 'src-tauri/tauri.macos.conf.json',
|
darwin: 'tauri.macos.conf.json',
|
||||||
linux: 'src-tauri/tauri.linux.conf.json',
|
linux: 'tauri.linux.conf.json',
|
||||||
};
|
};
|
||||||
const configPath = path.join(npmDirectory, platformConfigPaths[platform]);
|
const configPath = path.join(tauriConfigDirectory, platformConfigPaths[platform]);
|
||||||
const bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
|
const bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
|
||||||
await fsExtra.writeJson(configPath, bundleConf, { spaces: 4 });
|
await fsExtra.outputJSON(configPath, bundleConf, { spaces: 4 });
|
||||||
const pakeConfigPath = path.join(npmDirectory, 'src-tauri/pake.json');
|
const pakeConfigPath = path.join(tauriConfigDirectory, 'pake.json');
|
||||||
await fsExtra.writeJson(pakeConfigPath, tauriConf.pake, { spaces: 4 });
|
await fsExtra.outputJSON(pakeConfigPath, tauriConf.pake, { spaces: 4 });
|
||||||
let tauriConf2 = JSON.parse(JSON.stringify(tauriConf));
|
let tauriConf2 = JSON.parse(JSON.stringify(tauriConf));
|
||||||
delete tauriConf2.pake;
|
delete tauriConf2.pake;
|
||||||
delete tauriConf2.tauri.bundle;
|
delete tauriConf2.tauri.bundle;
|
||||||
const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json');
|
const configJsonPath = path.join(tauriConfigDirectory, 'tauri.conf.json');
|
||||||
await fsExtra.writeJson(configJsonPath, tauriConf2, { spaces: 4 });
|
await fsExtra.outputJSON(configJsonPath, tauriConf2, { spaces: 4 });
|
||||||
}
|
}
|
||||||
|
|
||||||
class BaseBuilder {
|
class BaseBuilder {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
"analyze": "cd src-tauri && cargo bloat --release --crates",
|
"analyze": "cd src-tauri && cargo bloat --release --crates",
|
||||||
"tauri": "tauri",
|
"tauri": "tauri",
|
||||||
"cli": "rollup -c rollup.config.js --watch",
|
"cli": "rollup -c rollup.config.js --watch",
|
||||||
"cli:dev": "cross-env DEV=true tsx watch ./bin/dev.ts & npm run dev",
|
"cli:dev": "cross-env NODE_ENV=development rollup -c rollup.config.js -w",
|
||||||
"cli:build": "cross-env NODE_ENV=production rollup -c rollup.config.js",
|
"cli:build": "cross-env NODE_ENV=production rollup -c rollup.config.js",
|
||||||
"prepublishOnly": "npm run cli:build"
|
"prepublishOnly": "npm run cli:build"
|
||||||
},
|
},
|
||||||
@@ -68,6 +68,7 @@
|
|||||||
"@rollup/plugin-alias": "^4.0.2",
|
"@rollup/plugin-alias": "^4.0.2",
|
||||||
"@rollup/plugin-commonjs": "^23.0.2",
|
"@rollup/plugin-commonjs": "^23.0.2",
|
||||||
"@rollup/plugin-json": "^5.0.2",
|
"@rollup/plugin-json": "^5.0.2",
|
||||||
|
"@rollup/plugin-replace": "^5.0.2",
|
||||||
"@rollup/plugin-terser": "^0.1.0",
|
"@rollup/plugin-terser": "^0.1.0",
|
||||||
"@types/fs-extra": "^9.0.13",
|
"@types/fs-extra": "^9.0.13",
|
||||||
"@types/is-url": "^1.2.30",
|
"@types/is-url": "^1.2.30",
|
||||||
|
|||||||
43
plugins/pakeCliDevPlugin.js
Normal file
43
plugins/pakeCliDevPlugin.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import chalk from 'chalk';
|
||||||
|
import {spawn, exec} from 'child_process';
|
||||||
|
|
||||||
|
|
||||||
|
// just run in development mode
|
||||||
|
export default function pakeCliDevPlugin() {
|
||||||
|
return {
|
||||||
|
name: 'pake-cli-dev-plugin',
|
||||||
|
buildEnd() {
|
||||||
|
|
||||||
|
const command = 'node';
|
||||||
|
const cliCmdArgs = ['./dist/dev.js'];
|
||||||
|
const cliChildProcess = spawn(command, cliCmdArgs);
|
||||||
|
|
||||||
|
cliChildProcess.stdout.on('data', (data) => {
|
||||||
|
console.log(chalk.green(data.toString()));
|
||||||
|
});
|
||||||
|
|
||||||
|
cliChildProcess.stderr.on('data', (data) => {
|
||||||
|
console.error(chalk.yellow(data.toString()));
|
||||||
|
});
|
||||||
|
|
||||||
|
cliChildProcess.on('close', async (code) => {
|
||||||
|
console.log(chalk.yellow(`cli running end with code: ${code}`));
|
||||||
|
cliChildProcess.kill();
|
||||||
|
const dev = await exec('npm run tauri dev -- --config ./src-tauri/.pake/tauri.conf.json --features cli-build');
|
||||||
|
|
||||||
|
dev.stdout.on('data', (data) => {
|
||||||
|
console.error(chalk.green(data.toString()));
|
||||||
|
});
|
||||||
|
|
||||||
|
dev.stderr.on('data', (data) => {
|
||||||
|
console.error(chalk.yellow(data.toString()));
|
||||||
|
});
|
||||||
|
|
||||||
|
dev.on('close', () => {
|
||||||
|
dev.kill();
|
||||||
|
console.log(chalk.green('rebuild start'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
rollup.config.js
vendored
21
rollup.config.js
vendored
@@ -4,12 +4,23 @@ import typescript from 'rollup-plugin-typescript2';
|
|||||||
import alias from '@rollup/plugin-alias';
|
import alias from '@rollup/plugin-alias';
|
||||||
import commonjs from '@rollup/plugin-commonjs';
|
import commonjs from '@rollup/plugin-commonjs';
|
||||||
import json from '@rollup/plugin-json';
|
import json from '@rollup/plugin-json';
|
||||||
|
import replace from '@rollup/plugin-replace';
|
||||||
|
|
||||||
|
import pakeCliDevPlugin from './plugins/pakeCliDevPlugin.js';
|
||||||
|
|
||||||
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
|
const devPlugins = !isProduction ? [pakeCliDevPlugin()] : [];
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
input: 'bin/cli.ts',
|
input: isProduction ? 'bin/cli.ts' : 'bin/dev.ts',
|
||||||
output: {
|
output: {
|
||||||
file: 'dist/cli.js',
|
file: isProduction ? 'dist/cli.js' : 'dist/dev.js',
|
||||||
format: 'es'
|
format: 'es',
|
||||||
|
sourcemap: !isProduction,
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
include: 'bin/**',
|
||||||
|
exclude: 'node_modules/**',
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
json(),
|
json(),
|
||||||
@@ -18,8 +29,12 @@ export default {
|
|||||||
clean: true, // 清理缓存
|
clean: true, // 清理缓存
|
||||||
}),
|
}),
|
||||||
commonjs(),
|
commonjs(),
|
||||||
|
replace({
|
||||||
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
||||||
|
}),
|
||||||
alias({
|
alias({
|
||||||
entries: [{ find: '@', replacement: path.join(appRootPath.path, 'bin') }],
|
entries: [{ find: '@', replacement: path.join(appRootPath.path, 'bin') }],
|
||||||
}),
|
}),
|
||||||
|
...devPlugins,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-works
|
|||||||
cargo-bloat = "0.11.1"
|
cargo-bloat = "0.11.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
# this feature is used for development builds from development cli
|
||||||
|
cli-build = []
|
||||||
# by default Tauri runs in production mode
|
# by default Tauri runs in production mode
|
||||||
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
|
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
|
||||||
default = ["custom-protocol"]
|
default = ["custom-protocol"]
|
||||||
|
|||||||
@@ -4,9 +4,16 @@ use std::path::PathBuf;
|
|||||||
use tauri::{api, Config, Window};
|
use tauri::{api, Config, Window};
|
||||||
|
|
||||||
pub fn get_pake_config() -> (PakeConfig, Config) {
|
pub fn get_pake_config() -> (PakeConfig, Config) {
|
||||||
|
#[cfg(feature = "cli-build")]
|
||||||
|
let pake_config: PakeConfig =
|
||||||
|
serde_json::from_str(include_str!("../.pake/pake.json")).expect("Failed to parse pake config");
|
||||||
|
#[cfg(not(feature = "cli-build"))]
|
||||||
let pake_config: PakeConfig =
|
let pake_config: PakeConfig =
|
||||||
serde_json::from_str(include_str!("../pake.json")).expect("Failed to parse pake config");
|
serde_json::from_str(include_str!("../pake.json")).expect("Failed to parse pake config");
|
||||||
|
#[cfg(feature = "cli-build")]
|
||||||
|
let tauri_config: Config = serde_json::from_str(include_str!("../.pake/tauri.conf.json"))
|
||||||
|
.expect("Failed to parse tauri config");
|
||||||
|
#[cfg(not(feature = "cli-build"))]
|
||||||
let tauri_config: Config = serde_json::from_str(include_str!("../tauri.conf.json"))
|
let tauri_config: Config = serde_json::from_str(include_str!("../tauri.conf.json"))
|
||||||
.expect("Failed to parse tauri config");
|
.expect("Failed to parse tauri config");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user