diff --git a/electron/index.js b/electron/index.js index fecc9d11..c5c42bec 100644 --- a/electron/index.js +++ b/electron/index.js @@ -11,14 +11,14 @@ const isLocal = process.argv.indexOf("--local") >= 0; const roamingFolder = process.env.APPDATA || - (process.platform == "darwin" ? - process.env.HOME + "/Library/Preferences" : - process.env.HOME + "/.local/share"); + (process.platform == "darwin" + ? process.env.HOME + "/Library/Preferences" + : process.env.HOME + "/.local/share"); let storePath = path.join(roamingFolder, "shapez.io", "saves"); let modsPath = path.join(roamingFolder, "shapez.io", "mods"); if (!fs.existsSync(storePath)) -// No try-catch by design + // No try-catch by design fs.mkdirSync(storePath, { recursive: true }); if (!fs.existsSync(modsPath)) fs.mkdirSync(modsPath); @@ -157,89 +157,84 @@ ipcMain.on("exit-app", (event, flag) => { function performFsJob(job) { let parent = storePath; - if (job.mods) - let parent = modsPath; + if (job.mods) parent = modsPath; const fname = path.join(parent, job.filename); const relative = path.relative(parent, fname); //If not a child of parent - if(!relative && !relative.startsWith('..') && !path.isAbsolute(relative)) + if (!relative && !relative.startsWith("..") && !path.isAbsolute(relative)) return { - error: "Cannot get above parent folder" - } + error: "Cannot get above parent folder", + }; switch (job.type) { - case "readDir": - { - let contents = ""; - try { - contents = fs.readdirSync(fname, { encoding: "utf8" }); - } catch (ex) { - return { - error: ex, - }; - } + case "readDir": { + let contents = ""; + try { + contents = fs.readdirSync(fname, { encoding: "utf8" }); + } catch (ex) { return { - success: true, - data: contents, + error: ex, }; } - case "read": - { - if (!fs.existsSync(fname)) { - return { - // Special FILE_NOT_FOUND error code - error: "file_not_found", - }; - } - - let contents = ""; - try { - contents = fs.readFileSync(fname, { encoding: "utf8" }); - } catch (ex) { - return { - error: ex, - }; - } - + return { + success: true, + data: contents, + }; + } + case "read": { + if (!fs.existsSync(fname)) { return { - success: true, - data: contents, - }; - } - case "write": - { - try { - fs.writeFileSync(fname, job.contents); - } catch (ex) { - return { - error: ex, - }; - } - - return { - success: true, - data: job.contents, + // Special FILE_NOT_FOUND error code + error: "file_not_found", }; } - case "delete": - { - try { - fs.unlinkSync(fname); - } catch (ex) { - return { - error: ex, - }; - } - + let contents = ""; + try { + contents = fs.readFileSync(fname, { encoding: "utf8" }); + } catch (ex) { return { - success: true, - data: null, + error: ex, }; } + return { + success: true, + data: contents, + }; + } + case "write": { + try { + fs.writeFileSync(fname, job.contents); + } catch (ex) { + return { + error: ex, + }; + } + + return { + success: true, + data: job.contents, + }; + } + + case "delete": { + try { + fs.unlinkSync(fname); + } catch (ex) { + return { + error: ex, + }; + } + + return { + success: true, + data: null, + }; + } + default: throw new Error("Unkown fs job: " + job.type); } @@ -253,4 +248,4 @@ ipcMain.on("fs-job", (event, arg) => { ipcMain.on("fs-sync-job", (event, arg) => { const result = performFsJob(arg); event.returnValue = result; -}); \ No newline at end of file +}); diff --git a/gulp/atlas2json.js b/gulp/atlas2json.js index b77a47f3..8286a195 100644 --- a/gulp/atlas2json.js +++ b/gulp/atlas2json.js @@ -4,7 +4,7 @@ const { readFileSync, readdirSync, writeFileSync } = require("fs"); const suffixToScale = { lq: "0.25", mq: "0.5", - hq: "0.75" + hq: "0.75", }; function convert(srcDir) { @@ -65,7 +65,7 @@ function convert(srcDir) { x: xy[0], y: xy[1], w: size[0], - h: size[1] + h: size[1], }, // Whether image was rotated @@ -75,21 +75,21 @@ function convert(srcDir) { // How is the image trimmed spriteSourceSize: { x: offset[0], - y: (orig[1] - size[1]) - offset[1], + y: orig[1] - size[1] - offset[1], w: size[0], - h: size[1] + h: size[1], }, - + sourceSize: { w: orig[0], - h: orig[1] - } - } + h: orig[1], + }, + }; } // Simple object that will hold other metadata current = { - name: line + name: line, }; } else { // Read and set current image metadata @@ -108,14 +108,14 @@ function convert(srcDir) { format: srcMeta.format, size: { w: atlasSize[0], - h: atlasSize[1] + h: atlasSize[1], }, - scale: atlasScale.toString() - } + scale: atlasScale.toString(), + }, }); writeFileSync(atlas.replace(".atlas", ".json"), result, { - encoding: "utf-8" + encoding: "utf-8", }); } } diff --git a/gulp/buildutils.js b/gulp/buildutils.js index ea253773..8b5e389b 100644 --- a/gulp/buildutils.js +++ b/gulp/buildutils.js @@ -29,7 +29,7 @@ module.exports = { try { return execSync("git describe --tag --exact-match").toString("ascii"); } catch (e) { - throw new Error('Current git HEAD is not a version tag'); + throw new Error("Current git HEAD is not a version tag"); } }, diff --git a/gulp/js.js b/gulp/js.js index 28c037bd..1bc36d15 100644 --- a/gulp/js.js +++ b/gulp/js.js @@ -6,7 +6,6 @@ function requireUncached(module) { } function gulptasksJS($, gulp, buildFolder, browserSync) { - //// DEV gulp.task("js.dev.watch", () => { diff --git a/gulp/release-uploader.js b/gulp/release-uploader.js index eececa4a..faf3aff2 100644 --- a/gulp/release-uploader.js +++ b/gulp/release-uploader.js @@ -24,7 +24,7 @@ function gulptasksReleaseUploader($, gulp, buildFolder) { const currentTag = buildutils.getTag(); const octokit = new Octokit({ - auth: process.env.SHAPEZ_CLI_GITHUB_TOKEN + auth: process.env.SHAPEZ_CLI_GITHUB_TOKEN, }); const createdRelease = await octokit.request("POST /repos/{owner}/{repo}/releases", { @@ -32,10 +32,12 @@ function gulptasksReleaseUploader($, gulp, buildFolder) { repo: "shapez.io", tag_name: currentTag, name: currentTag, - draft: true + draft: true, }); - const { data: { id, upload_url } } = createdRelease; + const { + data: { id, upload_url }, + } = createdRelease; console.log(`Created release ${id} for tag ${currentTag}`); const dmgContents = fs.readFileSync(dmgPath); @@ -46,21 +48,23 @@ function gulptasksReleaseUploader($, gulp, buildFolder) { method: "POST", url: upload_url, headers: { - "content-type": "application/x-apple-diskimage" + "content-type": "application/x-apple-diskimage", }, name: dmgName, - data: dmgContents + data: dmgContents, }); cb(); }); - gulp.task("standalone.uploadRelease.darwin64", + gulp.task( + "standalone.uploadRelease.darwin64", gulp.series( "standalone.uploadRelease.darwin64.cleanup", "standalone.uploadRelease.darwin64.compress", "standalone.uploadRelease.darwin64.upload" - )); + ) + ); } module.exports = { gulptasksReleaseUploader }; diff --git a/gulp/webpack.config.js b/gulp/webpack.config.js index 8101ed78..6e1d7388 100644 --- a/gulp/webpack.config.js +++ b/gulp/webpack.config.js @@ -27,7 +27,8 @@ module.exports = ({ watch = false, standalone = false }) => { new webpack.DefinePlugin({ assert: "window.assert", assertAlways: "window.assert", - abstract: "window.assert(false, 'abstract method called of: ' + (this.name || (this.constructor && this.constructor.name)));", + abstract: + "window.assert(false, 'abstract method called of: ' + (this.name || (this.constructor && this.constructor.name)));", G_HAVE_ASSERT: "true", G_APP_ENVIRONMENT: JSON.stringify("dev"), G_TRACKING_ENDPOINT: JSON.stringify( @@ -60,7 +61,8 @@ module.exports = ({ watch = false, standalone = false }) => { }), ], module: { - rules: [{ + rules: [ + { test: /\.json$/, enforce: "pre", use: ["./gulp/loader.compressjson"], @@ -69,7 +71,8 @@ module.exports = ({ watch = false, standalone = false }) => { { test: /\.(png|jpe?g|svg)$/, loader: "ignore-loader" }, { test: /\.md$/, - use: [{ + use: [ + { loader: "html-loader", }, "markdown-loader", @@ -79,13 +82,15 @@ module.exports = ({ watch = false, standalone = false }) => { test: /\.js$/, enforce: "pre", exclude: /node_modules/, - use: [{ - loader: "webpack-strip-block", - options: { - start: "typehints:start", - end: "typehints:end", + use: [ + { + loader: "webpack-strip-block", + options: { + start: "typehints:start", + end: "typehints:end", + }, }, - }, ], + ], }, { test: /\.worker\.js$/, @@ -109,4 +114,4 @@ module.exports = ({ watch = false, standalone = false }) => { path: path.resolve(__dirname, "..", "build"), }, }; -}; \ No newline at end of file +}; diff --git a/gulp/webpack.production.config.js b/gulp/webpack.production.config.js index 6e286914..c26bca68 100644 --- a/gulp/webpack.production.config.js +++ b/gulp/webpack.production.config.js @@ -139,7 +139,8 @@ module.exports = ({ beautify: false, braces: false, ecma: es6 ? 6 : 5, - preamble: "/* shapez.io Codebase - Copyright 2020 Tobias Springer - " + + preamble: + "/* shapez.io Codebase - Copyright 2020 Tobias Springer - " + getVersion() + " @ " + getRevision() + @@ -163,7 +164,8 @@ module.exports = ({ }), ], module: { - rules: [{ + rules: [ + { test: /\.json$/, enforce: "pre", use: ["./gulp/loader.compressjson"], @@ -174,7 +176,8 @@ module.exports = ({ test: /\.js$/, enforce: "pre", exclude: /node_modules/, - use: [{ + use: [ + { loader: "webpack-strip-block", options: { start: "typehints:start", @@ -225,7 +228,8 @@ module.exports = ({ }, { test: /\.worker\.js$/, - use: [{ + use: [ + { loader: "worker-loader", options: { fallback: false, @@ -254,4 +258,4 @@ module.exports = ({ ], }, }; -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 56884803..1de2357d 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "dev": "cd gulp && yarn gulp main.serveDev", "tslint": "cd src/js && tsc", "lint": "eslint src/js", - "prettier-all": "prettier --write src/**/*.* && prettier --write gulp/**/*.*", + "prettier-all": "prettier --write src/**/*.* && prettier --write gulp/**/*.* && prettier --write electron/**/*.*", "publishOnItchWindows": "butler push tmp_standalone_files/shapez.io-standalone-win32-x64 tobspr/shapezio:windows --userversion-file version", "publishOnItchLinux": "butler push tmp_standalone_files/shapez.io-standalone-linux-x64 tobspr/shapezio:linux --userversion-file version", "publishOnItch": "yarn publishOnItchWindows && yarn publishOnItchLinux", @@ -110,4 +110,4 @@ "trim": "^0.0.1", "yarn": "^1.22.4" } -} \ No newline at end of file +}