@accordproject/cicero-cli
Version:
250 lines • 7.36 kB
JavaScript
;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { Logger } = require('@accordproject/concerto-util');
const commands_1 = require("./commands");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const yargs = require('yargs');
yargs
.scriptName('cicero')
.usage('$0 <cmd> [args]')
.demandCommand(1, '# Please specify a command')
.recommendCommands()
.strict()
.command('verify', 'verify the template signatures of the template author/developer', (yargs) => {
yargs.option('template', {
describe: 'path to the template',
type: 'string'
});
yargs.option('warnings', {
describe: 'print warnings',
type: 'boolean',
default: false
});
}, (argv) => {
if (argv.verbose) {
Logger.info(`verify the signature of author/developer of ${argv.template} template`);
}
try {
argv = commands_1.Commands.validateVerifyArgs(argv);
const options = {
warnings: argv.warnings,
};
return commands_1.Commands.verify(argv.template, options)
.then((result) => {
Logger.info(`Author/developer's signature for ${argv.template} template is verified`);
})
.catch((err) => {
Logger.error(err.message);
});
}
catch (err) {
Logger.error(err.message);
return;
}
})
.command('archive', 'create a template archive', (yargs) => {
yargs.option('template', {
describe: 'path to the template',
type: 'string'
});
yargs.option('target', {
describe: 'the target language of the archive',
type: 'string',
default: null
});
yargs.option('output', {
describe: 'file name for new archive',
type: 'string',
default: null
});
yargs.option('warnings', {
describe: 'print warnings',
type: 'boolean',
default: false
});
yargs.option('keystore', {
describe: 'p12 keystore path',
type: 'string',
default: null
});
yargs.option('passphrase', {
describe: 'p12 keystore passphrase',
type: 'string',
default: null
});
}, (argv) => {
if (argv.verbose) {
Logger.info(`create an archive for ${argv.template}`);
}
try {
argv = commands_1.Commands.validateArchiveArgs(argv);
let options = {};
if (argv.keystore) {
options = {
warnings: argv.warnings,
keystore: {
path: argv.keystore,
passphrase: argv.passphrase
}
};
}
else {
options = {
warnings: argv.warnings,
};
}
return commands_1.Commands.archive(argv.template, argv.target, argv.output, options)
.catch((err) => {
Logger.error(err.message);
});
}
catch (err) {
Logger.error(err.message);
return;
}
})
.command('draft', 'create sample text by merging a template with data', (yargs) => {
yargs.option('template', {
describe: 'path to the template',
type: 'string'
});
yargs.option('data', {
describe: 'path to the JSON data for the template',
type: 'string'
});
yargs.option('output', {
describe: 'path to the output file',
type: 'string',
default: null
});
yargs.option('format', {
describe: 'the output format (e.g. markdown, html)',
type: 'string',
default: 'markdown'
});
yargs.option('currentTime', {
describe: 'set the current time',
type: 'string',
default: null
});
yargs.option('warnings', {
describe: 'print warnings',
type: 'boolean',
default: false
});
}, (argv) => {
if (argv.verbose) {
Logger.info(`draft sample text from data ${argv.data} using template ${argv.template}`);
}
try {
argv = commands_1.Commands.validateDraftArgs(argv);
const options = {
warnings: argv.warnings,
};
return commands_1.Commands.draft(argv.template, argv.data, argv.output, argv.format, argv.currentTime, options)
.then((result) => {
if (result) {
Logger.info(result);
}
})
.catch((err) => {
Logger.error(err.message);
});
}
catch (err) {
Logger.error(err.message);
return;
}
})
.command('compile', 'generate code for a target platform', (yargs) => {
yargs.option('template', {
describe: 'path to the template',
type: 'string'
});
yargs.option('target', {
describe: 'target of the code generation',
type: 'string',
default: 'JSONSchema'
});
yargs.option('output', {
describe: 'path to the output directory',
type: 'string',
default: './output/'
});
yargs.option('warnings', {
describe: 'print warnings',
type: 'boolean',
default: false
});
}, (argv) => {
if (argv.verbose) {
Logger.info(`compile template ${argv.template} for target ${argv.target}`);
}
try {
argv = commands_1.Commands.validateCompileArgs(argv);
const options = {
warnings: argv.warnings,
};
return commands_1.Commands.compile(argv.template, argv.target, argv.output, options)
.then((result) => {
Logger.info('Completed.');
})
.catch((err) => {
Logger.error(err.message + ' ' + JSON.stringify(err));
});
}
catch (err) {
Logger.error(err.message);
return;
}
})
.command('get', 'save local copies of external dependencies', (yargs) => {
yargs.option('template', {
describe: 'path to the template',
type: 'string'
});
yargs.option('output', {
describe: 'output directory path',
type: 'string'
});
}, (argv) => {
if (argv.verbose) {
Logger.info(`saving external models into directory: ${argv.output}`);
}
try {
argv = commands_1.Commands.validateGetArgs(argv);
return commands_1.Commands.get(argv.template, argv.output)
.then((result) => {
Logger.info(result);
})
.catch((err) => {
Logger.error(err.message);
});
}
catch (err) {
Logger.error(err.message);
return;
}
})
.option('verbose', {
alias: 'v',
default: false
})
.help()
.argv;
//# sourceMappingURL=cli.js.map