Skip to content

Commit

Permalink
Provide bundling of morphir CLI with Vite (more work to do)
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianReeves committed May 25, 2024
1 parent 548dccc commit 4257944
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .prototools
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bun = "1.1.8"
bun = "1.1.10"
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/morphir-elm-compiler/elm.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "application",
"source-directories": ["../../../src", "src/elm"],
"source-directories": ["../../src", "src/elm"],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
Expand Down
4 changes: 3 additions & 1 deletion packages/morphir-elm-compiler/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import * as util from "util";
import * as path from "path";
import * as FileChanges from "./FileChanges";
import * as Dependencies from "./dependencies";

import { DependencyConfig } from "./dependencies";
import { z } from "zod";
import CLI from './elm/Morphir/Elm/CLI.elm';

const fsExists = util.promisify(fs.exists);
const fsWriteFile = util.promisify(fs.writeFile);
const fsMakeDir = util.promisify(fs.mkdir);
const fsReadFile = util.promisify(fs.readFile);
const readdir = util.promisify(fs.readdir);

const worker = require("./../Morphir.Elm.CLI").Elm.Morphir.Elm.CLI.init();
const worker = CLI.init();

const Includes = z.array(z.string()).optional();
type Includes = z.infer<typeof Includes>;
Expand Down
34 changes: 19 additions & 15 deletions packages/morphir-elm-compiler/src/morphir-make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ import { make } from './cliAPI'
// logging
require('log-timestamp')

// Set up Commander
const program = new Command()
program
.name('morphir make')
.description('Translate Elm sources to Morphir IR')
.option('-p, --project-dir <path>', 'Root directory of the project where morphir.json is located.', '.')
.option('-o, --output <path>', 'Target file location where the Morphir IR will be saved.', 'morphir-ir.json')
.option('-t, --types-only', 'Only include type information in the IR, no values.', false)
.option('-i, --indent-json', 'Use indentation in the generated JSON file.', false)
.option("-I, --include [pathOrUrl...]", "Include additional Morphir distributions as a dependency. Can be specified multiple times. Can be a path, url, or data-url.")
.parse(process.argv)
export function createCommand() {
// Set up Commander
const program = new Command()
program
.name('make')
.description('Translate Elm sources to Morphir IR')
.option('-p, --project-dir <path>', 'Root directory of the project where morphir.json is located.', '.')
.option('-o, --output <path>', 'Target file location where the Morphir IR will be saved.', 'morphir-ir.json')
.option('-t, --types-only', 'Only include type information in the IR, no values.', false)
.option('-i, --indent-json', 'Use indentation in the generated JSON file.', false)
.option("-I, --include [pathOrUrl...]", "Include additional Morphir distributions as a dependency. Can be specified multiple times. Can be a path, url, or data-url.")
.action((options) => {
const dirAndOutput =options;
// run make
make(dirAndOutput['projectDir'], dirAndOutput)
})
//.parse(process.argv)
return program;
}

const dirAndOutput = program.opts()

// run make
make(dirAndOutput['projectDir'], dirAndOutput)
13 changes: 8 additions & 5 deletions packages/morphir-elm-compiler/src/morphir.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#!/usr/bin/env node
// NPM imports
import path from 'path'
import {Command} from 'commander'
import { Command } from 'commander';
import { readPackageUpSync } from 'read-package-up';
import * as morphirMake from './morphir-make';

// Read the package.json of this package
const packageJson = require(path.join(__dirname, '../../package.json'))
const packageJson = readPackageUpSync()?.packageJson;

let version = packageJson?.version || '0.0.0';

// Set up Commander
const program = new Command()
program
.version(packageJson.version, '-v, --version')
.command('make', 'Translate Elm sources to Morphir IR')
.version(version, '-v, --version')
.addCommand(morphirMake.createCommand())
.command('scala-gen', 'Generate scala code from Morphir IR')
.command('json-schema-gen', 'Generate Json Schema from the Morphir IR')
.command('snowpark-gen','Generate Scala with Snowpark code from Morphir IR')
Expand Down
15 changes: 5 additions & 10 deletions packages/morphir-elm-compiler/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@

import { defineConfig } from 'vite'
//import elmPlugin from 'vite-plugin-elm'
import elm from 'vite-plugin-elm-watch'


export default defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
if (command === 'serve') {
return {
plugins: [elm({ mode: 'debug' })]
}
} else {
return {
plugins: [elm()]
}
}
let isServe = command === 'serve'
return {
plugins: [elm({ mode: 'debug' })]
};
})

0 comments on commit 4257944

Please sign in to comment.