UNPKG

2.12 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const endent_1 = tslib_1.__importDefault(require("endent"));
5const file_type_1 = tslib_1.__importDefault(require("file-type"));
6const fs_1 = tslib_1.__importDefault(require("fs"));
7const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
8const path_1 = tslib_1.__importDefault(require("path"));
9const util_1 = require("util");
10const stat = util_1.promisify(fs_1.default.stat);
11const readFile = util_1.promisify(fs_1.default.readFile);
12/** Attach extra assets to a GitHub Release */
13class UploadAssetsPlugin {
14 /** Initialize the plugin with it's options */
15 constructor(options) {
16 /** The name of the plugin */
17 this.name = 'Upload Assets';
18 this.options = Array.isArray(options) ? { assets: options } : options;
19 }
20 /** Tap into auto plugin points. */
21 apply(auto) {
22 auto.hooks.afterRelease.tapPromise(this.name, async ({ response }) => {
23 const assets = await fast_glob_1.default(this.options.assets);
24 auto.logger.log.info(endent_1.default `
25 Uploading:
26
27 ${assets.map(asset => `\t- ${asset}`).join('\n')}
28
29 `);
30 await Promise.all(assets.map(async (asset) => {
31 if (!auto.git || !response) {
32 return;
33 }
34 const file = await readFile(asset);
35 const stats = await stat(asset);
36 const type = file_type_1.default(file);
37 await auto.git.github.repos.uploadReleaseAsset({
38 url: response.data.upload_url,
39 file,
40 name: path_1.default.basename(asset),
41 headers: {
42 'content-length': stats.size,
43 'content-type': type ? type.mime : 'application/octet-stream'
44 }
45 });
46 auto.logger.log.success(`Uploaded asset: ${asset}`);
47 }));
48 });
49 }
50}
51exports.default = UploadAssetsPlugin;
52//# sourceMappingURL=index.js.map
\No newline at end of file