diff --git a/gulp/buildutils.js b/gulp/buildutils.js index ea253773..02ca4a8c 100644 --- a/gulp/buildutils.js +++ b/gulp/buildutils.js @@ -1,40 +1,39 @@ const glob = require("glob"); -const execSync = require("child_process").execSync; -const trim = require("trim"); -const fs = require("fs"); -const path = require("path"); +const childProcess = require("child_process"); +const { version } = require("../package.json"); + +function execSync(command) { + return childProcess.execSync(command, { + encoding: "utf-8", + }); +} module.exports = { getRevision: function (useLast = false) { - const commitHash = execSync("git rev-parse --short " + (useLast ? "HEAD^1" : "HEAD")).toString( - "ascii" - ); + const commitHash = execSync(`git rev-parse --short ${useLast ? "HEAD^1" : "HEAD"}`); return commitHash.replace(/^\s+|\s+$/g, ""); }, getAllResourceImages() { - return glob - .sync("res/**/*.@(png|svg|jpg)", { cwd: ".." }) - .map(f => f.replace(/^res\//gi, "")) - .filter(f => { - if (f.indexOf("ui") >= 0) { - // We drop all ui images except for the noinline ones - return f.indexOf("noinline") >= 0; - } - return true; - }); + return ( + glob + .sync("res/**/*.@(png|svg|jpg)", { cwd: ".." }) + .map(f => f.replace(/^res\//gi, "")) + // We drop all ui images except for the noinline ones + .filter(f => (f.includes("ui") ? f.includes("noinline") : true)) + ); }, getTag() { try { - return execSync("git describe --tag --exact-match").toString("ascii"); + return execSync("git describe --tag --exact-match"); } catch (e) { - throw new Error('Current git HEAD is not a version tag'); + throw new Error("Current git HEAD is not a version tag"); } }, getVersion() { - return trim(fs.readFileSync(path.join(__dirname, "..", "version")).toString()); + return version; }, /** @@ -42,6 +41,6 @@ module.exports = { * @param {string} commitHash */ cachebust(url, commitHash) { - return "/v/" + commitHash + "/" + url; + return `/v/${commitHash}/${url}`; }, }; diff --git a/gulp/gulpfile.js b/gulp/gulpfile.js index c01ec73d..46cf7aba 100644 --- a/gulp/gulpfile.js +++ b/gulp/gulpfile.js @@ -6,7 +6,15 @@ const gulp = require("gulp"); const browserSync = require("browser-sync").create({}); const path = require("path"); const deleteEmpty = require("delete-empty"); -const execSync = require("child_process").execSync; + +/** + * @param {string} cmd + * @returns {string} + */ +const execSync = cmd => + require("child_process").execSync(cmd, { + encoding: "utf-8", + }); // Load other plugins dynamically const $ = require("gulp-load-plugins")({ @@ -54,7 +62,7 @@ const js = require("./js"); js.gulptasksJS($, gulp, buildFolder, browserSync); const html = require("./html"); -html.gulptasksHTML($, gulp, buildFolder, browserSync); +html.gulptasksHTML($, gulp, buildFolder); const ftp = require("./ftp"); ftp.gulptasksFTP($, gulp, buildFolder); @@ -63,13 +71,13 @@ const docs = require("./docs"); docs.gulptasksDocs($, gulp, buildFolder); const standalone = require("./standalone"); -standalone.gulptasksStandalone($, gulp, buildFolder); +standalone.gulptasksStandalone($, gulp); const releaseUploader = require("./release-uploader"); releaseUploader.gulptasksReleaseUploader($, gulp, buildFolder); const translations = require("./translations"); -translations.gulptasksTranslations($, gulp, buildFolder); +translations.gulptasksTranslations($, gulp); // FIXME // const cordova = require("./cordova"); @@ -91,7 +99,7 @@ gulp.task("utils.cleanup", gulp.series("utils.cleanBuildFolder", "utils.cleanBui // Requires no uncomitted files gulp.task("utils.requireCleanWorkingTree", cb => { - let output = $.trim(execSync("git status -su").toString("ascii")).replace(/\r/gi, "").split("\n"); + let output = execSync("git status -su").trim().replace(/\r/gi, "").split("\n"); // Filter files which are OK to be untracked output = output diff --git a/gulp/package.json b/gulp/package.json index ec69f4ce..e19ef4ec 100644 --- a/gulp/package.json +++ b/gulp/package.json @@ -105,7 +105,6 @@ "postcss-unprefix": "^2.1.3", "sass-unused": "^0.3.0", "strip-json-comments": "^3.0.1", - "trim": "^0.0.1", "webpack-stream": "^5.2.1", "yaml-loader": "^0.6.0" } diff --git a/gulp/standalone.js b/gulp/standalone.js index 8d247672..3e0d90b8 100644 --- a/gulp/standalone.js +++ b/gulp/standalone.js @@ -71,11 +71,19 @@ function gulptasksStandalone($, gulp) { }); gulp.task("standalone.killRunningInstances", cb => { - try { - execSync("taskkill /F /IM shapezio.exe"); - } catch (ex) { - console.warn("Failed to kill running instances, maybe none are up."); + const commands = ["taskkill /F /IM shapezio.exe", "killall -SIGKILL shapezio"]; + + while (commands.length) { + try { + execSync(commands.shift()); + break; + } catch (ex) { + if (!commands.length) { + console.warn("Failed to kill running instances, maybe none are up."); + } + } } + cb(); }); diff --git a/gulp/translations.js b/gulp/translations.js index 2d0791b5..f1e8f8ba 100644 --- a/gulp/translations.js +++ b/gulp/translations.js @@ -2,8 +2,6 @@ const path = require("path"); const fs = require("fs"); const gulpYaml = require("gulp-yaml"); const YAML = require("yaml"); -const stripIndent = require("strip-indent"); -const trim = require("trim"); const translationsSourceDir = path.join(__dirname, "..", "translations"); const translationsJsonDir = path.join(__dirname, "..", "src", "js", "built-temp"); @@ -75,7 +73,7 @@ function gulptasksTranslations($, gulp) { `; - fs.writeFileSync(destpath, trim(content.replace(/(\n[ \t\r]*)/gi, "\n")), { + fs.writeFileSync(destpath, content.replace(/(\n[ \t\r]*)/gi, "\n").trim(), { encoding: "utf-8", }); }); diff --git a/gulp/yarn.lock b/gulp/yarn.lock index 0fbce524..f69b92bc 100644 --- a/gulp/yarn.lock +++ b/gulp/yarn.lock @@ -12488,11 +12488,6 @@ trim-right@^1.0.1: resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003" integrity sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM= -trim@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/trim/-/trim-0.0.1.tgz#5858547f6b290757ee95cccc666fb50084c460dd" - integrity sha1-WFhUf2spB1fulczMZm+1AITEYN0= - "true-case-path@^1.0.2": version "1.0.3" resolved "https://registry.yarnpkg.com/true-case-path/-/true-case-path-1.0.3.tgz#f813b5a8c86b40da59606722b144e3225799f47d" diff --git a/package.json b/package.json index acd23c07..e4516cea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "shapez.io", - "version": "1.0.0", + "version": "1.2.0", "main": "index.js", "repository": "https://github.com/tobspr/shapez.io", "author": "Tobias Springer ", @@ -71,7 +71,7 @@ "yawn-yaml": "^1.5.0" }, "devDependencies": { - "@octokit/rest": "^18.0.6", + "@octokit/rest": "^18.0.6", "@typescript-eslint/eslint-plugin": "3.0.1", "@typescript-eslint/parser": "3.0.1", "autoprefixer": "^9.4.3", @@ -95,7 +95,6 @@ "prettier": "^2.0.4", "sass-unused": "^0.3.0", "strip-json-comments": "^3.0.1", - "trim": "^0.0.1", "yarn": "^1.22.4" } } diff --git a/src/js/game/systems/constant_signal.js b/src/js/game/systems/constant_signal.js index 0b2f38da..b8bf5ef4 100644 --- a/src/js/game/systems/constant_signal.js +++ b/src/js/game/systems/constant_signal.js @@ -1,4 +1,3 @@ -import trim from "trim"; import { THIRDPARTY_URLS } from "../../core/config"; import { DialogWithForm } from "../../core/modal_dialog_elements"; import { FormElementInput, FormElementItemChooser } from "../../core/modal_dialog_forms"; @@ -142,7 +141,7 @@ export class ConstantSignalSystem extends GameSystemWithFilter { return null; } - code = trim(code); + code = code.trim(); const codeLower = code.toLowerCase(); if (enumColors[codeLower]) { diff --git a/src/js/states/main_menu.js b/src/js/states/main_menu.js index 0d186ffd..b40dca47 100644 --- a/src/js/states/main_menu.js +++ b/src/js/states/main_menu.js @@ -17,8 +17,6 @@ import { getApplicationSettingById } from "../profile/application_settings"; import { FormElementInput } from "../core/modal_dialog_forms"; import { DialogWithForm } from "../core/modal_dialog_elements"; -const trim = require("trim"); - /** * @typedef {import("../savegame/savegame_typedefs").SavegameMetadata} SavegameMetadata * @typedef {import("../profile/setting_types").EnumSetting} EnumSetting @@ -441,7 +439,7 @@ export class MainMenuState extends GameState { label: null, placeholder: "", defaultValue: game.name || "", - validator: val => val.match(regex) && trim(val).length > 0, + validator: val => val.match(regex) && val.trim().length > 0, }); const dialog = new DialogWithForm({ app: this.app, @@ -454,7 +452,7 @@ export class MainMenuState extends GameState { // When confirmed, save the name dialog.buttonSignals.ok.add(() => { - game.name = trim(nameInput.getValue()); + game.name = nameInput.getValue().trim(); this.app.savegameMgr.writeAsync(); this.renderSavegames(); }); diff --git a/version b/version deleted file mode 100644 index 867e5243..00000000 --- a/version +++ /dev/null @@ -1 +0,0 @@ -1.2.0 \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index da9d4625..300060b8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8117,11 +8117,6 @@ trim-repeated@^1.0.0: dependencies: escape-string-regexp "^1.0.2" -trim@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/trim/-/trim-0.0.1.tgz#5858547f6b290757ee95cccc666fb50084c460dd" - integrity sha1-WFhUf2spB1fulczMZm+1AITEYN0= - tryer@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8"