From bb8e77dc70fbbd1570caeb570d0c1c5969cc077b Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Sun, 23 Aug 2020 16:37:24 -0400 Subject: [PATCH] Updated admin scripts. --- admin/cmds/publish.js | 102 +++++++++++++++++++++++++++++++++++--- admin/cmds/serve-docs.js | 2 +- admin/cmds/spell-check.js | 8 +-- 3 files changed, 99 insertions(+), 13 deletions(-) diff --git a/admin/cmds/publish.js b/admin/cmds/publish.js index a06b9b42c..845d1fb0b 100644 --- a/admin/cmds/publish.js +++ b/admin/cmds/publish.js @@ -1,5 +1,10 @@ "use strict"; +const { basename, resolve } = require("path"); +const fs = require("fs"); + +const AWS = require('aws-sdk'); + const config = require("../config"); const { ChangelogPath, latestChange } = require("../changelog"); @@ -33,6 +38,45 @@ if (process.argv.length > 2) { dirnames = dirnames.filter((dirname) => (filter.indexOf(dirname) >= 0)); } + +function putObject(s3, info) { + return new Promise(function(resolve, reject) { + s3.putObject(info, function(error, data) { + if (error) { + reject(error); + } else { + resolve({ + name: info.Key, + hash: data.ETag.replace(/"/g, '') + }); + } + }); + }); +} + +function invalidate(cloudfront, distributionId) { + return new Promise((resolve, reject) => { + cloudfront.createInvalidation({ + DistributionId: distributionId, + InvalidationBatch: { + CallerReference: `${ USER_AGENT }-${ parseInt(((new Date()).getTime()) / 1000) }`, + Paths: { + Quantity: "1", + Items: [ + "/\*" + ] + } + } + }, function(error, data) { + if (error) { + console.log(error); + return; + } + resolve(data.Invalidation.Id); + }); + }); +} + (async function() { let token = null; @@ -98,27 +142,69 @@ if (process.argv.length > 2) { // Publish the GitHub release const beta = false; if (includeEthers) { + + // Get the latest change from the changelog + const change = latestChange(); + + // Publish the release to GitHub { // The password above already succeeded const username = await config.get("github-user"); const password = await config.get("github-release"); - // Get the latest change from the changelog - const change = latestChange(); // Publish the release const link = await createRelease(username, password, change.version, change.title, change.content, beta, gitCommit); log(` ${ link }`); } - /* + // Upload the scripts to the CDN and refresh the edge caches { - const accessKey = await config.get("aws-upload-scripts-accesskey"); - const secretKey = await config.get("aws-upload-scripts-secretkey"); - const s3 = - } - */ + const awsAccessId = await config.get("aws-upload-scripts-accesskey"); + const awsSecretKey = await config.get("aws-upload-scripts-secretkey"); + const bucketName = await config.get("aws-upload-scripts-bucket"); + const originRoot = await config.get("aws-upload-scripts-root"); + const distributionId = await config.get("aws-upload-scripts-distribution-id"); + const s3 = new AWS.S3({ + apiVersion: '2006-03-01', + accessKeyId: awsAccessId, + secretAccessKey: awsSecretKey + }); + + // Upload the libs to ethers-v5.0 and ethers-5.0.x + const fileInfos = [ + { filename: "packages/ethers/dist/ethers.esm.min.js", key: `ethers-${ change.version.substring(1) }.esm.min.js` }, + { filename: "packages/ethers/dist/ethers.umd.min.js", key: `ethers-${ change.version.substring(1) }.umd.min.js` }, + { filename: "packages/ethers/dist/ethers.esm.min.js", key: `ethers-5.0.esm.min.js` }, + { filename: "packages/ethers/dist/ethers.umd.min.js", key: `ethers-5.0.umd.min.js` }, + ]; + + for (let i = 0; i < fileInfos.length; i++) { + const fileInfo = fileInfos[i]; + const status = await putObject(s3, { + ACL: 'public-read', + Body: fs.readFileSync(resolve(__dirname, "../../", fileInfo.filename)), + Bucket: bucketName, + ContentType: "application/javascript; charset=utf-8", + Key: (originRoot + fileInfo.key) + }); + + log(` https://cdn.ethers.io/lib/${ fileInfo.key }`); + } + + // Flush the edge caches + { + const cloudfront = new AWS.CloudFront({ + //apiVersion: '2006-03-01', + accessKeyId: awsAccessId, + secretAccessKey: awsSecretKey + }); + + const invalidationId = await invalidate(cloudfront, distributionId); + log(` ${ invalidationId }`); + } + } } })(); diff --git a/admin/cmds/serve-docs.js b/admin/cmds/serve-docs.js index 90f0d9556..2920f0a80 100644 --- a/admin/cmds/serve-docs.js +++ b/admin/cmds/serve-docs.js @@ -87,7 +87,7 @@ function start(root, options) { }); server.listen(options.port, () => { - console.log(`Listening on port: ${ options.port }`); + console.log(`Server running on: http://localhost:${ options.port }`); }); return server; diff --git a/admin/cmds/spell-check.js b/admin/cmds/spell-check.js index 78b612ddc..b66428b09 100644 --- a/admin/cmds/spell-check.js +++ b/admin/cmds/spell-check.js @@ -16,13 +16,13 @@ decrypt decrypted decrypting deployed deploying deprecated detected discontinued earliest email enabled encoded encoding encrypt encrypted encrypting entries euro exceeded existing expected expired failed fetches formatted formatting funding generated -hardened has ignoring implemented implementer imported including instantiate +hardened has highly ignoring implemented implementer imported including instantiate joined keyword labelled larger lookup matches mined modified modifies multi named needed nested neutered numeric offline optimizer overriding owned packed -padded parsed parsing passed placeholder processing properties reached +padded parsed parsing passed placeholder processing properties prototyping reached recommended recovered redacted remaining replaced required serializes shared signed signing skipped stored supported tagging targetted -transactions uninstall unstake unsubscribe using verifies website +throttled transactions uninstall unstake unsubscribe using verifies website // Overly Specific Words BIP BIP39 BIP44 crypto eip hashes hmac icap @@ -47,7 +47,7 @@ bytecode callback calldata checksum ciphertext cli codepoint commify config contenthash ctr ctrl debug dd dklen eexist encseed eof ethaddr ethseed ethers eval exec filename func gz hid http https hw iv info init ipc json kdf kdfparams labelhash lang lib mm multihash nfc -nfkc nfd nfkd nodehash nullish oob opcode pbkdf pc plugin pragma pre prf +nfkc nfd nfkd nodehash notok nullish oob opcode pbkdf pc plugin pragma pre prf repl rpc sighash topichash solc stdin stdout subclasses subnode timeout todo txt ufixed utc utf util url uuid vm vs websocket wikipedia wx xe xpriv xpub xx yyyy zlib