// Helper to get sites for autocomplete const getAutoCompleteSites = (answers, lando, input = null) => { if (!_.isEmpty(pantheonSites)) { return lando.Promise.resolve(pantheonSites).filter(site => _.startsWith(site.name, input)); } else { const api = new PantheonApiClient(answers['pantheon-auth'], lando.log); return api.auth().then(() => api.getSites().map(site => ({name: site.name, value: site.name}))).then(sites => { pantheonSites = sites; return pantheonSites; }); }; }
// Helper to find the default service const getDefaultService = data => { if (_.has(data, 'service')) { if (_.startsWith(data.service, ':')) { const option = _.trimStart(data.service, ':'); return _.get(data, `options.${option}.default`, 'appserver'); } else { return _.get(data, 'service'); } } else { return 'appserver'; } }
// Helper to get excludes const getExcludes = (data = [], inverse = false) => _(data) .filter(exclude => _.startsWith(exclude, '!') === inverse) .map(exclude => _.trimStart(exclude, '!')) .uniq() .compact() .value()
const frameworkType = (framework = 'drupal8') => { if (_.startsWith(framework, 'wordpress')) return 'pressy'; else return 'drupaly'; }
constructor(id, options = {}) { options = _.merge({}, config, options); // Rebase on top of any default config we might already have options.defaultFiles = _.merge({}, getConfigDefaults(_.cloneDeep(options)), options.defaultFiles); options.services = _.merge({}, getServices(options), options.services); options.tooling = _.merge({}, getTooling(options), options.tooling); // Switch the proxy if needed if (!_.has(options, 'proxyService')) { if (_.startsWith(options.via, 'nginx')) options.proxyService = 'appserver_nginx'; else if (_.startsWith(options.via, 'apache')) options.proxyService = 'appserver'; } options.proxy = _.set({}, options.proxyService, [`${options.app}.${options._app._config.domain}`]); // Downstream super(id, options); }
// Helper to get sites for autocomplete const getAutoCompleteRepos = (answers, Promise, input = null) => { if (!_.isEmpty(gitHubRepos)) { return Promise.resolve(gitHubRepos).filter(site => _.startsWith(site.name, input)); } else { return getRepos(answers, Promise).then(sites => { gitHubRepos = sites; return gitHubRepos; }); }; }
// Helper to get sites for autocomplete const getAutoCompleteSites = (answers, lando, input = null) => { const api = new PlatformshApiClient({api_token: _.trim(answers['platformsh-auth'])}); if (!_.isEmpty(platformshSites)) { return lando.Promise.resolve(platformshSites).filter(site => _.startsWith(site.name, input)); } else { return api.getAccountInfo().then(me => { platformshSites = _.map(me.projects, project => ({name: project.title, value: project.name})); return platformshSites; }) .catch(err => lando.Promise.reject(Error(err.error_description))); } }
/* * Helper to handle dynamic services * * Set SERVICE from answers and strip out that noise from the rest of * stuff, check answers/argv for --service or -s, validate and then remove */ const handleDynamic = (config, options = {}, answers = {}) => { if (_.startsWith(config.service, ':')) { const answer = answers[config.service.split(':')[1]]; // Remove dynamic service option from argv _.remove(process.argv, arg => _.includes(getDynamicKeys(answer, answers).concat(answer), arg)); // Return updated config return _.merge({}, config, {service: answers[config.service.split(':')[1]]}); } else { return config; } }
/* * 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 = {}) { options = _.merge({}, config, options); if (_.startsWith(options.version, '5.7')) { options.authentication = 'mysql_native_password';
XDEBUG_CONFIG: `remote_enable=true remote_host=${options._app.env.LANDO_HOST_IP}`, }), networks: (_.startsWith(options.via, 'nginx')) ? {default: {aliases: ['fpm']}} : {default: {}}, ports: (_.startsWith(options.via, 'apache') && options.version !== 'custom') ? ['80'] : [], volumes: options.volumes, command: options.command.join(' '), if (_.startsWith(options.via, 'nginx')) {
const needsWrapping = s => !_.startsWith(s, '\'') && !_.endsWith(s, '\'') && _.includes(s, 'lando.')
code = isFinite(_.last(url.split('.'))) ? _.last(url.split('.')) : 200; return (_.startsWith(code, 2)) ? Promise.resolve() : Promise.reject({response: {status: _.toInteger(code)}}); }, }));
isSelf(moveTo, moveFrom) { const target = this.server.path(moveTo); const source = this.server.path(moveFrom); if (!_.startsWith(target, source)) { return false; } const end = target.slice(source.length); if (!end) { return true; } return _.startsWith(end, '/'); }
convertToConditionArgs(matched) { return matched ? [ _.compact( _.trim(matched[1]) .split(',') .map((str) => str.replace(/["'“”]/g, ''))), !_.startsWith(matched[0], '-'), ] : [] }