🎨 Unified code style

This commit is contained in:
Tw93
2023-06-24 20:17:52 +08:00
parent 07938f02f4
commit 00c01a9638
23 changed files with 107 additions and 117 deletions

11
bin/options/icon.ts vendored
View File

@@ -1,14 +1,13 @@
import path from 'path';
import axios from 'axios';
import fsExtra from "fs-extra";
import fsExtra from 'fs-extra';
import chalk from 'chalk';
import { dir } from 'tmp-promise';
import logger from './logger';
import { npmDirectory } from '@/utils/dir';
import { IS_LINUX, IS_WIN } from '@/utils/platform';
import { getSpinner } from "@/utils/info";
import { getSpinner } from '@/utils/info';
import { fileTypeFromBuffer } from 'file-type';
import { PakeAppOptions } from '@/types';
@@ -21,7 +20,11 @@ export async function handleIcon(options: PakeAppOptions) {
}
} else {
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';
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);
}
}

11
bin/options/index.ts vendored
View File

@@ -1,5 +1,5 @@
import fsExtra from "fs-extra";
import logger from "@/options/logger";
import fsExtra from 'fs-extra';
import logger from '@/options/logger';
import { handleIcon } from './icon';
import { getDomain } from '@/utils/url';
@@ -20,14 +20,17 @@ function isValidName(name: string, platform: NodeJS.Platform): boolean {
return !!name && reg.test(name);
}
export default async function handleOptions(options: PakeCliOptions, url: string): Promise<PakeAppOptions> {
export default async function handleOptions(
options: PakeCliOptions,
url: string,
): Promise<PakeAppOptions> {
const { platform } = process;
const isActions = process.env.GITHUB_ACTIONS;
let name = options.name;
const pathExists = await fsExtra.pathExists(url);
if (!options.name) {
const defaultName = pathExists ? "" : resolveAppName(url, platform);
const defaultName = pathExists ? '' : resolveAppName(url, platform);
const promptMessage = 'Enter your application name';
const namePrompt = await promptText(promptMessage, defaultName);
name = namePrompt || defaultName;

10
bin/options/logger.ts vendored
View File

@@ -3,20 +3,20 @@ import log from 'loglevel';
const logger = {
info(...msg: any[]) {
log.info(...msg.map((m) => chalk.white(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(m)));
log.error(...msg.map(m => chalk.red(m)));
},
warn(...msg: any[]) {
log.info(...msg.map((m) => chalk.yellow(m)));
log.info(...msg.map(m => chalk.yellow(m)));
},
success(...msg: any[]) {
log.info(...msg.map((m) => chalk.green(m)));
}
log.info(...msg.map(m => chalk.green(m)));
},
};
export default logger;