Include lamdera/codecs dependency in elm.json rewriting helpers.

This commit is contained in:
Dillon Kearns 2023-03-11 14:10:57 -08:00
parent 15edcd502e
commit c548e9b85b
22 changed files with 96 additions and 51 deletions

View File

@ -32,8 +32,6 @@
"elm-community/list-extra": "8.6.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"matheus23/elm-default-tailwind-modules": "2.0.3",
"mdgriffith/elm-codegen": "2.0.0",
"miniBill/elm-codec": "2.0.0",
@ -71,4 +69,4 @@
},
"indirect": {}
}
}
}

View File

@ -20,7 +20,7 @@
"dillonkearns/elm-cli-options-parser": "3.2.0",
"dillonkearns/elm-date-or-date-time": "2.0.0",
"dillonkearns/elm-graphql": "5.0.11",
"dillonkearns/elm-markdown": "7.0.0",
"dillonkearns/elm-markdown": "7.0.1",
"elm/browser": "1.0.2",
"elm/bytes": "1.0.8",
"elm/core": "1.0.5",
@ -34,12 +34,11 @@
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.3",
"elm-community/dict-extra": "2.4.0",
"elm-community/list-extra": "8.6.0",
"elm-community/json-extra": "4.3.0",
"elm-community/list-extra": "8.7.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"mdgriffith/elm-codegen": "2.0.0",
"mdgriffith/elm-codegen": "2.1.0",
"mgold/elm-nonempty-list": "4.2.0",
"miniBill/elm-codec": "2.0.0",
"noahzgordon/elm-color-extra": "1.0.2",
@ -48,7 +47,7 @@
"rtfeldman/elm-iso8601-date-strings": "1.1.4",
"the-sett/elm-pretty-printer": "3.0.0",
"the-sett/elm-syntax-dsl": "6.0.2",
"turboMaCk/non-empty-list-alias": "1.3.0",
"turboMaCk/non-empty-list-alias": "1.3.1",
"vito/elm-ansi": "10.0.1"
},
"indirect": {
@ -60,7 +59,7 @@
"fredcy/elm-parseint": "2.0.1",
"j-maas/elm-ordered-containers": "1.0.0",
"lukewestby/elm-string-interpolate": "1.0.4",
"miniBill/elm-unicode": "1.0.2",
"miniBill/elm-unicode": "1.0.3",
"robinheghan/murmur3": "1.0.0",
"rtfeldman/elm-hex": "1.0.0",
"stil4m/elm-syntax": "7.2.9",

View File

@ -31,8 +31,6 @@
"elm-community/list-extra": "8.6.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"matheus23/elm-default-tailwind-modules": "2.0.3",
"mdgriffith/elm-codegen": "2.1.0",
"miniBill/elm-codec": "2.0.0",

View File

@ -35,8 +35,6 @@
"elm-community/list-extra": "8.7.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"matheus23/elm-default-tailwind-modules": "4.0.1",
"mdgriffith/elm-codegen": "2.1.0",
"miniBill/elm-codec": "2.0.0",
@ -77,4 +75,4 @@
"elm/random": "1.0.0"
}
}
}
}

View File

@ -37,8 +37,6 @@
"jgrenat/elm-html-test-runner": "1.0.3",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"mdgriffith/elm-codegen": "2.0.0",
"mgold/elm-nonempty-list": "4.2.0",
"miniBill/elm-codec": "2.0.0",
@ -70,4 +68,4 @@
"direct": {},
"indirect": {}
}
}
}

View File

@ -31,8 +31,6 @@
"elm-community/list-extra": "8.6.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"matheus23/elm-default-tailwind-modules": "2.0.3",
"mdgriffith/elm-codegen": "2.0.0",
"miniBill/elm-codec": "2.0.0",

View File

@ -31,8 +31,6 @@
"elm-community/list-extra": "8.6.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"matheus23/elm-default-tailwind-modules": "2.0.3",
"mdgriffith/elm-codegen": "2.0.0",
"miniBill/elm-codec": "2.0.0",
@ -68,4 +66,4 @@
"direct": {},
"indirect": {}
}
}
}

