From 5c6480118e2f2d227de8446583e9afa148cf3345 Mon Sep 17 00:00:00 2001 From: ivojawer Date: Wed, 26 Jun 2024 21:22:02 -0300 Subject: [PATCH 1/3] download libs with a node script --- package.json | 2 +- scripts/download-libs.js | 75 ++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 2 +- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 scripts/download-libs.js diff --git a/package.json b/package.json index a4ef449..315170d 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ ], "main": "./build/src/index.js", "scripts": { - "preinstall": "sh scripts/download-libs.sh", + "preinstall": "node ./scripts/download-libs.js", "start": "node ./build/src/index.js", "test": "npm run lint && npm run test:unit", "test-with-coverage": "npm run lint && nyc --reporter=json --lines 70 npm run test:unit", diff --git a/scripts/download-libs.js b/scripts/download-libs.js new file mode 100644 index 0000000..dfbcc39 --- /dev/null +++ b/scripts/download-libs.js @@ -0,0 +1,75 @@ +var path = require("node:path"); +var fs = require("fs"); +var http = require("node:http"); + +const libsToDownload = [ + { + libDest: "game", + libs: [ + { + filename: "p5.js", + url: "http://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.js", + }, + { + filename: "p5.sound.js", + url: "http://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/addons/p5.sound.js", + }, + { + filename: "socket.io.esm.min.js", + url: "http://cdn.socket.io/4.4.1/socket.io.esm.min.js", + }, + ], + }, + { + libDest: "diagram", + libs: [ + { + filename: "socket.io.esm.min.js", + url: "http://cdn.socket.io/4.4.1/socket.io.esm.min.js", + }, + { + filename: "socket.io.esm.min.js.map", + url: "http://cdn.socket.io/4.4.1/socket.io.esm.min.js.map", + }, + { + filename: "cytoscape.min.js", + url: "http://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.26.0/cytoscape.min.js", + }, + ], + }, +]; + +for (const { libDest, libs } of libsToDownload) { + console.log(`Downloading ${libDest} libraries`); + + const libFolder = path.resolve(__dirname, "../public", libDest, "lib"); + + if (!fs.existsSync(libFolder)) { + console.log("Creating lib folder"); + fs.mkdirSync(libFolder, { recursive: true }); + } + + for (const { filename, url } of libs) { + const dest = path.join(libFolder, filename); + if (!fs.existsSync(dest)) { + download(url, dest); + } else { + console.log(`Found local version of ${filename}, skipping download`); + } + } +} + +function download(url, dest) { + console.log(`Downloading from ${url}`); + const file = fs.createWriteStream(dest); + const options = {}; + http + .get(url, options, (response) => { + response.pipe(file); + file.on("finish", () => file.close()); + }) + .on("error", function (err) { + fs.unlink(dest); + console.log(err.message); + }); +} diff --git a/tsconfig.json b/tsconfig.json index bce212b..fa748bb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,6 @@ "esModuleInterop": true, "experimentalDecorators": true }, - "include": ["test/**/*.ts", "src/**/*.ts", "public/**/*"], + "include": ["test/**/*.ts", "src/**/*.ts"], "exclude": ["**/*.js", "node_modules"] } From 279984b34be89f8ba9186af1318f0ae52b434527 Mon Sep 17 00:00:00 2001 From: ivojawer Date: Wed, 26 Jun 2024 21:22:23 -0300 Subject: [PATCH 2/3] game libraries also downloaded --- .gitignore | 1 + public/game/index.html | 6 +++--- scripts/download-libs.sh | 12 ------------ 3 files changed, 4 insertions(+), 15 deletions(-) delete mode 100755 scripts/download-libs.sh diff --git a/.gitignore b/.gitignore index cf21122..1dbd420 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ src/wre/wre.json coverage .DS_Store /public/diagram/lib/* +/public/game/lib/* wollok.log \ No newline at end of file diff --git a/public/game/index.html b/public/game/index.html index 82a1a38..4171cfb 100644 --- a/public/game/index.html +++ b/public/game/index.html @@ -2,8 +2,8 @@ - - + + Wollok Game