Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node lib download #169

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ src/wre/wre.json
coverage
.DS_Store
/public/diagram/lib/*
/public/game/lib/*
wollok.log
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions public/game/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<html>
<head>
<meta charset="UTF-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/addons/p5.sound.js"></script>
<script src="./lib/p5.js"></script>
<script src="./lib/p5.sound.js"></script>
<title>Wollok Game</title>

<script
Expand All @@ -27,7 +27,7 @@
let socket = 1;
</script>
<script type="module">
import { io } from "https://cdn.socket.io/4.4.1/socket.io.esm.min.js";
import { io } from "./lib/socket.io.esm.min.js";

socket = io();
socket.on("connect", function () {
Expand Down
75 changes: 75 additions & 0 deletions scripts/download-libs.js
Original file line number Diff line number Diff line change
@@ -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",
Comment on lines +18 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto quedo duplicado, pero el server hace un serve por carpeta, por lo que si quisiera hacer una compartida tambien deberia compartir los archivos del diagrama.

},
],
},
{
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);
});
}
12 changes: 0 additions & 12 deletions scripts/download-libs.sh

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"esModuleInterop": true,
"experimentalDecorators": true
},
"include": ["test/**/*.ts", "src/**/*.ts", "public/**/*"],
"include": ["test/**/*.ts", "src/**/*.ts"],
"exclude": ["**/*.js", "node_modules"]
}
Loading