UNPKG

@tangelo/tangelo-configuration-toolkit

Version:

Tangelo Configuration Toolkit is a command-line toolkit which offers support for developing a Tangelo configuration.

141 lines (134 loc) 6.75 kB
const yargs = require('yargs'); module.exports = function cli () { _write(); const txtTitle = 'Tangelo Configuration Toolkit'.bold.underline.cyan; const txtVersion = `v${_package.version}`.lblack; yargs .scriptName('tct') .usage(`${txtTitle} ${txtVersion}\n\nUsage: $0 <command> [options]`) .middleware(argv => { // executes before command handlers const command = argv._[0]; const optionsPassed = Object.keys(argv).length > 2; const gitInitOrClone = (command === 'git' || command === 'g') && (argv.init || argv.clone); if (!command && argv.config) { _info(`Loaded appconfig:`); _write(_paths.appconfig); _write(_appconfig); } else if (optionsPassed && !gitInitOrClone) { if (_tdiSubmoduleExists()) process.chdir(_paths.repo); // set cwd to repo root before executing an option else _error('This option can only be used inside a git repo having the TDI submodule!'); } }) .command({ command: 'build', aliases: ['b'], desc: 'Build the customer repository', builder: { init: {alias: 'i', desc: 'Create repository content structure', conflicts: ['p', 's', 'c']}, project: {alias: 'p', desc: 'Create project configuration', conflicts: ['i', 's', 'c']}, symlinks: {alias: 's', desc: 'Recreate symlinks to TDI', conflicts: ['p', 'i', 'c']}, oxygen: {alias: 'x', desc: 'Create or update oXygen project file (.xpr)', conflicts: ['p', 'i', 'c']}, file: {alias: 'f', desc: '[hidden] Use preset answers from appconfig', requiresArg: true, hidden: !_devmode} }, handler: require('./modules/build') }) .command({ command: 'deploy', aliases: ['d'], desc: 'Copy configuration to server', builder: { test: {alias: 't', desc: 'Test what files qualify for copy', conflicts: ['c', 'w', 'l']}, copy: {alias: 'c', desc: 'Copy files', conflicts: ['t', 'w', 'l']}, watch: {alias: 'w', desc: 'Watch files for copy on change', conflicts: ['t', 'c', 'l']}, live: {alias: 'l', desc: 'Watch files for copy on change, and reload webpage', conflicts: ['t', 'c', 'w']}, server: {alias: 's', desc: 'Pass server name (set in config file)', default: _appconfig.defaultServer}, filter: {alias: 'f', desc: 'Pass glob filter', default: '**'} }, handler: require('./modules/deploy') }) .command({ command: 'fonto', aliases: ['f'], desc: 'Setting up the Fonto editor', builder: { init: {alias: 'i', desc: `Initialize editor (optionally pass version number or 'latest')`}, schema: {alias: 's', desc: 'Compile schemas to json'}, elements: {alias: 'e', desc: 'List schema elements not having a default configuration'}, attributes: {alias: 'a', desc: 'List schema attributes not having a default configuration'}, localize: {alias: 'l', desc: 'Update localization file'}, build: {alias: 'b', desc: 'Build the editor instance'}, run: {alias: 'r', desc: 'Start editor instance on localhost and watch changes'} }, handler: require('./modules/fonto') }) .command({ command: 'git', aliases: ['g'], desc: 'Git repo actions (requires global git installation)', builder: { init: {alias: 'i', desc: 'Initialize repository and add submodule', conflicts: ['r', 'c', 'u']}, reset: {alias: 'r', desc: 'Reset repository to last commit', conflicts: ['i', 'c', 'u']}, clone: {alias: 'c', desc: 'Clone a client repository and do basic setup', conflicts: ['i', 'r', 'u']}, 'update-repo': {alias: 'ur', desc: 'Update repository', conflicts: ['i', 'r', 'c']}, 'update-submodule': {alias: 'us', desc: 'Update TDI submodule, optionally pass release branch (without "release/")', conflicts: ['i', 'r', 'c']}, dates: {alias: 'd', desc: '[hidden] Use i.c.w. update-submodule, pass 2 dates in format yyyy-mm-dd', conflicts: ['i', 'r', 'c'], implies: 'update-submodule', requiresArg: true, array: true, hidden: !_devmode} }, handler: require('./modules/git') }) .command({ command: 'migrate', aliases: ['m'], desc: 'Execute migration scripts on configuration files', builder: { execute: {alias: 'e', desc: 'Execute migration'}, dry: {alias: 'd', desc: 'Dry run (does not persist changes)'}, filter: {alias: 'f', desc: 'Pass glob filter (only used for applicable steps)'} }, handler: require('./modules/migrate') }) .command({ command: 'sql', aliases: ['s'], desc: 'Execute sql scripts', builder: { install: {alias: 'i', desc: 'Install TDI schema and custom schema'}, configure: {alias: 'c', desc: 'Load configuration for projects'}, generate: {alias: 'g', desc: 'Generate configuration scripts for a project', conflicts: ['i', 'c', 'r']}, remove: {alias: 'r', desc: 'Remove project configuration', conflicts: ['i', 'c', 'g']} }, handler: require('./modules/sql') }) .command({ command: 'info', aliases: ['i'], desc: 'Show project information', builder: { doctypes: {alias: 'd', desc: `List document-types information`}, versions: {alias: 'v', desc: `Find all version information, sorted by project or type`, choices: ['project', 'type'], conflicts: ['d']}, server: {alias: 's', desc: 'Pass server name (set in config file)', default: _appconfig.defaultServer} }, handler: require('./modules/info') }) .recommendCommands() .option('config', {alias: 'c', desc: 'Show loaded appconfig', global: false}) .version(false) .help(false) .example([ ['$0 deploy --copy --server demo', 'Copy files to server "demo"'], ['$0 d -c -s demo', 'Same as above'], ['$0 f -sb && $0 d -c', 'Compile schema and build Fonto, then deploy to default server'], ['$0 git --update-repo', 'Pull git repository and submodule to latest repository commit'], ['$0 git --update-submodule', 'Update TDI submodule to latest within current TDI branch'], ['$0 git --update-submodule 5.4', 'Update TDI submodule to latest in specified branch'] ]) .check((argv, options) => { const nonDefaultOptions = Object.keys(options.key).filter(o => !Object.keys(options.default).includes(o)); if (nonDefaultOptions.some(o => argv[o])) return true; else throw new Error('Pass a non-default option'); }) .strict() .wrap(120) .parse() ; };