@@ -6,57 +6,85 @@ const compileToString = require("node-elm-compiler").compileToString;
6// template: "./tests-rendering/automation/templates/gather-styles.html",
6// template: "./tests-rendering/automation/templates/gather-styles.html",
7// target: "./tmp/test.html",
7// target: "./tmp/test.html",
8// elm: "src/Tests/Run.elm",
8// elm: "src/Tests/Run.elm",
9// elmOptions: { cwd: "./tests-rendering" },
10// elmOptions: { cwd: "./tests-rendering" },
12async function compile_and_embed(config) {
13async function compile_and_embed(config) {
13− const template = fs.readFileSync(config.template);
15 const elm_entry_module = fs.readFileSync(
14 const elm_entry_module = fs.readFileSync(
16 path.join(config.elmOptions.cwd, config.elm),
15 path.join(config.elmOptions.cwd, config.elm),
19− // console.log(elm_entry_module);
18+
20 const module_name = elm_entry_module
19 const module_name = elm_entry_module
21 .split(/[\r\n]+/)[0]
20 .split(/[\r\n]+/)[0]
22 .match(/module ([A-Za-z0-9\.]+)/i)[1];
21 .match(/module ([A-Za-z0-9\.]+)/i)[1];
23− // console.log(module_name);
27 // we embed the compiled js to avoid having to start a server to read the app.
23 // we embed the compiled js to avoid having to start a server to read the app.
28 await compileToString([config.elm], config.elmOptions).then(function (
24 await compileToString([config.elm], config.elmOptions).then(function (
29 compiled_elm_code
25 compiled_elm_code
27+ // console.log(compiled_elm_code);
31− const compiled = eval(`\`${template}\``);
28+ const compiled = fs
29+ .readFileSync(config.template, "utf8")
30+ .replace(/~~_compiled_elm_code_~~/, () => compiled_elm_code)
31+ .replace(/~~_module_name_~~/, () => module_name);
32 fs.writeFileSync(config.target, compiled);
33 fs.writeFileSync(config.target, compiled);
36async function compile_to_string(config) {
37async function compile_to_string(config) {
37− const template = fs.readFileSync(config.template);
39 const elm_entry_module = fs.readFileSync(
38 const elm_entry_module = fs.readFileSync(
40 path.join(config.elmOptions.cwd, config.elm),
39 path.join(config.elmOptions.cwd, config.elm),
43− // console.log(elm_entry_module);
42+
44 const module_name = elm_entry_module
43 const module_name = elm_entry_module
45 .split(/[\r\n]+/)[0]
44 .split(/[\r\n]+/)[0]
46 .match(/module ([A-Za-z0-9\.]+)/i)[1];
45 .match(/module ([A-Za-z0-9\.]+)/i)[1];
47− // console.log(module_name);
51− // we embed the compiled js to avoid having to start a server to read the app.
52 const compiled = await compileToString([config.elm], config.elmOptions).then(
47 const compiled = await compileToString([config.elm], config.elmOptions).then(
53 function (compiled_elm_code) {
48 function (compiled_elm_code) {
54− return eval(`\`${template}\``);
49+ return fs
50+ .readFileSync(config.template, "utf8")
51+ .replace(/~~_module_name_~~/g, () => module_name)
52+ .replace(/~~_compiled_elm_code_~~/g, () => compiled_elm_code);
57 return compiled;
55 return compiled;
58+async function get_module_name(config) {
59+ const elm_entry_module = fs.readFileSync(
60+ path.join(config.cwd, config.elm),
64+ const module_name = elm_entry_module
66+ .match(/module ([A-Za-z0-9\.]+)/i)[1];
70+async function create_runner(config) {
71+ const elm_entry_module = fs.readFileSync(config.elm, "utf8");
73+ let module_name = elm_entry_module
75+ .match(/module ([A-Za-z0-9\.]+)/i)[1];
77+ const module_name_sentence = module_name.replace(/([A-Z])/g, " $1");
80+ .readFileSync(config.template, "utf8")
81+ .replace(/~~_module_name_~~/g, () => module_name)
82+ .replace(/~~_module_name_sentence_~~/g, () => module_name_sentence);
83+ fs.writeFileSync(config.target, runner);
60exports.compile_and_embed = compile_and_embed;
86exports.compile_and_embed = compile_and_embed;
88+exports.create_runner = create_runner;
62exports.compile_to_string = compile_to_string;
90exports.compile_to_string = compile_to_string;