Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
elm-stuff
guida-stuff
.DS_Store
.idea

Expand Down
22 changes: 17 additions & 5 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,33 @@
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"debois/elm-dom": "1.3.0",
"dillonkearns/elm-markdown": "7.0.1",
"elm/browser": "1.0.2",
"elm/bytes": "1.0.8",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"elm/parser": "1.1.0",
"elm/project-metadata-utils": "1.0.2",
"elm/regex": "1.0.0",
"elm/svg": "1.0.1",
"elm/url": "1.0.0"
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm-community/result-extra": "2.4.0",
"fapian/elm-html-aria": "1.4.0",
"feathericons/elm-feather": "1.5.0",
"justinmimbs/time-extra": "1.2.0",
"krisajenkins/remotedata": "6.1.0",
"mdgriffith/elm-ui": "1.1.8",
"ryan-haskell/date-format": "1.0.0"
},
"indirect": {
"elm/bytes": "1.0.8",
"elm/file": "1.0.5",
"elm/parser": "1.1.0",
"elm/time": "1.0.0",
"elm/virtual-dom": "1.0.3"
"elm/virtual-dom": "1.0.3",
"justinmimbs/date": "4.1.0",
"rtfeldman/elm-hex": "1.0.0"
}
},
"test-dependencies": {
Expand Down
76 changes: 71 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,74 @@
import "@vanillawc/wc-codemirror";
import guida from "guida";
import { createFs } from "indexeddb-fs";
import { Elm } from "../tmp/elm.js";

(async () => {
const guidaApp = await guida.init({
const fs = createFs({ databaseName: "guida-fs" });

const config = {
env: {
GUIDA_REGISTRY: "https://guida-package-registry.fly.dev"
},
writeFile: fs.writeFile,
readFile: fs.readFile,
details: fs.details,
createDirectory: fs.createDirectory,
readDirectory: fs.readDirectory
};

(async () => {
await fs.createDirectory("root/src");

const theme = localStorage.getItem("theme");
const app = Elm.Main.init({ flags: { theme, year: new Date().getFullYear() } });

if (theme === "dark") {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}

app.ports.setTheme.subscribe((theme) => {
localStorage.setItem("theme", theme);

if (theme === "dark") {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
});

const app = Elm.Main.init({ flags: new Date().getFullYear() });
app.ports.setupProject.subscribe(async ({ direct, indirect, content }) => {
const directDependencies = direct.map((d) => `"${d.author}/${d.project}": "${d.version}"`).join(", ");
const indirectDependencies = indirect.map((d) => `"${d.author}/${d.project}": "${d.version}"`).join(", ");

fs.writeFile("root/elm.json", `{
"type": "application",
"source-directories": [ "src" ],
"elm-version": "0.19.1",
"dependencies": {
"direct": { ${directDependencies} },
"indirect": { ${indirectDependencies} }
},
"test-dependencies": { "direct": {}, "indirect": {} }
}`);

if (content) {
await setEditorContentAndRebuild(content);
}
});

const setEditorContentAndRebuild = async (content) => {
if (content) {
document.getElementById("editor").value = content;
}

const result = await guidaApp.make(content || document.getElementById("editor").value, {
const path = "root/src/Main.guida";
await fs.writeFile(path, content || document.getElementById("editor").value);

const result = await guida.make(config, path, {
debug: false,
optimize: true,
optimize: false,
sourcemaps: false
});

Expand All @@ -31,4 +83,18 @@ import { Elm } from "../tmp/elm.js";
app.ports.rebuild.subscribe(async () => {
await setEditorContentAndRebuild(null);
});

app.ports.install.subscribe(async (info) => {
await guida.install(config, info.packageString);
const elmJsonContent = await fs.readFile("root/elm.json");
const result = JSON.parse(elmJsonContent);
app.ports.installResult.send({ ...info, result });
});

app.ports.uninstall.subscribe(async (info) => {
await guida.uninstall(config, info.packageString);
const elmJsonContent = await fs.readFile("root/elm.json");
const result = JSON.parse(elmJsonContent);
app.ports.uninstallResult.send({ ...info, result });
});
})();
Loading