diff --git a/index.js b/index.js index 2d9217b..45b4dd7 100644 --- a/index.js +++ b/index.js @@ -1,46 +1,58 @@ -'use strict'; -const {createHash} = require('crypto'); -const through2 = require('through2'); -const {readFile} = require('fs-extra'); +"use strict"; +const { createHash } = require("crypto"); +const through2 = require("through2"); +const { readFile } = require("fs-extra"); +const ejs = require("ejs"); const action = async context => { - const uploadEndpoint = 'https://api.vercel.com/v2/now/files'; - const deploymentEndpoint = 'https://api.vercel.com/v12/now/deployments'; - const Authorization = 'Bearer ' + context.config.get('token'); + const uploadEndpoint = "https://api.vercel.com/v2/now/files"; + const deploymentEndpoint = "https://api.vercel.com/v12/now/deployments"; + const Authorization = "Bearer " + context.config.get("token"); const filePath = await context.filePath(); const data = await readFile(filePath); - const sha = createHash('sha1') + const sha = createHash("sha1") .update(data) - .digest('hex'); + .digest("hex"); const stream = through2(); stream.write(data); stream.end(); - context.setProgress('Uploading…'); + context.setProgress("Uploading…"); await context.request(uploadEndpoint, { headers: { - 'Content-Type': 'application/octet-stream', - 'x-now-digest': sha, - 'x-now-size': data.length, + "Content-Type": "application/octet-stream", + "x-now-digest": sha, + "x-now-size": data.length, Authorization }, body: stream }); - context.setProgress('Creating Vercel deployment…'); + context.setProgress("Generating Landing Page…"); + const page = await ejs.renderFile( + __dirname + "/template.ejs", + { title: context.defaultFileName, format: context.format }, + { async: true } + ); + + context.setProgress("Creating Vercel deployment…"); const deploymentResponse = await context.request(deploymentEndpoint, { headers: { Authorization }, json: true, body: { - name: context.config.get('name'), + name: context.config.get("name"), files: [ { file: context.defaultFileName, sha, size: data.length + }, + { + file: "index.html", + data: page } ], projectSettings: { @@ -56,20 +68,20 @@ const action = async context => { }; const vercel = { - title: 'Share on Vercel', - formats: ['gif', 'mp4', 'webm', 'apng'], + title: "Share on Vercel", + formats: ["gif", "mp4", "webm", "apng"], action, config: { token: { - title: 'Vercel Personal Access Token', - description: 'Create one here https://vercel.com/account/tokens', - type: 'string', + title: "Vercel Personal Access Token", + description: "Create one here https://vercel.com/account/tokens", + type: "string", required: true }, name: { - title: 'Name used in the deployment URL', - type: 'string', - default: 'kapture', + title: "Name used in the deployment URL", + type: "string", + default: "kapture", required: true } } diff --git a/package-lock.json b/package-lock.json index 3f90b6a..be2be59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -231,7 +231,6 @@ "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, "requires": { "color-convert": "^1.9.0" } @@ -354,6 +353,11 @@ "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, + "async": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", + "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=" + }, "async-each": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.3.tgz", @@ -962,8 +966,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "base": { "version": "0.11.2", @@ -1081,7 +1084,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1224,7 +1226,6 @@ "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, "requires": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", @@ -1379,7 +1380,6 @@ "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, "requires": { "color-name": "1.1.3" } @@ -1387,8 +1387,7 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, "common-path-prefix": { "version": "1.0.0", @@ -1411,8 +1410,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "concordance": { "version": "3.0.0", @@ -1754,6 +1752,14 @@ "integrity": "sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=", "dev": true }, + "ejs": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.5.tgz", + "integrity": "sha512-dldq3ZfFtgVTJMLjOe+/3sROTzALlL9E34V4/sDtUd/KlBSS0s6U1/+WPE1B4sj9CXHJpL1M6rhNJnc9Wbal9w==", + "requires": { + "jake": "^10.6.1" + } + }, "emoji-regex": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", @@ -1845,8 +1851,7 @@ "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "eslint": { "version": "5.16.0", @@ -2748,6 +2753,14 @@ "dev": true, "optional": true }, + "filelist": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.1.tgz", + "integrity": "sha512-8zSK6Nu0DQIC08mUC46sWGXi+q3GGpKydAG36k+JDba6VRpkevvOWUW5a/PhShij4+vHT9M+ghgG7eM+a9JDUQ==", + "requires": { + "minimatch": "^3.0.4" + } + }, "filename-regex": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz", @@ -3682,6 +3695,17 @@ "isarray": "1.0.0" } }, + "jake": { + "version": "10.8.2", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.2.tgz", + "integrity": "sha512-eLpKyrfG3mzvGE2Du8VoPbeSkRry093+tyNjdYaBbJS9v17knImYGNXQCUV0gLxQtF82m3E8iRb/wdSQZLoq7A==", + "requires": { + "async": "0.9.x", + "chalk": "^2.4.2", + "filelist": "^1.0.1", + "minimatch": "^3.0.4" + } + }, "jest-docblock": { "version": "21.2.0", "resolved": "https://registry.npmjs.org/jest-docblock/-/jest-docblock-21.2.0.tgz", @@ -4198,7 +4222,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -6008,7 +6031,6 @@ "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, "requires": { "has-flag": "^3.0.0" }, @@ -6016,8 +6038,7 @@ "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" } } }, diff --git a/package.json b/package.json index df5ddba..04742ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kap-vercel", - "version": "0.3.0", + "version": "0.4.0", "description": "Share on Vercel", "main": "index.js", "scripts": { @@ -39,6 +39,7 @@ }, "homepage": "https://github.com/delianides/kap-vercel#readme", "dependencies": { + "ejs": "^3.1.5", "fs-extra": "^7.0.0", "through2": "^2.0.3" }, diff --git a/template.ejs b/template.ejs new file mode 100644 index 0000000..0fb88e0 --- /dev/null +++ b/template.ejs @@ -0,0 +1,80 @@ + + +
+ + + + <%if (format == 'webm' || format == 'mp4') { %> + + + + + <% } else { %> + + <% } %> + + +