Skip to content

Commit b8107da

Browse files
committed
✨ CLI more beautiful.
1 parent 2669e71 commit b8107da

File tree

8 files changed

+69
-64
lines changed

8 files changed

+69
-64
lines changed

bin/builders/BaseBuilder.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path';
22
import fsExtra from "fs-extra";
3+
import chalk from "chalk";
34
import prompts from 'prompts';
45

56
import { PakeAppOptions } from '@/types';
@@ -22,8 +23,8 @@ export default abstract class BaseBuilder {
2223

2324
async prepare() {
2425
if (!IS_MAC) {
25-
logger.info('The first use requires installing system dependencies.');
26-
logger.info('See more in https://tauri.app/v1/guides/getting-started/prerequisites#installing.');
26+
logger.info('⚙︎ The first use requires installing system dependencies.');
27+
logger.info('⚙︎ See more in https://tauri.app/v1/guides/getting-started/prerequisites.');
2728
}
2829

2930
if (!checkRustInstalled()) {
@@ -36,15 +37,15 @@ export default abstract class BaseBuilder {
3637
if (res.value) {
3738
await installRust();
3839
} else {
39-
logger.error('Error: Rust required to package your webapp!');
40+
logger.error(' Rust required to package your webapp.');
4041
process.exit(0);
4142
}
4243
}
4344

4445
const isChina = await isChinaDomain("www.npmjs.com");
4546
const spinner = getSpinner('Installing package...');
4647
if (isChina) {
47-
logger.info("Located in China, using npm/rsProxy CN mirror.");
48+
logger.info("⚙︎ Located in China, using npm/rsProxy CN mirror.");
4849
const rustProjectDir = path.join(npmDirectory, 'src-tauri', ".cargo");
4950
await fsExtra.ensureDir(rustProjectDir);
5051
const projectCnConf = path.join(npmDirectory, "src-tauri", "rust_proxy.toml");
@@ -54,7 +55,7 @@ export default abstract class BaseBuilder {
5455
} else {
5556
await shellExec(`cd "${npmDirectory}" && npm install`);
5657
}
57-
spinner.succeed('Package installed.');
58+
spinner.succeed(chalk.green('Package installed!'));
5859
}
5960

6061
async build(url: string) {

bin/helpers/merge.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function mergeConfig(
4343
//Judge the type of URL, whether it is a file or a website.
4444
const pathExists = await fsExtra.pathExists(url);
4545
if (pathExists) {
46-
logger.warn('Your input might be a local file.');
46+
logger.warn('Your input might be a local file.');
4747
tauriConf.pake.windows[0].url_type = 'local';
4848

4949
const fileName = path.basename(url);
@@ -98,7 +98,7 @@ export async function mergeConfig(
9898
tauriConf.tauri.bundle.targets = options.targets === 'all' ? ['deb', 'appimage'] : [options.targets];
9999
} else {
100100
logger.warn(
101-
`The target must be one of ${validTargets.join(', ')}, the default 'deb' will be used.`,
101+
`The target must be one of ${validTargets.join(', ')}, the default 'deb' will be used.`,
102102
);
103103
}
104104
}
@@ -132,7 +132,7 @@ export async function mergeConfig(
132132

133133
if (customIconExt !== iconInfo.fileExt) {
134134
updateIconPath = false;
135-
logger.warn(`${iconInfo.message}, but you give ${customIconExt}`);
135+
logger.warn(`${iconInfo.message}, but you give ${customIconExt}`);
136136
tauriConf.tauri.bundle.icon = [iconInfo.defaultIcon];
137137
} else {
138138
const iconPath = path.join(npmDirectory, 'src-tauri/', iconInfo.path);
@@ -143,12 +143,10 @@ export async function mergeConfig(
143143
if (updateIconPath) {
144144
tauriConf.tauri.bundle.icon = [options.icon];
145145
} else {
146-
logger.warn(`Icon will remain as default.`);
146+
logger.warn(`Icon will remain as default.`);
147147
}
148148
} else {
149-
logger.warn(
150-
'Custom icon path may be invalid. Default icon will be used instead.',
151-
);
149+
logger.warn('✼ Custom icon path may be invalid, default icon will be used instead.');
152150
tauriConf.tauri.bundle.icon = [iconInfo.defaultIcon];
153151
}
154152

@@ -168,13 +166,13 @@ export async function mergeConfig(
168166
await fsExtra.copy(systemTrayIcon, trayIcoPath);
169167
} else {
170168
logger.warn(
171-
`System tray icon must be .ico or .png, but you provided ${iconExt}.`,
169+
`System tray icon must be .ico or .png, but you provided ${iconExt}.`,
172170
);
173-
logger.warn(`Default system tray icon will be used.`);
171+
logger.warn(`Default system tray icon will be used.`);
174172
}
175173
} catch {
176-
logger.warn(`${systemTrayIcon} not exists!`);
177-
logger.warn(`Default system tray icon will remain unchanged.`);
174+
logger.warn(`${systemTrayIcon} not exists!`);
175+
logger.warn(`Default system tray icon will remain unchanged.`);
178176
}
179177
}
180178

bin/helpers/rust.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import chalk from "chalk";
12
import shelljs from 'shelljs';
23

34
import { getSpinner } from "@/utils/info";
@@ -16,10 +17,10 @@ export async function installRust() {
1617

1718
try {
1819
await shellExec(IS_WIN ? rustInstallScriptForWindows : rustInstallScriptForMac);
19-
spinner.succeed('Rust installed successfully.');
20+
spinner.succeed(chalk.green('Rust installed successfully!'));
2021
} catch (error) {
2122
console.error('Error installing Rust:', error.message);
22-
spinner.fail('Rust installation failed.');
23+
spinner.fail(chalk.red('Rust installation failed!'));
2324
process.exit(1);
2425
}
2526
}

bin/options/icon.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { getSpinner } from "@/utils/info";
21
import path from 'path';
32
import axios from 'axios';
43
import fsExtra from "fs-extra";
4+
import chalk from 'chalk';
55
import { dir } from 'tmp-promise';
6-
import { fileTypeFromBuffer } from 'file-type';
6+
77

88
import logger from './logger';
99
import { npmDirectory } from '@/utils/dir';
1010
import { IS_LINUX, IS_WIN } from '@/utils/platform';
11+
import { getSpinner } from "@/utils/info";
12+
import { fileTypeFromBuffer } from 'file-type';
1113
import { PakeAppOptions } from '@/types';
1214

1315
export async function handleIcon(options: PakeAppOptions) {
@@ -18,7 +20,7 @@ export async function handleIcon(options: PakeAppOptions) {
1820
return path.resolve(options.icon);
1921
}
2022
} else {
21-
logger.info('No app icon provided, default icon used. Use --icon option to assign an icon.');
23+
logger.warn('✼ No icon given, default in use. For a custom icon, use --icon option.');
2224
const iconPath = IS_WIN ? 'src-tauri/png/icon_256.ico' : IS_LINUX ? 'src-tauri/png/icon_512.png' : 'src-tauri/icons/icon.icns';
2325
return path.join(npmDirectory, iconPath);
2426
}
@@ -42,10 +44,10 @@ export async function downloadIcon(iconUrl: string) {
4244
const { path: tempPath } = await dir();
4345
const iconPath = `${tempPath}/icon.${fileDetails.ext}`;
4446
await fsExtra.outputFile(iconPath, iconData);
45-
spinner.succeed('Icon downloaded successfully.');
47+
spinner.succeed(chalk.green('Icon downloaded successfully!'));
4648
return iconPath;
4749
} catch (error) {
48-
spinner.fail('Icon download failed.');
50+
spinner.fail(chalk.red('Icon download failed!'));
4951
if (error.response && error.response.status === 404) {
5052
return null;
5153
}

bin/options/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ export default async function handleOptions(options: PakeCliOptions, url: string
3434
}
3535

3636
if (!isValidName(name, platform)) {
37-
const LINUX_NAME_ERROR = `Package name is invalid. It should only include lowercase letters, numbers, and dashes, and must contain at least one lowercase letter. Examples: com-123-xxx, 123pan, pan123, weread, we-read.`;
38-
const DEFAULT_NAME_ERROR = `Package name is invalid. It should only include letters and numbers, and must contain at least one letter. Examples: 123pan, 123Pan, Pan123, weread, WeRead, WERead.`;
37+
const LINUX_NAME_ERROR = ` name should only include lowercase letters, numbers, and dashes, and must contain at least one lowercase letter. Examples: com-123-xxx, 123pan, pan123, weread, we-read.`;
38+
const DEFAULT_NAME_ERROR = `✕ Name should only include letters and numbers, and must contain at least one letter. Examples: 123pan, 123Pan, Pan123, weread, WeRead, WERead.`;
3939
const errorMsg = platform === 'linux' ? LINUX_NAME_ERROR : DEFAULT_NAME_ERROR;
4040
logger.error(errorMsg);
4141
if (isActions) {
4242
name = resolveAppName(url, platform);
43-
logger.warn(`Inside github actions, use the default name: ${name}`);
43+
logger.warn(`Inside github actions, use the default name: ${name}`);
4444
} else {
4545
process.exit(1);
4646
}

bin/options/logger.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import log from 'loglevel';
33

44
const logger = {
55
info(...msg: any[]) {
6-
log.info(...msg.map((m) => chalk.blue.bold(m)));
6+
log.info(...msg.map((m) => chalk.white(m)));
77
},
88
debug(...msg: any[]) {
99
log.debug(...msg);
1010
},
1111
error(...msg: any[]) {
12-
log.error(...msg.map((m) => chalk.red.bold(m)));
12+
log.error(...msg.map((m) => chalk.red(m)));
1313
},
1414
warn(...msg: any[]) {
15-
log.info(...msg.map((m) => chalk.yellow.bold(m)));
15+
log.info(...msg.map((m) => chalk.yellow(m)));
1616
},
1717
success(...msg: any[]) {
18-
log.info(...msg.map((m) => chalk.green.bold(m)));
18+
log.info(...msg.map((m) => chalk.green(m)));
1919
}
2020
};
2121

bin/utils/info.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import crypto from 'crypto';
22
import prompts from "prompts";
33
import ora from "ora";
4+
import chalk from 'chalk';
45

56
// Generates an identifier based on the given URL.
67
export function getIdentifier(url: string) {
@@ -29,14 +30,15 @@ export function getSpinner(text: string) {
2930
const loadingType = {
3031
"interval": 80,
3132
"frames": [
33+
"✦",
3234
"✶",
35+
"✺",
3336
"✵",
3437
"✸",
38+
"✴︎",
3539
"✹",
3640
"✺",
37-
"✹",
38-
"✷",
3941
]
4042
}
41-
return ora({ text: `${text}\n`, spinner: loadingType }).start();
43+
return ora({ text: `${chalk.blue(text)}\n`, spinner: loadingType, color: 'blue' }).start();
4244
}

0 commit comments

Comments
 (0)