Changeset View
Changeset View
Standalone View
Standalone View
lib/app/app.js
const locreq = require("locreq")(__dirname); | const locreq = require("locreq")(__dirname); | ||||
const assert = require("assert"); | const assert = require("assert"); | ||||
const path = require("path"); | |||||
const Sealious = locreq("lib/main.js"); | const Sealious = locreq("lib/main.js"); | ||||
const ConfigManager = locreq("lib/app/config-manager.js"); | const ConfigManager = locreq("lib/app/config-manager.js"); | ||||
const ChipManager = locreq("lib/app/chip-manager.js"); | const ChipManager = locreq("lib/app/chip-manager.js"); | ||||
const { Hookable } = locreq("lib/app/hookable.js"); | const { Hookable } = locreq("lib/app/hookable.js"); | ||||
const Logger = locreq("lib/app/logger.js"); | const Logger = locreq("lib/app/logger.js"); | ||||
const RootSubject = locreq("lib/subject/predefined-subjects/root-subject.js"); | const RootSubject = locreq("lib/subject/predefined-subjects/root-subject.js"); | ||||
Show All 22 Lines | constructor(custom_config, manifest) { | ||||
this.launch_time = Date.now(); | this.launch_time = Date.now(); | ||||
this.status = "stopped"; | this.status = "stopped"; | ||||
this.Sealious = Sealious; | this.Sealious = Sealious; | ||||
this.Query = Query; | this.Query = Query; | ||||
this.manifest = manifest; | this.manifest = manifest; | ||||
this.checkManifest(manifest); | this.checkManifest(); | ||||
this.i18n = i18nFactory(manifest.default_language); | this.i18n = i18nFactory(manifest.default_language); | ||||
this.ConfigManager = new ConfigManager(); | this.ConfigManager = new ConfigManager(); | ||||
for (let key in default_config) { | for (let key in default_config) { | ||||
this.ConfigManager.setDefault(key, default_config[key]); | this.ConfigManager.setDefault(key, default_config[key]); | ||||
} | } | ||||
Show All 32 Lines | constructor(custom_config, manifest) { | ||||
this.FileManager = new FileManager( | this.FileManager = new FileManager( | ||||
this.Datastore, | this.Datastore, | ||||
this.Logger, | this.Logger, | ||||
this.ConfigManager.get("upload_path") | this.ConfigManager.get("upload_path") | ||||
); | ); | ||||
} | } | ||||
checkManifest(manifest) { | checkManifest() { | ||||
assert(manifest, "Please provide the app manifest"); | assert(this.manifest, "Please provide the app manifest"); | ||||
[ | [ | ||||
"name", | "name", | ||||
"logo", | "logo", | ||||
"version", | "version", | ||||
"default_language", | "default_language", | ||||
"base_url", | "base_url", | ||||
"admin_email", | "admin_email", | ||||
].forEach(key => { | ].forEach(key => { | ||||
assert( | assert( | ||||
manifest[key], | this.manifest[key], | ||||
`Please specify '${key}' field in the app manifest` | `Please specify '${key}' field in the app manifest` | ||||
); | ); | ||||
}); | }); | ||||
} | } | ||||
createChip(constructor, declaration) { | createChip(constructor, declaration) { | ||||
const chip = new constructor( | const chip = new constructor(this, declaration); | ||||
this, | |||||
declaration | |||||
); | |||||
this.ChipManager.add_chip( | this.ChipManager.add_chip( | ||||
constructor.type_name, | constructor.type_name, | ||||
declaration.name, | declaration.name, | ||||
chip | chip | ||||
); | ); | ||||
return chip; | return chip; | ||||
} | } | ||||
async start() { | async start() { | ||||
this.status = "starting"; | this.status = "starting"; | ||||
assert( | assert( | ||||
["dev", "production"].includes( | ["dev", "production"].includes( | ||||
this.ConfigManager.get("core.environment") | this.ConfigManager.get("core.environment") | ||||
), | ), | ||||
`"core.environment" config should be either "dev" or "production"` | `"core.environment" config should be either "dev" or "production"` | ||||
); | ); | ||||
await this.emit({ when: "before", action: "start" }); | await this.emit({ when: "before", action: "start" }); | ||||
await this.FileManager.init(); | |||||
await this.Datastore.start(); | await this.Datastore.start(); | ||||
await this.Mail.init(); | await this.Mail.init(); | ||||
await this.ChipManager.start_chips(); | await this.ChipManager.start_chips(); | ||||
await this.emit({ when: "after", action: "start" }); | await this.emit({ when: "after", action: "start" }); | ||||
this.status = "running"; | this.status = "running"; | ||||
return this; | return this; | ||||
} | } | ||||
Show All 11 Lines |