const path = require('path'); const fs = require('fs'); /*/ SVN server setup https://computingforgeeks.com/how-to-install-svn-server-on-ubuntu-debian/ https://tecadmin.net/install-subversion-server-on-ubuntu/ /*/ class Svn { constructor(script) { this.script = script; } getErrorDesc(vars) { const vals = vars.map(v => { return `${v}: ${this.script.env[v]}` }).join(', '); return `One or more environmet variables were not defined: ${vals}`; } checkout() { const origin = this.script.env.TLN_SVN_ORIGIN; const subPath = this.script.env.TLN_SVN_PATH; const user = this.script.env.TLN_SVN_USER; const dest = this.script.env.TLN_SVN_DEST; if (origin && user) { let url = origin; if (subPath) { url = [url, subPath].join('/'); } this.script.set([ `svn checkout --username ${user} ${url} ${dest}` ]); } else { this.script.logger.error(this.getErrorDesc(['TLN_SVN_ORIGIN', 'TLN_SVN_USER', 'TLN_SVN_DEST'])); } } createRepo() { const name = this.script.env.TLN_SVN_NAME; if (name) { this.script.set([ `sudo svnadmin create /var/lib/svn/${name}`, `sudo chown -R www-data:www-data /var/lib/svn/${name}` ]); } else { this.script.logger.error(this.getErrorDesc(['TLN_SVN_NAME'])); } } } module.exports = { tags: async (tln) => [], options: async (tln, args) => { args .prefix('TLN_SVN') .option('origin', { describe: 'Repository origin url', default: null, type: 'string' }) .option('user', { describe: 'SVN user name', default: null, type: 'string' }) .option('path', { describe: 'Subpath inside repository', default: null, type: 'string' }) .option('dest', { describe: 'Checkout into folder(s)', default: '.', type: 'string' }) .option('name', { describe: 'Repository name', default: null, type: 'string' }) ; }, env: async (tln, env) => {}, dotenvs: async (tln) => [], inherits: async (tln) => [], depends: async (tln) => [], steps: async (tln) => [ { id: 'create-repo', desc: 'Create new SVN repository', builder: async (tln, script) => (new Svn(script)).createRepo() }, { id: 'checkout', desc: 'Checkout repository', builder: async (tln, script) => (new Svn(script)).checkout() } ], components: async (tln) => [] }