node-web-mvc
Version:
node spring mvc
79 lines (78 loc) • 3.02 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const RuntimeAnnotation_1 = __importDefault(require("./annotations/annotation/RuntimeAnnotation"));
const SpringBootApplication_1 = __importDefault(require("./SpringBootApplication"));
const path_1 = __importDefault(require("path"));
const isProduction = process.env.NODE_ENV === 'production';
class BootConfiguration {
constructor(primarySources) {
this.annoConfigs = [];
if (!primarySources)
return;
for (const primarySource of primarySources) {
const configAnno = RuntimeAnnotation_1.default.getClassAnnotation(primarySource, SpringBootApplication_1.default);
this.annoConfigs.push(configAnno.nativeAnnotation);
}
this.annoConfigs;
}
resolvePaths(dirs) {
const paths = dirs instanceof Array ? dirs : [dirs].filter(Boolean);
return paths.map((m) => {
return path_1.default.isAbsolute(m) ? m : path_1.default.resolve(m);
});
}
getScanBasePackages() {
const scanBasePackages = this.annoConfigs.reduce((v, item) => v.concat(item.scanBasePackages), []).filter(Boolean);
if (scanBasePackages.length < 1) {
return [process.cwd()];
}
else {
return this.resolvePaths(scanBasePackages);
}
}
getHotOptions() {
if (isProduction) {
// 生产模式无论如何禁止热更新
return null;
}
const config = this.annoConfigs.find((m) => !!m.hot);
if (!(config === null || config === void 0 ? void 0 : config.hot)) {
return null;
}
let hot = config.hot;
if (typeof config.hot == 'string' || config.hot instanceof Array) {
hot = { cwd: config.hot };
}
return Object.assign(Object.assign({}, hot), { cwd: this.resolvePaths(hot.cwd) });
}
getServerOptions() {
if (!this.serverOptions) {
let config = {};
this.annoConfigs.forEach((m) => {
config = Object.assign(Object.assign({}, config), m.server);
});
this.serverOptions = config;
}
this.serverOptions.port = this.serverOptions.port || 8080;
return this.serverOptions;
}
getExcludeScan() {
const fileOrDirs = this.annoConfigs.reduce((v, item) => v.concat(item.excludeScan), []).filter(Boolean);
return (fileOrDirs);
}
getLaunchLogOff() {
var _a;
return (_a = this.annoConfigs[0]) === null || _a === void 0 ? void 0 : _a.launchLogOff;
}
getPort() {
return this.getServerOptions().port;
}
getEanbleSwagger() {
var _a;
return ((_a = this.annoConfigs[0]) === null || _a === void 0 ? void 0 : _a.swagger) === true;
}
}
exports.default = BootConfiguration;