experimenting with gradual loading of features in cli...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-12-23 20:02:37 +03:00
parent 98bc9ecc24
commit f17280597e
7 changed files with 62 additions and 21 deletions

View File

@ -21,14 +21,16 @@
var _requirejs = typeof(requirejs) != 'undefined' && requirejs var _requirejs = typeof(requirejs) != 'undefined' && requirejs
var setup = function(require){ var setup = function(require, root){
var res = {} var res = {}
var requirejs = _requirejs var requirejs = _requirejs
var requirejs_cfg = { var requirejs_cfg = {
// NOTE: this is really odd: running electron as a packed binary breaks // NOTE: this is really odd: running electron as a packed binary breaks
// requirejs' paths... // requirejs' paths...
baseUrl: typeof(process) != 'undefined' baseUrl: root ?
root
: typeof(process) != 'undefined'
&& process.versions.electron ? && process.versions.electron ?
(require.main ? (require.main ?
require.main.filename.split(/[\\\/]/g).slice(0, -1).join('/') require.main.filename.split(/[\\\/]/g).slice(0, -1).join('/')
@ -79,7 +81,6 @@ var setup = function(require){
], ],
} }
// node contexts... // node contexts...
if(typeof(process) != 'undefined'){ if(typeof(process) != 'undefined'){
var nodeRequire = var nodeRequire =

View File

@ -56,8 +56,7 @@ require('features/examples')
if(typeof(window) == 'undefined' || window.nodejs != null){ if(typeof(window) == 'undefined' || window.nodejs != null){
require('features/filesystem') require('features/filesystem')
require('features/sharp') require('features/sharp')
require('features/cli') require('features/cli') }
}
//--------------------------------------------------------------------- //---------------------------------------------------------------------

View File

@ -19,12 +19,14 @@ var core = require('features/core')
var base = require('features/base') var base = require('features/base')
//require('features/all')
if(typeof(process) != 'undefined'){ if(typeof(process) != 'undefined'){
var pathlib = requirejs('path') var pathlib = requirejs('path')
var argv = requirejs('lib/argv') var argv = requirejs('lib/argv')
var progress = requirejs('cli-progress') var progress = requirejs('cli-progress')
var colors = requirejs('colors') var colors = requirejs('colors') }
}
@ -175,6 +177,18 @@ var CLIActions = actions.Actions({
}], }],
// XXX SETUP revise default...
setupFeatures: ['- System/',
function(...tags){
var features = this.features.FeatureSet
requirejs('features/all')
features.setup(this, tags.length == 0 ?
[
'imagegrid-testing',
...this.features.input,
]
: tags) }],
// Startup commands... // Startup commands...
// //
@ -187,6 +201,9 @@ var CLIActions = actions.Actions({
var that = this var that = this
var repl = nodeRequire('repl') var repl = nodeRequire('repl')
// XXX SETUP
this.setupFeatures()
this.__keep_running = true this.__keep_running = true
// setup the global ns... // setup the global ns...
@ -197,11 +214,13 @@ var CLIActions = actions.Actions({
global.help = function(...actions){ global.help = function(...actions){
global.ig.help(...actions) } global.ig.help(...actions) }
require('features/all') var features = global.ImageGridFeatures = core.ImageGridFeatures
global.ImageGridFeatures = core.ImageGridFeatures
//var ig = core.ImageGridFeatures //var ig = core.ImageGridFeatures
// print banner...
//XXX
repl repl
.start({ .start({
prompt: 'ig> ', prompt: 'ig> ',
@ -292,7 +311,11 @@ var CLIActions = actions.Actions({
doc: 'Show image filename pattern info and exit', doc: 'Show image filename pattern info and exit',
priority: 89, priority: 89,
handler: function(){ handler: function(){
this.parent.context.help('formatImageName') this.parent.context
// XXX SETUP
//.setupFeatures('fs', 'commandline')
.setupFeatures()
.help('formatImageName')
return argv.STOP } }, return argv.STOP } },
'-version': undefined, '-version': undefined,
'-quiet': undefined, '-quiet': undefined,
@ -347,6 +370,9 @@ var CLIActions = actions.Actions({
function(path, options={}){ function(path, options={}){
var that = this var that = this
// XXX SETUP
this.setupFeatures()
path = path || options.from path = path || options.from
path = util.normalizePath( path = util.normalizePath(
path ? path ?
@ -398,6 +424,9 @@ var CLIActions = actions.Actions({
//valueRequired: true, //valueRequired: true,
}}, }},
function(path, options){ function(path, options){
// XXX SETUP
this.setupFeatures()
// get mode... // get mode...
if(path == 'create' || path == 'update'){ if(path == 'create' || path == 'update'){
var [mode, path, options] = arguments } var [mode, path, options] = arguments }
@ -490,6 +519,9 @@ module.CLI = core.ImageGridFeatures.Feature({
// XXX // XXX
var interactive = false var interactive = false
// XXX SETUP need to setup everything that has command-line features...
//this.setupFeatures()
argv.Parser({ argv.Parser({
context: this, context: this,

View File

@ -76,6 +76,8 @@ var text = module.text = object.text
// //
var ImageGridMetaActions = var ImageGridMetaActions =
module.ImageGridMetaActions = { module.ImageGridMetaActions = {
__proto__: actions.MetaActions,
// Test if the action is a Toggler... // Test if the action is a Toggler...
// //
isToggler: isToggler:
@ -109,19 +111,21 @@ module.ImageGridMetaActions = {
} }
}), }),
} }
ImageGridMetaActions.__proto__ = actions.MetaActions
var ImageGrid = var ImageGrid =
module.ImageGrid = module.ImageGrid =
object.Constructor('ImageGrid', ImageGridMetaActions) object.Constructor('ImageGrid', ImageGridMetaActions)
// Root ImageGrid feature set.... // Root ImageGrid feature set....
var ImageGridFeatures = var ImageGridFeatures =
module.ImageGridFeatures = new features.FeatureSet() module.ImageGridFeatures =
new features.FeatureSet()
// setup base instance constructor... // setup base instance constructor...
ImageGridFeatures.__actions__ = ImageGridFeatures.__actions__ =
function(){ return actions.Actions(ImageGrid()) } function(){
return actions.Actions(ImageGrid()) }
@ -994,6 +998,7 @@ var LifeCycleActions = actions.Actions({
&& func.call(this) } }], && func.call(this) } }],
// helpers... // helpers...
//
restart: ['System/Soft restart', restart: ['System/Soft restart',
doc`Soft restart doc`Soft restart
@ -1004,8 +1009,6 @@ var LifeCycleActions = actions.Actions({
.stop() .stop()
.clear() .clear()
.start() }], .start() }],
}) })
var LifeCycle = var LifeCycle =

View File

@ -26,8 +26,10 @@ require('v8-compile-cache')
// conflicting with stuff... // conflicting with stuff...
require('repl') require('repl')
var path = require('path')
// setup module loaders... // setup module loaders...
require = require('./cfg/requirejs')(require).requirejs require = require('./cfg/requirejs')(require, path.resolve(__dirname)).requirejs
require.main = {filename: (nodeRequire.main || {}).filename} require.main = {filename: (nodeRequire.main || {}).filename}
var core = require('features/core') var core = require('features/core')
@ -40,6 +42,9 @@ var meta = require('features/meta')
/*********************************************************************/ /*********************************************************************/
// XXX SETUP
//require('features/all')
// NOTE: this is here to simplify importing... // NOTE: this is here to simplify importing...
var ImageGridFeatures = var ImageGridFeatures =
module.ImageGridFeatures = module.ImageGridFeatures =
@ -48,7 +53,8 @@ module.ImageGridFeatures =
// setup actions and start... // setup actions and start...
ImageGridFeatures ImageGridFeatures
.setup([ .setup([
'imagegrid-testing', // XXX SETUP should this do a full setup...
//'imagegrid-testing',
'imagegrid-commandline', 'imagegrid-commandline',
]) ])
.start() .start()

View File

@ -1197,9 +1197,9 @@
} }
}, },
"ig-features": { "ig-features": {
"version": "3.4.5", "version": "3.4.7",
"resolved": "https://registry.npmjs.org/ig-features/-/ig-features-3.4.5.tgz", "resolved": "https://registry.npmjs.org/ig-features/-/ig-features-3.4.7.tgz",
"integrity": "sha512-koFV8Rx5MUmnbwQcGKuO6A62XQB4F/TJ2ZwDwpTGDkeUmNkLLkPaPaW9fwMosUZRZoKCiH6evARqaSW/PX91Ww==", "integrity": "sha512-ejwYjnP1K5mXzbnLTrsuuB0lGSeUtO6UtBxYcGbXGdu9rgKjz3Q46qC9XYiM01zYw3MltivLCdc2kN6/RiOvZw==",
"requires": { "requires": {
"ig-actions": "^3.24.28", "ig-actions": "^3.24.28",
"ig-object": "^5.4.14" "ig-object": "^5.4.14"

View File

@ -32,7 +32,7 @@
"guarantee-events": "^1.0.0", "guarantee-events": "^1.0.0",
"ig-actions": "^3.24.29", "ig-actions": "^3.24.29",
"ig-argv": "^2.16.3", "ig-argv": "^2.16.3",
"ig-features": "^3.4.5", "ig-features": "^3.4.7",
"ig-object": "^5.4.14", "ig-object": "^5.4.14",
"ig-types": "^6.0.7", "ig-types": "^6.0.7",
"json5": "^2.1.3", "json5": "^2.1.3",