1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Simplify execSync, get rid of trim@npm, use version from package.json

This commit is contained in:
Даниїл Григор'єв 2020-10-03 20:03:21 +03:00
parent beb09a9e3e
commit 52cedb8eb6
11 changed files with 51 additions and 54 deletions

View File

@ -1,40 +1,39 @@
const glob = require("glob"); const glob = require("glob");
const execSync = require("child_process").execSync; const childProcess = require("child_process");
const trim = require("trim"); const { version } = require("../package.json");
const fs = require("fs");
const path = require("path"); function execSync(command) {
return childProcess.execSync(command, {
encoding: "utf-8",
});
}
module.exports = { module.exports = {
getRevision: function (useLast = false) { getRevision: function (useLast = false) {
const commitHash = execSync("git rev-parse --short " + (useLast ? "HEAD^1" : "HEAD")).toString( const commitHash = execSync(`git rev-parse --short ${useLast ? "HEAD^1" : "HEAD"}`);
"ascii"
);
return commitHash.replace(/^\s+|\s+$/g, ""); return commitHash.replace(/^\s+|\s+$/g, "");
}, },
getAllResourceImages() { getAllResourceImages() {
return glob return (
glob
.sync("res/**/*.@(png|svg|jpg)", { cwd: ".." }) .sync("res/**/*.@(png|svg|jpg)", { cwd: ".." })
.map(f => f.replace(/^res\//gi, "")) .map(f => f.replace(/^res\//gi, ""))
.filter(f => {
if (f.indexOf("ui") >= 0) {
// We drop all ui images except for the noinline ones // We drop all ui images except for the noinline ones
return f.indexOf("noinline") >= 0; .filter(f => (f.includes("ui") ? f.includes("noinline") : true))
} );
return true;
});
}, },
getTag() { getTag() {
try { try {
return execSync("git describe --tag --exact-match").toString("ascii"); return execSync("git describe --tag --exact-match");
} catch (e) { } 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() { getVersion() {
return trim(fs.readFileSync(path.join(__dirname, "..", "version")).toString()); return version;
}, },
/** /**
@ -42,6 +41,6 @@ module.exports = {
* @param {string} commitHash * @param {string} commitHash
*/ */
cachebust(url, commitHash) { cachebust(url, commitHash) {
return "/v/" + commitHash + "/" + url; return `/v/${commitHash}/${url}`;
}, },
}; };

View File

@ -6,7 +6,15 @@ const gulp = require("gulp");
const browserSync = require("browser-sync").create({}); const browserSync = require("browser-sync").create({});
const path = require("path"); const path = require("path");
const deleteEmpty = require("delete-empty"); 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 // Load other plugins dynamically
const $ = require("gulp-load-plugins")({ const $ = require("gulp-load-plugins")({
@ -54,7 +62,7 @@ const js = require("./js");
js.gulptasksJS($, gulp, buildFolder, browserSync); js.gulptasksJS($, gulp, buildFolder, browserSync);
const html = require("./html"); const html = require("./html");
html.gulptasksHTML($, gulp, buildFolder, browserSync); html.gulptasksHTML($, gulp, buildFolder);
const ftp = require("./ftp"); const ftp = require("./ftp");
ftp.gulptasksFTP($, gulp, buildFolder); ftp.gulptasksFTP($, gulp, buildFolder);
@ -63,13 +71,13 @@ const docs = require("./docs");
docs.gulptasksDocs($, gulp, buildFolder); docs.gulptasksDocs($, gulp, buildFolder);
const standalone = require("./standalone"); const standalone = require("./standalone");
standalone.gulptasksStandalone($, gulp, buildFolder); standalone.gulptasksStandalone($, gulp);
const releaseUploader = require("./release-uploader"); const releaseUploader = require("./release-uploader");
releaseUploader.gulptasksReleaseUploader($, gulp, buildFolder); releaseUploader.gulptasksReleaseUploader($, gulp, buildFolder);
const translations = require("./translations"); const translations = require("./translations");
translations.gulptasksTranslations($, gulp, buildFolder); translations.gulptasksTranslations($, gulp);
// FIXME // FIXME
// const cordova = require("./cordova"); // const cordova = require("./cordova");
@ -91,7 +99,7 @@ gulp.task("utils.cleanup", gulp.series("utils.cleanBuildFolder", "utils.cleanBui
// Requires no uncomitted files // Requires no uncomitted files
gulp.task("utils.requireCleanWorkingTree", cb => { 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 // Filter files which are OK to be untracked
output = output output = output

View File

@ -105,7 +105,6 @@
"postcss-unprefix": "^2.1.3", "postcss-unprefix": "^2.1.3",
"sass-unused": "^0.3.0", "sass-unused": "^0.3.0",
"strip-json-comments": "^3.0.1", "strip-json-comments": "^3.0.1",
"trim": "^0.0.1",
"webpack-stream": "^5.2.1", "webpack-stream": "^5.2.1",
"yaml-loader": "^0.6.0" "yaml-loader": "^0.6.0"
} }

View File

@ -71,11 +71,19 @@ function gulptasksStandalone($, gulp) {
}); });
gulp.task("standalone.killRunningInstances", cb => { gulp.task("standalone.killRunningInstances", cb => {
const commands = ["taskkill /F /IM shapezio.exe", "killall -SIGKILL shapezio"];
while (commands.length) {
try { try {
execSync("taskkill /F /IM shapezio.exe"); execSync(commands.shift());
break;
} catch (ex) { } catch (ex) {
if (!commands.length) {
console.warn("Failed to kill running instances, maybe none are up."); console.warn("Failed to kill running instances, maybe none are up.");
} }
}
}
cb(); cb();
}); });

View File

@ -2,8 +2,6 @@ const path = require("path");
const fs = require("fs"); const fs = require("fs");
const gulpYaml = require("gulp-yaml"); const gulpYaml = require("gulp-yaml");
const YAML = require("yaml"); const YAML = require("yaml");
const stripIndent = require("strip-indent");
const trim = require("trim");
const translationsSourceDir = path.join(__dirname, "..", "translations"); const translationsSourceDir = path.join(__dirname, "..", "translations");
const translationsJsonDir = path.join(__dirname, "..", "src", "js", "built-temp"); 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", encoding: "utf-8",
}); });
}); });

