# k-toolkit-node

> - [Install](#install) - [CLI Usage](#cli-usage) - [API](#api) - [KToolkit](#ktoolkit) - [createProject](#createproject) - [initProject](#initproject) - [initLocalProject](#initlocalproject) - [installPlugin](#installplugin) -

Latest version **0.1.3** (published 2021-06-21) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install k-toolkit-node
pnpm add k-toolkit-node
yarn add k-toolkit-node
bun add k-toolkit-node
```

Provides the command `k-toolkit-cli`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2021-06-21 |
| First published | 2021-06-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 51.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | alanwalk |

## Links

- npm: https://www.npmjs.com/package/k-toolkit-node
- Repository: https://git.shiyou.kingsoft.com/neon/client-framework/k-toolkit-node
- npm.io page: https://npm.io/package/k-toolkit-node

## Dependencies (6)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [download](https://npm.io/package/download.md) ^8.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [commander](https://npm.io/package/commander.md) ^7.2.0
- [rename-files-b](https://npm.io/package/rename-files-b.md) ^1.0.1
- [replace-in-file](https://npm.io/package/replace-in-file.md) ^6.2.0

## Recent versions

- 0.1.3 (latest) — 2021-06-21
- 0.1.2 — 2021-06-21
- 0.1.1 — 2021-06-21
- 0.1.0 — 2021-06-01

## README

# KToolkit

- [Install](#install)
- [CLI Usage](#cli-usage)
- [API](#api)
  - [KToolkit](#ktoolkit)
    - [createProject](#createproject)
    - [initProject](#initproject)
    - [initLocalProject](#initlocalproject)
    - [installPlugin](#installplugin)
    - [uninstallPlugin](#uninstallplugin)
    - [updatePlugin](#updateplugin)
  - [utils](#utils)
    - [renameFiles](#renamefiles)
    - [exec](#exec)
    - [projectNameValidator](#projectnamevalidator)
    - [isValidProjectPath](#isvalidprojectpath)
    - [buildLocalConfig](#buildlocalconfig)
    - [downloadRemoteConfig](#downloadremoteconfig)
    - [addToGitIgnore](#addtogitignore)
    - [removeFromGitIgnore](#removefromgitignore)

## 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
``` typescript
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
``` typescript
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<boolean>          | 命令执行结果 |

#### 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内容 |

---
_Source: https://npm.io/package/k-toolkit-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
