Skip to content

Commit

Permalink
More work on the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianReeves committed May 26, 2024
1 parent b64694a commit ded4931
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 55 deletions.
30 changes: 14 additions & 16 deletions packages/morphir-elm-compiler/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as Dependencies from "./dependencies";

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

const fsExists = util.promisify(fs.exists);
const fsWriteFile = util.promisify(fs.writeFile);
Expand Down Expand Up @@ -38,7 +38,6 @@ async function make(
const hashFilePath: string = path.join(projectDir, "morphir-hashes.json");
const morphirIrPath: string = path.join(projectDir, "morphir-ir.json");


// Load the `morphir.json` file that describes the project
const morphirJson: MorphirJson = JSON.parse(
(await fsReadFile(morphirJsonPath)).toString()
Expand All @@ -48,8 +47,8 @@ async function make(
const dependencyConfig = DependencyConfig.parse({
dependencies: morphirJson.dependencies,
localDependencies: morphirJson.localDependencies,
includes: includes
})
includes: includes,
});

//load List Of Dependency IR
const dependencies = await Dependencies.loadAllDependencies(dependencyConfig);
Expand Down Expand Up @@ -521,31 +520,30 @@ async function testCoverage(
irPath: string,
testsPath: string,
_outputPath: string,
_options: CommandOptions
_options: { ir: string; tests: string; output: string }
) {
// Morphir IR
const morphirIR: Buffer = await fsReadFile(path.resolve(irPath))
const morphirIRJson: JSON = JSON.parse(morphirIR.toString())
const morphirIR: Buffer = await fsReadFile(path.resolve(irPath));
const morphirIRJson: JSON = JSON.parse(morphirIR.toString());

// read Morphir Test
const morphirTest: Buffer = await fsReadFile(path.resolve(testsPath))
const morphirTestJson: JSON = JSON.parse(morphirTest.toString())
const morphirTest: Buffer = await fsReadFile(path.resolve(testsPath));
const morphirTestJson: JSON = JSON.parse(morphirTest.toString());

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

return new Promise((resolve, reject) => {
worker.ports.testCoverageResult.subscribe(([err, data]: any) => {
if (err) {
reject(err)
}
else {
resolve(data)
reject(err);
} else {
resolve(data);
}
})
});

// send files through port
worker.ports.testCoverage.send([morphirIRJson, morphirTestJson])
worker.ports.testCoverage.send([morphirIRJson, morphirTestJson]);
});
}

Expand Down
29 changes: 17 additions & 12 deletions packages/morphir-elm-compiler/src/morphir-dockerize.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#!/usr/bin/env node

// NPM Imports
// NPM Imports
import { Command } from "commander";
import { dockerize } from "./cliAPI";

// logging
require('log-timestamp')
// logging
require("log-timestamp");

const program = new Command()
program
.name('morphir dockerize')
.description('Creates a Docker image of a Morphir IR with Morphir Develop')
.option('-p, --project-dir <path>', 'Root directory of the project where morphir.json is located.', '.')
.option('-f, --force', 'Overwrite any Dockerfile in target location', false)
.parse(process.argv)
export const command = new Command();
command
.name("dockerize")
.description("Creates a Docker image of a Morphir IR with Morphir Develop")
.option(
"-p, --project-dir <path>",
"Root directory of the project where morphir.json is located.",
"."
)
.option("-f, --force", "Overwrite any Dockerfile in target location", false)
.action(run);

// run
dockerize( program.opts()['projectDir'], program.opts() )
function run(options: { projectDir: string; force: boolean }) {
dockerize(options.projectDir, options);
}
2 changes: 1 addition & 1 deletion packages/morphir-elm-compiler/src/morphir-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function run() {
console.log(
"I'll create a new morphir project for you, you just need to provide some details.\n"
);
inquirer
return inquirer
.prompt<InitAnswers>([
{
type: "list",
Expand Down
50 changes: 33 additions & 17 deletions packages/morphir-elm-compiler/src/morphir-test-coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,41 @@ import cli from "./cli";
require("log-timestamp");
const fsWriteFile = util.promisify(fs.writeFile);

const program = new Command();
program
.name("morphir test-coverage")
.description("Generates report on number of branches in a Morphir value and TestCases covered")
.option("-i, --ir <path>", "Source location where the Morphir IR will be loaded from.", "morphir-ir.json")
.option("-t, --tests <path>", "Source location where the Morphir Test Json will be loaded from.", "morphir-tests.json")
.option("-o, --output <path>", "Source location where the Morphir Test Coverage result will be ouput to.", ".")
.parse(process.argv);
export const command = new Command();
command
.name("test-coverage")
.description(
"Generates report on number of branches in a Morphir value and TestCases covered"
)
.option(
"-i, --ir <path>",
"Source location where the Morphir IR will be loaded from.",
"morphir-ir.json"
)
.option(
"-t, --tests <path>",
"Source location where the Morphir Test Json will be loaded from.",
"morphir-tests.json"
)
.option(
"-o, --output <path>",
"Source location where the Morphir Test Coverage result will be ouput to.",
"."
)
.action(run);

const { ir: irPath, tests: irTestPath, output: output } = program.opts();

cli.testCoverage(irPath, irTestPath, output, program.opts())
function run(options: { ir: string; tests: string; output: string }) {
const { ir: irPath, tests: irTestPath, output: output } = options;
return cli
.testCoverage(irPath, irTestPath, output, options)
.then((data) => {
fsWriteFile(
path.join(output, "morphir-test-coverage.json"),
JSON.stringify(data)
);
fsWriteFile(
path.join(output, "morphir-test-coverage.json"),
JSON.stringify(data)
);
})
.catch((err) => {
console.log("err --", err);
process.exit(1);
console.log("err --", err);
process.exit(1);
});
}
14 changes: 5 additions & 9 deletions packages/morphir-elm-compiler/src/morphir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// NPM imports
import { Command } from "commander";
import { readPackageUpSync } from "read-package-up";
import * as morphirDockerize from "./morphir-dockerize";
import * as morphirInit from "./morphir-init";
import * as morphirMake from "./morphir-make";
import * as morphirStats from "./morphir-stats";
import * as morphirInit from "./morphir-init";
import * as testCoverage from "./morphir-test-coverage";

// Read the package.json of this package
const packageJson = readPackageUpSync()?.packageJson;
Expand All @@ -20,14 +22,8 @@ program
.command("json-schema-gen", "Generate Json Schema from the Morphir IR")
.command("snowpark-gen", "Generate Scala with Snowpark code from Morphir IR")
.addCommand(morphirStats.command)
.command(
"dockerize",
"Creates a docker image of a Morphir IR and Morphir Develop"
)
.command(
"test-coverage",
"Generates report on number of branches in a Morphir value and TestCases covered"
)
.addCommand(morphirDockerize.command)
.addCommand(testCoverage.command)
.command(
"generate-test-data",
"Creates a docker image of a Morphir IR and Morphir Develop"
Expand Down

0 comments on commit ded4931

Please sign in to comment.