🎨 Unified code style
This commit is contained in:
33
bin/builders/BaseBuilder.ts
vendored
33
bin/builders/BaseBuilder.ts
vendored
@@ -1,17 +1,17 @@
|
||||
import path from 'path';
|
||||
import fsExtra from "fs-extra";
|
||||
import chalk from "chalk";
|
||||
import fsExtra from 'fs-extra';
|
||||
import chalk from 'chalk';
|
||||
import prompts from 'prompts';
|
||||
|
||||
import { PakeAppOptions } from '@/types';
|
||||
import { checkRustInstalled, installRust } from '@/helpers/rust';
|
||||
import { mergeConfig } from "@/helpers/merge";
|
||||
import { mergeConfig } from '@/helpers/merge';
|
||||
import tauriConfig from '@/helpers/tauriConfig';
|
||||
import { npmDirectory } from '@/utils/dir';
|
||||
import { getSpinner } from "@/utils/info";
|
||||
import { getSpinner } from '@/utils/info';
|
||||
import { shellExec } from '@/utils/shell';
|
||||
import { isChinaDomain } from '@/utils/ip';
|
||||
import { IS_MAC } from "@/utils/platform";
|
||||
import { IS_MAC } from '@/utils/platform';
|
||||
import logger from '@/options/logger';
|
||||
|
||||
export default abstract class BaseBuilder {
|
||||
@@ -23,8 +23,8 @@ export default abstract class BaseBuilder {
|
||||
|
||||
async prepare() {
|
||||
if (!IS_MAC) {
|
||||
logger.info('⚙︎ The first use requires installing system dependencies.');
|
||||
logger.info('⚙︎ See more in https://tauri.app/v1/guides/getting-started/prerequisites.');
|
||||
logger.info('✺ The first use requires installing system dependencies.');
|
||||
logger.info('✺ See more in https://tauri.app/v1/guides/getting-started/prerequisites.');
|
||||
}
|
||||
|
||||
if (!checkRustInstalled()) {
|
||||
@@ -42,14 +42,14 @@ export default abstract class BaseBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
const isChina = await isChinaDomain("www.npmjs.com");
|
||||
const isChina = await isChinaDomain('www.npmjs.com');
|
||||
const spinner = getSpinner('Installing package...');
|
||||
if (isChina) {
|
||||
logger.info("⚙︎ Located in China, using npm/rsProxy CN mirror.");
|
||||
const rustProjectDir = path.join(npmDirectory, '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(npmDirectory, "src-tauri", "rust_proxy.toml");
|
||||
const projectConf = path.join(rustProjectDir, "config");
|
||||
const projectCnConf = path.join(npmDirectory, 'src-tauri', 'rust_proxy.toml');
|
||||
const projectConf = path.join(rustProjectDir, 'config');
|
||||
await fsExtra.copy(projectCnConf, projectConf);
|
||||
await shellExec(`cd "${npmDirectory}" && npm install --registry=https://registry.npmmirror.com`);
|
||||
} else {
|
||||
@@ -89,7 +89,7 @@ export default abstract class BaseBuilder {
|
||||
abstract getFileName(): string;
|
||||
|
||||
protected getBuildCommand(): string {
|
||||
return "npm run build";
|
||||
return 'npm run build';
|
||||
}
|
||||
|
||||
protected getBasePath(): string {
|
||||
@@ -97,11 +97,6 @@ export default abstract class BaseBuilder {
|
||||
}
|
||||
|
||||
protected getBuildAppPath(npmDirectory: string, fileName: string, fileType: string): string {
|
||||
return path.join(
|
||||
npmDirectory,
|
||||
this.getBasePath(),
|
||||
fileType.toLowerCase(),
|
||||
`${fileName}.${fileType}`
|
||||
);
|
||||
return path.join(npmDirectory, this.getBasePath(), fileType.toLowerCase(), `${fileName}.${fileType}`);
|
||||
}
|
||||
}
|
||||
|
||||
7
bin/builders/LinuxBuilder.ts
vendored
7
bin/builders/LinuxBuilder.ts
vendored
@@ -3,22 +3,21 @@ import { PakeAppOptions } from '@/types';
|
||||
import tauriConfig from '@/helpers/tauriConfig';
|
||||
|
||||
export default class LinuxBuilder extends BaseBuilder {
|
||||
|
||||
constructor(options: PakeAppOptions) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
getFileName(): string {
|
||||
const { name } = this.options;
|
||||
const arch = process.arch === "x64" ? "amd64" : process.arch;
|
||||
const arch = process.arch === 'x64' ? 'amd64' : process.arch;
|
||||
return `${name}_${tauriConfig.package.version}_${arch}`;
|
||||
}
|
||||
|
||||
// Customize it, considering that there are all targets.
|
||||
async build(url: string) {
|
||||
const targetTypes = ["deb", "appimage"];
|
||||
const targetTypes = ['deb', 'appimage'];
|
||||
for (const target of targetTypes) {
|
||||
if (this.options.targets === target || this.options.targets === "all") {
|
||||
if (this.options.targets === target || this.options.targets === 'all') {
|
||||
await this.buildAndCopy(url, target);
|
||||
}
|
||||
}
|
||||
|
||||
4
bin/builders/MacBuilder.ts
vendored
4
bin/builders/MacBuilder.ts
vendored
@@ -5,7 +5,7 @@ import BaseBuilder from './BaseBuilder';
|
||||
export default class MacBuilder extends BaseBuilder {
|
||||
constructor(options: PakeAppOptions) {
|
||||
super(options);
|
||||
this.options.targets = "dmg";
|
||||
this.options.targets = 'dmg';
|
||||
}
|
||||
|
||||
getFileName(): string {
|
||||
@@ -14,7 +14,7 @@ export default class MacBuilder extends BaseBuilder {
|
||||
if (this.options.multiArch) {
|
||||
arch = 'universal';
|
||||
} else {
|
||||
arch = process.arch === "arm64" ? "aarch64" : process.arch;
|
||||
arch = process.arch === 'arm64' ? 'aarch64' : process.arch;
|
||||
}
|
||||
return `${name}_${tauriConfig.package.version}_${arch}`;
|
||||
}
|
||||
|
||||
2
bin/builders/WinBuilder.ts
vendored
2
bin/builders/WinBuilder.ts
vendored
@@ -5,7 +5,7 @@ import tauriConfig from '@/helpers/tauriConfig';
|
||||
export default class WinBuilder extends BaseBuilder {
|
||||
constructor(options: PakeAppOptions) {
|
||||
super(options);
|
||||
this.options.targets = "msi";
|
||||
this.options.targets = 'msi';
|
||||
}
|
||||
|
||||
getFileName(): string {
|
||||
|
||||
Reference in New Issue
Block a user