-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a997e2d
commit 9e5a41e
Showing
3 changed files
with
381 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "hubs-architecture-kit", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"repository": "https://github.com/MozillaReality/hubs-architecture-kit.git", | ||
"author": "Robert Long <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"deploy-prod": "node ./scripts/deploy.js ./glTF/ArchKit assets.reticulum-prod-b99b35f30242f894 kits/architecture/", | ||
"deploy-dev": "node ./scripts/deploy.js ./glTF/ArchKit assets.reticulum-dev-7f8d39c45878ee2e kits/architecture/" | ||
}, | ||
"devDependencies": { | ||
"aws-sdk": "^2.556.0", | ||
"commander": "^3.0.2", | ||
"glob-promise": "^3.4.0", | ||
"promptly": "^3.0.3" | ||
}, | ||
"dependencies": { | ||
"glob": "^7.1.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
const program = require("commander"); | ||
const promptly = require("promptly"); | ||
const AWS = require("aws-sdk"); | ||
const glob = require("glob-promise"); | ||
const fs = require("fs"); | ||
const zlib = require("zlib"); | ||
const path = require("path"); | ||
const { version } = require("../package.json"); | ||
|
||
program | ||
.version(version) | ||
.arguments("<src> <bucket> <dest>") | ||
.parse(process.argv); | ||
|
||
async function uploadFiles(s3Client, srcDir, bucket, destDir) { | ||
const files = await glob(path.join(srcDir, "**", "*"), { | ||
absolute: true, | ||
nodir: true | ||
}); | ||
|
||
const rootDir = path.resolve(srcDir); | ||
|
||
const uploadTasks = files.map(filePath => | ||
createUploadTask(s3Client, rootDir, filePath, bucket, destDir) | ||
); | ||
|
||
const uploadPromises = uploadTasks.map((req, idx) => | ||
req | ||
.promise() | ||
.then(() => { | ||
console.log(`Successfully uploaded: ${files[idx]}`); | ||
}) | ||
.catch(err => { | ||
console.error(`Error uploading: ${files[idx]}`); | ||
throw err; | ||
}) | ||
); | ||
|
||
await Promise.all(uploadPromises); | ||
} | ||
|
||
function createUploadTask(s3Client, rootDir, filePath, bucket, destDir) { | ||
const extension = path.extname(filePath); | ||
|
||
const fileStream = createFileStream(filePath, extension); | ||
|
||
const key = destDir + path.relative(rootDir, filePath).replace(/\\/g, "/"); | ||
|
||
const req = s3Client.upload({ | ||
ACL: "public-read", | ||
Body: fileStream, | ||
Bucket: bucket, | ||
CacheControl: getCacheControl(filePath), | ||
ContentEncoding: shouldGzip(extension) ? "gzip" : undefined, | ||
ContentType: getContentType(filePath, extension), | ||
Key: key | ||
}); | ||
|
||
return req; | ||
} | ||
|
||
const GZIPPED_EXTENSIONS = [".json", ".gltf", ".bin"]; | ||
|
||
function shouldGzip(extension) { | ||
return GZIPPED_EXTENSIONS.indexOf(extension) !== -1; | ||
} | ||
|
||
function createFileStream(filePath, extension) { | ||
const readStream = fs.createReadStream(filePath); | ||
|
||
if (shouldGzip(extension)) { | ||
const gzipStream = zlib.createGzip(); | ||
return readStream.pipe(gzipStream); | ||
} | ||
|
||
return readStream; | ||
} | ||
|
||
function getContentType(filePath, extension) { | ||
switch (extension) { | ||
case ".json": | ||
return "application/json"; | ||
case ".gltf": | ||
return "model/gltf+json"; | ||
case ".bin": | ||
return "application/octet-stream"; | ||
case ".png": | ||
return "image/png"; | ||
case ".jpeg": | ||
return "image/jpeg"; | ||
case ".jpg": | ||
return "image/jpeg"; | ||
default: | ||
throw `Unsupported file type ${extension} for ${filePath}`; | ||
} | ||
} | ||
|
||
function getCacheControl(filePath) { | ||
if (filePath.endsWith(".json")) { | ||
return "no-cache, no-store, must-revalidate"; | ||
} | ||
|
||
return "public, max-age=31536000"; | ||
} | ||
|
||
(async function execute() { | ||
const normalizedPath = path.normalize(program.args[0]); | ||
const bucket = program.args[1]; | ||
const destPath = program.args[2]; | ||
|
||
|
||
if ( | ||
await promptly.confirm( | ||
`Are you sure you wish to deploy to ${bucket}? (y/n)` | ||
) | ||
) { | ||
const s3 = new AWS.S3({ | ||
accessKeyId: AWS.config.credentials.accessKeyId, | ||
secretAccessKey: AWS.config.credentials.secretAccessKey | ||
}); | ||
|
||
await uploadFiles(s3, normalizedPath, bucket, destPath); | ||
console.log("Done!"); | ||
process.exit(0); | ||
} | ||
})().catch(e => { | ||
console.error(e); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@types/events@*": | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" | ||
integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g== | ||
|
||
"@types/glob@*": | ||
version "7.1.1" | ||
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575" | ||
integrity sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w== | ||
dependencies: | ||
"@types/events" "*" | ||
"@types/minimatch" "*" | ||
"@types/node" "*" | ||
|
||
"@types/minimatch@*": | ||
version "3.0.3" | ||
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" | ||
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== | ||
|
||
"@types/node@*": | ||
version "12.11.7" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.11.7.tgz#57682a9771a3f7b09c2497f28129a0462966524a" | ||
integrity sha512-JNbGaHFCLwgHn/iCckiGSOZ1XYHsKFwREtzPwSGCVld1SGhOlmZw2D4ZI94HQCrBHbADzW9m4LER/8olJTRGHA== | ||
|
||
aws-sdk@^2.556.0: | ||
version "2.556.0" | ||
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.556.0.tgz#5c96bacf7942b530b20c94f3307e6650a97fd7be" | ||
integrity sha512-qILMUNl/a7FYWU67Y24OGsXFhyDHM4qYdplMR2tps/g17pN9bEQ5ijxvGzW2T8VVyAsTanmn+dFyl/CH38pC5Q== | ||
dependencies: | ||
buffer "4.9.1" | ||
events "1.1.1" | ||
ieee754 "1.1.13" | ||
jmespath "0.15.0" | ||
querystring "0.2.0" | ||
sax "1.2.1" | ||
url "0.10.3" | ||
uuid "3.3.2" | ||
xml2js "0.4.19" | ||
|
||
balanced-match@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" | ||
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= | ||
|
||
base64-js@^1.0.2: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1" | ||
integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g== | ||
|
||
brace-expansion@^1.1.7: | ||
version "1.1.11" | ||
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" | ||
integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== | ||
dependencies: | ||
balanced-match "^1.0.0" | ||
concat-map "0.0.1" | ||
|
||
[email protected]: | ||
version "4.9.1" | ||
resolved "https://registry.yarnpkg.com/buffer/-/buffer-4.9.1.tgz#6d1bb601b07a4efced97094132093027c95bc298" | ||
integrity sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg= | ||
dependencies: | ||
base64-js "^1.0.2" | ||
ieee754 "^1.1.4" | ||
isarray "^1.0.0" | ||
|
||
commander@^3.0.2: | ||
version "3.0.2" | ||
resolved "https://registry.yarnpkg.com/commander/-/commander-3.0.2.tgz#6837c3fb677ad9933d1cfba42dd14d5117d6b39e" | ||
integrity sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow== | ||
|
||
[email protected]: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" | ||
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= | ||
|
||
[email protected]: | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924" | ||
integrity sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ= | ||
|
||
fs.realpath@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" | ||
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= | ||
|
||
glob-promise@^3.4.0: | ||
version "3.4.0" | ||
resolved "https://registry.yarnpkg.com/glob-promise/-/glob-promise-3.4.0.tgz#b6b8f084504216f702dc2ce8c9bc9ac8866fdb20" | ||
integrity sha512-q08RJ6O+eJn+dVanerAndJwIcumgbDdYiUT7zFQl3Wm1xD6fBKtah7H8ZJChj4wP+8C+QfeVy8xautR7rdmKEw== | ||
dependencies: | ||
"@types/glob" "*" | ||
|
||
glob@^7.1.5: | ||
version "7.1.5" | ||
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.5.tgz#6714c69bee20f3c3e64c4dd905553e532b40cdc0" | ||
integrity sha512-J9dlskqUXK1OeTOYBEn5s8aMukWMwWfs+rPTn/jn50Ux4MNXVhubL1wu/j2t+H4NVI+cXEcCaYellqaPVGXNqQ== | ||
dependencies: | ||
fs.realpath "^1.0.0" | ||
inflight "^1.0.4" | ||
inherits "2" | ||
minimatch "^3.0.4" | ||
once "^1.3.0" | ||
path-is-absolute "^1.0.0" | ||
|
||
[email protected], ieee754@^1.1.4: | ||
version "1.1.13" | ||
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84" | ||
integrity sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg== | ||
|
||
inflight@^1.0.4: | ||
version "1.0.6" | ||
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" | ||
integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= | ||
dependencies: | ||
once "^1.3.0" | ||
wrappy "1" | ||
|
||
inherits@2: | ||
version "2.0.4" | ||
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" | ||
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== | ||
|
||
isarray@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" | ||
integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= | ||
|
||
[email protected]: | ||
version "0.15.0" | ||
resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.15.0.tgz#a3f222a9aae9f966f5d27c796510e28091764217" | ||
integrity sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc= | ||
|
||
minimatch@^3.0.4: | ||
version "3.0.4" | ||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" | ||
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== | ||
dependencies: | ||
brace-expansion "^1.1.7" | ||
|
||
mute-stream@~0.0.4: | ||
version "0.0.8" | ||
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" | ||
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== | ||
|
||
once@^1.3.0: | ||
version "1.4.0" | ||
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" | ||
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= | ||
dependencies: | ||
wrappy "1" | ||
|
||
path-is-absolute@^1.0.0: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" | ||
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= | ||
|
||
pify@^3.0.0: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" | ||
integrity sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY= | ||
|
||
promptly@^3.0.3: | ||
version "3.0.3" | ||
resolved "https://registry.yarnpkg.com/promptly/-/promptly-3.0.3.tgz#e178f722e73d82c60d019462044bccfdd9872f42" | ||
integrity sha512-EWnzOsxVKUjqKeE6SStH1/cO4+DE44QolaoJ4ojGd9z6pcNkpgfJKr1ncwxrOFHSTIzoudo7jG8y0re30/LO1g== | ||
dependencies: | ||
pify "^3.0.0" | ||
read "^1.0.4" | ||
|
||
[email protected]: | ||
version "1.3.2" | ||
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d" | ||
integrity sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0= | ||
|
||
[email protected]: | ||
version "0.2.0" | ||
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" | ||
integrity sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA= | ||
|
||
read@^1.0.4: | ||
version "1.0.7" | ||
resolved "https://registry.yarnpkg.com/read/-/read-1.0.7.tgz#b3da19bd052431a97671d44a42634adf710b40c4" | ||
integrity sha1-s9oZvQUkMal2cdRKQmNK33ELQMQ= | ||
dependencies: | ||
mute-stream "~0.0.4" | ||
|
||
[email protected]: | ||
version "1.2.1" | ||
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.1.tgz#7b8e656190b228e81a66aea748480d828cd2d37a" | ||
integrity sha1-e45lYZCyKOgaZq6nSEgNgozS03o= | ||
|
||
sax@>=0.6.0: | ||
version "1.2.4" | ||
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" | ||
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== | ||
|
||
[email protected]: | ||
version "0.10.3" | ||
resolved "https://registry.yarnpkg.com/url/-/url-0.10.3.tgz#021e4d9c7705f21bbf37d03ceb58767402774c64" | ||
integrity sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ= | ||
dependencies: | ||
punycode "1.3.2" | ||
querystring "0.2.0" | ||
|
||
[email protected]: | ||
version "3.3.2" | ||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131" | ||
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA== | ||
|
||
wrappy@1: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" | ||
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= | ||
|
||
[email protected]: | ||
version "0.4.19" | ||
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.19.tgz#686c20f213209e94abf0d1bcf1efaa291c7827a7" | ||
integrity sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q== | ||
dependencies: | ||
sax ">=0.6.0" | ||
xmlbuilder "~9.0.1" | ||
|
||
xmlbuilder@~9.0.1: | ||
version "9.0.7" | ||
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d" | ||
integrity sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0= |