🎨 Optimize CLI usage.
This commit is contained in:
8
bin/builders/BaseBuilder.ts
vendored
8
bin/builders/BaseBuilder.ts
vendored
@@ -7,9 +7,9 @@ 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';
|
||||
import { PakeAppOptions } from '@/types';
|
||||
|
||||
export default abstract class BaseBuilder {
|
||||
abstract build(url: string, options: PakeAppOptions): Promise<void>;
|
||||
@@ -37,7 +37,7 @@ export default abstract class BaseBuilder {
|
||||
}
|
||||
|
||||
const isChina = await isChinaDomain("www.npmjs.com");
|
||||
const spinner = getSpinner('Installing package.');
|
||||
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");
|
||||
@@ -53,8 +53,8 @@ export default abstract class BaseBuilder {
|
||||
}
|
||||
|
||||
protected async runBuildCommand(command: string = "npm run build") {
|
||||
const spinner = getSpinner('Building app.');
|
||||
const spinner = getSpinner('Building app...');
|
||||
setTimeout(() => spinner.stop(), 3000);
|
||||
await shellExec(`cd "${npmDirectory}" && ${command}`);
|
||||
spinner.stop();
|
||||
}
|
||||
}
|
||||
|
||||
8
bin/builders/LinuxBuilder.ts
vendored
8
bin/builders/LinuxBuilder.ts
vendored
@@ -22,8 +22,8 @@ export default class LinuxBuilder extends BaseBuilder {
|
||||
const distPath = path.resolve(`${name}.deb`);
|
||||
await fsExtra.copy(appPath, distPath);
|
||||
await fsExtra.remove(appPath);
|
||||
logger.success('Build Deb success!');
|
||||
logger.success('Deb app installer located in', distPath);
|
||||
logger.success('✔ Build Deb success!');
|
||||
logger.success('✔ Deb app installer located in', distPath);
|
||||
}
|
||||
|
||||
if (options.targets === "appimage" || options.targets === "all") {
|
||||
@@ -32,8 +32,8 @@ export default class LinuxBuilder extends BaseBuilder {
|
||||
const distAppPath = path.resolve(`${name}.AppImage`);
|
||||
await fsExtra.copy(appImagePath, distAppPath);
|
||||
await fsExtra.remove(appImagePath);
|
||||
logger.success('Build AppImage success!');
|
||||
logger.success('AppImage installer located in', distAppPath);
|
||||
logger.success('✔ Build AppImage success!');
|
||||
logger.success('✔ AppImage installer located in', distAppPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
4
bin/builders/MacBuilder.ts
vendored
4
bin/builders/MacBuilder.ts
vendored
@@ -25,8 +25,8 @@ export default class MacBuilder extends BaseBuilder {
|
||||
const distPath = path.resolve(`${name}.dmg`);
|
||||
await fsExtra.copy(appPath, distPath);
|
||||
await fsExtra.remove(appPath);
|
||||
logger.success('Build success!');
|
||||
logger.success('App installer located in', distPath);
|
||||
logger.success('✔ Build success!');
|
||||
logger.success('✔ App installer located in', distPath);
|
||||
}
|
||||
|
||||
getBuildAppPath(npmDirectory: string, dmgName: string, multiArch: boolean) {
|
||||
|
||||
4
bin/builders/WinBuilder.ts
vendored
4
bin/builders/WinBuilder.ts
vendored
@@ -21,8 +21,8 @@ export default class WinBuilder extends BaseBuilder {
|
||||
const distPath = path.resolve(`${name}.msi`);
|
||||
await fsExtra.copy(appPath, distPath);
|
||||
await fsExtra.remove(appPath);
|
||||
logger.success('Build success!');
|
||||
logger.success('App installer located in', distPath);
|
||||
logger.success('✔ Build success!');
|
||||
logger.success('✔ App installer located in', distPath);
|
||||
}
|
||||
|
||||
getBuildAppPath(npmDirectory: string, msiName: string) {
|
||||
|
||||
17
bin/cli.ts
vendored
17
bin/cli.ts
vendored
@@ -1,17 +1,17 @@
|
||||
import log from 'loglevel';
|
||||
import chalk from 'chalk';
|
||||
import { program } from 'commander';
|
||||
import log from 'loglevel';
|
||||
import packageJson from '../package.json';
|
||||
import BuilderProvider from './builders/BuilderProvider';
|
||||
import { DEFAULT_PAKE_OPTIONS as DEFAULT } from './defaults';
|
||||
import { checkUpdateTips } from './helpers/updater';
|
||||
import handleInputOptions from './options/index';
|
||||
|
||||
import { PakeCliOptions } from './types';
|
||||
import handleInputOptions from './options/index';
|
||||
import BuilderProvider from './builders/BuilderProvider';
|
||||
import { checkUpdateTips } from './helpers/updater';
|
||||
import packageJson from '../package.json';
|
||||
import { validateNumberInput, validateUrlInput } from './utils/validate';
|
||||
import { DEFAULT_PAKE_OPTIONS as DEFAULT } from './defaults';
|
||||
|
||||
program
|
||||
.description(chalk.green('Pake: A CLI that can turn any webpage into a desktop app with Rust.'))
|
||||
.description(chalk.green('Pake can turn any webpage into a desktop app with Rust.'))
|
||||
.usage('[url] [options]')
|
||||
.showHelpAfterError();
|
||||
|
||||
@@ -39,11 +39,10 @@ program
|
||||
|
||||
if (!url) {
|
||||
program.outputHelp((str) => {
|
||||
const filteredOutput = str
|
||||
return str
|
||||
.split('\n')
|
||||
.filter((line) => !/((-h,|--help)|((-v|-V),|--version))\s+.+$/.test(line))
|
||||
.join('\n');
|
||||
return filteredOutput.trim(); // Trim any leading/trailing whitespace
|
||||
});
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
2
bin/helpers/rust.ts
vendored
2
bin/helpers/rust.ts
vendored
@@ -12,7 +12,7 @@ export async function installRust() {
|
||||
: "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y";
|
||||
const rustInstallScriptForWindows = 'winget install --id Rustlang.Rustup';
|
||||
|
||||
const spinner = getSpinner('Downloading Rust.');
|
||||
const spinner = getSpinner('Downloading Rust...');
|
||||
|
||||
try {
|
||||
await shellExec(IS_WIN ? rustInstallScriptForWindows : rustInstallScriptForMac);
|
||||
|
||||
2
bin/options/icon.ts
vendored
2
bin/options/icon.ts
vendored
@@ -25,7 +25,7 @@ export async function handleIcon(options: PakeAppOptions) {
|
||||
}
|
||||
|
||||
export async function downloadIcon(iconUrl: string) {
|
||||
const spinner = getSpinner('Downloading icon.');
|
||||
const spinner = getSpinner('Downloading icon...');
|
||||
try {
|
||||
const iconResponse = await axios.get(iconUrl, { responseType: 'arraybuffer' });
|
||||
const iconData = await iconResponse.data;
|
||||
|
||||
Reference in New Issue
Block a user