-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 新增创建函数脚本,优化创建使用体验 * feat: 调整create脚本的实现方式 * fix: 修复无法执行子命令的问题 * feat: 调整忽略文件 * feat: 修改贡献者指南文档
- Loading branch information
Showing
14 changed files
with
386 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
export * from './src/isType' | ||
export * from './src/isString' | ||
export * from './src/isNull' | ||
export * from './src/isRegExp' | ||
export * from './src/isUndefined' | ||
export * from './src/isDate' | ||
export * from './src/isNumber' | ||
export * from './src/isPromise' | ||
export * from './src/isFunction' | ||
export * from './src/isArray' | ||
export * from './src/isBigInt' | ||
export * from './src/isSymbol' | ||
export * from './src/isFalse' | ||
export * from './src/isTrue' | ||
export * from './src/isNaN' | ||
export * from './src/isMap' | ||
export * from './src/isBoolean' | ||
export * from './src/isSet' | ||
export * from './src/isArray' | ||
export * from './src/isObject' | ||
export * from './src/isMobile' | ||
export * from './src/isEmail' | ||
export * from './src/isDate' | ||
export * from './src/isElement' | ||
export * from './src/isHttp' | ||
export * from './src/isLowerCase' | ||
export * from './src/isEmptyObject' | ||
export * from './src/isEmail' | ||
export * from './src/isEmptyArray' | ||
export * from './src/isEmptyObject' | ||
export * from './src/isError' | ||
export * from './src/isFalse' | ||
export * from './src/isFunction' | ||
export * from './src/isHttp' | ||
export * from './src/isIDCard' | ||
export * from './src/isLowerCase' | ||
export * from './src/isMap' | ||
export * from './src/isMobile' | ||
export * from './src/isNaN' | ||
export * from './src/isNull' | ||
export * from './src/isNumber' | ||
export * from './src/isNumberString' | ||
export * from './src/isObject' | ||
export * from './src/isPromise' | ||
export * from './src/isRegExp' | ||
export * from './src/isSet' | ||
export * from './src/isString' | ||
export * from './src/isSymbol' | ||
export * from './src/isTrue' | ||
export * from './src/isType' | ||
export * from './src/isUndefined' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import process from 'node:process' | ||
import fs from 'node:fs' | ||
import prompts from '@posva/prompts' | ||
import ora from 'ora' | ||
import { loadFunction, loadSubpackage, packagePrefix, resolveRealPath, spinnersPrefixText, toCamelCase, writeSubpackageFunction, writeSubpackageFunctionTest } from './utils' | ||
|
||
const [, , ...args] = process.argv | ||
|
||
// 写子包的index.ts - 这里侧重的是增加导出 | ||
function writeSubpackageIndex(subpackageName: string, functionName: string) { | ||
const exportPath = resolveRealPath(`../packages/${subpackageName}/index.ts`) | ||
let exportContent = fs.readFileSync(exportPath, 'utf-8').trim().split('\n').sort().join('\n') | ||
exportContent += '\n' + `export * from './src/${functionName}'` + '\n' | ||
fs.writeFileSync(exportPath, exportContent) | ||
} | ||
|
||
// 创建函数 | ||
export async function createFunction() { | ||
let subpackageName = args[0] | ||
let functionName = args[1] | ||
const { choices } = loadSubpackage() | ||
if (!subpackageName || !functionName) { | ||
// 无参调起交互式命令行 | ||
const response = await prompts([ | ||
{ | ||
name: 'subpackage', | ||
type: 'select', | ||
message: '请选择子包', | ||
choices, | ||
}, | ||
{ | ||
name: 'name', | ||
type: 'text', | ||
message: '请输入函数名称', | ||
validate: (value) => { | ||
if (!value.trim()) { | ||
return '请输入函数名称' | ||
} | ||
return true | ||
}, | ||
}, | ||
]) | ||
subpackageName = response.subpackage.trim() | ||
functionName = response.name.trim() | ||
} | ||
|
||
// 转换为小驼峰 | ||
functionName = toCamelCase(functionName!) | ||
|
||
const { dirNames: functionDirNames } = loadFunction(subpackageName!) | ||
|
||
// 校验方法是否存在 | ||
if (functionDirNames.includes(functionName)) { | ||
return console.error(`方法${functionName}已存在`) | ||
} | ||
|
||
const spinners = ora() | ||
spinners.text = `${spinnersPrefixText}创建[${packagePrefix}/${subpackageName}] => ${functionName}中...` | ||
spinners.start() | ||
writeSubpackageIndex(subpackageName!, functionName) | ||
writeSubpackageFunction(subpackageName!, functionName) | ||
writeSubpackageFunctionTest(subpackageName!, functionName) | ||
spinners.succeed(`${spinnersPrefixText}创建[${packagePrefix}/${subpackageName}] => ${functionName}成功`) | ||
} | ||
|
||
await createFunction() |
Oops, something went wrong.