Skip to content

Commit

Permalink
feat(create): support mirror and template options
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 21, 2022
1 parent c19798c commit b956b81
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
58 changes: 58 additions & 0 deletions docs/guide/introduction/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,61 @@ git submodule add https://github.com/username/koishi-plugin-aircon.git plugins/a
```

## 使用 TypeScript

## 插件开发

若非额外说明,下面示例中的 `name` 均指插件的目录名而非包名。例如你在 `plugins/foo` 目录下有一个名为 `@bar/foo` 的插件,则构建此插件时你仍然只需要写 `npm run build foo`

### 创建新插件

```sh
npm run create [name]
```

创建一个新的插件工作区。

- name: 插件的短名或包名,缺省时将进行提问

### 构建源代码

```sh
npm run build [...name]
```

按依赖顺序构建插件相关的源代码,包括后端 + 前端。后端代码将输出到 `lib` 目录,前端代码将输出到 `dist` 目录。

- name: 要构建的插件列表,输入 `*` 或缺省时都表示全部

### 更新版本号

```sh
npm run bump [...name] [-1|-2|-3|-p|-v <ver>] [-r] [-s]
```

更新某些插件的版本号。当进行此操作时,其他相关插件的依赖版本也会同步更新,确保所有工作区内依赖的插件版本一致。

- name: 要发布的插件列表,输入 `*` 表示全部,缺省时无效果
- 版本选项:
- -1, --major: 跳到下一个大版本,例如 `3.1.4` -> `4.0.0`
- -2, --minor: 跳到下一个中版本,例如 `3.1.4` -> `3.2.0`
- -3, --patch: 跳到下一个小版本,例如 `3.1.4` -> `3.1.5`
- -p, --prerelease: 跳到下一个预览版本,具体行为如下
- 如果当前版本是 `alpha.x`,则跳到 `beta.0`
- 如果当前版本是 `beta.x`,则跳到 `rc.0`
- 如果当前版本是 `rc.x`,则移除 prerelease 部分
- 其他情况下,跳到下一个大版本的 `alpha.0`
- -v, --version: 设置具体的版本号
- 缺省情况:当前版本的最后一位递增
- 其他选项:
- -r, --recursive: 当更新一个插件的版本时,依赖其的插件也随时更新版本
- -s, --sync: 与云端进行同步,基于 npm 上的最新版本而非本地版本更新

### 发布插件

```sh
npm run publish [...name]
```

发布所有版本号发生变动的插件。

- name: 要发布的插件列表,输入 `*` 或缺省时都表示全部
7 changes: 5 additions & 2 deletions packages/create/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const cwd = process.cwd()
const argv = parse(process.argv.slice(2), {
alias: {
forced: ['f'],
mirror: ['m'],
template: ['t'],
},
})

Expand Down Expand Up @@ -90,8 +92,9 @@ async function prepare() {
async function scaffold() {
console.log(dim(' Scaffolding project in ') + project + dim(' ...'))

const mirror = process.env.GITHUB_MIRROR || 'https://hub.fastgit.xyz'
const url = `${mirror}/koishijs/boilerplate/archive/refs/heads/master.tar.gz`
const mirror = argv.mirror || 'https://github.com'
const template = argv.template || 'koishijs/boilerplate'
const url = `${mirror}/${template}/archive/refs/heads/master.tar.gz`

try {
const { data } = await axios.get<NodeJS.ReadableStream>(url, { responseType: 'stream' })
Expand Down

0 comments on commit b956b81

Please sign in to comment.