Skip to content

deploy project dist to ali-oss with version. 将项目的打包输出文件夹文件输出到阿里云oss

License

Notifications You must be signed in to change notification settings

microJ/ali-oss-deploy-with-version

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ali-oss-deploy-with-version

Install

3 ways:

  1. clone this repo, and require ./index.js

  2. npm install --save-dev ali-oss-deploy-with-version

  3. yarn add --dev ali-oss-deploy-with-version

Usage

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

API

deploy2OSS

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 property filename and content.filename is path relative to aliOSSBasePath.

  • rename: Optional. A function that receive file path relative to localFolderPath and return a new file path.

License

MIT

About

deploy project dist to ali-oss with version. 将项目的打包输出文件夹文件输出到阿里云oss

Resources

License

Stars

Watchers

Forks

Packages

No packages published