CLI more beautiful.

This commit is contained in:
Tw93
2023-06-24 00:01:44 +08:00
parent d300ac8a16
commit baf59a3300
8 changed files with 69 additions and 64 deletions

12
bin/options/icon.ts vendored
View File

@@ -1,13 +1,15 @@
import { getSpinner } from "@/utils/info";
import path from 'path';
import axios from 'axios';
import fsExtra from "fs-extra";
import chalk from 'chalk';
import { dir } from 'tmp-promise';
import { fileTypeFromBuffer } from 'file-type';
import logger from './logger';
import { npmDirectory } from '@/utils/dir';
import { IS_LINUX, IS_WIN } from '@/utils/platform';
import { getSpinner } from "@/utils/info";
import { fileTypeFromBuffer } from 'file-type';
import { PakeAppOptions } from '@/types';
export async function handleIcon(options: PakeAppOptions) {
@@ -18,7 +20,7 @@ export async function handleIcon(options: PakeAppOptions) {
return path.resolve(options.icon);
}
} else {
logger.info('No app icon provided, default icon used. Use --icon option to assign an icon.');
logger.warn('No icon given, default in use. For a custom icon, use --icon option.');
const iconPath = IS_WIN ? 'src-tauri/png/icon_256.ico' : IS_LINUX ? 'src-tauri/png/icon_512.png' : 'src-tauri/icons/icon.icns';
return path.join(npmDirectory, iconPath);
}
@@ -42,10 +44,10 @@ export async function downloadIcon(iconUrl: string) {
const { path: tempPath } = await dir();
const iconPath = `${tempPath}/icon.${fileDetails.ext}`;
await fsExtra.outputFile(iconPath, iconData);
spinner.succeed('Icon downloaded successfully.');
spinner.succeed(chalk.green('Icon downloaded successfully!'));
return iconPath;
} catch (error) {
spinner.fail('Icon download failed.');
spinner.fail(chalk.red('Icon download failed!'));
if (error.response && error.response.status === 404) {
return null;
}

View File

@@ -34,13 +34,13 @@ export default async function handleOptions(options: PakeCliOptions, url: string
}
if (!isValidName(name, platform)) {
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.`;
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.`;
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.`;
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.`;
const errorMsg = platform === 'linux' ? LINUX_NAME_ERROR : DEFAULT_NAME_ERROR;
logger.error(errorMsg);
if (isActions) {
name = resolveAppName(url, platform);
logger.warn(`Inside github actions, use the default name: ${name}`);
logger.warn(`Inside github actions, use the default name: ${name}`);
} else {
process.exit(1);
}

View File

@@ -3,19 +3,19 @@ import log from 'loglevel';
const logger = {
info(...msg: any[]) {
log.info(...msg.map((m) => chalk.blue.bold(m)));
log.info(...msg.map((m) => chalk.white(m)));
},
debug(...msg: any[]) {
log.debug(...msg);
},
error(...msg: any[]) {
log.error(...msg.map((m) => chalk.red.bold(m)));
log.error(...msg.map((m) => chalk.red(m)));
},
warn(...msg: any[]) {
log.info(...msg.map((m) => chalk.yellow.bold(m)));
log.info(...msg.map((m) => chalk.yellow(m)));
},
success(...msg: any[]) {
log.info(...msg.map((m) => chalk.green.bold(m)));
log.info(...msg.map((m) => chalk.green(m)));
}
};