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

feat(*): add compile option for including metamodel #494

Merged
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
17 changes: 15 additions & 2 deletions packages/concerto-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ require('yargs')
}
})
.command('compile', 'generate code for a target platform', (yargs) => {
yargs.demandOption(['model'], 'Please provide models');
yargs.option('model', {
describe: 'array of concerto model files',
type: 'string',
array: true
array: true,
default: [],
});
yargs.option('offline', {
describe: 'do not resolve external models',
Expand All @@ -106,6 +106,11 @@ require('yargs')
type: 'string',
default: './output/'
});
yargs.option('metamodel', {
describe: 'Include the Concerto Metamodel in the output',
type: 'boolean',
default: false,
});
yargs.option('useSystemTextJson', {
describe: 'Compile for System.Text.Json library (`csharp` target only)',
type: 'boolean',
Expand All @@ -120,13 +125,21 @@ require('yargs')
describe: 'A prefix to add to all namespaces (`csharp` target only)',
type: 'string',
});
yargs.check(({ model, metamodel }) => {
if (model.length > 0 || metamodel) {
return true;
} else {
throw new Error('Please provide models, or specify metamodel');
}
});
}, (argv) => {
if (argv.verbose) {
Logger.info(`generate code for target ${argv.target} from models ${argv.model} into directory: ${argv.output}`);
}

const options = {};
options.offline = argv.offline;
options.metamodel = argv.metamodel;
options.useSystemTextJson = argv.useSystemTextJson;
options.useNewtonsoftJson = argv.useNewtonsoftJson;
options.namespacePrefix = argv.namespacePrefix;
Expand Down
4 changes: 4 additions & 0 deletions packages/concerto-cli/lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class Commands {
* @param {string} output the output directory
* @param {object} options - optional parameters
* @param {boolean} [options.offline] - do not resolve external models
* @param {boolean} [options.metamodel] - include the Concerto Metamodel
* @param {boolean} [options.useSystemTextJson] - compile for System.Text.Json library
* @param {boolean} [options.useNewtonsoftJson] - compile for Newtonsoft.Json library
*/
Expand All @@ -155,6 +156,9 @@ class Commands {
};

const modelManager = await ModelLoader.loadModelManager(ctoFiles, modelManagerOptions);
if (options && options.metamodel) {
modelManager.addCTOModel(MetaModelUtil.metaModelCto);
}

let visitor = null;

Expand Down
12 changes: 12 additions & 0 deletions packages/concerto-cli/test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ describe('concerto-cli', () => {
fs.readdirSync(dir.path).length.should.be.equal(0);
dir.cleanup();
});
it('should compile to a TypeScript model with the metamodel', async () => {
const dir = await tmp.dir({ unsafeCleanup: true });
await Commands.compile('Typescript', models, dir.path, {metamodel: true, offline:false});
fs.readdirSync(dir.path).should.contain('[email protected]');
dir.cleanup();
});
it('should compile to a CSharp model with the metamodel', async () => {
const dir = await tmp.dir({ unsafeCleanup: true });
await Commands.compile('CSharp', models, dir.path, {metamodel: true, offline:false});
fs.readdirSync(dir.path).should.contain('[email protected]');
dir.cleanup();
});
});

describe('#get', () => {
Expand Down