const path = require('path'); module.exports = { tags: async (tln) => [], options: async (tln, args) => { args .prefix('TLN_GOLANG') .option('main', { describe: 'Module name with main entry point', default: 'service', type: 'string' }) .option('target', { describe: 'Output folder', default: 'target', type: 'string' }) .option('module', { describe: 'Module name, is used from init & get commands', default: [], type: 'array' }) ; }, env: async (tln, env) => { env.GOLANG_HOME = env.TLN_COMPONENT_HOME; env.PATH = [path.join(env.TLN_COMPONENT_HOME, 'bin'), env.PATH].join(path.delimiter); }, dotenvs: async (tln) => [], inherits: async (tln) => [], depends: async (tln) => [], steps: async (tln) => [ // { id: 'init', builder: async (tln, script) => { const modules = script.env.TLN_GOLANG_MODULE.join(' '); script.set([` go mod init ${modules} `]); } }, // { id: 'update', builder: async (tln, script) => { script.set([` go mod tidy && go mod download `]); } }, // { id: 'build', builder: async (tln, script) => { const target = script.env.TLN_GOLANG_TARGET; const main = script.env.TLN_GOLANG_MAIN; script.set([` go build -o ${target}/${main} ${main}.go `]); } }, // { id: 'get', builder: async (tln, script) => { const modules = script.env.TLN_GOLANG_MODULE.join(' '); script.set([` go get ${modules} `]); } }, // { id: 'serve', builder: async (tln, script) => { const target = script.env.TLN_GOLANG_TARGET; const main = script.env.TLN_GOLANG_MAIN; script.set([` ${target}/${main} `]); } }, // { id: 'version', 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) { script.set([` echo [golang] && go version `]); } }}, // { id: 'install', 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(tln.getDownloadScript(tln, { linux: { name: `go${version}.linux-amd64.tar.gz`, opts: { src: `go`, flt:`*`, dest:`.`, rmv: `go` }, url: `https://dl.google.com/go/go${version}.linux-amd64.tar.gz` }, darwin: { name: `go${version}.darwin-amd64.tar.gz`, opts: { src: `go`, flt: `*`, dest: `.`, rmv: `go` }, url: `https://dl.google.com/go/go${version}.darwin-amd64.tar.gz` }, win32: { name: `go${version}.windows-amd64.zip`, opts: { src: `go`, flt: `*`, dest: `.`, rmv: `go` }, url: `https://dl.google.com/go/go${version}.windows-amd64.zip` } })); } }} ], components: async (tln) => require('./components.js') }