/* * Helper to parse a command into useful metadataz */ const parseCmd = meta => _.merge({}, meta, { bin: _.trimEnd(path.basename(_.first(meta._), '"')), cmd: meta._[1], args: _.drop(meta._, 2), })
/* * Helper to return a type and version from platform data */ const getPlatformServiceType = ({name = 'app', type} = {}) => ({ name, type: _.first(type.split(':')), version: _.last(type.split(':')), })
_(files) .flatMap(file => traverseUp(path.resolve(startFrom, file))) .sortBy().reverse() .filter(file => fs.existsSync(file) && path.isAbsolute(file)) .thru(files => _.isEmpty(files) ? [] : [_.first(files)]) .flatMap(dirFile => _.map(files, file => path.join(path.dirname(dirFile), file))) .filter(file => fs.existsSync(file)) .value()
// Set a different default if needed lando.events.on('cli-ssh-run', 2, data => { if (data.options.service === 'appserver') { // Discovery const services = _.keys(data.options._app.services); const hasRecipe = _.has(data, 'options._app.recipe'); // If this is not a recipe and we have no appserver container then set a new default if (!hasRecipe && !_.includes(services, 'appserver')) { data.options.service = _.first(services); data.options.s = data.options.service; } } });
// Switch the default service for the ssh command if its used lando.events.on('cli-ssh-run', data => { if (_.get(data, 'options._app.recipe') === 'lagoon' && data.options.service === 'appserver') { // Get lagoon config const appRoot = _.get(data, 'options._app.root', process.cwd()); const config = lagoonConf.loadConfigFiles(appRoot); // Find CLI containers const cliServices = _(_.get(config, 'compose.services', {})) .map((service, name) => _.merge({}, service, {name})) .filter(service => _.includes(cliServiceTypes, service.labels['lando.type'])) .map('name') .value(); // Use the first CLI container we find data.options.service = _.first(cliServices); data.options.s = _.first(cliServices); } });
_(routes) // Add implicit data and defaults .map((config, url) => ([url, _.merge({primary: false, attributes: {}, id: null, original_url: url}, config)])) // Replace URL defaults .map(route => ([replaceDefault(route[0], domain), route[1]])) // Replace config defaults .map(route => ([route[0], _.merge(route[1], replaceDefault(_.omit(route[1], ['original_url']), domain))])) // Strip upstream if needed .map(route => { if (route[1].upstream) route[1].upstream = _.first(route[1].upstream.split(':')); return [route[0], route[1]]; }) // Back to object .fromPairs() // Set the primary route .thru(routes => setPrimaryRoute(routes)) // Return .value()
// Key find helper const getFirstKey = obj => _.first(_.keys(obj))
const key = _.first(option.split('=')); _.set(landoFile, `config.${key}`, _.last(option.split('='))); });
/* * Helper to get config defaults */ const getConfigDefaults = options => { // Get the viaconf if (_.startsWith(options.via, 'nginx')) options.defaultFiles.vhosts = 'default.conf.tpl'; // Get the default db conf const dbConfig = _.get(options, 'database', 'mysql'); const database = _.first(dbConfig.split(':')); const version = _.last(dbConfig.split(':')); if (database === 'mysql' || database === 'mariadb') { if (version === '8.0') { options.defaultFiles.database = 'mysql8.cnf'; } else { options.defaultFiles.database = 'mysql.cnf'; } } // Verify files exist and remove if it doesn't _.forEach(options.defaultFiles, (file, type) => { if (!fs.existsSync(`${options.confDest}/${file}`)) { delete options.defaultFiles[type]; } }); // Return return options.defaultFiles; }
constructor(id, options = {}) { // Get our options options = _.merge({}, config, options); // Get the lagoon config weve loaded and parsed const lagoonConfig = _.get(options, '_app.lagoon', {}); // Map into lando services options.services = getLandoServices(lagoonConfig.services); // Add in any additional dev services eg mailhog we need options.services = getLandoAuxServices(options.services, options._app._config); // Map into lando tooling commands options.tooling = getLandoTooling(options.services); // If we have a SQL service then add in the db import/export commands const sqlServices = getSQLServices(options.services); if (!_.isEmpty(sqlServices)) { const firstDbService = _.first(sqlServices); options.tooling = _.merge({}, options.tooling, getDBUtils(firstDbService.name)); } // If we have the lagoong cli then add that in as well if (_.has(options, 'services.lagooncli')) { options.tooling.lagoon = {service: 'lagooncli', cmd: '/lagoon', user: 'root'}; } // Map into lando proxy routes options.proxy = getLandoProxyRoutes(options.services, _.get(options, '_app.lagoon.domain')); // Send downstream super(id, options); }
const run = child.spawn(_.first(cmd), _.tail(cmd), _.merge({}, {detached, cwd}, stdio));
self.rGet("rows", Context, function(data) { data.forEach(function(d) { d.DoRemove = false; d.IsNew = false; }) self.Rows = data; self.GetClassInfo(); var Doc = MFolders.FindDocument(CxCtrl.CodeDoc()); var Root = _.first(Doc.Link_docrow); if (Root && Root.CodeRow) self.RootBase = Root.CodeRow; return done && done() })
getRawCoreInfo(i, function (rawCoreInfo) { rawCoreInfo.forEach(function (rawInfo) { var info = rawInfo.split(':'); var key = _.camelCase(_.trim(_.first(info))); var value = _.trim(_.last(info)); coreInfo[key] = value; }); });
function testSum(sums, sum, fPath) { let serverSum = _.first(sums.filter(function (s) { return s.getPath === fPath; })); if (serverSum && serverSum.sum === sum) { return; } throw new Error("SHA sum of file '" + fPath + "' mismatch!"); }