From f4bc3c290d04065eb126cba18ab84603e2462666 Mon Sep 17 00:00:00 2001 From: Ara Yeressian Date: Wed, 24 Jun 2020 22:47:59 +0400 Subject: [PATCH] WIP --- .gitignore | 1 - action.yml | 7 +++++-- dist/index.js | 18 ++++++++++++++++++ dist/index.js.map | 1 + dist/uploader.js | 28 ++++++++++++++++++++++++++++ dist/uploader.js.map | 1 + package.json | 5 +++-- tsconfig.json | 7 +++++-- 8 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 dist/index.js create mode 100644 dist/index.js.map create mode 100644 dist/uploader.js create mode 100644 dist/uploader.js.map diff --git a/.gitignore b/.gitignore index 76add87..3c3629e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ node_modules -dist \ No newline at end of file diff --git a/action.yml b/action.yml index 3e768a8..d47a271 100644 --- a/action.yml +++ b/action.yml @@ -10,5 +10,8 @@ inputs: apiKey: required: true runs: - using: 'node12' - main: 'index.js' + using: 'node14' + main: 'dist/index.js' +branding: + icon: 'upload-cloud' + color: 'orange' diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..8adcfe1 --- /dev/null +++ b/dist/index.js @@ -0,0 +1,18 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const uploader_1 = __importDefault(require("./uploader")); +const core_1 = __importDefault(require("@actions/core")); +const path_1 = require("path"); +try { + const source = core_1.default.getInput('source'); + const storageZoneName = core_1.default.getInput('storageZoneName'); + const accessKey = core_1.default.getInput('accessKey'); + uploader_1.default(path_1.resolve(source), storageZoneName, accessKey); +} +catch (error) { + core_1.default.setFailed(error.message); +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map new file mode 100644 index 0000000..6f24607 --- /dev/null +++ b/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,0DAAkC;AAClC,yDAAiC;AACjC,+BAA6B;AAE7B,IAAI;IACF,MAAM,MAAM,GAAG,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,eAAe,GAAG,cAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,cAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC7C,kBAAQ,CAAC,cAAO,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC;CACvD;AAAC,OAAO,KAAK,EAAE;IACd,cAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;CAC/B"} \ No newline at end of file diff --git a/dist/uploader.js b/dist/uploader.js new file mode 100644 index 0000000..89d9683 --- /dev/null +++ b/dist/uploader.js @@ -0,0 +1,28 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs_1 = __importDefault(require("fs")); +const node_fetch_1 = __importDefault(require("node-fetch")); +const readdirp_1 = __importDefault(require("readdirp")); +function uploadFile(entry, storageName, accessKey) { + const stats = fs_1.default.statSync(entry.fullPath); + const fileSizeInBytes = stats.size; + let readStream = fs_1.default.createReadStream(entry.fullPath); + return node_fetch_1.default(`https://storage.bunnycdn.com/${storageName}/${entry.path}`, { + method: 'POST', + headers: { + "AccessKey": accessKey, + "Content-length": fileSizeInBytes.toString() + }, + body: readStream + }); +} +async function run(path, storageName, accessKey) { + for await (const entry of readdirp_1.default(path)) { + uploadFile(entry, storageName, accessKey); + } +} +exports.default = run; +//# sourceMappingURL=uploader.js.map \ No newline at end of file diff --git a/dist/uploader.js.map b/dist/uploader.js.map new file mode 100644 index 0000000..ca3fb09 --- /dev/null +++ b/dist/uploader.js.map @@ -0,0 +1 @@ +{"version":3,"file":"uploader.js","sourceRoot":"","sources":["../src/uploader.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,4DAA+B;AAC/B,wDAAgC;AAEhC,SAAS,UAAU,CAAC,KAAyB,EAAE,WAAmB,EAAE,SAAiB;IACnF,MAAM,KAAK,GAAG,YAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC;IAEnC,IAAI,UAAU,GAAG,YAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAErD,OAAO,oBAAK,CAAC,gCAAgC,WAAW,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE;QACxE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,WAAW,EAAE,SAAS;YACtB,gBAAgB,EAAE,eAAe,CAAC,QAAQ,EAAE;SAC7C;QACD,IAAI,EAAE,UAAU;KACjB,CAAC,CAAC;AACL,CAAC;AAEc,KAAK,UAAU,GAAG,CAAC,IAAY,EAAE,WAAmB,EAAE,SAAiB;IACpF,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,kBAAQ,CAAC,IAAI,CAAC,EAAE;QACxC,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;KAC3C;AACH,CAAC;AAJD,sBAIC"} \ No newline at end of file diff --git a/package.json b/package.json index dc5c7ff..4f1f50c 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,11 @@ "name": "bunnycdn-storage-deploy", "version": "1.0.0", "description": "", - "main": "index.js", + "main": "dist/index.js", "scripts": { "start": "tsc && node dist/test.js", - "test": "jest --watch" + "test": "jest --watch", + "build": "tsc" }, "repository": { "type": "git", diff --git a/tsconfig.json b/tsconfig.json index 00f1fdd..b25e2f9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,5 +11,8 @@ "noImplicitAny": true, "esModuleInterop": true, "resolveJsonModule": true, - } -} \ No newline at end of file + }, + "include": [ + "src" + ] +}