Skip to content

Commit

Permalink
Setting up compilation of morphir-elm-compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianReeves committed May 25, 2024
1 parent d15443e commit 548dccc
Show file tree
Hide file tree
Showing 27 changed files with 264 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ zig-out/

# Build Artifacts
out/

dist/
Binary file modified bun.lockb
Binary file not shown.
109 changes: 53 additions & 56 deletions packages/morphir-elm-compiler/elm.json
Original file line number Diff line number Diff line change
@@ -1,60 +1,57 @@
{
"type": "application",
"source-directories": [
"../src",
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"TSFoster/elm-uuid": "4.2.0",
"chain-partners/elm-bignum": "1.0.1",
"cuducos/elm-format-number": "8.1.4",
"dillonkearns/elm-markdown": "7.0.0",
"dosarf/elm-tree-view": "3.0.0",
"elm/browser": "1.0.2",
"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/random": "1.0.0",
"elm/regex": "1.0.0",
"elm/svg": "1.0.1",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm-community/array-extra": "2.3.0",
"elm-community/graph": "6.0.0",
"elm-community/list-extra": "8.2.3",
"elm-community/maybe-extra": "5.2.0",
"elm-community/random-extra": "3.2.0",
"elm-explorations/markdown": "1.0.0",
"justinmimbs/date": "4.0.1",
"mdgriffith/elm-ui": "1.1.8",
"pzp1997/assoc-list": "1.0.0",
"rundis/elm-bootstrap": "5.2.0",
"stil4m/elm-syntax": "7.2.0"
},
"indirect": {
"TSFoster/elm-bytes-extra": "1.3.0",
"TSFoster/elm-md5": "2.0.1",
"TSFoster/elm-sha1": "2.1.1",
"avh4/elm-color": "1.0.0",
"avh4/elm-fifo": "1.0.4",
"danfishgold/base64-bytes": "1.1.0",
"elm/bytes": "1.0.8",
"elm/file": "1.0.5",
"elm/virtual-dom": "1.0.2",
"elm-community/intdict": "3.0.0",
"elm-community/json-extra": "4.2.0",
"myrho/elm-round": "1.0.4",
"rtfeldman/elm-hex": "1.0.0",
"rtfeldman/elm-iso8601-date-strings": "1.1.3",
"stil4m/structured-writer": "1.0.2"
}
"type": "application",
"source-directories": ["../../../src", "src/elm"],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"TSFoster/elm-uuid": "4.2.0",
"chain-partners/elm-bignum": "1.0.1",
"cuducos/elm-format-number": "8.1.4",
"dillonkearns/elm-markdown": "7.0.0",
"dosarf/elm-tree-view": "3.0.0",
"elm/browser": "1.0.2",
"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/random": "1.0.0",
"elm/regex": "1.0.0",
"elm/svg": "1.0.1",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm-community/array-extra": "2.3.0",
"elm-community/graph": "6.0.0",
"elm-community/list-extra": "8.2.3",
"elm-community/maybe-extra": "5.2.0",
"elm-community/random-extra": "3.2.0",
"elm-explorations/markdown": "1.0.0",
"justinmimbs/date": "4.0.1",
"mdgriffith/elm-ui": "1.1.8",
"pzp1997/assoc-list": "1.0.0",
"rundis/elm-bootstrap": "5.2.0",
"stil4m/elm-syntax": "7.2.0"
},
"test-dependencies": {
"direct": {},
"indirect": {}
"indirect": {
"TSFoster/elm-bytes-extra": "1.3.0",
"TSFoster/elm-md5": "2.0.1",
"TSFoster/elm-sha1": "2.1.1",
"avh4/elm-color": "1.0.0",
"avh4/elm-fifo": "1.0.4",
"danfishgold/base64-bytes": "1.1.0",
"elm/bytes": "1.0.8",
"elm/file": "1.0.5",
"elm/virtual-dom": "1.0.2",
"elm-community/intdict": "3.0.0",
"elm-community/json-extra": "4.2.0",
"myrho/elm-round": "1.0.4",
"rtfeldman/elm-hex": "1.0.0",
"rtfeldman/elm-iso8601-date-strings": "1.1.3",
"stil4m/structured-writer": "1.0.2"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as util from 'util'
import * as fs from 'fs'
import * as path from 'path'
import crypto from 'crypto'
import * as util from 'util';
import * as fs from 'fs';
import * as path from 'path';
import crypto from 'crypto';

const fsExists = util.promisify(fs.exists)
const fsReadDir = util.promisify(fs.readdir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ interface CommandOptions {
const stats = async (
input: string,
outputPath: string,
options: CommandOptions
_options: CommandOptions
) => {
await fsMakeDir(outputPath, {
recursive: true,
Expand Down Expand Up @@ -338,7 +338,7 @@ const stats = async (
};

const fileExist = async (filePath: string) => {
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
fs.access(filePath, fs.constants.F_OK, (err) => {
if (err) {
resolve(false);
Expand Down Expand Up @@ -375,7 +375,7 @@ const findFilesToDelete = async (outputPath: string, fileMap: string[]) => {
}, Promise.resolve([]));
return filesToDelete.concat(await subDirFilesToDelete);
};
const files = fileMap.map(([[dirPath, fileName], content]: any) => {
const files = fileMap.map(([[dirPath, fileName], _content]: any) => {
const fileDir = dirPath.reduce(
(accum: string, next: string) => path.join(accum, next),
outputPath
Expand All @@ -386,7 +386,7 @@ const findFilesToDelete = async (outputPath: string, fileMap: string[]) => {
};

function copyRedistributables(options: CommandOptions, outputPath: string) {
const copyFiles = (src: string, dest: string) => {
const copyFiles = (src: string, _dest: string) => {
const sourceDirectory: string = path.join(
path.dirname(__dirname),
"redistributable",
Expand Down Expand Up @@ -518,8 +518,8 @@ async function writeDockerfile(
async function testCoverage(
irPath: string,
testsPath: string,
outputPath: string,
options: CommandOptions
_outputPath: string,
_options: CommandOptions
) {
// Morphir IR
const morphirIR: Buffer = await fsReadFile(path.resolve(irPath))
Expand All @@ -530,7 +530,7 @@ async function testCoverage(
const morphirTestJson: JSON = JSON.parse(morphirTest.toString())

// output path
const output = path.join(path.resolve(outputPath), "morphir-test-coverage.json")
//const _output = path.join(path.resolve(outputPath), "morphir-test-coverage.json")

return new Promise((resolve, reject) => {
worker.ports.testCoverageResult.subscribe(([err, data]: any) => {
Expand All @@ -547,7 +547,7 @@ async function testCoverage(
});
}

export = {
export default {
gen,
make,
writeFile,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ This file serves as the entrypoint for Json Schema Backend configuration process
import * as fs from "fs";
import * as path from 'path';
import * as util from 'util'
import cli from "./cli";

const fsReadFile = util.promisify(fs.readFile);
const configFilePath: string = "JsonSchema.config.json";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as util from "util";
import * as fs from "fs";
// import * as util from "util";
// import * as fs from "fs";
import { z } from "zod";
import { getUri } from "get-uri";
import { decode, labelToName } from "whatwg-encoding";
import { Readable } from "stream";
import { ResultAsync } from "neverthrow";

const parseDataUrl = require("data-urls");
const fsReadFile = util.promisify(fs.readFile);
//const fsReadFile = util.promisify(fs.readFile);

const DataUrl = z.string().trim().transform((val, ctx) => {
const parsed = parseDataUrl(val)
Expand All @@ -34,15 +34,15 @@ const FileUrl = z.string().trim().url().transform((val, ctx) => {

const Url = z.string().url().transform((url) => new URL(url));

const PathOrUrl = z.union([FileUrl, z.string().trim().min(1)]);
//const PathOrUrl = z.union([FileUrl, z.string().trim().min(1)]);

const GithubData = z.object({
owner: z.string(),
repo: z.string(),
baseUrl: z.string().optional()
});
// const GithubData = z.object({
// owner: z.string(),
// repo: z.string(),
// baseUrl: z.string().optional()
// });

const GithubConfig = z.union([GithubData, z.string()]);
//const GithubConfig = z.union([GithubData, z.string()]);

const DependencySettings = z.union([DataUrl, FileUrl, z.string().trim()])
const Dependencies = z.array(DependencySettings).default([]);
Expand Down Expand Up @@ -88,22 +88,22 @@ const DependencyConfigToDependencyEvents = DependencyConfig.transform((config) =
});


const MorphirDistribution = z.tuple([z.string()]).rest(z.unknown());
const MorphirIRFile = z.object({
formatVersion: z.number().int(),
distribution: MorphirDistribution
}).passthrough();
//const MorphirDistribution = z.tuple([z.string()]).rest(z.unknown());
// const MorphirIRFile = z.object({
// formatVersion: z.number().int(),
// distribution: MorphirDistribution
// }).passthrough();

type DataUrl = z.infer<typeof DataUrl>;
type FileUrl = z.infer<typeof FileUrl>;
type Url = z.infer<typeof Url>;
type DependencyConfigToDependencyEvents = z.infer<typeof DependencyConfigToDependencyEvents>
type PathOrUrl = z.infer<typeof PathOrUrl>;
type GithubData = z.infer<typeof GithubData>;
type GithubConfig = z.infer<typeof GithubConfig>;
//type PathOrUrl = z.infer<typeof PathOrUrl>;
//type GithubData = z.infer<typeof GithubData>;
//type GithubConfig = z.infer<typeof GithubConfig>;
type DependencyEvent = z.infer<typeof DependencyEvent>;
type MorphirDistribution = z.infer<typeof MorphirDistribution>;
type MorphirIRFile = z.infer<typeof MorphirIRFile>;
//type MorphirDistribution = z.infer<typeof MorphirDistribution>;
//type MorphirIRFile = z.infer<typeof MorphirIRFile>;
export type DependencyConfig = z.infer<typeof DependencyConfig>;

export async function loadAllDependencies(config: DependencyConfig) {
Expand Down Expand Up @@ -218,23 +218,23 @@ class DependencyError extends Error {
source?: string;
}

class LocalDependencyNotFound extends Error {
constructor(message: string, source?: string, pathOrUrl?: PathOrUrl, cause?: Error | unknown) {
super(message);
this.name = "LocalDependencyNotFound";
if (cause) {
this.cause = cause;
}
if (pathOrUrl) {
this.pathOrUrl = pathOrUrl;
}
if (source) {
this.source = source;
}
}

cause?: Error | unknown;
pathOrUrl?: PathOrUrl;
source?: string;

}
// class LocalDependencyNotFound extends Error {
// constructor(message: string, source?: string, pathOrUrl?: PathOrUrl, cause?: Error | unknown) {
// super(message);
// this.name = "LocalDependencyNotFound";
// if (cause) {
// this.cause = cause;
// }
// if (pathOrUrl) {
// this.pathOrUrl = pathOrUrl;
// }
// if (source) {
// this.source = source;
// }
// }

// cause?: Error | unknown;
// pathOrUrl?: PathOrUrl;
// source?: string;

// }
69 changes: 69 additions & 0 deletions packages/morphir-elm-compiler/src/elm/Morphir/Elm/CLI.d.elm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export default CLI = {
init: (flags?: CLI.Args) => CLI.ElmApp
}

export namespace CLI {

interface ElmApp extends Object {
ports: Ports;
}

interface Args {
node?: HTMLElement;
flags?: any;
}

interface Subscribe<T> {
subscribe(callback: (value: T) => any): void;
unsubscribe(callback: (value: T) => any): void;
}

interface Send<T> {
send(value: T): void;
}

function init(args: Args): ElmApp;

interface Ports {
buildFromScratch: Send<any>;
reportProgress: Subscribe<string>;
}
}

function init(args: CLI.Args): CLI.ElmApp;


// export declare class Main {
// init(flags?: any): ElmApp;

// }



/*
* Prelude
*/

export type Unit =
{
variant: "()"
}

export type Maybe<T>
= {
variant: "Just"
, _0: T
}
| {
variant: "Nothing"
}

export type Result<E, T>
= {
variant: "Ok"
, _0: T
}
| {
variant: "Err"
, _0: E
}
Loading

0 comments on commit 548dccc

Please sign in to comment.