mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-27 21:29:55 +03:00
Merge pull request #262 from dillonkearns/elm-debug-flag
Add --debug flag for elm-pages dev
This commit is contained in:
commit
b2f514d0b0
@ -225,13 +225,13 @@ function elmOptimizeLevel2(elmEntrypointPath, outputPath, cwd) {
|
|||||||
*/
|
*/
|
||||||
async function spawnElmMake(options, elmEntrypointPath, outputPath, cwd) {
|
async function spawnElmMake(options, elmEntrypointPath, outputPath, cwd) {
|
||||||
if (options.debug) {
|
if (options.debug) {
|
||||||
await runElmMake(elmEntrypointPath, outputPath, cwd);
|
await runElmMake(options, elmEntrypointPath, outputPath, cwd);
|
||||||
} else {
|
} else {
|
||||||
await elmOptimizeLevel2(elmEntrypointPath, outputPath, cwd);
|
await elmOptimizeLevel2(elmEntrypointPath, outputPath, cwd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function runElmMake(elmEntrypointPath, outputPath, cwd) {
|
function runElmMake(options, elmEntrypointPath, outputPath, cwd) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const subprocess = spawnCallback(
|
const subprocess = spawnCallback(
|
||||||
`elm`,
|
`elm`,
|
||||||
@ -240,7 +240,7 @@ function runElmMake(elmEntrypointPath, outputPath, cwd) {
|
|||||||
elmEntrypointPath,
|
elmEntrypointPath,
|
||||||
"--output",
|
"--output",
|
||||||
outputPath,
|
outputPath,
|
||||||
"--debug",
|
...(options.debug ? ["--debug"] : []),
|
||||||
"--report",
|
"--report",
|
||||||
"json",
|
"json",
|
||||||
],
|
],
|
||||||
|
@ -43,6 +43,7 @@ async function main() {
|
|||||||
.command("dev")
|
.command("dev")
|
||||||
.description("start a dev server")
|
.description("start a dev server")
|
||||||
.option("--port <number>", "serve site at localhost:<port>", "1234")
|
.option("--port <number>", "serve site at localhost:<port>", "1234")
|
||||||
|
.option("--debug", "Run elm make with --debug")
|
||||||
.option(
|
.option(
|
||||||
"--keep-cache",
|
"--keep-cache",
|
||||||
"Preserve the HTTP and JS Port cache instead of deleting it on server start"
|
"Preserve the HTTP and JS Port cache instead of deleting it on server start"
|
||||||
|
@ -10,9 +10,9 @@ const pathToClientElm = path.join(
|
|||||||
"browser-elm.js"
|
"browser-elm.js"
|
||||||
);
|
);
|
||||||
|
|
||||||
async function spawnElmMake(elmEntrypointPath, outputPath, cwd) {
|
async function spawnElmMake(options, elmEntrypointPath, outputPath, cwd) {
|
||||||
const fullOutputPath = cwd ? path.join(cwd, outputPath) : outputPath;
|
const fullOutputPath = cwd ? path.join(cwd, outputPath) : outputPath;
|
||||||
await runElm(elmEntrypointPath, outputPath, cwd);
|
await runElm(options, elmEntrypointPath, outputPath, cwd);
|
||||||
|
|
||||||
await fs.promises.writeFile(
|
await fs.promises.writeFile(
|
||||||
fullOutputPath,
|
fullOutputPath,
|
||||||
@ -35,8 +35,12 @@ async function spawnElmMake(elmEntrypointPath, outputPath, cwd) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compileElmForBrowser() {
|
async function compileElmForBrowser(options) {
|
||||||
await runElm("./.elm-pages/TemplateModulesBeta.elm", pathToClientElm);
|
await runElm(
|
||||||
|
options,
|
||||||
|
"./.elm-pages/TemplateModulesBeta.elm",
|
||||||
|
pathToClientElm
|
||||||
|
);
|
||||||
return fs.promises.writeFile(
|
return fs.promises.writeFile(
|
||||||
"./.elm-pages/cache/elm.js",
|
"./.elm-pages/cache/elm.js",
|
||||||
inject(await fs.promises.readFile(pathToClientElm, "utf-8"))
|
inject(await fs.promises.readFile(pathToClientElm, "utf-8"))
|
||||||
@ -46,9 +50,10 @@ async function compileElmForBrowser() {
|
|||||||
/**
|
/**
|
||||||
* @param {string} elmEntrypointPath
|
* @param {string} elmEntrypointPath
|
||||||
* @param {string} outputPath
|
* @param {string} outputPath
|
||||||
* @param {string} [ cwd ]
|
* @param {string} [cwd]
|
||||||
|
* @param {{ debug: boolean; }} options
|
||||||
*/
|
*/
|
||||||
async function runElm(elmEntrypointPath, outputPath, cwd) {
|
async function runElm(options, elmEntrypointPath, outputPath, cwd) {
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const child = spawnCallback(
|
const child = spawnCallback(
|
||||||
@ -58,7 +63,7 @@ async function runElm(elmEntrypointPath, outputPath, cwd) {
|
|||||||
elmEntrypointPath,
|
elmEntrypointPath,
|
||||||
"--output",
|
"--output",
|
||||||
outputPath,
|
outputPath,
|
||||||
"--debug",
|
...(options.debug ? ["--debug"] : []),
|
||||||
"--report",
|
"--report",
|
||||||
"json",
|
"json",
|
||||||
],
|
],
|
||||||
|
@ -21,7 +21,7 @@ const baseMiddleware = require("./basepath-middleware.js");
|
|||||||
const devcert = require("devcert");
|
const devcert = require("devcert");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {{ port: string; base: string; https: boolean; }} options
|
* @param {{ port: string; base: string; https: boolean; debug: boolean; }} options
|
||||||
*/
|
*/
|
||||||
async function start(options) {
|
async function start(options) {
|
||||||
let threadReadyQueue = [];
|
let threadReadyQueue = [];
|
||||||
@ -59,8 +59,8 @@ async function start(options) {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
let clientElmMakeProcess = compileElmForBrowser();
|
let clientElmMakeProcess = compileElmForBrowser(options);
|
||||||
let pendingCliCompile = compileCliApp();
|
let pendingCliCompile = compileCliApp(options);
|
||||||
watchElmSourceDirs(true);
|
watchElmSourceDirs(true);
|
||||||
|
|
||||||
async function setup() {
|
async function setup() {
|
||||||
@ -105,8 +105,9 @@ async function start(options) {
|
|||||||
watcher.add("./port-data-source.js");
|
watcher.add("./port-data-source.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compileCliApp() {
|
async function compileCliApp(options) {
|
||||||
await spawnElmMake(
|
await spawnElmMake(
|
||||||
|
options,
|
||||||
".elm-pages/TemplateModulesBeta.elm",
|
".elm-pages/TemplateModulesBeta.elm",
|
||||||
"elm.js",
|
"elm.js",
|
||||||
"elm-stuff/elm-pages/"
|
"elm-stuff/elm-pages/"
|
||||||
@ -154,8 +155,8 @@ async function start(options) {
|
|||||||
if (needToRerunCodegen(eventName, pathThatChanged)) {
|
if (needToRerunCodegen(eventName, pathThatChanged)) {
|
||||||
try {
|
try {
|
||||||
await codegen.generate(options.base);
|
await codegen.generate(options.base);
|
||||||
clientElmMakeProcess = compileElmForBrowser();
|
clientElmMakeProcess = compileElmForBrowser(options);
|
||||||
pendingCliCompile = compileCliApp();
|
pendingCliCompile = compileCliApp(options);
|
||||||
|
|
||||||
Promise.all([clientElmMakeProcess, pendingCliCompile])
|
Promise.all([clientElmMakeProcess, pendingCliCompile])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@ -180,8 +181,8 @@ async function start(options) {
|
|||||||
clientElmMakeProcess = Promise.reject(errorJson);
|
clientElmMakeProcess = Promise.reject(errorJson);
|
||||||
pendingCliCompile = Promise.reject(errorJson);
|
pendingCliCompile = Promise.reject(errorJson);
|
||||||
} else {
|
} else {
|
||||||
clientElmMakeProcess = compileElmForBrowser();
|
clientElmMakeProcess = compileElmForBrowser(options);
|
||||||
pendingCliCompile = compileCliApp();
|
pendingCliCompile = compileCliApp(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all([clientElmMakeProcess, pendingCliCompile])
|
Promise.all([clientElmMakeProcess, pendingCliCompile])
|
||||||
|
Loading…
Reference in New Issue
Block a user