Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to copy the SDK with the generated files #386

Merged
merged 5 commits into from
Mar 5, 2021
Merged
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
18 changes: 16 additions & 2 deletions cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function gen(input, outputPath, options) {
await mkdir(outputPath, { recursive: true })
const morphirIrJson = await readFile(path.resolve(input))
const fileMap = await generate(options, JSON.parse(morphirIrJson.toString()))
const sourceDirectory = path.join(path.dirname(__dirname), 'redistributable', `${options["target"]}`)


const writePromises =
fileMap.map(async ([[dirPath, fileName], content]) => {
Expand All @@ -98,10 +98,23 @@ async function gen(input, outputPath, options) {
console.log(`DELETE - ${fileToDelete}`)
return fs.unlinkSync(fileToDelete)
})
const copyDirectoriesRecursive = await copyRecursiveSync(sourceDirectory, outputPath)
copyRedistributables(options, outputPath)
return Promise.all(writePromises.concat(deletePromises))
}

function copyRedistributables(options, outputPath) {
const copyFiles = (src, dest) => {
const sourceDirectory = path.join(path.dirname(__dirname), 'redistributable', src)
copyRecursiveSync(sourceDirectory, outputPath)
}
if (options.target == 'SpringBoot') {
copyFiles('SpringBoot', outputPath)
} else if (options.target == 'Scala' && options.copyDeps) {
copyFiles('Scala/sdk/src', outputPath)
copyFiles(`Scala/sdk/src-${options.targetVersion}`, outputPath)
}
}

function copyRecursiveSync(src, dest) {
const exists = fs.existsSync(src);
if (exists) {
Expand All @@ -116,6 +129,7 @@ function copyRecursiveSync(src, dest) {
});
} else {
fs.copyFileSync(src, dest);
console.log(`COPY - ${dest}`)
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion cli/morphir-elm-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ const path = require('path')
const commander = require('commander')
const cli = require('./cli')

// logging
require('log-timestamp')

// Set up Commander
const program = new commander.Command()
program
.name('morphir-elm gen')
.description('Generate 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('-t, --target <type>', 'Language to Generate (Scala | SpringBoot | cypher | triples', 'Scala')
.option('-t, --target <type>', 'Language to Generate (Scala | SpringBoot | cypher | triples).', 'Scala')
.option('-e, --target-version <version>', 'Language version to Generate.', '2.11')
.option('-c, --copy-deps', 'Copy the dependencies used by the generated code to the output path.', false)
.parse(process.argv)


Expand Down
79 changes: 79 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const { series, src, dest } = require('gulp');
const os = require('os')
const path = require('path')
const util = require('util')
const fs = require('fs')
const tmp = require('tmp')
const git = require('isomorphic-git')
const http = require('isomorphic-git/http/node')
const del = require('del')
const elmMake = require('node-elm-compiler').compile

const config = {
morphirJvmVersion: '0.7.0',
morphirJvmCloneDir: tmp.dirSync()
}

async function clean() {
return del([
'dist',
'tests-integration/generated'
])
}

async function cloneMorphirJVM() {
return await git.clone({
fs,
http,
dir: config.morphirJvmCloneDir.name,
url: 'https://github.com/finos/morphir-jvm',
ref: `tags/v${config.morphirJvmVersion}`,
singleBranch: true
})
}

function copyMorphirJVMAssets() {
const sdkFiles = path.join(config.morphirJvmCloneDir.name, 'morphir/sdk/core/src*/**')
return src([sdkFiles]).pipe(dest('redistributable/Scala/sdk'))
}

async function cleanupMorphirJVM() {
return del(config.morphirJvmCloneDir.name + '/**', { force: true });
}

function make(rootDir, source, target) {
return elmMake([source], { cwd: path.join(process.cwd(), rootDir), output: target })
}

function makeCLI() {
return make('cli', 'src/Morphir/Elm/CLI.elm', 'Morphir.Elm.CLI.js')
}

function makeDevServer() {
return make('cli', 'src/Morphir/Web/DevelopApp.elm', 'web/index.html')
}

function makeInsightAPI() {
return make('cli', 'src/Morphir/Web/Insight.elm', 'web/insight.js')
}

const build =
series(
makeCLI,
makeDevServer,
makeInsightAPI
)

exports.clean = clean;
exports.makeCLI = makeCLI;
exports.build = build;
exports.default =
series(
clean,
series(
cloneMorphirJVM,
copyMorphirJVMAssets,
cleanupMorphirJVM
),
build
);
Loading