Skip to content

Commit

Permalink
Merge pull request #2 from aceHubert/feature/env
Browse files Browse the repository at this point in the history
feat: add function getEnvOrThrow
  • Loading branch information
aceHubert committed Mar 25, 2024
2 parents edd8b14 + f0d21da commit 8310811
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 22 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/check-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check PR title
on:
pull_request_target:
types:
- opened
- reopened
- edited
- synchronize


permissions:
statuses: write

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: aslafy-z/conventional-pr-title-action@v3
with:
preset: "@commitlint/config-conventional@^12.1.4"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26 changes: 26 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Check Commit spec

on:
push:
branches: [master]
pull_request:
branches: [master]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:


permissions:
contents: read
pull-requests: read

jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0=
- uses: wagoid/commitlint-github-action@v3
env:
NODE_PATH: ${{ github.workspace }}/node_modules
31 changes: 14 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
# Fetch Provider
# Utils
公共工具库

> Vue 模块通过打包成 lib 的umd 脚本文件独立布置在任何远端服务器上,
> 主程序能过调用远程 umd 脚本文件动态渲染到前端页面

<br>
<br>

[Core](./packages/core/README.md)
[axios adapter](./packages/axios/README.md)
[cross-fetch adapter(开发中)](./packages/corss-fetch/README.md)
[vue adapter](./packages/vue/README.md)
[Core](./packages/core/README.md)

<br>
<br>

## 开发注意事项

### changelog
`lerna-changelog`基于`pr`来为项目生成`changelog`

`lerna-changelog`基于`pr`来为项目生成`changelog`

<strong>使用步骤</strong>

1、从`master`分支切换出`feature`/`bugfix`等分支。
2、完成开发后进行`commit`,推荐使用`commitizen`来规范`commit msg`,同时有助于对后续子项目生成`changelog`
3、将新分支`push``remote`端。
4、创建`pr`,并打上`label`,此处一定要打上`label``learn-changelog`就是根据label来确定该`pr`属于`feature`/`bugfix`/`document`等。
4、创建`pr`,并打上`label`,此处一定要打上`label``learn-changelog`就是根据 label 来确定该`pr`属于`feature`/`bugfix`/`document`等。
5、切记要在`merge`之前打上`label`
6、进行`merge` `pr`操作。
7、本地切换到`master`分支并进行`pull操`作。
8、执行`lerna-changelog`,既可得到一份`changeling`
8、执行`lerna-changelog`,既可得到一份`changeling`

<strong>注意</strong>

1、`pr``label`并不能随意设置,一定要在项目中声明对应才生效。
官方默认支持`breaking`/`enhancement`/`bug`/`documentation`/`internal`,如果想用其他,则需要在package.json中进行相应的配置。
``` json
1、`pr``label`并不能随意设置,一定要在项目中声明对应才生效。
官方默认支持`breaking`/`enhancement`/`bug`/`documentation`/`internal`,如果想用其他,则需要在 package.json 中进行相应的配置。

```json
{
"changelog": {
"labels": {
Expand All @@ -47,9 +42,11 @@
}
}
```

2、src/version 在 publish 时自动更新版本号,不需要手动修改。发布后不需要签入。

<br>

### 子项目的changelog
### 子项目的 changelog

具体还需参考[README](https://github.com/lerna/lerna/blob/514bc57a53/commands/version/README.md#--conventional-commits)
23 changes: 18 additions & 5 deletions packages/core/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@ import get from 'lodash.get';

/**
* get key from object
* @param key key
* @param path path
* @param defaultValue default value
* @param obj object, default: process.env
* @returns value
* @returns env value
* @example getEnv('NODE_ENV', 'development')
* @example getEnv('a.b.c', 0, {a: {b: {c: 1}}}})
*/
export const getEnv = <R = any>(key: string, defaultValue: R, obj: object = process.env): R => {
return get(obj || {}, key, defaultValue);
export const getEnv = <R = any>(path: string | number, defaultValue: R, obj: object = process.env): R => {
return get(obj || {}, path, defaultValue);
};


/**
* get key from object or throw error
* @param key key
* @param obj object, default: process.env
* @returns env value
* @example getEnvOrThrow('NODE_ENV')
*/
export const getEnvOrThrow = <R = any>(path: string | number, obj: object = process.env): R => {
const value = get(obj || {}, path);
if (value === undefined) {
throw new Error(`env ${path} is required`);
}
return value;
};

0 comments on commit 8310811

Please sign in to comment.