@travetto/di
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -13,18 +13,34 @@ //@ts-check | ||
function envFromApp(app) { | ||
return app.filename.includes('e2e') ? 'e2e' : 'dev'; | ||
} | ||
function generateAppHelpList(apps, cmd) { | ||
const lines = []; | ||
const choices = []; | ||
for (const conf of apps) { | ||
let line = conf.name; | ||
let lines = []; | ||
let usage = conf.name; | ||
if (conf.arguments) { | ||
usage = `${usage} ${conf.arguments.map(x => { | ||
return x.def ? `(${x.name}=${x.def})` : `[${x.name}]`; | ||
}).join(' ')}` | ||
} | ||
lines.push(usage); | ||
if (conf.description) { | ||
line = `${line} -- ${conf.description}`; | ||
lines.push(conf.description); | ||
} | ||
const watched = cmd.watchSpecified ? cmd.watch : (conf.watchable && cmd.env !== 'prod'); | ||
if (watched) { | ||
line = `${line} [watch=true]`; | ||
const features = []; | ||
if (cmd.watchReal || (conf.watchable && cmd.env !== 'prod')) { | ||
features.push('Watchable'); | ||
} | ||
const env = (!cmd.envSpecified && conf.filename.includes('e2e') && 'e2e') || cmd.env; | ||
line = `${line} [env=${env}]`; | ||
lines.push(line); | ||
features.push(`Environment ${cmd.env === undefined ? envFromApp(conf) : cmd.env}`); | ||
lines.push(`Flags: ${features.join(', ')}`); | ||
choices.push(lines.join('\n ')); | ||
} | ||
return lines.map(x => ` * ${x}`).join('\n'); | ||
return choices.map(x => ` * ${x}`).join('\n'); | ||
} | ||
@@ -34,2 +50,4 @@ | ||
try { | ||
//@ts-ignore | ||
require('@travetto/base/src/env').reload(); | ||
await require('@travetto/base/bin/bootstrap').run(); | ||
@@ -45,3 +63,3 @@ await require('../src/registry').DependencyRegistry.runApplication(app); | ||
if (require.main === module) { | ||
runApp(process.argv.pop()); //If loaded directly as main entry, run | ||
runApp(process.argv.slice(-1)[0]); //If loaded directly as main entry, run | ||
} else { | ||
@@ -66,9 +84,9 @@ module.exports = function () { | ||
}) | ||
.option('-e, --env [env]', 'Application environment (dev|test|e2e|prod)', /^(dev|test|e2e|prod)$/i, 'dev') | ||
.option('-w, --watch', 'Run the application in watch mode') | ||
.option('-e, --env [env]', 'Application environment (dev|test|e2e|prod), defaults to dev', /^(dev|test|e2e|prod)$/i) | ||
.option('-w, --watch [watch]', 'Run the application in watch mode, defaults to auto', /^(1|0|yes|no|on|off|auto|true|false)$/i) | ||
.option('-p, --profile [profile]', 'Specify additional application profiles', (v, ls) => { ls.push(v); return ls; }, []) | ||
.action(async (app, cmd) => { | ||
cmd.watchSpecified = cmd.watch !== undefined; | ||
cmd.envSpecified = !(cmd.env === undefined || (cmd.env === 'dev' && !process.argv.find(x => x === 'dev'))); // If env is default selected | ||
cmd.env = cmd.env || process.env.ENV || process.env.env || undefined; | ||
cmd.watchReal = /^(1|yes|on|true)$/.test(cmd.watch || ''); | ||
@@ -94,10 +112,4 @@ cmd.profile = [ | ||
} else { | ||
cmd.env = cmd.env || process.env.ENV || process.env.env; | ||
if (!cmd.envSpecified && selected.filename.includes('e2e')) { | ||
cmd.env = 'e2e'; | ||
} | ||
if (!cmd.watchSpecified) { | ||
cmd.watch = selected.watchable && cmd.env !== 'prod'; | ||
} | ||
cmd.env = cmd.env !== undefined ? cmd.env : envFromApp(selected); | ||
cmd.watch = cmd.watch !== undefined ? cmd.watchReal : (selected.watchable && cmd.env !== 'prod'); | ||
} | ||
@@ -104,0 +116,0 @@ |
@@ -32,2 +32,3 @@ #!/usr/bin/env node | ||
description: x.description, | ||
arguments: x.arguments, | ||
name: x.name, | ||
@@ -34,0 +35,0 @@ filename: x.target.__filename, |
@@ -14,8 +14,8 @@ { | ||
"dependencies": { | ||
"@travetto/config": "^0.5.0", | ||
"@travetto/registry": "^0.5.1" | ||
"@travetto/config": "^0.5.1", | ||
"@travetto/registry": "^0.5.2" | ||
}, | ||
"description": "Dependency registration/management and injection support.", | ||
"devDependencies": { | ||
"@travetto/test": "^0.5.1" | ||
"@travetto/test": "^0.5.2" | ||
}, | ||
@@ -37,4 +37,4 @@ "homepage": "https://travetto.io", | ||
}, | ||
"version": "0.5.1", | ||
"gitHead": "ccc6eaefc6ec7c6e9ecbb649f8f78ec96c1b3983" | ||
"version": "0.5.2", | ||
"gitHead": "c4ce2d9eb57b8939eb0b24b51a9cfc6a490dee4d" | ||
} |
@@ -33,7 +33,13 @@ import { Class } from '@travetto/registry'; | ||
export interface ApplicationParameter { | ||
name: string; | ||
def?: string; | ||
} | ||
export interface ApplicationConfig<T = any> { | ||
name: string; | ||
description?: string; | ||
arguments?: ApplicationParameter[]; | ||
target: Class<T>; | ||
watchable?: boolean; | ||
} |
40208
14
835
Updated@travetto/config@^0.5.1
Updated@travetto/registry@^0.5.2