0.1.3 • Published 5 years agoCLI
k-toolkit-node
Licence
ISC
Version
0.1.3
Deps
6
Size
51 kB
Vulns
1
Weekly
0
DeprecatedThis package is deprecated
KToolkit
Install
npm install k-toolkit-node
CLI Usage
Usage: k-toolkit-node [options] [command]
Options:
-v, --version output the current version
-p, --project-path <path> set local config path (default: process.cwd())
-u, --remote-url <url> set remote config url (default: "https://s3.shiyou.kingsoft.com/neon/client-framework/ks-framework.json")
-h, --help display help for command
Commands:
create <projectName>
init <repositoryUrl>
init-local
install-plugin <pluginName>
uninstall-plugin <pluginName>
help [command] display help for command
API
KToolkit
import { KToolkit } from 'k-toolkit-node';
let toolkit = new KToolkit(...);
toolkit.createProject(...);
createProject
创建一个新工程
| Param | Type | Description |
|---|---|---|
| projectName | string | 工程名称 |
| projectPath | string | 工程保存路径 |
initProject
通过Git仓库初始化一个工程
| Param | Type | Description |
|---|---|---|
| repositoryUrl | string | Git仓库地址 |
| projectPath | string | 工程保存路径 |
initLocalProject
初始化一个本地已有的工程
| Param | Type | Description |
|---|---|---|
| None | None | None |
installPlugin
安装一个插件
| Param | Type | Description |
|---|---|---|
| pluginName | string | 插件名称 |
| pluginInfo | PluginInfo | 插件具体信息,通过Config获取 |
uninstallPlugin
卸载一个插件
| Param | Type | Description |
|---|---|---|
| pluginName | string | 插件名称 |
updatePlugin
更新一个插件
| Param | Type | Description |
|---|---|---|
| pluginName | string | 插件名称 |
utils
import { utils } from 'k-toolkit-node';
utils.renameFiles(...);
renameFiles
递归修改目录、文件名
| Param | Type | Description |
|---|---|---|
| dir | string | 待修改名称根路径 |
| from | string / RegExp | 替换前字符 |
| to | string | 替换后字符 |
| recursive | boolean | 是否递归替换所有子路径,默认true |
exec
childProcess exec的Promise封装
| Param | Type | Description |
|---|---|---|
| command | string | 待执行的命令 |
| options | child_process.ExecOptions | 命令执行选项 |
| returns | promise | 命令执行结果 |
projectNameValidator
项目名称验证函数
| Param | Type | Description |
|---|---|---|
| projectName | string | 项目名称 |
| returns | string|null | 名称有效时返回null,无效时返回原因字符串 |
isValidProjectPath
项目路径是否有效(目录不存在或为空目录即有效)
| Param | Type | Description |
|---|---|---|
| projectPath | string | 项目路径 |
| returns | boolean | 路径是否有效 |
buildLocalConfig
根据配置路径构造本地配置对象
| Param | Type | Description |
|---|---|---|
| projectPath | string | 项目路径 |
| returns | LocalConfig | undefined | 本地配置对象 |
downloadRemoteConfig
根据配置地址下载远程配置对象
| Param | Type | Description |
|---|---|---|
| remoteConfigUrl | string | 配置地址 |
| returns | Promise<RemoteConfig | undefined> | 远程配置对象 |
addToGitIgnore
添加记录到gitignore
| Param | Type | Description |
|---|---|---|
| repositoryPath | string | git本地仓库地址 |
| ignoreContent | string | 需要添加的ignore内容 |
| matchLine | string | 匹配行,找到的话把ignoreContent插到这行后,没找到在文件尾插入该行内容和ignoreContent |
removeFromGitIgnore
从gitignore中移除记录
| Param | Type | Description |
|---|---|---|
| repositoryPath | string | git本地仓库地址 |
| ignoreContent | string | 需要移除的ignore内容 |