View File

@ -12488,11 +12488,6 @@ trim-right@^1.0.1:
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003" resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
integrity sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM= 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": "true-case-path@^1.0.2":
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/true-case-path/-/true-case-path-1.0.3.tgz#f813b5a8c86b40da59606722b144e3225799f47d" resolved "https://registry.yarnpkg.com/true-case-path/-/true-case-path-1.0.3.tgz#f813b5a8c86b40da59606722b144e3225799f47d"

View File

@ -1,6 +1,6 @@
{ {
"name": "shapez.io", "name": "shapez.io",
"version": "1.0.0", "version": "1.2.0",
"main": "index.js", "main": "index.js",
"repository": "https://github.com/tobspr/shapez.io", "repository": "https://github.com/tobspr/shapez.io",
"author": "Tobias Springer <tobias.springer1@gmail.com>", "author": "Tobias Springer <tobias.springer1@gmail.com>",
@ -95,7 +95,6 @@
"prettier": "^2.0.4", "prettier": "^2.0.4",
"sass-unused": "^0.3.0", "sass-unused": "^0.3.0",
"strip-json-comments": "^3.0.1", "strip-json-comments": "^3.0.1",
"trim": "^0.0.1",
"yarn": "^1.22.4" "yarn": "^1.22.4"
} }
} }

View File

@ -1,4 +1,3 @@
import trim from "trim";
import { THIRDPARTY_URLS } from "../../core/config"; import { THIRDPARTY_URLS } from "../../core/config";
import { DialogWithForm } from "../../core/modal_dialog_elements"; import { DialogWithForm } from "../../core/modal_dialog_elements";
import { FormElementInput, FormElementItemChooser } from "../../core/modal_dialog_forms"; import { FormElementInput, FormElementItemChooser } from "../../core/modal_dialog_forms";
@ -142,7 +141,7 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
return null; return null;
} }
code = trim(code); code = code.trim();
const codeLower = code.toLowerCase(); const codeLower = code.toLowerCase();
if (enumColors[codeLower]) { if (enumColors[codeLower]) {

View File

@ -17,8 +17,6 @@ import { getApplicationSettingById } from "../profile/application_settings";
import { FormElementInput } from "../core/modal_dialog_forms"; import { FormElementInput } from "../core/modal_dialog_forms";
import { DialogWithForm } from "../core/modal_dialog_elements"; import { DialogWithForm } from "../core/modal_dialog_elements";
const trim = require("trim");
/** /**
* @typedef {import("../savegame/savegame_typedefs").SavegameMetadata} SavegameMetadata * @typedef {import("../savegame/savegame_typedefs").SavegameMetadata} SavegameMetadata
* @typedef {import("../profile/setting_types").EnumSetting} EnumSetting * @typedef {import("../profile/setting_types").EnumSetting} EnumSetting
@ -441,7 +439,7 @@ export class MainMenuState extends GameState {
label: null, label: null,
placeholder: "", placeholder: "",
defaultValue: game.name || "", 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({ const dialog = new DialogWithForm({
app: this.app, app: this.app,
@ -454,7 +452,7 @@ export class MainMenuState extends GameState {
// When confirmed, save the name // When confirmed, save the name
dialog.buttonSignals.ok.add(() => { dialog.buttonSignals.ok.add(() => {
game.name = trim(nameInput.getValue()); game.name = nameInput.getValue().trim();
this.app.savegameMgr.writeAsync(); this.app.savegameMgr.writeAsync();
this.renderSavegames(); this.renderSavegames();
}); });

View File

@ -1 +0,0 @@
1.2.0

View File

@ -8117,11 +8117,6 @@ trim-repeated@^1.0.0:
dependencies: dependencies:
escape-string-regexp "^1.0.2" 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: tryer@^1.0.1:
version "1.0.1" version "1.0.1"
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8" resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8"