0.10.1 • Published 2 years ago
cos-cdn-test v0.10.1
nbugs-ship-cdn
ship web assets to the CDN mirror server
Usage
建议 nbugs-ship-cdn
用于与 package.json
文件相同目录下执行,因为它会读出 package.json
文件的 name
和 version
作为参数。
将单个文件发布到 CDN 源站:
nbugs-ship-cdn public/index.js
将多个文件发布到 CDN 源站:
nbugs-ship-cdn "public/**"
手动设置参数:
nbugs-ship-cdn "**/*" --name nbugs --version 1.0.0 --force
通过 node 模块编写自定义脚本:
const shipCDN = require('nbugs-ship-cdn');
// 设置发布选项
const options = {
// 项目名称
name: "nbugs",
// 项目版本
version: "1.0.0",
// 是否可以覆盖
force: false, // overwrite flag
// 单个文件发送前的回调函数
itemBeforeShip: () => {},
// 单个文件的发布回调函数
itemCallback: () => {}
}
// ship 单个文件
shipCDN(__dirname + '/index.js', options);
// 使用数组 ship 多个文件
shipCDN([__dirname + '/index.js', __dirname + '/index.css'], options);
// 使用 glob 语法 ship 多文件
shipCDN.ship(__dirname + '/**', options);
// ship 回调
shipCDN.ship(file, options, (err, result) => {
});
Changelog
v2.0.0
- 使用 async 框架限制每次同时上传的文件个数最大为 5 个
- 记录上传过程中出错的文件,任务完成之后,如果文件上传出错,1 秒钟后会对出错的文件进行重试,最多重试 3 次
- 增加 eslint 语法检查
v3.0.3
- 在不影响原来项目上传逻辑的情况下,增加自定义上传文件/目录至腾讯云 cos 功能
1.命令:
cos-cdn [files] [--directoryPath directoryPath] [--jsPolyfill] [--compress] [--jsCompress] [--imgCompress] [--cdnRefresh] [--cdnPathTxt] [--cdnDomain cdnDomain] [--secretId secretId] [--secretKey secretKey] [--cdnSecretId cdnSecretId] [--cdnSecretKey cdnSecretKey]
2.例子:
cos-cdn dist/** example/index.js C:/Users/h_s_z_/Desktop/desktop.txt --directoryPath named-20220721 --jsPolyfill --compress --cdnRefresh
3.参数:
参数 | 类型 | 是否必传 | 备注 | ||||
---|---|---|---|---|---|---|---|
files | string(以空格隔开) | 是 | 文件或目录,需要遵循glob规范 | ||||
directoryPath | string | 否 | 上传到 cos 的目录 | ||||
jsPolyfill | boolean | 否 | 是否转译 js | ||||
compress | boolean | 否 | 是否压缩文件(包括 js 和图片) | ||||
jsCompress | boolean | 否 | 是否压缩 js | ||||
imgCompress | boolean | 否 | 是否压缩图片(仅支持png/jpeg/svg/gif) | cdnRefresh | boolean | 否 | 是否刷新 cdn 缓存 |
cdnPathTxt | boolean | 否 | 是否下载上传到 cos 的所有文件路径列表 | ||||
cdnDomain | string | 否 | cdn 域名,默认是 https://s.xiaoyuanhao.com | ||||
secretId | string | 否 | cos 服务秘钥字段,默认是 AKIDGK8gwvd5GAnAGJ8h01lERM0MTJDqCJ9h | ||||
secretKey | string | 否 | cos 服务秘钥字段,默认是 IK4XjeIfkY6NO8cojNkqfDTTCdnhKhne | ||||
cdnSecretId | string | 否 | cdn 服务秘钥字段,默认是 AKIDymSxFJCuPgleLn2IQMBuBF7mCOXZNyQg | ||||
cdnSecretKey | string | 否 | cdn 服务秘钥字段,默认是 95nJdnohvwoXCgw3xfCYigT6ZqwqZ6Qb |