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 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}`;
},
};

View File

@ -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

View File

@ -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"
}

View File

@ -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();
});

View File

@ -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",
});
});

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"
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"

View File

@ -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 <tobias.springer1@gmail.com>",
@ -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"
}
}

View File

@ -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]) {

View File

@ -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();
});

View File

@ -1 +0,0 @@
1.2.0

View File

@ -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"