feat: support cli development
This commit is contained in:
4
bin/builders/BaseBuilder.ts
vendored
4
bin/builders/BaseBuilder.ts
vendored
@@ -71,6 +71,10 @@ export default abstract class BaseBuilder {
|
||||
await this.buildAndCopy(url, this.options.targets);
|
||||
}
|
||||
|
||||
async start(url: string) {
|
||||
await mergeConfig(url, this.options, tauriConfig);
|
||||
}
|
||||
|
||||
async buildAndCopy(url: string, target: string) {
|
||||
const { name } = this.options;
|
||||
await mergeConfig(url, this.options, tauriConfig);
|
||||
|
||||
8
bin/defaults.ts
vendored
8
bin/defaults.ts
vendored
@@ -18,3 +18,11 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
|
||||
inject: [],
|
||||
safeDomain: [],
|
||||
};
|
||||
|
||||
// just for cli development
|
||||
export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & {url: string} = {
|
||||
...DEFAULT_PAKE_OPTIONS,
|
||||
url: 'https://zbook.lol',
|
||||
name: 'Zbook',
|
||||
safeDomain: ['zbook.eu.org']
|
||||
}
|
||||
17
bin/dev.ts
vendored
Normal file
17
bin/dev.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import log from 'loglevel';
|
||||
import {DEFAULT_DEV_PAKE_OPTIONS} from './defaults';
|
||||
import handleInputOptions from './options/index';
|
||||
import BuilderProvider from './builders/BuilderProvider';
|
||||
|
||||
async function startBuild() {
|
||||
log.setDefaultLevel('debug');
|
||||
|
||||
const appOptions = await handleInputOptions(DEFAULT_DEV_PAKE_OPTIONS, DEFAULT_DEV_PAKE_OPTIONS.url);
|
||||
log.debug('PakeAppOptions', appOptions);
|
||||
|
||||
const builder = BuilderProvider.create(appOptions);
|
||||
await builder.prepare();
|
||||
await builder.start(DEFAULT_DEV_PAKE_OPTIONS.url);
|
||||
}
|
||||
|
||||
startBuild();
|
||||
8
bin/helpers/merge.ts
vendored
8
bin/helpers/merge.ts
vendored
@@ -183,7 +183,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
||||
}
|
||||
|
||||
tauriConf.tauri.systemTray.iconPath = trayIconPath;
|
||||
|
||||
const injectFilePath = path.join(npmDirectory, `src-tauri/src/inject/_INJECT_.js`);
|
||||
// inject js or css files
|
||||
if (inject?.length > 0) {
|
||||
if (!inject.every(item => item.endsWith('.css') || item.endsWith('.js'))) {
|
||||
@@ -192,7 +192,10 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
||||
}
|
||||
const files = inject.map(filepath => path.isAbsolute(filepath) ? filepath : path.join(process.cwd(), filepath));
|
||||
tauriConf.pake.inject = files;
|
||||
await combineFiles(files, path.join(npmDirectory, `src-tauri/src/inject/_INJECT_.js`));
|
||||
await combineFiles(files, injectFilePath);
|
||||
} else {
|
||||
tauriConf.pake.inject = [];
|
||||
await fsExtra.writeFile(injectFilePath, '');
|
||||
}
|
||||
|
||||
// Save config file.
|
||||
@@ -205,7 +208,6 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
||||
|
||||
const bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
|
||||
await fsExtra.writeJson(configPath, bundleConf, { spaces: 4 });
|
||||
|
||||
const pakeConfigPath = path.join(npmDirectory, 'src-tauri/pake.json');
|
||||
await fsExtra.writeJson(pakeConfigPath, tauriConf.pake, { spaces: 4 });
|
||||
|
||||
|
||||
2
bin/utils/dir.ts
vendored
2
bin/utils/dir.ts
vendored
@@ -5,4 +5,4 @@ import { fileURLToPath } from 'url';
|
||||
const currentModulePath = fileURLToPath(import.meta.url);
|
||||
|
||||
// Resolve the parent directory of the current module
|
||||
export const npmDirectory = path.join(path.dirname(currentModulePath), '..');
|
||||
export const npmDirectory = process.env.DEV === 'true' ? process.cwd() : path.join(path.dirname(currentModulePath), '..');
|
||||
|
||||
Reference in New Issue
Block a user