🎨 Simplify usage
This commit is contained in:
57
bin/builders/BaseBuilder.ts
vendored
57
bin/builders/BaseBuilder.ts
vendored
@@ -1,11 +1,12 @@
|
||||
import path from 'path';
|
||||
import ora from "ora";
|
||||
import fsExtra from "fs-extra";
|
||||
import prompts from 'prompts';
|
||||
|
||||
import logger from '@/options/logger';
|
||||
import { shellExec } from '@/utils/shell';
|
||||
import { isChinaDomain } from '@/utils/ip';
|
||||
import { getSpinner } from "@/utils/info";
|
||||
import { npmDirectory } from '@/utils/dir';
|
||||
import { PakeAppOptions } from '@/types';
|
||||
import { IS_MAC } from "@/utils/platform";
|
||||
import { checkRustInstalled, installRust } from '@/helpers/rust';
|
||||
@@ -14,46 +15,46 @@ export default abstract class BaseBuilder {
|
||||
abstract build(url: string, options: PakeAppOptions): Promise<void>;
|
||||
|
||||
async prepare() {
|
||||
|
||||
// Windows and Linux need to install necessary build tools.
|
||||
if (!IS_MAC) {
|
||||
logger.info('Install Rust and required build tools to build the app.');
|
||||
logger.info('The first use requires installing system dependencies.');
|
||||
logger.info('See more in https://tauri.app/v1/guides/getting-started/prerequisites#installing.');
|
||||
}
|
||||
|
||||
if (checkRustInstalled()) {
|
||||
return;
|
||||
if (!checkRustInstalled()) {
|
||||
const res = await prompts({
|
||||
type: 'confirm',
|
||||
message: 'Rust not detected. Install now?',
|
||||
name: 'value',
|
||||
});
|
||||
|
||||
if (res.value) {
|
||||
await installRust();
|
||||
} else {
|
||||
logger.error('Error: Rust required to package your webapp!');
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
const res = await prompts({
|
||||
type: 'confirm',
|
||||
message: 'Rust not detected. Install now?',
|
||||
name: 'value',
|
||||
});
|
||||
|
||||
if (res.value) {
|
||||
await installRust();
|
||||
} else {
|
||||
logger.error('Error: Rust required to package your webapp!');
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
protected async runBuildCommand(directory: string, command: string) {
|
||||
const spinner = ora('Building...').start();
|
||||
setTimeout(() => spinner.succeed(), 5000);
|
||||
const isChina = await isChinaDomain("www.npmjs.com");
|
||||
const spinner = getSpinner('Installing package.');
|
||||
if (isChina) {
|
||||
logger.info("Located in China, using npm/Rust CN mirror.");
|
||||
const rustProjectDir = path.join(directory, 'src-tauri', ".cargo");
|
||||
logger.info("Located in China, using npm/rsProxy CN mirror.");
|
||||
const rustProjectDir = path.join(npmDirectory, 'src-tauri', ".cargo");
|
||||
await fsExtra.ensureDir(rustProjectDir);
|
||||
const projectCnConf = path.join(directory, "src-tauri", "rust_proxy.toml");
|
||||
const projectCnConf = path.join(npmDirectory, "src-tauri", "rust_proxy.toml");
|
||||
const projectConf = path.join(rustProjectDir, "config");
|
||||
await fsExtra.copy(projectCnConf, projectConf);
|
||||
|
||||
await shellExec(`cd "${directory}" && npm install --registry=https://registry.npmmirror.com && ${command}`);
|
||||
await shellExec(`cd "${npmDirectory}" && npm install --registry=https://registry.npmmirror.com`);
|
||||
} else {
|
||||
await shellExec(`cd "${directory}" && npm install && ${command}`);
|
||||
await shellExec(`cd "${npmDirectory}" && npm install`);
|
||||
}
|
||||
spinner.succeed('Package installed.');
|
||||
}
|
||||
|
||||
protected async runBuildCommand(command: string = "npm run build") {
|
||||
const spinner = getSpinner('Building app.');
|
||||
await shellExec(`cd "${npmDirectory}" && ${command}`);
|
||||
spinner.stop();
|
||||
}
|
||||
}
|
||||
|
||||
2
bin/builders/LinuxBuilder.ts
vendored
2
bin/builders/LinuxBuilder.ts
vendored
@@ -12,7 +12,7 @@ export default class LinuxBuilder extends BaseBuilder {
|
||||
async build(url: string, options: PakeAppOptions) {
|
||||
const { name } = options;
|
||||
await mergeConfig(url, options, tauriConfig);
|
||||
await this.runBuildCommand(npmDirectory, 'npm run build');
|
||||
await this.runBuildCommand();
|
||||
|
||||
const arch = process.arch === "x64" ? "amd64" : process.arch;
|
||||
|
||||
|
||||
4
bin/builders/MacBuilder.ts
vendored
4
bin/builders/MacBuilder.ts
vendored
@@ -14,10 +14,10 @@ export default class MacBuilder extends BaseBuilder {
|
||||
await mergeConfig(url, options, tauriConfig);
|
||||
let dmgName: string;
|
||||
if (options.multiArch) {
|
||||
await this.runBuildCommand(npmDirectory, 'npm run build:mac');
|
||||
await this.runBuildCommand('npm run build:mac');
|
||||
dmgName = `${name}_${tauriConfig.package.version}_universal.dmg`;
|
||||
} else {
|
||||
await this.runBuildCommand(npmDirectory, 'npm run build');
|
||||
await this.runBuildCommand();
|
||||
let arch = process.arch === "arm64" ? "aarch64" : process.arch;
|
||||
dmgName = `${name}_${tauriConfig.package.version}_${arch}.dmg`;
|
||||
}
|
||||
|
||||
2
bin/builders/WinBuilder.ts
vendored
2
bin/builders/WinBuilder.ts
vendored
@@ -12,7 +12,7 @@ export default class WinBuilder extends BaseBuilder {
|
||||
async build(url: string, options: PakeAppOptions) {
|
||||
const { name } = options;
|
||||
await mergeConfig(url, options, tauriConfig);
|
||||
await this.runBuildCommand(npmDirectory, 'npm run build');
|
||||
await this.runBuildCommand();
|
||||
|
||||
const language = tauriConfig.tauri.bundle.windows.wix.language[0];
|
||||
const arch = process.arch;
|
||||
|
||||
Reference in New Issue
Block a user