Skip to content

Commit

Permalink
Finalize getting snowpark-gen and generate-test-data on the new build…
Browse files Browse the repository at this point in the history
… pipeline
  • Loading branch information
DamianReeves committed May 26, 2024
1 parent cf110d0 commit a0093c1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 35 deletions.
20 changes: 13 additions & 7 deletions packages/morphir-elm-compiler/src/morphir-generate-test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ command
"--config <path-to-config>",
"specify a json file where configuration can be read from. Overrides other command options."
)
.parse(process.argv);
.action(generateData);

interface GenerationOptions {
morphirIrJson: any;
Expand All @@ -58,27 +58,33 @@ interface GenerationOptions {
}

// run data generation
async function generateData(options) {
async function generateData(options: {
projectDir: string;
output: string;
seed: string;
size: string;
targets: [string];
}) {
const programOptions = options;

// CREATE CONFIG OPTIONS
const morphirJsonPath: string = path.join(
programOptions["projectDir"],
programOptions.projectDir,
"morphir-ir.json"
);
if (!(await fsExists(morphirJsonPath)))
throw Error("Not a morphir directory");
const distroData = (await fsReadFile(morphirJsonPath)).toString();
const distroJson = JSON.parse(distroData);

if (!programOptions["targets"] || programOptions["targets"].length <= 0)
if (!programOptions.targets || programOptions.targets.length <= 0)
throw "targets not provided";

const opts: GenerationOptions = {
morphirIrJson: distroJson,
targets: programOptions["targets"],
seed: parseInt(programOptions["seed"]),
size: parseInt(programOptions["size"]),
targets: programOptions.targets,
seed: parseInt(programOptions.seed),
size: parseInt(programOptions.size),
};

// SEND OFF TO ELM
Expand Down
69 changes: 42 additions & 27 deletions packages/morphir-elm-compiler/src/morphir-snowpark-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

// NPM imports
import * as fs from "fs";
import path from 'path';
import { Command } from 'commander';
import * as util from 'util';
const cli = require('./cli');
import path from "path";
import { Command } from "commander";
import * as util from "util";
import cli from "./cli";
import CLI from "./elm/Morphir/Elm/CLI.elm";

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

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

interface CommandOptions {
/**
Expand All @@ -36,7 +37,10 @@ function copyRedistributables(outputPath: string) {
src
);
if (fs.existsSync(sourceDirectory)) {
fs.cpSync(sourceDirectory, outputPath, { recursive: true, errorOnExist: false });
fs.cpSync(sourceDirectory, outputPath, {
recursive: true,
errorOnExist: false,
});
} else {
console.warn(`WARNING: Cannot find directory ${sourceDirectory}`);
}
Expand Down Expand Up @@ -74,16 +78,18 @@ const gen = async (
});

// Add default values for these options
options.limitToModules = '';
options.limitToModules = "";
options.includeCodecs = false;
options.target = 'Snowpark'
options.target = "Snowpark";

if (options.decorations) {
if (fs.existsSync(path.resolve(options.decorations))) {
let fileContents = await fsReadFile(path.resolve(options.decorations));
options.decorationsObj = JSON.parse(fileContents.toString());
} else {
console.warn(`WARNING: The specified decorations file do not exist: ${options.decorations}`)
console.warn(
`WARNING: The specified decorations file do not exist: ${options.decorations}`
);
}
}

Expand Down Expand Up @@ -126,21 +132,30 @@ const gen = async (
return Promise.all(writePromises.concat(deletePromises));
};

const program = new Command()
program
.name('morphir snowpark-gen')
.description('Generate Scala with Snowpark code from Morphir IR')
.option('-i, --input <path>', 'Source location where the Morphir IR will be loaded from.', 'morphir-ir.json')
.option('-o, --output <path>', 'Target location where the generated code will be saved.', './dist')
.option('-dec, --decorations <filename>', 'JSON file with decorations')

.parse(process.argv)

gen(program.opts()['input'], path.resolve(program.opts()['output']), program.opts())
.then(() => {
console.log('Done')
})
.catch((err) => {
console.log(err)
process.exit(1)
})
export const command = new Command();
command
.name("snowpark-gen")
.description("Generate Scala with Snowpark code from Morphir IR")
.option(
"-i, --input <path>",
"Source location where the Morphir IR will be loaded from.",
"morphir-ir.json"
)
.option(
"-o, --output <path>",
"Target location where the generated code will be saved.",
"./dist"
)
.option("-dec, --decorations <filename>", "JSON file with decorations")
.action(run);

async function run(options: { input: string; output: string }) {
return await gen(options.input, path.resolve(options.output), command.opts())
.then(() => {
console.log("Done");
})
.catch((err) => {
console.log(err);
process.exit(1);
});
}
3 changes: 2 additions & 1 deletion packages/morphir-elm-compiler/src/morphir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as morphirInit from "./morphir-init";
import * as morphirJsonSchemaGen from "./morphir-json-schema-gen";
import * as morphirMake from "./morphir-make";
import * as morphirScalaGen from "./morphir-scala-gen";
import * as morphirSnowparkGen from "./morphir-snowpark-gen";
import * as morphirStats from "./morphir-stats";
import * as testCoverage from "./morphir-test-coverage";

Expand All @@ -23,7 +24,7 @@ program
.addCommand(morphirMake.createCommand())
.addCommand(morphirScalaGen.command)
.addCommand(morphirJsonSchemaGen.command)
.command("snowpark-gen", "Generate Scala with Snowpark code from Morphir IR")
.addCommand(morphirSnowparkGen.command)
.addCommand(morphirStats.command)
.addCommand(morphirDockerize.command)
.addCommand(testCoverage.command)
Expand Down

0 comments on commit a0093c1

Please sign in to comment.