View File

@ -32,8 +32,6 @@
"elm-community/list-extra": "8.6.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"matheus23/elm-default-tailwind-modules": "2.0.3",
"mdgriffith/elm-codegen": "2.0.0",
"miniBill/elm-codec": "2.0.0",
@ -71,4 +69,4 @@
},
"indirect": {}
}
}
}

View File

@ -31,8 +31,6 @@
"elm-community/list-extra": "8.6.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"matheus23/elm-default-tailwind-modules": "2.0.3",
"mdgriffith/elm-codegen": "2.0.0",
"miniBill/elm-codec": "2.0.0",

View File

@ -35,8 +35,6 @@
"elm-community/list-extra": "8.3.1",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"mdgriffith/elm-codegen": "2.0.0",
"miniBill/elm-codec": "1.2.0",
"noahzgordon/elm-color-extra": "1.0.2",
@ -71,4 +69,4 @@
"direct": {},
"indirect": {}
}
}
}

View File

@ -31,8 +31,6 @@
"elm-community/list-extra": "8.3.0",
"elm-community/result-extra": "2.4.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"mdgriffith/elm-codegen": "2.0.0",
"miniBill/elm-codec": "2.0.0",
"noahzgordon/elm-color-extra": "1.0.2",
@ -65,4 +63,4 @@
"mgold/elm-nonempty-list": "4.2.0"
}
}
}
}

View File

@ -36,7 +36,6 @@
"elm-community/result-extra": "2.4.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"mdgriffith/elm-codegen": "2.0.0",
"miniBill/elm-codec": "2.0.0",
"noahzgordon/elm-color-extra": "1.0.2",
@ -74,4 +73,4 @@
"direct": {},
"indirect": {}
}
}
}

View File

@ -30,8 +30,6 @@
"elm-community/list-extra": "8.7.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"matheus23/elm-default-tailwind-modules": "2.0.1",
"mdgriffith/elm-codegen": "2.0.0",
"miniBill/elm-codec": "2.0.0",
@ -64,4 +62,4 @@
"elm/random": "1.0.0"
}
}
}
}

View File

@ -37,8 +37,6 @@
"elm-community/list-extra": "8.3.1",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"mdgriffith/elm-codegen": "2.0.0",
"miniBill/elm-codec": "1.2.0",
"noahzgordon/elm-color-extra": "1.0.2",
@ -73,4 +71,4 @@
"direct": {},
"indirect": {}
}
}
}

View File

@ -37,8 +37,6 @@
"elm-community/list-extra": "8.6.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"mdgriffith/elm-codegen": "2.0.0",
"mgold/elm-nonempty-list": "4.2.0",
"miniBill/elm-codec": "2.0.0",
@ -71,4 +69,4 @@
"direct": {},
"indirect": {}
}
}
}

View File

@ -35,8 +35,6 @@
"elm-community/list-extra": "8.3.1",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"lamdera/core": "1.0.0",
"miniBill/elm-codec": "1.2.0",
"noahzgordon/elm-color-extra": "1.0.2",
"pablohirafuji/elm-syntax-highlight": "3.4.1",
@ -65,4 +63,4 @@
"direct": {},
"indirect": {}
}
}
}

View File

