npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cosup

v0.2.2

Published

腾讯云对象存储(COS)资源上传命令行工具

Downloads

22

Readme

cosup

腾讯云对象存储(COS)资源上传命令行工具。

命令行

全局安装:

npm i -g cosup

或者安装在项目中:

npm i cosup

然后在 package.json 中加入 script:

{
  "scripts": {
    "deploy": "cosup -u xxx -p xxx -r ap-shanghai -b test-123456 dist /"
  }
}
cosup [src] [dest]

Upload files in [src] directory or single file to [dest] directory on COS.

Options:
  --help, -h          Show help                                        [boolean]
  --version, -v       Show version number                              [boolean]
  --config, -c        Path to JSON config file
  --secret-id, -u     SecretId                                        [required]
  --secret-key, -p    SecretKey                                       [required]
  --region, -r        Region                                          [required]
  --bucket, -b        Bucket                                          [required]
  --max-age, -e       Cache-Control: max-age header
                                [array] [default: -e "*.html" 10 -e "*" 2592000]
  --content-type, -t  set Content-Type of a file pattern. e.g. -t
                      apple-app-site-association application/json -t "*.foo"
                      text/plain                                         [array]
  --ignore, -i        Don' upload the files which matches the glob pattern. e.g.
                      -i "*.sh" -i ".gitignore"                          [array]
  --parallel, -n      Parallel upload limit               [number] [default: 10]
  --log, -l           Output logs to console           [boolean] [default: true]

Examples:
  cosup -u xxx -p xxx -r ap-shanghai -b test-123456 dist /

环境变量

参数可以通过 COS_* 前缀的环境变量传入,比如:

COS_SECRET_ID=xxx COS_SECRET_KEY=xxx COS_REGION=ap-shanghai COS_BUCKET=test-12345 cosup dist / 

在 CI 工具中配置环境变量,可以方便地作为参数传入。

配置文件

参数还可以通过 json 配置文件传入。比如:

cosup -c config.json

config.json:

{
  "secretId": "xxx",
  "secretKey": "xxx",
  "region": "ap-shanghai",
  "bucket": "test-12345",
  "src": "dist",
  "dest": "/",
  "maxAge": ["*.html", 10, "*", 2592000],
  "ignore": ["*.sh", ".gitignore"]
}

参数优先级

命令行参数 > 环境变量 > 配置文件

Windows 注意事项

在 Windows 的 Git Bash/MSYS2 命令行中,路径会被转换导致上传的文件路径不对,需要设置环境变量 MSYS_NO_PATHCONV=1

MSYS_NO_PATHCONV=1 cosup -c config.json dist /

作为模块使用

const cosup = require('cosup')
cosup({
  src,
  dest,
  secretId,
  secretKey,
  region,
  bucket,
  maxAge = ['*.html', 10, '*', 2592000],
  ignore
  parallel = 10
  log
})

src

String。源文件夹或文件

dest

String。COS 目标文件夹

secretId

String。开发者拥有的项目身份识别 ID,用以身份认证

secretKey

String。开发者拥有的项目身份密钥

region

String。域名中的地域信息。枚举值参见 可用地域 文档,如:ap-beijing, ap-hongkong, eu-frankfurt 等

bucket

String。COS 中用于存储数据的容器

maxAge

Array。文件的 Cache-Control: max-age 头信息。 格式:[pattern, maxAge, pattern, maxAge, ...]。 匹配 pattern 的文件的 max-agepattern 右边的元素值。数组顺序很重要,当找到第一条匹配的规则即停止寻找。 比如 ['*.html', 10, '*', 2592000]index.htmlmax-age 为 10 秒,favicon.pngmax-age 为 2592000 秒。

pattern 写法参考 glob

默认值:['*.html', 10, '*', 2592000]

contentType

Array。文件的 Content-Type 头信息。格式:[pattern, type, pattern, type, ...]

ignore

Array。不上传匹配的的文件。比如:['*.sh', '.gitignore']

parallel

Number。上传并发数。默认值:10

log

Boolean。是否在控制台打印上传进度。Cli 模式默认为 true, 作为模块使用默认为 false

License

MIT