1
- const { Command } = require ( '@oclif/config' ) ;
2
- const { flags} = require ( '@oclif/command' ) ;
3
- const Config = require ( '@oclif/config' ) ;
4
-
5
- class DynamicPlugin extends Config . Plugin {
6
- get hooks ( ) { return { } }
7
- get topics ( ) {
8
- return [ ]
9
- }
10
- get commandIDs ( ) {
11
- return [ 'mydynamiccommand' ]
12
- }
13
-
14
- get commands ( ) {
15
- const cmd = require ( './../more/bye' ) ;
16
- cmd . id = 'bye' ;
17
- cmd . load = ( ) => cmd ;
18
- return [ cmd ] ;
19
- }
20
- }
21
-
22
- /*
23
- * New plugin types:
24
- * HyperdrivePlugin extends Config.Plugin
25
- * 1. accepts a list of commands and an optional selector function for a "parent"
26
- *
27
- *
28
- */
29
-
30
- module . exports = async ( options ) => {
31
- // commands = [require('./../more/bye')];
32
- // config.plugins.push(new DynamicPlugin(config))
33
- // console.log(config.plugins);
34
- // config.plugins[0].commands[0].flags.stuff = flags.string({char: 'z', description: 'name to print'});
35
- console . log ( options ) ; // {id, argv, conf}
1
+ 'use strict' ;
36
2
37
- // Set DEBUG=* when -vvv is set?
3
+ // @NOTE : We use LET so we can rename the debugger as needed
4
+ const createDebugger = require ( './../../lib/debug' ) ;
5
+ const path = require ( 'path' ) ;
6
+ const Ministrapper = require ( './../../lib/ministrapper' ) ;
38
7
39
- // Load in bootstrap config from configDir
40
- /*
41
- bootstrap:
42
- bootstrapper: ./lib/bootstrap.js
43
- envPrefix:
44
- - HYPERDRIVE_
45
- configSources:
46
- - config.yml
47
- mode: 'cli',
48
- packaged: _.has(process, 'pkg'),
49
-
50
- channel: stable?
51
- leia: _.has(process, 'env.LEIA_PARSER_RUNNING')
52
- pluginDirs: _.compact(pluginDirs.concat(process.landoAppPluginDirs))
53
- plugins: ,
54
- product: 'lando',
55
- userAgent: `Lando/${version}`,
56
-
57
- //
58
- channel: 'stable',
59
- landoFile: '.lando.yml',
60
- logLevelConsole: (this.argv().verbose) ? this.argv().verbose + 1 : this.logLevel,
61
- logDir: path.join(this.userConfRoot, 'logs'),
62
- mode: 'cli',
63
- packaged: _.has(process, 'pkg'),
64
- pluginDirs: _.compact(pluginDirs.concat(process.landoAppPluginDirs)),
65
- preLandoFiles: ['.lando.base.yml', '.lando.dist.yml', '.lando.upstream.yml'],
66
- postLandoFiles: ['.lando.local.yml'],
67
- userConfRoot: this.userConfRoot,
68
- version,
8
+ module . exports = async ( { id, argv, config} ) => {
9
+ let debug = createDebugger ( config . dirname , 'hooks' , 'init' ) ;
10
+ const sourceConfig = path . join ( __dirname , '..' , '..' , 'config.yml' ) ;
11
+ const userConfig = path . join ( config . configDir , 'config.yml' ) ;
69
12
70
- */
13
+ // @TODO : set this based on some options (--debug?). if boolean/null should set * if string should set as if DEBUG
14
+ // envvar was set.
15
+ // @NOTE : this shows all debug right now for dev purposes. see @TODO above.
16
+ require ( 'debug' ) . enable ( '*' ) ; // eslint-disable-line node/no-extraneous-require
17
+ debug ( 'cli init start with id=%s, argv=%O' , id , argv ) ;
18
+
19
+ // Get config vars
20
+ const ENV_PREFIX = process . env . HYPERDRIVE_BOOTSTRAP_ENV_PREFIX || 'HYPERDRIVE' ;
21
+ const ENV_SEPARATOR = process . env . HYPERDRIVE_BOOTSTRAP_ENV_SEPARATOR || '_' ;
22
+
23
+ // Build up hyperdrive/product config from various sources
24
+ const bootstrapConf = new Ministrapper ( [ config . name , 'lib' , 'ministrapper' ] ) ;
25
+
26
+ // @NOTE : do we want to accept some hidden args for this eg `hyperdrive --config bootstrap.module=something?`
27
+ // ENVARS are highest priority
28
+ bootstrapConf . env ( ENV_PREFIX , ENV_SEPARATOR ) ;
29
+ debug ( 'get config from %s%s* envvars done' , ENV_PREFIX , ENV_SEPARATOR ) ;
30
+
31
+ // Then user config if it exists
32
+ bootstrapConf . file ( 'user' , { file : userConfig , format : require ( 'nconf-yaml' ) } ) ;
33
+ debug ( 'get config from file %s done' , userConfig ) ;
71
34
72
- // run bootstrap
73
- // 1. merge in more config
74
- // 2. go through plugins and build manifest of components/config/whatever
75
- // 3. traverse plugins to find commands
76
- // 4. what do commandIDs do?
77
- // 5. install defaults eg desktop -> lando-desktop
78
- /*
35
+ // Then source config
36
+ bootstrapConf . file ( 'source' , { file : sourceConfig , format : require ( 'nconf-yaml' ) } ) ;
37
+ debug ( 'get config from file %s done' , sourceConfig ) ;
38
+
39
+ // Then defaults
40
+ bootstrapConf . defaults ( {
41
+ mode : 'cli' ,
42
+ leia : Object . prototype . hasOwnProperty . call ( process . env , 'LEIA_PARSER_RUNNING' ) ,
43
+ packaged : Object . prototype . hasOwnProperty . call ( process , 'pkg' ) ,
44
+ product : 'hyperdrive' ,
45
+ } ) ;
46
+ debug ( 'get config from defaults' ) ;
47
+
48
+ // Reset debugger to indicate product status
49
+ debug = createDebugger ( bootstrapConf . get ( 'product' ) , 'hooks' , 'init' ) ;
50
+ debug ( 'bootstrap config set to %O' , bootstrapConf . get ( ) ) ;
51
+
52
+ // Set DEBUG=* when -vvv is set?
53
+ // run bootstrap
54
+ // 1. merge in more config
55
+ // 2. go through plugins and build manifest of components/config/whatever
56
+ // 3. traverse plugins to find commands
57
+ // 4. what do commandIDs do?
58
+ // 5. install defaults eg desktop -> lando-desktop
59
+ /*
79
60
hyperdrive:
80
61
// list of installers
81
62
installers:
@@ -91,5 +72,11 @@ module.exports = async (options) => {
91
72
mods: (?)
92
73
- {id: 'install', path: }
93
74
75
+ // commands = [require('./../more/bye')];
76
+ // config.plugins.push(new DynamicPlugin(config))
77
+ // console.log(config.plugins);
78
+ // config.plugins[0].commands[0].flags.stuff = flags.string({char: 'z', description: 'name to print'});
79
+ // console.log(id, argv, config); // {id, argv, conf}
80
+
94
81
*/
95
- }
82
+ } ;
0 commit comments