Skip to content

Commit

Permalink
HCK-9614: adapt FE to work in the browser (#16)
Browse files Browse the repository at this point in the history
* HCK-9614: adapt FE to work in the browser

* HCK-9614: update esbuild config

* HCK-9614: small fixes

* HCK-9614: revert package.lock

* Update package-lock.json
  • Loading branch information
Nightlngale authored Jan 23, 2025
1 parent 1dad1e5 commit 3ede0c0
Show file tree
Hide file tree
Showing 8 changed files with 5,837 additions and 5,680 deletions.
5 changes: 5 additions & 0 deletions api/fe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { generateContainerScript } = require('../forward_engineering/generateContainerScript');

module.exports = {
generateContainerScript,
};
10 changes: 9 additions & 1 deletion esbuild.package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs');
const path = require('path');
const esbuild = require('esbuild');
const { clean } = require('esbuild-plugin-clean');
const { copy } = require('esbuild-plugin-copy');
const { copyFolderFiles, addReleaseFlag } = require('@hackolade/hck-esbuild-plugins-pack');
const { EXCLUDED_EXTENSIONS, EXCLUDED_FILES, DEFAULT_RELEASE_FOLDER_PATH } = require('./buildConstants');

Expand All @@ -11,6 +12,7 @@ const RELEASE_FOLDER_PATH = path.join(DEFAULT_RELEASE_FOLDER_PATH, `${packageDat
esbuild
.build({
entryPoints: [
path.resolve(__dirname, 'api', 'fe.js'),
path.resolve(__dirname, 'forward_engineering', 'api.js'),
path.resolve(__dirname, 'reverse_engineering', 'api.js'),
],
Expand All @@ -25,6 +27,12 @@ esbuild
clean({
patterns: [DEFAULT_RELEASE_FOLDER_PATH],
}),
copy({
assets: {
from: [path.join('node_modules', 'lodash', '**', '*')],
to: [path.join('node_modules', 'lodash')],
},
}),
copyFolderFiles({
fromPath: __dirname,
targetFolderPath: RELEASE_FOLDER_PATH,
Expand All @@ -33,6 +41,6 @@ esbuild
}),
addReleaseFlag(path.resolve(RELEASE_FOLDER_PATH, 'package.json')),
],
external: ['electron'],
external: ['lodash', 'electron'],
})
.catch(() => process.exit(1));
31 changes: 2 additions & 29 deletions forward_engineering/api.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
const _ = require('lodash');
const { generateVertices, generateEdges } = require('./gremlinHelper');
const reverseEngineeringApi = require('../reverse_engineering/api');
const applyToInstanceHelper = require('./applyToInstanceHelper');
const { generateContainerScript } = require('./generateContainerScript');

module.exports = {
generateContainerScript(data, logger, cb) {
let { collections, relationships, jsonData } = data;
logger.clear();
try {
let resultScript = '';

collections = collections.map(JSON.parse);
relationships = relationships.map(JSON.parse);

const verticesScript = generateVertices(collections, jsonData);
const edgesScript = generateEdges(collections, relationships, jsonData);

if (verticesScript) {
resultScript += verticesScript;
}

if (edgesScript) {
resultScript += '\n\n' + edgesScript;
}

cb(null, resultScript);
} catch (e) {
logger.log('error', { message: e.message, stack: e.stack }, 'Forward-Engineering Error');

cb({ message: e.message, stack: e.stack });
}
},
generateContainerScript,

async applyToInstance(data, logger, cb, app) {
try {
Expand Down
34 changes: 34 additions & 0 deletions forward_engineering/generateContainerScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { generateVertices, generateEdges } = require('./gremlinHelper');

function generateContainerScript(data, logger, cb) {
const { jsonData } = data;
let { collections, relationships } = data;
logger.clear();
try {
let resultScript = '';

collections = collections.map(JSON.parse);
relationships = relationships.map(JSON.parse);

const verticesScript = generateVertices(collections, jsonData);
const edgesScript = generateEdges(collections, relationships, jsonData);

if (verticesScript) {
resultScript += verticesScript;
}

if (edgesScript) {
resultScript += '\n\n' + edgesScript;
}

cb(null, resultScript);
} catch (e) {
logger.log('error', { message: e.message, stack: e.stack }, 'Forward-Engineering Error');

cb({ message: e.message, stack: e.stack });
}
}

module.exports = {
generateContainerScript,
};
Loading

0 comments on commit 3ede0c0

Please sign in to comment.