@omnia/tooling-composers
Version:
Provide tooling to work with manifest things.
87 lines (86 loc) • 3.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DevelopmentHostingEnvironment = exports.getHosting = void 0;
const ManifestRegistry_1 = require("./ManifestRegistry");
var devHosting = null;
//export class DevelopmentHosting {
// portNumber: number;
// hotModuleReplacement: boolean;
// protocol: string;
// domain: string;
// pfxPath: string;
// pfxPassphrase: string;
// hostingAddress: string;
//}
function getHosting() {
if (devHosting === null) {
devHosting = new LocalOverrideable({
disableAutoReload: false,
hmr: true,
port: 44330,
userConfig: null
}, false, "Default Hosting");
}
if (process.argv.length > 0 && process.argv.find(argv => argv === "--bundle") !== undefined) {
devHosting.data.hmr = false;
}
return Object.assign({}, {
disableAutoReload: false,
hmr: true,
port: 44330
}, devHosting.data);
}
exports.getHosting = getHosting;
class LocalOverrideable {
constructor(data, isOverridden, writtenByManifest) {
this.data = data;
this.isOverridden = isOverridden;
this.writtenByManifest = writtenByManifest;
}
}
class DevelopmentHostingEnvironment {
constructor(localOverride) {
this.localOverride = localOverride;
this.use = (hostingInfo) => {
let setValue = true;
if (devHosting != null) {
if (devHosting.isOverridden) {
if (this.localOverride) {
throw Error("Hosting information has already been overridden by manifest: " + devHosting.writtenByManifest);
}
else {
//We have overridden the setting, keep override, do not replace with none override
//console.log("Hosting information set by manifest: " + ManifestRegistry.getCurrentManifestPath() + " overridden by manifest: " + devHosting.writtenByManifest );
setValue = false;
}
}
else if (!this.localOverride) {
throw Error("Hosting information has already been set by manifest: " + devHosting.writtenByManifest + " must override.");
}
else {
// console.log("Hosting information set by manifest: " + devHosting.writtenByManifest + " now overridden by manifest: " + ManifestRegistry.getCurrentManifestPath());
}
}
if (setValue) {
//let hosting = new DevelopmentHostingInfo();
//hosting.portNumber = hostingInfo.port;
//hosting.hotModuleReplacement = hostingInfo.disableHmr !== false ? true : false;
//hosting.domain = "localhost";
//hosting.protocol = hostingInfo.https === true ? "https" : "http";
//hosting.pfxPath = hostingInfo.pfxPath || "";
//hosting.pfxPassphrase = hostingInfo.pfxPassphrase || "";
//hosting.hostingAddress = `${hosting.protocol}://${hosting.domain}:${hosting.portNumber}`;
devHosting = new LocalOverrideable(hostingInfo, this.localOverride, ManifestRegistry_1.ManifestRegistry.getCurrentManifestPath());
}
};
}
}
exports.DevelopmentHostingEnvironment = DevelopmentHostingEnvironment;
DevelopmentHostingEnvironment.getServerManifests = (currentServiceId) => {
let serverManifests = new Array();
return serverManifests;
};
DevelopmentHostingEnvironment.clearState = () => {
devHosting = null;
};
DevelopmentHostingEnvironment.ServerSubscription = ManifestRegistry_1.ManifestRegistry.registerServerManifestProvider(new ManifestRegistry_1.StaticServerManifestProviderProxy(DevelopmentHostingEnvironment.getServerManifests, DevelopmentHostingEnvironment.clearState));