From 91d05c72e986fb8e142fa3747a918b33007fd257 Mon Sep 17 00:00:00 2001 From: Alexander Bazo Date: Wed, 28 Aug 2019 14:24:18 +0200 Subject: [PATCH] Update build script --- .gitignore | 5 ++++- Readme.md | 18 ++++++++++++++++-- build.js | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ get-gaze-client.js | 39 --------------------------------------- package-lock.json | 30 +++++++++++++++++++++++++++++- package.json | 6 ++++-- resources/js/Config.js | 2 +- 7 files changed, 140 insertions(+), 46 deletions(-) create mode 100644 build.js delete mode 100644 get-gaze-client.js diff --git a/.gitignore b/.gitignore index e2cf134..cba96f5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ node_modules # dependencies -vendors/ \ No newline at end of file +vendors/ + +# build +build/ \ No newline at end of file diff --git a/Readme.md b/Readme.md index 3d332c2..9af32fd 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,19 @@ # Star Gazer -## Usage +StarGazer is a multiplayer game using gaze data as an input source. This demo showcases the eye tracking classroom's abilities to utilize gaze based real time collaboration. -Run `node get-gaze-client.js` to install dependencies and `npm start` to run the game on a local test server. \ No newline at end of file +## Requirements + +To play the game using gaze data for input a local [gaze-server](https://lab.las3.de/gitlab/eye-tracking-classroom/gaze-server.cs) must be running at `ws://localhost:8001`. + +## Playing + +Hosted versions of the game are available here: + +- [Release version](https://regensburger-forscher.de/stargazer/game/) +- [Beta version](https://regensburger-forscher.de/stargazer/game/) + +## Building and Testing + +- Run `npm install` to install dependencies and build game to `build/` +- Run `npm start` to run the game on a local test server \ No newline at end of file diff --git a/build.js b/build.js new file mode 100644 index 0000000..477c1b9 --- /dev/null +++ b/build.js @@ -0,0 +1,86 @@ +#!/usr/bin/env node + +/* eslint-env node */ +/* eslint-disable no-console */ + +// Build deployable version to TARGET_DIR + +const fs = require("fs-extra"), + https = require("https"), + TARGET_DIR = "build/", + CONFIG_FILE = "build/resources/js/Config.js", + VERSION_PLACEHOLDER = "$VERSION", + version = require("./package.json").version, + fileList = [{ + url: "https://lab.las3.de/gitlab/eye-tracking-classroom/gaze-client.js/raw/master/build/gazeclient.js", + localPath: "build/vendors/gazeclient.js", + }, + { + url: "https://lab.las3.de/gitlab/eye-tracking-classroom/gaze-client.js/raw/master/build/gazeclient.js.map", + localPath: "build/vendors/gazeclient.js.map", + }, + { + url: "https://lab.las3.de/gitlab/eye-tracking-classroom/gaze-client.js/raw/master/build/gazeclient.min.js", + localPath: "build/vendors/gazeclient.min.js", + }, + ]; + +function run() { + createTargetDir(); + downloadLibrary(); + copyFiles(); + insertVersionNumber(); +} + +function onError(error) { + console.log(error); +} + +function createTargetDir() { + console.log(`Ensure target directory [${TARGET_DIR}] exists and is empty`); + fs.ensureDirSync(TARGET_DIR); + fs.emptyDirSync(TARGET_DIR); +} + +function downloadLibrary() { + console.log(`Downloading client library (${fileList.length} files]`); + let vendorsFolder = `${TARGET_DIR}vendors`; + fs.ensureDirSync(vendorsFolder); + for (let i = 0; i < fileList.length; i++) { + let file = fileList[i]; + downloadFile(file.url, file.localPath); + } +} + +function downloadFile(source, target) { + let file; + console.log(`Downloading [${source}] to ${target}`); + file = fs.createWriteStream(target); + https.get(source, function(response) { + response.pipe(file); + }); +} + +function copyFiles() { + console.log(`Copying files to ${TARGET_DIR}`); + fs.copySync("resources/", `${TARGET_DIR}resources`); + fs.copySync("index.html", `${TARGET_DIR}index.html`); +} + +function insertVersionNumber() { + console.log(`Replacing version placeholder in ${CONFIG_FILE}`); + let result; + fs.readFile(CONFIG_FILE, "utf8", function(err, data) { + if (err) { + onError(err); + } + result = data.replace(VERSION_PLACEHOLDER, version); + fs.writeFile(CONFIG_FILE, result, "utf8", function(err) { + if (err) { + onError(err); + } + }); + }); +} + +run(); \ No newline at end of file diff --git a/get-gaze-client.js b/get-gaze-client.js deleted file mode 100644 index 134cfb7..0000000 --- a/get-gaze-client.js +++ /dev/null @@ -1,39 +0,0 @@ -/* eslint-env node */ - -// Downloads gaze client library from https://lab.las3.de/gitlab/eye-tracking-classroom/gaze-client.js - -const https = require("https"), - fs = require("fs"), - fileList = [{ - url: "https://lab.las3.de/gitlab/eye-tracking-classroom/gaze-client.js/raw/master/build/gazeclient.js", - localPath: "vendors/gazeclient.js", - }, - { - url: "https://lab.las3.de/gitlab/eye-tracking-classroom/gaze-client.js/raw/master/build/gazeclient.js.map", - localPath: "vendors/gazeclient.js.map", - }, - { - url: "https://lab.las3.de/gitlab/eye-tracking-classroom/gaze-client.js/raw/master/build/gazeclient.min.js", - localPath: "vendors/gazeclient.min.js", - }, - ]; - -function downloadFile(source, target) { - let file = fs.createWriteStream(target); - https.get(source, function(response) { - response.pipe(file); - }); -} - -// Make sure vendors folder exists - -if (!fs.existsSync("vendors")){ - fs.mkdirSync("vendors"); -} - -// Download all file - -for (let i = 0; i < fileList.length; i++) { - let file = fileList[i]; - downloadFile(file.url, file.localPath); -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 669d1aa..36e4f66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "stargazer", - "version": "1.0.0", + "version": "0.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -51,6 +51,21 @@ "debug": "^3.2.6" } }, + "fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "graceful-fs": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.2.tgz", + "integrity": "sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q==" + }, "he": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", @@ -81,6 +96,14 @@ "union": "~0.4.3" } }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "requires": { + "graceful-fs": "^4.1.6" + } + }, "mime": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", @@ -175,6 +198,11 @@ "qs": "~2.3.3" } }, + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" + }, "url-join": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/url-join/-/url-join-2.0.5.tgz", diff --git a/package.json b/package.json index 4d275af..47b69ff 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,17 @@ { "name": "stargazer", - "version": "1.0.0", + "version": "0.1.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "http-server -o" + "postinstall": "node build.js", + "start": "http-server ./build -o" }, "author": "Alexander Bazo ", "license": "MIT", "dependencies": { + "fs-extra": "^8.1.0", "http-server": "^0.11.1" } } diff --git a/resources/js/Config.js b/resources/js/Config.js index 223fb48..0567014 100644 --- a/resources/js/Config.js +++ b/resources/js/Config.js @@ -3,7 +3,7 @@ var Config = { TARGET_FPS: 60, SCREEN_WIDTH: screen.width, SCREEN_HEIGHT: screen.height, - GAME_VERSION: 0.1, + GAME_VERSION: "$VERSION", }; Object.freeze(Config); -- libgit2 0.26.0