From b5122335779e17a55ed319037bb77baa459124d8 Mon Sep 17 00:00:00 2001 From: svrjs Date: Mon, 31 Jul 2023 15:48:52 +0200 Subject: [PATCH] Initial commit --- README.md | 10 +++++ downloader.js | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 1 + package.json | 36 +++++++++++++++++ warn.js | 2 + 5 files changed, 154 insertions(+) create mode 100644 README.md create mode 100755 downloader.js create mode 100644 index.js create mode 100644 package.json create mode 100644 warn.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..6adc1d3 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# SVR.JS +SVR.JS is a web server running on Node.JS. +This npm package supplies only *create-svrjs-server* utility for installing and updating SVR.JS on current working directory. It doesn't include SVR.JS itself. +To install SVR.JS type one of those commands: + +```bash +create-svrjs-server lts #Latest SVR.JS LTS version +create-svrjs-server latest #Latest SVR.JS version +create-svrjs-server 3.6.1 #SVR.JS 3.6.1 (replace 3.6.1 with your desired version) +``` diff --git a/downloader.js b/downloader.js new file mode 100755 index 0000000..ace8720 --- /dev/null +++ b/downloader.js @@ -0,0 +1,105 @@ +#!/usr/bin/env node + +var version = process.argv[2]; +var https = require("https"); +var os = require("os"); +var fs = require("fs"); +var zip = require("zip"); + +var isSVRJSinstalled = fs.existsSync("svr.js"); + +if(!version) { + console.log("A utility to create and update SVR.JS"); + console.log("Usage:"); + console.log("create-svrjs-server "); + console.log(" version - SVR.JS version you want to download"); + console.log(" 'latest' -> latest SVR.JS version"); + console.log(" 'lts' -> latest LTS SVR.JS version"); + console.log(" '3.6.1' -> SVR.JS 3.6.1"); + console.log("WARNING: Doesn't support nightly SVR.JS versions!"); +} else if(version == "latest" || version == "lts") { + https.get({ + hostname: "svrjs.org", + port: 443, + path: "/", + method: "GET", + headers: { + "User-Agent": "create-svrjs-server" + } + }, function(res) { + if(res.statusCode != 200) { + console.log("Server returns " + res.statusCode + " HTTP code"); + return; + } + var data = ""; + res.on("data", function(chunk) { + data += chunk; + }); + res.on("end", function() { + var regex = />Download SVR\.JS ([^ <]+)<\/a>/; + if(version == "lts") { + regex = />Download SVR\.JS ([^ <]+) LTS<\/a>/; + } + var dlver = data.match(regex); + if(!dlver) { + console.log("Can't obtain latest version from main page"); + } else { + console.log("Selected SVR.JS " + dlver[1]); + downloadSVRJS(dlver[1]); + } + }); + }).on("error", function() { + console.log("Can't connect to SVR.JS download server!"); + }); +} else { + downloadSVRJS(version); +} + +function downloadSVRJS(version) { + https.get({ + hostname: "svrjs.org", + port: 443, + path: "/dl/svr.js." + version + ".zip", + method: "GET", + headers: { + "User-Agent": "create-svrjs-server" + } + }, function(res) { + if(res.statusCode != 200) { + console.log("Server returns " + res.statusCode + " HTTP code while trying to download"); + return; + } + var zipFile = fs.createWriteStream("svrjs.zip"); + res.on("end", function() { + console.log("Downloaded .zip file"); + fs.readFile("svrjs.zip", function(err,data) { + if(err) { + console.log("Can't read downloaded file!"); + return; + } else { + var reader = zip.Reader(data); + var allFiles = reader.toObject(); + var allFileNames = Object.keys(allFiles); + for(var i=0;i= 8" + }, + "bin": { + "create-svrjs-server": "./downloader.js" + }, + "script": { + "postinstall": "node warn.js" + }, + "license": "MIT", + "dependencies": { + "zip": "^1.2.0" + } +} diff --git a/warn.js b/warn.js new file mode 100644 index 0000000..8605ccf --- /dev/null +++ b/warn.js @@ -0,0 +1,2 @@ +console.log("Thank you for installing SVR.JS downloader!"); +console.log("To install SVR.JS, use create-svrjs-server command.");