const path = require('path'); const fs = require('fs'); module.exports = { tags: async (tln) => [], options: async (tln, args) => { args .prefix('TLN') .option('new-version', { describe: 'New version', default: null, type: 'string' }) .option('service-type', { describe: 'Service type: frontend, backend, db', default: null, type: 'string' }) .option('dotenv-template', { describe: 'Template file name for .env', default: '.env.template', type: 'string' }); }, dotenvs: async (tln) => [], inherits: async (tln) => [], depends: async (tln) => [], env: async (tln, env) => {}, steps: async (tln) => [ /* TO REMOVE { id: 'prereq', filter: 'linux', desc: '', builder: async (tln, script) => { script.set([ `if [ -f "${script.env.TLN_DOTENV_TEMPLATE}" ]; then envsubst > .env < ${script.env.TLN_DOTENV_TEMPLATE}; fi`, 'if [ -f "sonar-project.properties.template" ]; then envsubst > sonar-project.properties < sonar-project.properties.template; fi' ]) } }, */ { id: 'null', filter: '(linux|darwin)', builder: async (tln, script) => script.set([]) }, { id: 'printenv', filter: '(linux|darwin)', builder: async (tln, script) => script.set(['printenv']) }, { id: 'printenv', filter: 'win32', builder: async (tln, script) => script.set(['set']) }, // { id: 'sys-info', builder: async (tln, script) => { const os = require('os'); script.set([ `echo Platform: ${os.platform()}`, `echo Architecture: ${os.arch()}`, `echo CPUs: ${os.cpus().length}`, `echo Machine: ${os.machine()}`, `echo Release: ${os.release()}`, `echo Version: "${os.version()}"`, `echo Type: ${os.type()}`, `echo Uptime: ${os.uptime()} seconds`, `echo Total Memory: ${os.totalmem() / (1024 * 1024)} MB`, `echo Free Memory: ${os.freemem() / (1024 * 1024)} MB`, `echo PWD: \$(pwd)`, ]); }}, // { id: 'shell', desc: '', filter: 'linux', builder: async (tln, script) => script.set([ `bash --rcfile <(cat ~/.bashrc; echo 'PS1="tln > "')` ]) }, { id: 'shell', desc: '', filter: 'darwin', builder: async (tln, script) => script.set([ `bash --rcfile <(cat ~/.bash_profile; echo 'export PS1="tln > "')` ]) }, { id: 'shell', desc: '', filter: 'win32', builder: async (tln, script) => script.set(['cmd']) }, { id: 'update-version', filter: '', builder: async (tln, script) => { if (script.env.TLN_NEW_VERSION) { const arr = []; const ver = script.env.TLN_NEW_VERSION; const home = script.env.TLN_COMPONENT_HOME; const versionFile = path.join(home, 'version'); const packageJson = path.join(home, 'package.json'); const pomXml = path.join(home, 'pom.xml'); // if (fs.existsSync(versionFile)) { arr.push(`printf "${ver}" > version`); } // if (fs.existsSync(packageJson)) { arr.push(`npm version ${ver}`); } // if (fs.existsSync(pomXml)) { arr.push(`mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${ver}`); } script.set(arr); } else { script.logger.error(`Version was not defined, please use next format: 'tln update-version -- --new-version 1.0.0'`); } return true; } }, { id: 'generate-dotenv', filter: '', builder: async (tln, script) => { const home = script.env.TLN_COMPONENT_HOME; const types = ['frontend', 'backend', 'db']; const type = script.env.TLN_SERVICE_TYPE; if (type && types.indexOf(type) != -1) { tln.copyTemplate( tln, script, path.join(__dirname, '.env.template'), path.join(home, '.env.template'), [path.join(__dirname, `${type}.template`)] ); } else { script.logger.error(`service type was not defined, please use next format: 'tln update-version -- --service-type=(${types.join(' | ')})'`); } } } ], components: async (tln) => [] }