@abramstyle/deploy-tools 中文文档教程

发布于 6年前 浏览 20 项目主页 更新于 3年前

Deploy tools

一些用于完成部署的实用程序。

Upload your file to AWS S3

const path = require('path');
const { S3Uploader } = require('@abramstyle/deploy-tools');

const buildPath = path.resolve(__dirname, '../dist');

const uploadConfig = {
  bucket: 'YOUR_BUCKET_NAME',
  keyPrefix: 'YOUR_DIRECTORY_PREFIX',
};

async function startJob() {
  const uploader = new S3Uploader(uploadConfig);

  uploader.on('success', ({ count, finished, filename }) => {
    console.log(`progress: ${finished}/${count}. file ${filename} upload success.`);
  });
  uploader.on('done', () => {
    console.log('uploading finished.');
  });

  await uploader.uploadDir(buildPath);
}

console.log('initializing...');

startJob().then(() => {
  console.log('start upload...');
}).catch((error) => {
  console.error('file upload failed.', error);
});

API

constructor

interface UploaderConfig {
  bucket: string,
  keyPrefix: string,
}
public constructor(config: UploaderConfig)

uploadFile

public async uploadFile(filepath: string): Promise<any>

uploadDir

public async uploadDir(distDir: string): Promise<void>

Deploy tools

Some utils to finish your deployment.

Upload your file to AWS S3

const path = require('path');
const { S3Uploader } = require('@abramstyle/deploy-tools');

const buildPath = path.resolve(__dirname, '../dist');

const uploadConfig = {
  bucket: 'YOUR_BUCKET_NAME',
  keyPrefix: 'YOUR_DIRECTORY_PREFIX',
};

async function startJob() {
  const uploader = new S3Uploader(uploadConfig);

  uploader.on('success', ({ count, finished, filename }) => {
    console.log(`progress: ${finished}/${count}. file ${filename} upload success.`);
  });
  uploader.on('done', () => {
    console.log('uploading finished.');
  });

  await uploader.uploadDir(buildPath);
}

console.log('initializing...');

startJob().then(() => {
  console.log('start upload...');
}).catch((error) => {
  console.error('file upload failed.', error);
});

API

constructor

interface UploaderConfig {
  bucket: string,
  keyPrefix: string,
}
public constructor(config: UploaderConfig)

uploadFile

public async uploadFile(filepath: string): Promise<any>

uploadDir

public async uploadDir(distDir: string): Promise<void>
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文