Skip to content

Commit 98d5924

Browse files
author
Simon Stone
authored
feat(*): add compile option for including metamodel (#494)
Signed-off-by: Simon Stone <[email protected]>
1 parent b246faa commit 98d5924

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

packages/concerto-cli/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ require('yargs')
8585
}
8686
})
8787
.command('compile', 'generate code for a target platform', (yargs) => {
88-
yargs.demandOption(['model'], 'Please provide models');
8988
yargs.option('model', {
9089
describe: 'array of concerto model files',
9190
type: 'string',
92-
array: true
91+
array: true,
92+
default: [],
9393
});
9494
yargs.option('offline', {
9595
describe: 'do not resolve external models',
@@ -106,6 +106,11 @@ require('yargs')
106106
type: 'string',
107107
default: './output/'
108108
});
109+
yargs.option('metamodel', {
110+
describe: 'Include the Concerto Metamodel in the output',
111+
type: 'boolean',
112+
default: false,
113+
});
109114
yargs.option('useSystemTextJson', {
110115
describe: 'Compile for System.Text.Json library (`csharp` target only)',
111116
type: 'boolean',
@@ -120,13 +125,21 @@ require('yargs')
120125
describe: 'A prefix to add to all namespaces (`csharp` target only)',
121126
type: 'string',
122127
});
128+
yargs.check(({ model, metamodel }) => {
129+
if (model.length > 0 || metamodel) {
130+
return true;
131+
} else {
132+
throw new Error('Please provide models, or specify metamodel');
133+
}
134+
});
123135
}, (argv) => {
124136
if (argv.verbose) {
125137
Logger.info(`generate code for target ${argv.target} from models ${argv.model} into directory: ${argv.output}`);
126138
}
127139

128140
const options = {};
129141
options.offline = argv.offline;
142+
options.metamodel = argv.metamodel;
130143
options.useSystemTextJson = argv.useSystemTextJson;
131144
options.useNewtonsoftJson = argv.useNewtonsoftJson;
132145
options.namespacePrefix = argv.namespacePrefix;

packages/concerto-cli/lib/commands.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class Commands {
143143
* @param {string} output the output directory
144144
* @param {object} options - optional parameters
145145
* @param {boolean} [options.offline] - do not resolve external models
146+
* @param {boolean} [options.metamodel] - include the Concerto Metamodel
146147
* @param {boolean} [options.useSystemTextJson] - compile for System.Text.Json library
147148
* @param {boolean} [options.useNewtonsoftJson] - compile for Newtonsoft.Json library
148149
*/
@@ -155,6 +156,9 @@ class Commands {
155156
};
156157

157158
const modelManager = await ModelLoader.loadModelManager(ctoFiles, modelManagerOptions);
159+
if (options && options.metamodel) {
160+
modelManager.addCTOModel(MetaModelUtil.metaModelCto);
161+
}
158162

159163
let visitor = null;
160164

packages/concerto-cli/test/cli.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ describe('concerto-cli', () => {
190190
fs.readdirSync(dir.path).length.should.be.equal(0);
191191
dir.cleanup();
192192
});
193+
it('should compile to a TypeScript model with the metamodel', async () => {
194+
const dir = await tmp.dir({ unsafeCleanup: true });
195+
await Commands.compile('Typescript', models, dir.path, {metamodel: true, offline:false});
196+
fs.readdirSync(dir.path).should.contain('[email protected]');
197+
dir.cleanup();
198+
});
199+
it('should compile to a CSharp model with the metamodel', async () => {
200+
const dir = await tmp.dir({ unsafeCleanup: true });
201+
await Commands.compile('CSharp', models, dir.path, {metamodel: true, offline:false});
202+
fs.readdirSync(dir.path).should.contain('[email protected]');
203+
dir.cleanup();
204+
});
193205
});
194206

195207
describe('#get', () => {

0 commit comments

Comments
 (0)