Skip to content

Commit

Permalink
[INTERNAL] serve: Adapt to new ProjectGraph API
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed May 20, 2022
1 parent 21dea1d commit 5ca3f20
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/cli/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,32 @@ serve.builder = function(cli) {
};

serve.handler = async function(argv) {
const normalizer = require("@ui5/project").normalizer;
const generateProjectGraph = require("@ui5/project").generateProjectGraph;
const ui5Server = require("@ui5/server");
const server = ui5Server.server;

const normalizerOptions = {
translatorName: argv.translator,
configPath: argv.config
};

if (argv.frameworkVersion) {
normalizerOptions.frameworkOptions = {
let graph;
if (argv.dependencyDefinition) {
graph = await generateProjectGraph.usingStaticFile({
filePath: argv.dependencyDefinition,
versionOverride: argv.frameworkVersion
});
} else {
graph = await generateProjectGraph.usingNodePackageDependencies({
rootConfigPath: argv.config,
versionOverride: argv.frameworkVersion
};
});
}

const tree = await normalizer.generateProjectTree(normalizerOptions);
let port = argv.port;
let changePortIfInUse = false;

if (!port && tree.server && tree.server.settings) {
if (!port && graph.getRoot().getServerSettings()) {
const serverSettings = graph.getRoot().getServerSettings();
if (argv.h2) {
port = tree.server.settings.httpsPort;
port = serverSettings.httpsPort;
} else {
port = tree.server.settings.httpPort;
port = serverSettings.httpPort;
}
}

Expand Down Expand Up @@ -127,7 +129,7 @@ serve.handler = async function(argv) {
serverConfig.cert = cert;
}

const {h2, port: actualPort} = await server.serve(tree, serverConfig);
const {h2, port: actualPort} = await server.serve(graph, serverConfig);

const protocol = h2 ? "https" : "http";
let browserUrl = protocol + "://localhost:" + actualPort;
Expand Down

0 comments on commit 5ca3f20

Please sign in to comment.