@fluent/core
Advanced tools
Comparing version 1.0.5 to 1.0.8
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const console_1 = require("@fluent/console"); | ||
class ApplicationBuilder { | ||
constructor() { | ||
this.commandCollection = new console_1.CommandCollection(); | ||
} | ||
addCommand(commandType, commandInstance) { | ||
if (commandInstance) { | ||
this.commandCollection.addCommand(commandType, commandInstance); | ||
} | ||
else { | ||
this.commandCollection.addCommand(commandType); | ||
} | ||
return this; | ||
} | ||
} | ||
exports.ApplicationBuilder = ApplicationBuilder; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path = require("path"); | ||
const fileSystem = require("fs"); | ||
const application_builder_1 = require("./application-builder"); | ||
const environment_1 = require("./environment"); | ||
const root_path_1 = require("./root-path"); | ||
const importer_1 = require("./importer"); | ||
const console_1 = require("@fluent/console"); | ||
const di_1 = require("@fluent/di"); | ||
const root_dir_1 = require("./root-dir"); | ||
const importer_1 = require("./importer"); | ||
const configuration_1 = require("./configuration"); | ||
const help_command_1 = require("./commands/help-command"); | ||
const logging_1 = require("@fluent/logging"); | ||
const service_collection_1 = require("./service-collection"); | ||
class Application { | ||
constructor() { | ||
this.serviceCollection = new di_1.ServiceCollection(); | ||
constructor(inputCommand = new console_1.InputCommand(...process.argv)) { | ||
this.inputCommand = inputCommand; | ||
this.applicationBuilder = new application_builder_1.ApplicationBuilder(); | ||
this.importer = new importer_1.Importer(); | ||
this.environment = new environment_1.Environment(); | ||
this.importer = new importer_1.Importer(); | ||
this.environment.rootPath = root_dir_1.rootPath; | ||
this.serviceCollection = new service_collection_1.ServiceCollection(); | ||
this.environment.rootPath = root_path_1.rootPath; | ||
this.serviceCollection.addSingleton(environment_1.Environment, this.environment); | ||
const optionAsEnvironment = inputCommand.optionValues.get('--environment') | ||
|| inputCommand.optionValues.get('--env'); | ||
if (typeof optionAsEnvironment === 'string') { | ||
this.environment.name = optionAsEnvironment; | ||
} | ||
if (!this.configuration) { | ||
const configurationPath = this.configurationPath; | ||
this.configuration = configurationPath === null ? new configuration_1.Configuration() : configuration_1.Configuration.readFromFile(configurationPath); | ||
} | ||
this.serviceCollection.addSingleton(configuration_1.Configuration, this.configuration); | ||
this.serviceCollection.addSingleton(logging_1.Logger, () => new logging_1.Logger()); | ||
const loggingConfiguration = this.configuration.get('logging'); | ||
if (loggingConfiguration instanceof Object && loggingConfiguration.logLevel) { | ||
if (this.serviceCollection.loggerBuilder) { | ||
this.serviceCollection.loggerBuilder.logLevel = loggingConfiguration.logLevel; | ||
} | ||
} | ||
if (process.env.FLUENT_RUNTIME !== 'WEBPACK') { | ||
this.importer.scanDirectory(this.environment.rootPath); | ||
this.importer.importAll(); | ||
this.autoImportExecuted = true; | ||
} | ||
else { | ||
this.autoImportExecuted = false; | ||
} | ||
const helpCommandInstance = new help_command_1.HelpCommand(this.commandCollection); | ||
const helpCommandDescriptor = new console_1.CommandDescriptor('help', help_command_1.HelpCommand, helpCommandInstance); | ||
this.commandCollection.add(helpCommandDescriptor); | ||
this.commandCollection.defaultHandler = helpCommandDescriptor; | ||
} | ||
get commandCollection() { | ||
return this.applicationBuilder.commandCollection; | ||
} | ||
buildServiceProvider() { | ||
return this.serviceProvider = di_1.ServiceFactory | ||
.createServiceProvider(this.serviceCollection); | ||
} | ||
execute() { | ||
let serviceProvider = this.serviceProvider; | ||
if (!serviceProvider) { | ||
serviceProvider = this.buildServiceProvider(); | ||
} | ||
let commandProvider = new console_1.CommandProvider(this.commandCollection, serviceProvider); | ||
commandProvider.executeAsync(this.inputCommand).then(executed => { | ||
if (!executed) { | ||
console.warn(`Command signature '${Array.from(this.inputCommand.argumentCollection).join(' ')}' not registered.`); | ||
} | ||
}).catch(error => console.error(error)); | ||
} | ||
get configurationPath() { | ||
const filePaths = []; | ||
if (this.environment.isProduction) { | ||
filePaths.push(path.join(this.environment.rootPath, `configuration.json`)); | ||
} | ||
filePaths.push(path.join(this.environment.rootPath, `configuration.${this.environment.name}.json`)); | ||
for (const filePath of filePaths) { | ||
try { | ||
const fileStat = fileSystem.statSync(filePath); | ||
if (fileStat.isFile) { | ||
return filePath; | ||
} | ||
} | ||
catch (error) { | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
exports.Application = Application; |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fileSystem = require("fs"); | ||
class Configuration extends Map { | ||
const di_1 = require("@fluent/di"); | ||
let Configuration = Configuration_1 = class Configuration extends Map { | ||
static readFromFile(filePath, encoding = 'utf8') { | ||
@@ -19,5 +26,9 @@ const fileContent = fileSystem.readFileSync(filePath, { | ||
} | ||
return new Configuration(configuration); | ||
return new Configuration_1(configuration); | ||
} | ||
} | ||
}; | ||
Configuration = Configuration_1 = __decorate([ | ||
di_1.Injectable() | ||
], Configuration); | ||
exports.Configuration = Configuration; | ||
var Configuration_1; |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const di_1 = require("@fluent/di"); | ||
var EnvironmentName; | ||
@@ -9,3 +16,3 @@ (function (EnvironmentName) { | ||
})(EnvironmentName = exports.EnvironmentName || (exports.EnvironmentName = {})); | ||
class Environment { | ||
let Environment = class Environment { | ||
constructor() { | ||
@@ -23,3 +30,6 @@ this.name = process.env['FLUENT_ENVIRONMENT'] || EnvironmentName.Production; | ||
} | ||
} | ||
}; | ||
Environment = __decorate([ | ||
di_1.Injectable() | ||
], Environment); | ||
exports.Environment = Environment; |
@@ -37,3 +37,3 @@ "use strict"; | ||
importFile(filePath) { | ||
require(filePath); | ||
require(`${filePath}`); | ||
} | ||
@@ -40,0 +40,0 @@ isExcluded(entryPath) { |
@@ -13,2 +13,10 @@ "use strict"; | ||
__export(require("./importer")); | ||
__export(require("./root-dir")); | ||
__export(require("./root-path")); | ||
__export(require("./service-collection")); | ||
var di_1 = require("@fluent/di"); | ||
exports.ServiceProvider = di_1.ServiceProvider; | ||
exports.Injectable = di_1.Injectable; | ||
exports.Inject = di_1.Inject; | ||
var logging_1 = require("@fluent/logging"); | ||
exports.Logger = logging_1.Logger; | ||
exports.LoggerBuilder = logging_1.LoggerBuilder; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function Main(applicationConstructor) { | ||
const application_1 = require("./application"); | ||
const reflect_1 = require("@fluent/reflect"); | ||
const environment_1 = require("./environment"); | ||
const configuration_1 = require("./configuration"); | ||
function Main(applicationConstructor = application_1.Application) { | ||
return (startupConstructor) => { | ||
if (!applicationConstructor) { | ||
throw new Error(`Application type not selected. Try use Application from "Application" from "@fluent/console".`); | ||
} | ||
const application = new applicationConstructor(); | ||
const startup = new startupConstructor(); | ||
const parameters = reflect_1.Reflection.getParameterTypes(startupConstructor) | ||
.map(parameterType => { | ||
switch (parameterType) { | ||
case environment_1.Environment: | ||
return application.environment; | ||
case configuration_1.Configuration: | ||
return application.configuration; | ||
default: | ||
return undefined; | ||
} | ||
}); | ||
const startup = new startupConstructor(...parameters); | ||
if (startup.configureServices) { | ||
startup.configureServices(application.serviceCollection); | ||
} | ||
const serviceProvider = application.buildServiceProvider(); | ||
if (startup.configure) { | ||
startup.configure(application.applicationBuilder); | ||
startup.configure(application.applicationBuilder, serviceProvider); | ||
} | ||
application.runAsync(); | ||
application.execute(); | ||
}; | ||
} | ||
exports.Main = Main; |
{ | ||
"name": "@fluent/core", | ||
"version": "1.0.5", | ||
"version": "1.0.8", | ||
"description": "Fluent - core component", | ||
"main": "build/index.js", | ||
"typings": "build/index.d.ts", | ||
"typings": "types/index.d.ts", | ||
"scripts": { | ||
@@ -24,6 +24,9 @@ "build": "tsc", | ||
"dependencies": { | ||
"reflect-metadata": "^0.1.12" | ||
"reflect-metadata": "0.1.*" | ||
}, | ||
"peerDependencies": { | ||
"@fluent/di": "^1.0.5" | ||
"@fluent/di": "1.0.8", | ||
"@fluent/console": "1.0.8", | ||
"@fluent/logging": "1.0.8", | ||
"@fluent/reflect": "1.0.8" | ||
}, | ||
@@ -30,0 +33,0 @@ "devDependencies": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
33210
30
774
5
+ Added@fluent/console@1.0.8(transitive)
+ Added@fluent/logging@1.0.8(transitive)
+ Addedasync@2.6.4(transitive)
+ Addedcolors@1.0.3(transitive)
+ Addedcycle@1.0.3(transitive)
+ Addedeyes@0.1.8(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedstack-trace@0.0.10(transitive)
+ Addedwinston@2.4.7(transitive)
Updatedreflect-metadata@0.1.*