mirror of
https://github.com/mdgriffith/elm-ui.git
synced 2024-11-29 15:24:07 +03:00
update template viewer so we can both view a file and import it to the automation
This commit is contained in:
parent
2c582df903
commit
ee7398958f
@ -6,57 +6,85 @@ const compileToString = require("node-elm-compiler").compileToString;
|
|||||||
// template: "./tests-rendering/automation/templates/gather-styles.html",
|
// template: "./tests-rendering/automation/templates/gather-styles.html",
|
||||||
// target: "./tmp/test.html",
|
// target: "./tmp/test.html",
|
||||||
// elm: "src/Tests/Run.elm",
|
// elm: "src/Tests/Run.elm",
|
||||||
|
// replace:
|
||||||
// elmOptions: { cwd: "./tests-rendering" },
|
// elmOptions: { cwd: "./tests-rendering" },
|
||||||
// }
|
// }
|
||||||
|
|
||||||
async function compile_and_embed(config) {
|
async function compile_and_embed(config) {
|
||||||
const template = fs.readFileSync(config.template);
|
|
||||||
|
|
||||||
const elm_entry_module = fs.readFileSync(
|
const elm_entry_module = fs.readFileSync(
|
||||||
path.join(config.elmOptions.cwd, config.elm),
|
path.join(config.elmOptions.cwd, config.elm),
|
||||||
"utf8"
|
"utf8"
|
||||||
);
|
);
|
||||||
// console.log(elm_entry_module);
|
|
||||||
const module_name = elm_entry_module
|
const module_name = elm_entry_module
|
||||||
.split(/[\r\n]+/)[0]
|
.split(/[\r\n]+/)[0]
|
||||||
.match(/module ([A-Za-z0-9\.]+)/i)[1];
|
.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.
|
// we embed the compiled js to avoid having to start a server to read the app.
|
||||||
await compileToString([config.elm], config.elmOptions).then(function (
|
await compileToString([config.elm], config.elmOptions).then(function (
|
||||||
compiled_elm_code
|
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);
|
fs.writeFileSync(config.target, compiled);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compile_to_string(config) {
|
async function compile_to_string(config) {
|
||||||
const template = fs.readFileSync(config.template);
|
|
||||||
|
|
||||||
const elm_entry_module = fs.readFileSync(
|
const elm_entry_module = fs.readFileSync(
|
||||||
path.join(config.elmOptions.cwd, config.elm),
|
path.join(config.elmOptions.cwd, config.elm),
|
||||||
"utf8"
|
"utf8"
|
||||||
);
|
);
|
||||||
// console.log(elm_entry_module);
|
|
||||||
const module_name = elm_entry_module
|
const module_name = elm_entry_module
|
||||||
.split(/[\r\n]+/)[0]
|
.split(/[\r\n]+/)[0]
|
||||||
.match(/module ([A-Za-z0-9\.]+)/i)[1];
|
.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(
|
const compiled = await compileToString([config.elm], config.elmOptions).then(
|
||||||
function (compiled_elm_code) {
|
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;
|
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.compile_and_embed = compile_and_embed;
|
||||||
|
|
||||||
|
exports.create_runner = create_runner;
|
||||||
|
|
||||||
exports.compile_to_string = compile_to_string;
|
exports.compile_to_string = compile_to_string;
|
||||||
|
14
tests-rendering/automation/templates/Run.elm
Normal file
14
tests-rendering/automation/templates/Run.elm
Normal file
@ -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
|
||||||
|
]
|
@ -2,9 +2,9 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>Rendering Benchmark Viewer</title>
|
<title>Elm UI Rendering Test</title>
|
||||||
<script>
|
<script>
|
||||||
${compiled_elm_code}
|
~~_compiled_elm_code_~~
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
// Helpers
|
// Helpers
|
||||||
@ -138,11 +138,10 @@
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// Starting Elm App,
|
// Starting Elm App,
|
||||||
var app = Elm.${module_name}.init({
|
var app = Elm.~~_module_name_~~.init({
|
||||||
node: document.getElementById("elm-home"),
|
node: document.getElementById("elm-home"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// create a canvas for text measurements
|
// create a canvas for text measurements
|
||||||
let canvas = createHiDPICanvas(200, 100, "canvas");
|
let canvas = createHiDPICanvas(200, 100, "canvas");
|
||||||
|
|
||||||
|
@ -9,16 +9,16 @@ const http = require("http");
|
|||||||
|
|
||||||
var filepath = null;
|
var filepath = null;
|
||||||
program
|
program
|
||||||
.option("--run", "run all the tests")
|
.option("--all", "run all the tests")
|
||||||
.option("--debug", "run with debug on")
|
.option("--debug", "run with debug on")
|
||||||
.arguments("<filepath>")
|
.arguments("<filepath>")
|
||||||
.action(function (p) {
|
.action(function (p) {
|
||||||
filepath = path.join("./cases/open", p);
|
test_filepath = path.join("./tests-rendering/cases/open", p);
|
||||||
})
|
})
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
if (filepath == null && !program.run) {
|
if (test_filepath == null && !program.run) {
|
||||||
console.log("Open Cases");
|
console.log("Open Cases");
|
||||||
console.log("");
|
console.log("");
|
||||||
fs.readdirSync("./tests-rendering/cases/open").forEach((file) => {
|
fs.readdirSync("./tests-rendering/cases/open").forEach((file) => {
|
||||||
@ -29,15 +29,27 @@ program
|
|||||||
console.log("");
|
console.log("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (program.run) {
|
|
||||||
filepath = "./src/Tests/Run.elm";
|
if (program.all) {
|
||||||
|
filepath = "./src/Tests/All.elm";
|
||||||
|
} else {
|
||||||
|
filepath = "src/Tests/Run.elm";
|
||||||
|
build.create_runner({
|
||||||
|
elm: test_filepath,
|
||||||
|
template: "./tests-rendering/automation/templates/Run.elm",
|
||||||
|
target: "./tests-rendering/src/Tests/Run.elm",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
console.log("Compiling tests");
|
|
||||||
|
//
|
||||||
|
// Compile and serve
|
||||||
|
|
||||||
let content = await build.compile_to_string({
|
let content = await build.compile_to_string({
|
||||||
template: "./tests-rendering/automation/templates/gather-styles.html",
|
template: "./tests-rendering/automation/templates/gather-styles.html",
|
||||||
elm: filepath,
|
elm: filepath,
|
||||||
elmOptions: { cwd: "./tests-rendering", debug: program.debug },
|
elmOptions: { cwd: "./tests-rendering", debug: program.debug },
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Finished compiling");
|
console.log("Finished compiling");
|
||||||
// console.log(content);
|
// console.log(content);
|
||||||
|
|
||||||
|
@ -1,28 +1,25 @@
|
|||||||
{
|
{
|
||||||
"type": "application",
|
"type": "application",
|
||||||
"source-directories": [
|
"source-directories": ["src", "../src", "cases/open"],
|
||||||
"src",
|
"elm-version": "0.19.1",
|
||||||
"../src"
|
"dependencies": {
|
||||||
],
|
"direct": {
|
||||||
"elm-version": "0.19.1",
|
"elm/browser": "1.0.2",
|
||||||
"dependencies": {
|
"elm/core": "1.0.0",
|
||||||
"direct": {
|
"elm/html": "1.0.0",
|
||||||
"elm/browser": "1.0.2",
|
"elm/json": "1.0.0",
|
||||||
"elm/core": "1.0.0",
|
"elm/parser": "1.1.0",
|
||||||
"elm/html": "1.0.0",
|
"elm/random": "1.0.0",
|
||||||
"elm/json": "1.0.0",
|
"elm/time": "1.0.0",
|
||||||
"elm/parser": "1.1.0",
|
"elm/virtual-dom": "1.0.2",
|
||||||
"elm/random": "1.0.0",
|
"elm-explorations/test": "1.1.0"
|
||||||
"elm/time": "1.0.0",
|
|
||||||
"elm/virtual-dom": "1.0.2",
|
|
||||||
"elm-explorations/test": "1.1.0"
|
|
||||||
},
|
|
||||||
"indirect": {
|
|
||||||
"elm/url": "1.0.0"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"test-dependencies": {
|
"indirect": {
|
||||||
"direct": {},
|
"elm/url": "1.0.0"
|
||||||
"indirect": {}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"test-dependencies": {
|
||||||
|
"direct": {},
|
||||||
|
"indirect": {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user