ali-oss-publish
v0.4.0
Published
a cli interface of publish resources to ali oss
Downloads
76
Readme
ali-oss-publish
a cli interface of publish resources to ali-oss
Installation
yarn add ali-oss-publish
Api
publish: function(options: object[, cb: function(err: Error, stats: Stats)]): Promise
options: object
: publish optionsoptions.id: string
: accessKeyId in ali oss, see ali-oss-optionsoptions.secret: string
: accessKeySecret in ali oss, see ali-oss-optionsoptions.token: string
: stsToken in ali oss, see ali-oss-optionsoptions.region: string,
: region in ali oss, see ali-oss-optionsoptions.bucket: string,
: bucket in ali oss, see ali-oss-optionsoptions.entry = '.': string
: entry point, defaults to "."options.include: ?RegExp
: match files will publish to ali ossoptions.exclude: ?RegExp
: match files will ignore to publish to ali ossoptions.mime: ?(string|function(path: string): string|void)
: custom mime to all files, see ali-oss-put-file-optionsoptions.meta: ?(object|function(path: string): object|void)
: custom meta to all files, see ali-oss-put-file-optionsoptions.headers: ?(object|function(path: string): object|void)
: custom headers to all files, see ali-oss-put-file-optionsoptions.rules = []: Array<object>
: custom operations options for the match files, defaults to []options.rules[].test: ?RegExp|boolean
: match files or the test is true will apply custom operationsoptions.rules[].include: ?RegExp
: match files will apply custom operationsoptions.rules[].exclude: ?RegExp
: match files will ignore to apply custom operationsoptions.rules[].use: ?object
: custom operationsoptions.rules[].use.mime: ?(string|function(path: string): string|void)
: custom mime to the match files, see ali-oss-put-file-optionsoptions.rules[].use.meta: ?(object|function(path: string): object|void)
: custom meta to the match files, see ali-oss-put-file-optionsoptions.rules[].use.headers: ?(object|function(path: string): object|void)
: custom headers to the match files, see ali-oss-put-file-options
options.output = '.': string
: output path for publish to ali oss, defaults to "."options.force: boolean
: force remove the files that not in the publish entryoptions.config: string
: path to the config file, defaults to try load config from "ali-oss-publish.config.js" when config is not setoptions.retry: ?number
: retry times when encountered non-fatal errorsoptions.concurrency: ?number
: concurrency for publish
cb = noop: function(err: Error[, stats: Stats])
: callback function, defaults to nooperr: Error
: fatal errorstats: Stats
: publish statsstats.message: string
: message for statsstats.type: ?string
: type for statsstats.index: ?number
: concurrency indexstats.current: ?number
: current stepstats.total: ?number
: total stepstats.warnings: ?Array<string>
: warnings for statsstats.errors: ?Array<Error>
: errors for statsstats.hasProgress: function(): boolean
: ensure whether has progressstats.hasWarnings: function(): boolean
: ensure whether has warningsstats.hasErrors: function(): boolean
: ensure whether has errors
- Returns
Promise
: promise
const publish = require('ali-oss-publish')
publish({
id: 'accessKeyId-in-ali-oss-options',
secret: 'accessKeySecret-in-ali-oss-options',
token: 'stsToken-in-ali-oss-options',
region: 'region-in-ali-oss-options',
bucket: 'bucket-in-ali-oss-options',
entry: '/path/to/publish/files', // defaults to '.'
include: /bin|cli|lib|index\.js$|\.md$/,
exclude: /.DS_Store$/,
mime: (filename) => {
if (/\.md$/.test(filename)) {
return 'text/markdown'
}
return undefined
},
meta: {
ref: Date.now()
},
headers: {
'Cache-Control': 'max-age=30672000'
},
rules: [{
test: /(index\.html|service-worker\.js)$/,
use: {
headers: {
'Cache-Control': 'no-cache'
}
}
}],
output: '/path/to/ali-oss/to/publish',
config: '/path/to/config/file.js', // defaults to try load config from 'ali-oss-publish.config.js' when config is not set
retry: 1,
concurrency: 4,
force: true
}, (err, stats) => {
if (err) {
console.error('ali-oss-publish encountered a fatal error.')
console.error(err)
process.exit(1)
}
if (stats.hasProgress()) {
const {
type,
index,
current,
total,
message
} = stats
console.log('[%s] [%s/%s] #%s: %s', type, current, total, index, message)
} else {
console.log(stats.message)
}
if (stats.hasWarnings()) {
console.warn('ali-oss-publish encountered some warnings.')
stats.warnings.forEach((x) => {
console.warn(x)
})
}
if (stats.hasErrors()) {
console.error('ali-oss-publish encountered some errors.')
stats.errors.forEach((x) => {
console.error(x)
})
}
})
Cli
Usage: ali-oss-publish [options]
a cli interface of publish resources to ali oss
Options:
-V, --version output the version number
-i, --id <id> accessKeyId in ali oss
-s, --secret <secret> accessKeySecret in ali oss
-t, --token <token> stsToken in ali oss
-r, --region <region> region in ali oss
-b, --bucket <bucket> bucket in ali oss
-e, --entry <entry> entry point, defaults to "."
-o, --output <output> output path for publish to ali oss, defaults to "."
-c, --config <config> path to the config file, defaults to try load config from "ali-oss-publish.config.js" when config is not set
--retry <retry> retry times when encountered non-fatal errors
--concurrency <concurrency> concurrency for publish
--force force remove the files that not in the publish entry
-h, --help display help for command
Environment
Env Name | Config Name ------------------------|------------- ALI_OSS_PUBLISH_ID | id ALI_OSS_PUBLISH_SECRET | secret ALI_OSS_PUBLISH_TOKEN | token ALI_OSS_PUBLISH_REGION | regin ALI_OSS_PUBLISH_BUCKET | bucket ALI_OSS_PUBLISH_ENTRY | entry ALI_OSS_PUBLISH_OUTPUT | output
Config File
module.exports = {
// publish options
}
Options Override
EnvOptions < FileOptions < ParamsOptions