From ee7398958f10869e7dfce78ad9ab63e15de5acc0 Mon Sep 17 00:00:00 2001 From: Elm UI Automation Date: Fri, 15 May 2020 09:19:13 -0400 Subject: [PATCH] update template viewer so we can both view a file and import it to the automation --- tests-rendering/automation/build.js | 58 ++++++++++++++----- tests-rendering/automation/templates/Run.elm | 14 +++++ .../automation/templates/gather-styles.html | 7 +-- tests-rendering/automation/view.js | 24 ++++++-- tests-rendering/elm.json | 45 +++++++------- 5 files changed, 99 insertions(+), 49 deletions(-) create mode 100644 tests-rendering/automation/templates/Run.elm diff --git a/tests-rendering/automation/build.js b/tests-rendering/automation/build.js index 5ada4fb..973d7c2 100644 --- a/tests-rendering/automation/build.js +++ b/tests-rendering/automation/build.js @@ -6,57 +6,85 @@ const compileToString = require("node-elm-compiler").compileToString; // template: "./tests-rendering/automation/templates/gather-styles.html", // target: "./tmp/test.html", // elm: "src/Tests/Run.elm", +// replace: // elmOptions: { cwd: "./tests-rendering" }, // } async function compile_and_embed(config) { - const template = fs.readFileSync(config.template); - const elm_entry_module = fs.readFileSync( path.join(config.elmOptions.cwd, config.elm), "utf8" ); - // console.log(elm_entry_module); + const module_name = elm_entry_module .split(/[\r\n]+/)[0] .match(/module ([A-Za-z0-9\.]+)/i)[1]; - // console.log(module_name); - - // throw "Ugh"; // we embed the compiled js to avoid having to start a server to read the app. await compileToString([config.elm], config.elmOptions).then(function ( compiled_elm_code ) { - const compiled = eval(`\`${template}\``); + // console.log(compiled_elm_code); + const compiled = fs + .readFileSync(config.template, "utf8") + .replace(/~~_compiled_elm_code_~~/, () => compiled_elm_code) + .replace(/~~_module_name_~~/, () => module_name); + fs.writeFileSync(config.target, compiled); }); } async function compile_to_string(config) { - const template = fs.readFileSync(config.template); - const elm_entry_module = fs.readFileSync( path.join(config.elmOptions.cwd, config.elm), "utf8" ); - // console.log(elm_entry_module); + const module_name = elm_entry_module .split(/[\r\n]+/)[0] .match(/module ([A-Za-z0-9\.]+)/i)[1]; - // console.log(module_name); - // throw "Ugh"; - - // we embed the compiled js to avoid having to start a server to read the app. const compiled = await compileToString([config.elm], config.elmOptions).then( function (compiled_elm_code) { - return eval(`\`${template}\``); + return fs + .readFileSync(config.template, "utf8") + .replace(/~~_module_name_~~/g, () => module_name) + .replace(/~~_compiled_elm_code_~~/g, () => compiled_elm_code); } ); return compiled; } +async function get_module_name(config) { + const elm_entry_module = fs.readFileSync( + path.join(config.cwd, config.elm), + "utf8" + ); + + const module_name = elm_entry_module + .split(/[\r\n]+/)[0] + .match(/module ([A-Za-z0-9\.]+)/i)[1]; + return module_name; +} + +async function create_runner(config) { + const elm_entry_module = fs.readFileSync(config.elm, "utf8"); + + let module_name = elm_entry_module + .split(/[\r\n]+/)[0] + .match(/module ([A-Za-z0-9\.]+)/i)[1]; + + const module_name_sentence = module_name.replace(/([A-Z])/g, " $1"); + + const runner = fs + .readFileSync(config.template, "utf8") + .replace(/~~_module_name_~~/g, () => module_name) + .replace(/~~_module_name_sentence_~~/g, () => module_name_sentence); + fs.writeFileSync(config.target, runner); +} + exports.compile_and_embed = compile_and_embed; +exports.create_runner = create_runner; + exports.compile_to_string = compile_to_string; diff --git a/tests-rendering/automation/templates/Run.elm b/tests-rendering/automation/templates/Run.elm new file mode 100644 index 0000000..55118e9 --- /dev/null +++ b/tests-rendering/automation/templates/Run.elm @@ -0,0 +1,14 @@ +module Tests.Run exposing (main) + +{-| _NOTE_ this is auto-generated! Notouchy! +-} + +import ~~_module_name_~~ +import Testable.Runner + + +main : Testable.Runner.TestableProgram +main = + Testable.Runner.program + [ Testable.Runner.rename "~~_module_name_sentence_~~" ~~_module_name_~~.view + ] diff --git a/tests-rendering/automation/templates/gather-styles.html b/tests-rendering/automation/templates/gather-styles.html index 3024f29..388f04c 100644 --- a/tests-rendering/automation/templates/gather-styles.html +++ b/tests-rendering/automation/templates/gather-styles.html @@ -2,9 +2,9 @@ - Rendering Benchmark Viewer + Elm UI Rendering Test