UNPKG

@tripsnek/tmf

Version:

TypeScript Modeling Framework - A TypeScript port of the Eclipse Modeling Framework (EMF)

61 lines 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateFromEcore = generateFromEcore; exports.generateFromEPackage = generateFromEPackage; const ecoreparser_1 = require("../ecore/ecoreparser"); const tgenerator_main_1 = require("./tgenerator-main"); const environment_1 = require("../utils/environment"); /** * (1) Parses an ECore file. * (2) Generates source code into destinationPath/src/lib * (3) Generates barrel file (index.ts) into destinationPath/src * * If not specified, destinationPath will be that of the model file. * * @param ecorePath * @param overwriteImpl * @param destinationPath */ async function generateFromEcore(ecorePath, overwriteImpl, destinationPath, attemptFormatWithPrettier) { environment_1.Environment.requireNodeEnvironment('File-based code generation'); // parse the package const pkg = await new ecoreparser_1.EcoreParser().parseAsync(ecorePath); // auto-determine destination path from ecore location, if necessary let destPath; if (destinationPath) { destPath = destinationPath; } else { try { const path = await (0, environment_1.safeDynamicImport)('path'); destPath = path.dirname(ecorePath); } catch (error) { throw new Error(`Path resolution failed: ${error.message}. This operation requires Node.js environment.`); } } // generate the source return generateFromEPackage(pkg, destPath, overwriteImpl, attemptFormatWithPrettier); } /** * (1) Generates source code into destinationPath/src/lib * (2) Generates barrel file (index.ts) into destinationPath/src * * @param pkg * @param destPath * @param overwriteImpl */ async function generateFromEPackage(pkg, destPath, overwriteImpl, attemptInvokePrettier) { environment_1.Environment.requireNodeEnvironment('Code generation'); try { const path = await (0, environment_1.safeDynamicImport)('path'); const srcPath = path.resolve(destPath + '/src'); console.log('running TGeneratorMain, output to ' + srcPath); new tgenerator_main_1.TGeneratorMain(pkg, path.resolve(destPath + '/src'), overwriteImpl, path.resolve(destPath + '/src')).generate(attemptInvokePrettier); return srcPath; } catch (error) { throw new Error(`Path resolution failed: ${error.message}. This operation requires Node.js environment.`); } } //# sourceMappingURL=modelgenutils.js.map