1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const endent_1 = tslib_1.__importDefault(require("endent"));
|
5 | const file_type_1 = tslib_1.__importDefault(require("file-type"));
|
6 | const fs_1 = tslib_1.__importDefault(require("fs"));
|
7 | const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
|
8 | const path_1 = tslib_1.__importDefault(require("path"));
|
9 | const util_1 = require("util");
|
10 | const stat = util_1.promisify(fs_1.default.stat);
|
11 | const readFile = util_1.promisify(fs_1.default.readFile);
|
12 |
|
13 | class UploadAssetsPlugin {
|
14 |
|
15 | constructor(options) {
|
16 |
|
17 | this.name = 'Upload Assets';
|
18 | this.options = Array.isArray(options) ? { assets: options } : options;
|
19 | }
|
20 |
|
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 | }
|
51 | exports.default = UploadAssetsPlugin;
|
52 |
|
\ | No newline at end of file |