@ -6,6 +6,8 @@ import * as path from "path";
import * as kleur from "kleur/colors";
import { inject } from "elm-hot";
import { fileURLToPath } from "url";
import { rewriteElmJson } from "./rewrite-elm-json-help.js";
import { ensureDirSync } from "./file-helpers.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@ -16,7 +18,22 @@ export async function compileElmForBrowser(options) {
"elm-stuff/elm-pages/",
"browser-elm.js"
);
await runElm(options, "./.elm-pages/Main.elm", pathToClientElm);
const secretDir = path.join(process.cwd(), "elm-stuff/elm-pages/browser-elm");
await fsHelpers.tryMkdir(secretDir);
rewriteElmJson(process.cwd(), secretDir, function (elmJson) {
elmJson["source-directories"] = elmJson["source-directories"].map(
(item) => {
return "../../../" + item;
}
);
return elmJson;
});
await runElm(
options,
"../../../.elm-pages/Main.elm",
pathToClientElm,
secretDir
);
return fs.promises.writeFile(
"./.elm-pages/cache/elm.js",
inject(await fs.promises.readFile(pathToClientElm, "utf-8")).replace(

View File

@ -27,6 +27,7 @@ function rewriteClientElmJsonHelp(elmJson) {
elmJson["source-directories"] = elmJson["source-directories"].map((item) => {
return "../../../" + item;
});
elmJson["dependencies"]["direct"]["lamdera/codecs"] = "1.0.0";
// 3. add our own secret My.elm module 😈
elmJson["source-directories"].push(".elm-pages");
elmJson["source-directories"].push("app");

View File

@ -0,0 +1,56 @@
import * as fs from "node:fs";
import * as path from "node:path";
/**
* @param {string} sourceElmJsonPath
* @param {string} targetElmJsonPath
* @param {( (arg0: JSON) => JSON )?} modifyElmJson
*/
export async function rewriteElmJson(
sourceElmJsonPath,
targetElmJsonPath,
modifyElmJson
) {
if (!modifyElmJson) {
modifyElmJson = function (json) {
return json;
};
}
var elmJson = JSON.parse(
(
await fs.promises.readFile(path.join(sourceElmJsonPath, "elm.json"))
).toString()
);
let modifiedElmJson = modifyElmJson(elmJson);
// always add `lamdera/codecs` dependency
modifiedElmJson["dependencies"]["direct"]["lamdera/codecs"] = "1.0.0";
// write new elm.json
await writeFileIfChanged(
path.join(targetElmJsonPath, "elm.json"),
JSON.stringify(modifiedElmJson)
);
}
/**
* @param {fs.PathLike | fs.promises.FileHandle} filePath
* @param {string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | import("stream").Stream} content
*/
async function writeFileIfChanged(filePath, content) {
if (
!(await fileExists(filePath)) ||
(await fs.promises.readFile(filePath, "utf8")) !== content
) {
await fs.promises.writeFile(filePath, content);
}
}
/**
* @param {fs.PathLike} file
*/
function fileExists(file) {
return fs.promises
.access(file, fs.constants.F_OK)
.then(() => true)
.catch(() => false);
}

View File

@ -27,6 +27,7 @@ function rewriteElmJsonHelp(elmJson) {
elmJson["source-directories"] = elmJson["source-directories"].map((item) => {
return "../../" + item;
});
elmJson["dependencies"]["direct"]["lamdera/codecs"] = "1.0.0";
// 3. add our own secret My.elm module 😈
elmJson["source-directories"].push(".elm-pages");
return elmJson;

View File

@ -30,7 +30,6 @@
"elm-community/result-extra": "2.4.0",
"jluckyiv/elm-utc-date-strings": "1.0.0",
"justinmimbs/date": "4.0.1",
"lamdera/codecs": "1.0.0",
"mdgriffith/elm-codegen": "2.0.0",
"miniBill/elm-codec": "2.0.0",
"noahzgordon/elm-color-extra": "1.0.2",
@ -62,4 +61,4 @@
"direct": {},
"indirect": {}
}
}
}

View File

@ -309,6 +309,7 @@ init config flags url key =
type Msg userMsg pageData actionData sharedData errorPage
= LinkClicked Browser.UrlRequest
| UrlChanged Url
-- TODO rename to PagesMsg
| UserMsg (PagesMsg userMsg)
| SetField { formId : String, name : String, value : String }
| UpdateCacheAndUrlNew Bool Url (Maybe userMsg) (Result Http.Error ( Url, ResponseSketch pageData actionData sharedData ))