3 ways:
-
clone this repo, and require
./index.js -
npm install --save-dev ali-oss-deploy-with-version -
yarn add --dev ali-oss-deploy-with-version
const deploy2OSS = require("ali-oss-deploy-with-version")
const OSS = require("ali-oss")
const path = require("path")
const OSSClient = new OSS({
region: "",
bucket: "",
accessKeyId: "",
accessKeySecret: ""
})
const currentVersion = "20181106"
deploy2OSS(OSSClient, {
localFolderPath: path.resolve(__dirname, "../dist"),
aliOSSBasePath: "/demo/",
aliOSSFolderName: currentVersion,
filesAlsoCopy2Base: [/\.html/],
extendedFiles: [
{
filename: "info.json", // relative to aliOSSBasePath
content: `{currentVersion:${currentVersion}}`
},
{
filename: "test/index.txt",
content: "hello world!"
}
],
rename(file) {
if (/\.js$/.test(file)) {
const dotIndex = file.lastIndexOf(".")
return file.slice(0, dotIndex) + ".hash.js"
}
}
}).then(isAllJobDoneSuccess => {
if (isAllJobDoneSuccess) {
console.log("xixixi")
} else {
// balabala
}
})local files:
dist/
|-- hello/
|-- hi.js
|-- index.html
|-- index.js
files deployed with version 20181106 on ali-oss:
demo/
|-- 20181106/
|-- hello/
|-- hi.js
|-- index.html
|-- index.js
|-- test/
|-- index.txt
|-- index.html
|-- info.json
function deploy2OSS will return promise to recieve wheather all job done success.
const deploy2OSS = require("../index")
// Or require from package
const deploy2OSS = require("ali-oss-deploy-with-version")
deploy2OSS(aliOSSInstance, options).then(isAllJobDoneSuccess => {})aliOSSInstance:
const OSS = require("ali-oss")
const aliOSSInstance = new OSS({
region: "",
bucket: "",
accessKeyId: "",
accessKeySecret: ""
})options:
-
localFolderPath: Mandatory.
-
aliOSSBasePath: Mandatory.
-
aliOSSFolderName: Optional.
-
filesAlsoCopy2Base: Optional.
Array<RegExp>. Files matched RegExp will copy to aliOSSBaseFolder. -
extendedFiles: Optional.
Array<Object>. Define content will be created and upload to ali-oss.Each element has propertyfilenameandcontent.filenameis path relative to aliOSSBasePath. -
rename: Optional. A function that receive file path relative to
localFolderPathand return a new file path.
MIT