Skip to content

升级项目基础依赖,优化构建流程、开发体验 #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/src/__mock__
/src/__tests__
/test/*
/test/
node_modules
dist
site
esm
umd
*.js
*.d.ts
*.test.ts
15 changes: 5 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
module.exports = {
extends: [
'@qiniu'
],
settings: {
"import/resolver": {
node: {
extensions: ['.js', '.ts'],
moduleDirectory: ['node_modules', 'src/']
}
}
root: true,
extends: ['@qiniu'],
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./packages/*/tsconfig.json'],
}
}
24 changes: 15 additions & 9 deletions .github/workflows/dev-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,32 @@ jobs:
- uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: 12
- run: npm install
- run: npm run lint
node-version: 16
- run: |
npm install
npm run boot
npm run lint
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: 12
- run: npm install
- run: npm run test
node-version: 16
- run: |
npm install
npm run boot
npm run test
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: 12
- run: npm install
- run: npm run build
node-version: 16
- run: |
npm install
npm run boot
npm run build
11 changes: 7 additions & 4 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm install
- run: npm run build
- run: npm publish
- run: |
npm install
npm run boot
npm run build
cd packages/qiniu-js/
npm publish --dry-run
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
.DS_Store
.vscode
node_modules
bower_components
demo/config.js
deploy.sh
npm-debug.log
dist
test/config.json
coverage
lib
esm
9 changes: 0 additions & 9 deletions .npmignore

This file was deleted.

62 changes: 28 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* [准备](#ready)
* [引入](#install)
* [使用](#usage)
* [运行示例](#demo)
* [本地开发](#develop)
* [说明](#note)
* [常见问题](#faq)

Expand Down Expand Up @@ -80,24 +80,12 @@ Qiniu-JavaScript-SDK 的示例 [Demo](http://jssdk-v2.demo.qiniu.io) 中的服

支持以下几种安装方式

* 直接使用静态文件地址:

```
https://cdnjs.cloudflare.com/ajax/libs/qiniu-js/<version>/qiniu.min.js

// 当上方资源链接访问不稳定时,可选使用下方资源链接
https://cdn.staticfile.org/qiniu-js/<version>/qiniu.min.js
```

通过 script 标签引入该文件,会在全局生成名为 `qiniu` 的对象


* 使用 NPM 安装

NPM 的全称是 Node Package Manager,是一个 [NodeJS](https://nodejs.org) 包管理和分发工具,已经成为了非官方的发布 Node 模块(包)的标准。如果需要更详细的关于 NPM 的使用说明,您可以访问 [NPM 官方网站](https://www.npmjs.com),或对应的 [中文网站](http://www.npmjs.com.cn/)

```shell
npm install qiniu-js
$ npm install qiniu-js
```

```Javascript
Expand All @@ -106,9 +94,22 @@ Qiniu-JavaScript-SDK 的示例 [Demo](http://jssdk-v2.demo.qiniu.io) 中的服
import * as qiniu from 'qiniu-js'
```

* 通过源码编译
* 直接通过 `script` 标签引入,通过这种方式将会在全局生成名为 `qiniu` 的对象

`git clone git@github.com:qiniu/js-sdk.git`,进入项目根目录执行 `npm install` ,执行 `npm run build`,即可在dist 目录生成 `qiniu.min.js`。
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/qiniu-js/<version>/qiniu.min.js"></script>
// 当上方资源链接访问不稳定时,可选用下方资源链接
<script src="https://cdn.staticfile.org/qiniu-js/<version>/qiniu.min.js"></script>
```

* 通过源码编译,依次执行以下命令即可在本地构建

``` bash
$ git clone git@github.com:qiniu/js-sdk.git
$ cd js-sdk
$ npm install
$ npm run build
```

<a id="usage"></a>

Expand Down Expand Up @@ -461,27 +462,20 @@ qiniu.compressImage(file, options).then(data => {

fopArr包含的具体管道操作解释见 [管道操作](https://developer.qiniu.com/dora/manual/processing-mechanism)

<a id="demo"></a>
<a id="develop"></a>

### 运行示例
### 本地开发

1. 进入 test 目录,按照目录下的 `config.json.example` 示例,创建 `config.json` 文件,其中,`Access Key` 和 `Secret Key` 按如下方式获取

* [开通七牛开发者帐号](https://portal.qiniu.com/signup)
* [登录七牛开发者自助平台,查看 AccessKey 和 SecretKey](https://portal.qiniu.com/user/key) 。

```javascript
{
"AccessKey": "<Your Access Key>",
"SecretKey": "<Your Secret Key>",
"Bucket": "<Your Bucket Name>",
"Port": 9000,
"UptokenUrl": "<Your Uptoken_Url>", // demo 启动后会在本地 /uptoken 上提供获取 uptoken 的接口,所以这里可以填 'token'
"Domain": "<Your Bucket Domain>" // Bucket 的外链默认域名,在 Bucket 的内容管理里查看,如:'http://xxx.bkt.clouddn.com/'
}
```
```bash
$ git clone git@github.com:qiniu/js-sdk.git
$ cd js-sdk/
$ npm install
$ npm run boot
$ npm run dev
```

2. 进入项目根目录,执行 `npm install` 安装依赖库,然后打开两个终端,一个执行 `npm run serve` 跑 server, 一个执行 `npm run dev` 运行服务;demo1:`http://0.0.0.0:8080/test/demo1`;demo3:`http://0.0.0.0:8080/test/demo3`;demo1为测试上传功能的示例,demo3为测试图片压缩功能的示例;demo2 为测试 es6 语法的示例,进入 demo2 目录,执行 `npm install`,然后 `npm start` 运行 demo2;demo1、demo2 和 demo3 都共用一个 server,请注意 server 文件里的 `region` 设置跟 `config` 里的`region` 设置要保持一致。
打开您的浏览器并访问终端中提示的地址即可访问开发调试页面。
如果你在使用 `vscode`,推荐通过根目录下的 `js-sdk.code-workspace` 文件打开工作空间快速进行开发和调试。

<a id="note"></a>

Expand Down
25 changes: 15 additions & 10 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
function getProjectConfig(name) {
return {
displayName: name,
testEnvironment: 'jsdom',
transform: {
".ts": 'ts-jest'
},
testMatch: [`<rootDir>/packages/${name}/src/**/*.test.ts`],
}
}

module.exports = {
transform: {
".ts": 'ts-jest'
},
testRegex: '.+\\.test\\.ts$',
testPathIgnorePatterns: [
"esm",
"lib",
"examples",
"node_modules"
projects: [
getProjectConfig('qiniu-js'),
getProjectConfig('doc-site')
]
};
}
16 changes: 16 additions & 0 deletions js-sdk.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"folders": [
{
"name": "✨ root",
"path": "."
},
{
"name": "📦 dev-test",
"path": "packages/dev-test"
},
{
"name": "📦 qiniu-js",
"path": "packages/qiniu-js"
}
]
}
8 changes: 8 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"packages": [
"packages/*"
],
"useNx": false,
"npmClient": "npm",
"version": "independent"
}
Loading