Skip to content

Commit

Permalink
Cleanup5 (#197)
Browse files Browse the repository at this point in the history
* dedash rts

* pirostash

* update CLI to be more performant

* update @lando/core to 3.15.0

* clarify exports and return config to working

* improve YAMLDOC detection

* fix execPath path
  • Loading branch information
pirog authored Apr 13, 2023
1 parent 682b560 commit 4b33454
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 169 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"code": 150,
"ignoreComments": true
}],
"no-extra-semi": ["error"],
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
Expand Down
17 changes: 10 additions & 7 deletions bin/lando.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ debug('starting %o version %o runtime selector...', id, pjson.version);
const LOGLEVELCONSOLE = process.env.LANDO_CORE_LOGLEVELCONSOLE;
const ENVPREFIX = process.env.LANDO_CORE_ENVPREFIX;
const USERCONFROOT = process.env.LANDO_CORE_USERCONFROOT;
const RUNTIME = process.env.LANDO_CORE_RUNTIME;

// start by "minstrapping" the lando/app config
// primarily this means getting the MININMAL amount of stuff we need to determine the runtime to be used
let config = rts.getDefaultConfig({envPrefix: ENVPREFIX, userConfRoot: USERCONFROOT});
let config = rts.getDefaultConfig({envPrefix: ENVPREFIX, runtime: RUNTIME, userConfRoot: USERCONFROOT});

// @NOTE: is it safe to assume configSources exists and is iterable? i think so?
for (const file of config.configSources) {
Expand All @@ -52,14 +53,15 @@ for (const file of config.configSources) {
if (config.envPrefix) {
const data = rts.loadEnvs(config.envPrefix);
config = rts.merge(config, data);
debug('merged in additional config source from %o envvars with data %O', `${config.envPrefix}_*`, data);
debug('merged in additional config source from %o envvars with data %o', `${config.envPrefix}_*`, data);
}

// log minconf result
debug('final assembled minconf is %O', config);

// try to get app configuration if we can
const {preLandoFiles, landoFile, postLandoFiles, userConfRoot} = config;

const landoFiles = rts.getLandoFiles([preLandoFiles, [landoFile], postLandoFiles].flat(1));
const appConfig = (landoFiles.length > 0) ? rts.getApp(landoFiles, userConfRoot) : {};

Expand All @@ -79,10 +81,8 @@ debug('using %o runtime version %o', '@lando/core', runtime);
*/
// THIS IS @LANDO/CLI@3(ish) AND @LANDO/CORE@4
// THIS IS NOW THE HAPPENING SPOT!!!
if (runtime === 4) {
// get oclif
const oclif = require('@oclif/core');

if (runtime === 4) {
// handle legacy --verbose flags
if (!isDebugging &&
(argv.hasOption('--verbose')
Expand All @@ -95,13 +95,16 @@ if (runtime === 4) {

// Set the OCLIF debug flag
// we do a different check here because process.env.DEBUG should be set above
if (process.env.DEBUG) oclif.settings.debug = true;
if (process.env.DEBUG) {
const oclif = require('@oclif/core');
oclif.settings.debug = true;
}

// get what we need for cli-next
const cache = !argv.hasOption('--clear') && !argv.hasOption('--no-cache');
const cacheDir = `${rts.getOclifCacheDir(config.product)}.cli`;

debug('handing off to %o with caching %o', '@lando/cli/lib/cli-next', cache ? 'enabled' : 'disabled');
debug('handing off to %o with caching %o at %o', '@lando/cli@4', cache ? 'enabled' : 'disabled', cacheDir);

// get the cli
const Cli = require('./../lib/cli-next');
Expand Down
27 changes: 8 additions & 19 deletions config/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,19 @@
const fs = require('fs');
const path = require('path');

// const Config = require('@lando/core-next/config');
// const Templator = require('@lando/core-next/Templator');

module.exports = options => {
// start by figuring out the "core" location
// @NOTE: we prefer external core over the internal one for cases where core has been updated externally or
// if core is being developed
const inCore = path.resolve(__dirname, '..', 'node_modules', '@lando', 'core-next');
const exCore = path.join(options.dataDir, 'plugins', '@lando', 'core-next');
options.coreDir = fs.existsSync(exCore) ? exCore : inCore;
options.coreDir = fs.existsSync(exCore) ? exCore : '@lando/core-next';

// and where we should dump the result of the config
options.configCache = path.join(options.cacheDir, `${options.id}-config.json`);

// now that options is sort of set, get some stuff we need from it
const {configCache, configDir, configFile, dataDir, env, id, logger} = options;

// get core location dependent deps
// @NOTE: we can probably get rid of this for things like Config/Templator once they are in a stable state
// just like we invoke debug directly in bin/lando.js
const Config = require(`${options.coreDir}/lib/config`);
const Templator = require(`${options.coreDir}/lib/templator`);
const read = require(`${options.coreDir}/utils/read-file`);
const {configCache, configDir, configFile, coreDir, dataDir, env, id, logger} = options;
// @NOTE: do we think it makes sense to use coreDir for this? it seems to be a bit slower?
// and potentially it could be less? stable
const Config = require(`${coreDir}/lib/config`);
const Templator = require(`${coreDir}/lib/templator`);

// configuration templates we need to create
const templates = [
Expand All @@ -35,15 +26,13 @@ module.exports = options => {
// a "user" config file that can be manually edited by the user
[path.join(__dirname, 'user.yaml'), path.join(configDir, 'config.yaml'), {debug: logger.extend('templator')}],
];

// loop through and generate our templates as needed
templates.map(targs => new Templator(...targs)).map(template => template.generate(options));

// start our config collection and load config sources in decreasing priority
const config = new Config({cached: configCache, debug: logger.extend('minstrapper-config'), env, id, managed: 'global'});

// if we have a CLI provided config source then thats first
if (configFile) config.overrides('userfile', read(configFile), {encode: false});
if (configFile) config.overrides('userfile', Config.read(configFile), {encode: false});
// then load in product envvars
config.env(id);
// then the user config
Expand Down
Loading

0 comments on commit 4b33454

Please sign in to comment.