@fe-hl/cli-shared
v1.0.4
Published
cli脚手架工具库
Downloads
6
Readme
cli 脚手架工具库
引用
import {
fse,
pathExists,
chalk,
rootCheck,
semver,
logs,
isDebug,
request,
spinnerLoading,
makeList,
makeInput,
makeConfirm,
makePassword,
getLatestVersion,
checkGlobalUpdate,
welcome,
checkNodeVersion,
getPkgInfo,
getDirname,
getFilename,
exception,
printErrorLog,
} from "@fe-hl/cli-shared";
fse 等同 fs-extra 库
import fse from "fs-extra";
pathExists 等同 pathExists 库
import { pathExists } from "path-exists";
chalk 等同 chalk 库
import chalk from "chalk";
rootCheck 等同 rootCheck 库
import rootCheck from "root-check";
semver 等同 semver 库
import semver from "semver";
logs 日志输出
logs.silly(prefix, message);
logs.verbose(prefix, message);
logs.info(prefix, message);
logs.http(prefix, message);
logs.warn(prefix, message);
logs.error(prefix, message);
isDebug 模式判断
// hl-cli init createApp -- --debug
isDebug();
request http 请求
await request.get(url);
await request.post(url);
spinnerLoading
const { spinnerSucceed, spinnerFail } = spinnerLoading("开始创建远程仓库");
spinnerSucceed(message?);
spinnerFail(message?);
makeList,makeInput,makeConfirm,makePassword
await makeList({
choices: [
{
name: "项目",
value: "project",
},
],
message: "请选择初始化类型",
defaultValue: "project",
});
await makeInput({
message: "请输入开发语言",
});
await makeConfirm({
message: `检测到新版本【${latestVersion}】,是否使用最新版本模版?`,
});
await makePassword({
message: "请输入token信息",
});
getLatestVersion 获取 npm 最新的版本号
const lastVersion = await getLatestVersion(npmName);
checkGlobalUpdate 检测 npm 包是否有新版本
const importMeta = import.meta;
checkGlobalUpdate(importMeta);
welcome 欢迎语
const importMeta = import.meta;
welcome(importMeta);
checkNodeVersion 检测 Node 版本
checkNodeVersion("14.0.0");
getPkgInfo package.json 转 JSON
const importMeta = import.meta;
const pkg = getPkgInfo(importMeta);
getDirname 获取执行文件的目录路径
const importMeta = import.meta;
const dirname = getDirname(importMeta);
getFilename 获取执行文件的路径
const importMeta = import.meta;
const filename = getFilename(importMeta);
exception
- node 全局异常、promise 异常打印控制台
exception();