UNPKG

ring-websites-toolbelt

Version:

Ring Publishing Platform tool to work with Ring Websites

62 lines (51 loc) 2.25 kB
#!/usr/bin/env node const os = require('os'); const args = require('args'); const normalizePaths = require('../lib/utils/normalizePaths'); const checkPkgVersion = require('../lib/utils/checkPkgVersion'); require('better-logging')(console); normalizePaths(); process.on('unhandledRejection', error => { console.error(error.message || error); throw error; }); async function runUcsFunction(name, sub, options) { let scriptPath = './../lib/scripts/'; try { await checkPkgVersion(); if (name === 'setup') { scriptPath += name; } else { scriptPath += name === 'router' ? `router/${sub[0]}` : `theme/${name}`; } const ScriptClass = require(`${scriptPath}`); const script = new ScriptClass(options); await script.execute(); } catch (error) { if (options.verbose) { console.error(error.stack || error.message || error); } else { console.error(error.message || error); } process.exit(1); // exit with error status } } args.option('configPath', 'Path to configuration file', `${os.homedir()}/.ucs`) .option('verbose', 'Enable verbose logging', false) .command('setup', 'Configure Ring Websites Toolbelt to be able to develop your website', runUcsFunction) .command('install', 'Download modules for your theme', runUcsFunction) .command('build', 'Merge theme with modules', runUcsFunction) .command('start', 'Start developing your theme', runUcsFunction) .command('purge', 'Purge theme from upstream', runUcsFunction) .command('deploy', 'Deploy your theme to production environment', runUcsFunction) //.command('router', '[test, deploy] - Commands responsible for router development', runUcsFunction) .examples([ { usage: 'website --version', description: 'Check version of the library:' }, { usage: 'website start --verbose', description: 'Start developing theme with verbose logging:' }, { usage: 'website deploy --configPath /home/user/config.json', description: 'Deploy theme with specified config file:' } ]); const runParams = [...process.argv]; if (runParams.length <= 2) { runParams[2] = 'help'; } args.parse(runParams);