@@ -6,57 +6,85 @@ const compileToString = require("node-elm-compiler").compileToString;
66// template: "./tests-rendering/automation/templates/gather-styles.html",
77// target: "./tmp/test.html",
88// elm: "src/Tests/Run.elm",
9+// replace:
910// elmOptions: { cwd: "./tests-rendering" },
1011// }
1112
1213async function compile_and_embed(config) {
13− const template = fs.readFileSync(config.template);
14−
1514 const elm_entry_module = fs.readFileSync(
1615 path.join(config.elmOptions.cwd, config.elm),
1716 "utf8"
1817 );
19− // console.log(elm_entry_module);
18+
2019 const module_name = elm_entry_module
2120 .split(/[\r\n]+/)[0]
2221 .match(/module ([A-Za-z0-9\.]+)/i)[1];
23− // console.log(module_name);
24−
25− // throw "Ugh";
2622
2723 // we embed the compiled js to avoid having to start a server to read the app.
2824 await compileToString([config.elm], config.elmOptions).then(function (
2925 compiled_elm_code
3026 ) {
31− const compiled = eval(`\`${template}\``);
27+ // console.log(compiled_elm_code);
28+ const compiled = fs
29+ .readFileSync(config.template, "utf8")
30+ .replace(/~~_compiled_elm_code_~~/, () => compiled_elm_code)
31+ .replace(/~~_module_name_~~/, () => module_name);
32+
3233 fs.writeFileSync(config.target, compiled);
3334 });
3435}
3536
3637async function compile_to_string(config) {
37− const template = fs.readFileSync(config.template);
38−
3938 const elm_entry_module = fs.readFileSync(
4039 path.join(config.elmOptions.cwd, config.elm),
4140 "utf8"
4241 );
43− // console.log(elm_entry_module);
42+
4443 const module_name = elm_entry_module
4544 .split(/[\r\n]+/)[0]
4645 .match(/module ([A-Za-z0-9\.]+)/i)[1];
47− // console.log(module_name);
48−
49− // throw "Ugh";
5046
51− // we embed the compiled js to avoid having to start a server to read the app.
5247 const compiled = await compileToString([config.elm], config.elmOptions).then(
5348 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);
5553 }
5654 );
5755 return compiled;
5856}
5957
58+async function get_module_name(config) {
59+ const elm_entry_module = fs.readFileSync(
60+ path.join(config.cwd, config.elm),
61+ "utf8"
62+ );
63+
64+ const module_name = elm_entry_module
65+ .split(/[\r\n]+/)[0]
66+ .match(/module ([A-Za-z0-9\.]+)/i)[1];
67+ return module_name;
68+}
69+
70+async function create_runner(config) {
71+ const elm_entry_module = fs.readFileSync(config.elm, "utf8");
72+
73+ let module_name = elm_entry_module
74+ .split(/[\r\n]+/)[0]
75+ .match(/module ([A-Za-z0-9\.]+)/i)[1];
76+
77+ const module_name_sentence = module_name.replace(/([A-Z])/g, " $1");
78+
79+ const runner = fs
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);
84+}
85+
6086exports.compile_and_embed = compile_and_embed;
6187
88+exports.create_runner = create_runner;
89+
6290exports.compile_to_string = compile_to_string;