From b89c1283cfada2b2007ba07ea903387c5df99de5 Mon Sep 17 00:00:00 2001 From: jliddev Date: Tue, 28 Dec 2021 14:23:12 -0600 Subject: [PATCH] Fix gitignore of js files --- wowup-electron/.gitignore | 2 +- wowup-electron/assets/preload/wago.js | 36 ++++++ wowup-electron/gulpfile.js | 67 +++++++++++ wowup-electron/test-fixer.js | 166 ++++++++++++++++++++++++++ 4 files changed, 270 insertions(+), 1 deletion(-) create mode 100644 wowup-electron/assets/preload/wago.js create mode 100644 wowup-electron/gulpfile.js create mode 100644 wowup-electron/test-fixer.js diff --git a/wowup-electron/.gitignore b/wowup-electron/.gitignore index d39a17dd..393b464f 100644 --- a/wowup-electron/.gitignore +++ b/wowup-electron/.gitignore @@ -15,7 +15,7 @@ window-state.js src/**/*.js !src/karma.conf.js *.js.map -*.js +app/*.js !electron-build/*.js # dependencies diff --git a/wowup-electron/assets/preload/wago.js b/wowup-electron/assets/preload/wago.js new file mode 100644 index 00000000..26569906 --- /dev/null +++ b/wowup-electron/assets/preload/wago.js @@ -0,0 +1,36 @@ +const { contextBridge, ipcRenderer } = require("electron"); +const log = require("electron-log"); +const { join } = require("path"); + +const RELOAD_PERIOD_MS = 10 * 60 * 1000; +const LOG_PATH = getArg("log-path"); + +function getArg(argKey) { + for (const arg of window.process.argv) { + const [key, val] = arg.split("="); + if (key === `--${argKey}`) { + return val; + } + } + + throw new Error(`Arg not found: ${argKey}`); +} + +log.transports.file.resolvePath = (variables) => { + return join(LOG_PATH, variables.fileName); +}; + +contextBridge.exposeInMainWorld("wago", { + provideApiKey: (key) => { + log.debug(`[wago-preload] got key`, key); + ipcRenderer.send("wago-token-received", key); + }, +}); + +setTimeout(() => { + log.info(`[wago-preload] setTimeout reloading`); + window.location.reload(); +}, RELOAD_PERIOD_MS); + +log.info(`[wago-preload] init`); +log.info(`[wago-preload] next reload`, new Date(Date.now() + RELOAD_PERIOD_MS).toLocaleString()); diff --git a/wowup-electron/gulpfile.js b/wowup-electron/gulpfile.js new file mode 100644 index 00000000..41ba9253 --- /dev/null +++ b/wowup-electron/gulpfile.js @@ -0,0 +1,67 @@ +const gulp = require("gulp"); +const del = require("del"); +const { spawn } = require("child_process"); + +function defaultTask(cb) { + // place code for your default task here + cb(); +} + +function prePackageTask(cb) { + return del("package_workspace/**", { force: true }); +} + +function prePackageCopyTask(cb) { + return gulp + .src(["./**/*.*", "!node_modules/**/*.*", "!package_workspace/**/*.*", "!release/**/*.*"], { base: "./" }) + .pipe(gulp.dest("package_workspace/")); +} + +function packageChDir(cb) { + process.chdir("./package_workspace"); + cb(); +} + +function npmRunTask(cb, buildJob) { + console.log("packageTask", buildJob); + + const ls = spawn("npm", ["run", buildJob], { + shell: true, + }); + + ls.stdout.on("data", (data) => { + console.log(`stdout: ${data}`); + }); + + ls.stderr.on("data", (data) => { + console.log(`stderr: ${data}`); + }); + + ls.on("error", (error) => { + console.log(`error: ${error.message}`); + }); + + ls.on("close", (code) => { + console.log(`child process exited with code ${code}`); + cb(); + }); +} + +function npmRun(cmd) { + return function npmRunCmd(cb) { + npmRunTask(cb, cmd); + }; +} + +const prePackageTasks = [ + npmRun("lint"), + npmRun("build:prod"), + prePackageTask, + prePackageCopyTask, + packageChDir, + npmRun("install:prod"), +]; + +exports.default = defaultTask; +exports.package = gulp.series(...prePackageTasks, npmRun("electron:publish")); +exports.packageLocal = gulp.series(...prePackageTasks, npmRun("electron:publish:never:local")); diff --git a/wowup-electron/test-fixer.js b/wowup-electron/test-fixer.js new file mode 100644 index 00000000..776eb54a --- /dev/null +++ b/wowup-electron/test-fixer.js @@ -0,0 +1,166 @@ +const fs = require("fs"); +const path = require("path"); +const ignore = require("ignore"); +const { execSync, spawn } = require("child_process"); + +const gitIgnoreFile = fs.readFileSync(".gitignore", { encoding: "utf-8" }); +const gitIgnore = gitIgnoreFile.split("\n"); + +const ig = ignore().add(gitIgnore); + +const shouldClear = process.argv.indexOf("--clear") !== -1; +const shouldRepair = process.argv.indexOf("--repair") !== -1; +const shouldStep = process.argv.indexOf("--step") !== -1; +const shouldFindBreak = process.argv.indexOf("--find-break") !== -1; + +const getAllFiles = function (dirPath, arrayOfFiles) { + files = fs.readdirSync(dirPath); + + arrayOfFiles = arrayOfFiles || []; + + files.forEach(function (file) { + const filePath = path.join(dirPath, file); + + if (ig.ignores(filePath)) { + return; + } + + if (fs.statSync(filePath).isDirectory()) { + arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles); + } else { + arrayOfFiles.push(path.join(__dirname, dirPath, "/", file)); + } + }); + + return arrayOfFiles; +}; + +function repairPath(ogPath) { + const newPath = ogPath.slice(0, -1); + fs.renameSync(ogPath, newPath); + console.log(`${ogPath} -> ${newPath}`); +} + +function executeTests() { + return new Promise((resolve, reject) => { + try { + console.log(`Running ${countTests()} tests`); + const ls = spawn("ng.cmd", ["test", "--watch=false"], { + cwd: __dirname, + }); + + let output = []; + ls.stdout.on("data", (data) => { + // console.log(`stdout: ${data}`); + if (typeof data === "string") { + output.push(data); + } + }); + + ls.stderr.on("data", (data) => { + // console.error(`stderr: ${data}`); + if (typeof data === "string") { + output.push(data); + } + }); + + ls.on("close", (code) => { + if (code !== 0) { + console.log(output.join("\n")); + } + console.log(`child process exited with code ${code}`); + resolve(code); + }); + } catch (error) { + error.status; // Might be 127 in your example. + error.message; // Holds the message you typically want. + error.stderr; // Holds the stderr output. Use `.toString()`. + error.stdout; // Holds the stdout output. Use `.toString()`. + console.error(error.message || error); + } + }); +} + +function getTests() { + const allFiles = getAllFiles(".", []); + return allFiles.filter((f) => f.endsWith(".spec.ts")); +} + +function getTestOverrides() { + const allFiles = getAllFiles(".", []); + return allFiles.filter((f) => f.endsWith(".spec.tsw")); +} + +function countTestsOverrides() { + return getTestOverrides().length; +} + +function countTests() { + return getTests().length; +} + +function runClear() { + console.log(`Running Clear`); + const allFiles = getAllFiles(".", []); + const testFiles = allFiles.filter((f) => f.endsWith(".spec.ts")); + + testFiles.forEach((f) => { + const newPath = f + "w"; + fs.renameSync(f, newPath); + console.log(`${f} -> ${newPath}`); + }); +} + +function runRepair() { + console.log(`Running Repair`); + const allFiles = getAllFiles(".", []); + const testFiles = allFiles.filter((f) => f.endsWith(".spec.tsw")); + + testFiles.forEach((f) => { + repairPath(f); + }); +} + +function runStep() { + console.log(`Running Next`); + const allFiles = getAllFiles(".", []); + const testFiles = allFiles.filter((f) => f.endsWith(".spec.tsw")); + + const firstFile = testFiles[0]; + + repairPath(firstFile); +} + +async function runFindBreak() { + console.log(`Running Find Break`); + runClear(); + + while (countTestsOverrides() > 0) { + runStep(); + const code = await executeTests(); + if (code !== 0) { + throw new Error("executeTests failed"); + } + } +} + +if (shouldClear) { + runClear(); +} + +if (shouldRepair) { + runRepair(); +} + +if (shouldStep) { + runStep(); +} + +if (shouldFindBreak) { + runFindBreak().catch((e) => { + const allTests = getTests(); + const lastTestFile = allTests[allTests.length - 1]; + console.error(`Failed test found: ${lastTestFile}`); + console.error(e); + }); +}