const path = require('path'); module.exports = { tags: async (tln) => [], dotenvs: async (tln) => [], options: async (tln, args) => { args .prefix('TLN_ANGULAR') .option('configuration', { describe: 'Configuration to build', default: null, type: 'string' }) .option('ssl-cert', { describe: 'Include SSL certificates into docker images', default: false, type: 'boolean' }); }, env: async (tln, env) => { env.ANGULAR_HOME = env.TLN_COMPONENT_HOME; env.PATH = [path.join(env.TLN_COMPONENT_HOME, 'node_modules', '.bin'), env.PATH].join(path.delimiter); }, inherits: async (tln) => [], depends: async (tln) => [], steps: async (tln) => [ { id: 'install', desc: '', builder: async (tln, script) => { const id = script.env.TLN_COMPONENT_ID; const home = script.env.TLN_COMPONENT_HOME; const {name, version} = tln.unpackId(id); if (version && tln.canInstallComponent(tln, id, home)) { script.set([ `npm install @angular/cli@${version}`, ]) } } }, { id: 'init', desc: '', builder: async (tln, script) => { script.set([ `npm i` ]) } }, { id: 'build', desc: '', builder: async (tln, script) => { let cfg = ''; if (script.env.TLN_ANGULAR_CONFIGURATION) { cfg = `--configuration=${script.env.TLN_ANGULAR_CONFIGURATION}`; } script.set([ `ng build ${cfg}` ]) } }, { id: 'build-mobile', desc: '', builder: async (tln, script) => script.set([ `ng build --prod --configuration=production --base-href . --output-path mobile/` ]) }, { id: 'lint', desc: '', builder: async (tln, script) => { const id = script.env.TLN_COMPONENT_ID; script.set([ `ng lint ${id} --format=prose --type-check=true` ]) } }, { id: 'test', desc: '', builder: async (tln, script) => { const id = script.env.TLN_COMPONENT_ID; script.set([ `ng test ${id} --code-coverage` ]) } }, { id: 'serve', desc: '', builder: async (tln, script) => script.set([ 'ng serve --host=${TLN_COMPONENT_PARAM_LSTN} --port=${TLN_COMPONENT_PARAM_PORT}' ]) }, { id: 'build-docker', builder: async (tln, script) => { let conf = ['envsubst "\\${TLN_COMPONENT_PARAM_HOST}" > ./target/conf.d/default.conf < ./default.conf.template']; if(script.env.TLN_ANGULAR_SSL_CERT) { conf = [ 'envsubst "\\${TLN_COMPONENT_ID} \\${TLN_COMPONENT_PARAM_HOST}" > ./target/conf.d/default.conf < ./default.conf.https.template', 'cp -r ./ssl ./target/' ]; } script.set([ 'rm -rf ./target || true', 'mkdir target', 'mkdir target/conf.d']. concat(conf). concat([ 'docker build \\', ' -t ${TLN_COMPONENT_ID}:${TLN_COMPONENT_VERSION} .' ]) ) } }, { id: 'run-docker', builder: async (tln, script) => { script.set([ 'docker run -d --rm \\', ' -p ${TLN_COMPONENT_PARAM_PORT}:80 \\', ' -p ${TLN_COMPONENT_PARAM_PORTS}:443 \\', ' --name ${TLN_COMPONENT_ID} ${TLN_COMPONENT_ID}:${TLN_COMPONENT_VERSION}' ]) } } ], components: async (tln) => require('./components.js') }