From 2411ec83b12fd2457f6f22fe5a4de9122503a2e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 8 Nov 2016 18:14:46 +0100 Subject: [build] don't rewrite style code for every build revert of 93166aef482ea5835d87231f88d369449398ccdf On Android, we always rewrote the style code files, which lead to gratuitous recompiles --- scripts/style-code.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 scripts/style-code.js (limited to 'scripts/style-code.js') diff --git a/scripts/style-code.js b/scripts/style-code.js new file mode 100644 index 0000000000..156934a240 --- /dev/null +++ b/scripts/style-code.js @@ -0,0 +1,36 @@ +// Global functions // + +const fs = require('fs'); + +global.iff = function (condition, val) { + return condition() ? val : ""; +}; + +global.camelize = function (str) { + return str.replace(/(?:^|-)(.)/g, function (_, x) { + return x.toUpperCase(); + }); +}; + +global.camelizeWithLeadingLowercase = function (str) { + return str.replace(/-(.)/g, function (_, x) { + return x.toUpperCase(); + }); +}; + +global.snakeCaseUpper = function snakeCaseUpper(str) { + return str.replace(/-/g, "_").toUpperCase(); +}; + +global.writeIfModified = function(filename, newContent) { + try { + const oldContent = fs.readFileSync(filename, 'utf8'); + if (oldContent == newContent) { + console.warn(`* Skipping current file '${filename}'`); + return; + } + } catch(err) { + } + fs.writeFileSync(filename, newContent); + console.warn(`* Updating outdated file '${filename}'`); +}; -- cgit v1.2.1