Skip to content

Commit

Permalink
[BREAKING] Adapt to Project Graph APIs (#413)
Browse files Browse the repository at this point in the history
Adapt to new ui5-project Project Graph and builder APIs: SAP/ui5-project#457

BREAKING CHANGES:
* Removed CLI option `--translator`. Use new option `--dependency-definition` to provide a file with
  static dependency information
* Removed `ui5 build dev` command
* Refactored `ui5 tree`: Removed `--full`, `--json` and `--dedupe` options

Co-authored-by: Matthias Osswald <mat.osswald@sap.com>
  • Loading branch information
RandomByte and matz3 authored Jun 13, 2022
1 parent 697e9e5 commit 945b82b
Show file tree
Hide file tree
Showing 26 changed files with 2,196 additions and 2,587 deletions.
8 changes: 4 additions & 4 deletions lib/cli/commands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ addCommand.handler = async function(argv) {
throw new Error("Options 'development' and 'optional' cannot be combined");
}

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

const libraries = libraryNames.map((name) => {
Expand All @@ -57,7 +57,7 @@ addCommand.handler = async function(argv) {
});

const {yamlUpdated} = await require("../../framework/add")({
normalizerOptions,
projectGraphOptions,
libraries
});

Expand Down
14 changes: 9 additions & 5 deletions lib/cli/commands/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ const cli = require("yargs");
cli.usage("Usage: ui5 <command> [options]")
.demandCommand(1, "Command required! Please have a look at the help documentation above.")
.option("config", {
describe: "Path to configuration file",
describe: "Path to project configuration file in YAML format",
type: "string"
})
.option("translator", {
describe: "Translator to use. Including optional colon separated translator parameters.",
alias: "t8r",
default: "npm",
.option("dependency-definition", {
describe: "Path to a YAML file containing the project's dependency tree. " +
"This option will disable resolution of node package dependencies.",
type: "string"
})
.option("verbose", {
Expand All @@ -22,6 +21,11 @@ cli.usage("Usage: ui5 <command> [options]")
default: "info",
type: "string"
})
.option("x-perf", {
describe: "Outputs performance measurements",
default: false,
type: "boolean"
})
.showHelpOnFail(true)
.strict(true)
.alias("help", "h")
Expand Down
110 changes: 50 additions & 60 deletions lib/cli/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Build

const baseMiddleware = require("../middlewares/base.js");
const buildHelper = require("../../utils/buildHelper");

const build = {
command: "build",
Expand All @@ -12,11 +11,6 @@ const build = {

build.builder = function(cli) {
return cli
.command("dev", "Dev build: Skips non-essential and time-intensive tasks during build", {
handler: handleBuild,
builder: noop,
middlewares: [baseMiddleware]
})
.command("jsdoc", "Build JSDoc resources", {
handler: handleBuild,
builder: noop,
Expand All @@ -29,46 +23,46 @@ build.builder = function(cli) {
})
.command("self-contained",
"Build project and create self-contained bundle. " +
"Recommended to be used in conjunction with --all", {
"Recommended to be used in conjunction with --include-dependencies", {
handler: handleBuild,
builder: noop,
middlewares: [baseMiddleware]
})
.option("all", {
describe: "Include all project dependencies into build process",
alias: "a",
.option("include-all-dependencies", {
describe: "Include all dependencies in the build result",
alias: ["all", "a"],
default: false,
type: "boolean"
})
.option("include-dependency", {
describe: "A list of dependencies to be included into the build process. You can use the asterisk '*' as" +
" an alias for including all dependencies into the build process. The listed dependencies cannot be" +
describe: "A list of dependencies to be included in the build result. You can use the asterisk '*' as" +
" an alias for including all dependencies in the build result. The listed dependencies cannot be" +
" overruled by dependencies defined in 'exclude-dependency'.",
type: "array"
})
.option("include-dependency-regexp", {
describe: "A list of regular expressions defining dependencies to be included into the build process." +
describe: "A list of regular expressions defining dependencies to be included in the build result." +
" This list is prioritized like 'include-dependency'.",
type: "array"
})
.option("include-dependency-tree", {
describe: "A list of dependencies to be included into the build process. Transitive dependencies are" +
describe: "A list of dependencies to be included in the build result. Transitive dependencies are" +
" implicitly included and do not need to be part of this list. These dependencies overrule" +
" the selection of 'exclude-dependency-tree' but can be overruled by 'exclude-dependency'.",
type: "array"
})
.option("exclude-dependency", {
describe: "A list of dependencies to be excluded from the build process. The listed dependencies can" +
describe: "A list of dependencies to be excluded from the build result. The listed dependencies can" +
" be overruled by dependencies defined in 'include-dependency'.",
type: "array"
})
.option("exclude-dependency-regexp", {
describe: "A list of regular expressions defining dependencies to be excluded from the build process." +
describe: "A list of regular expressions defining dependencies to be excluded from the build result." +
" This list is prioritized like 'exclude-dependency'.",
type: "array"
})
.option("exclude-dependency-tree", {
describe: "A list of dependencies to be excluded from the build process. Transitive dependencies are" +
describe: "A list of dependencies to be excluded from the build result. Transitive dependencies are" +
" implicitly included and do not need to be part of this list.",
type: "array"
})
Expand All @@ -82,18 +76,19 @@ build.builder = function(cli) {
default: false,
type: "boolean"
})
.option("dev-exclude-project", {
describe:
"A list of specific projects to be excluded from dev mode " +
"(dev mode must be active for this to be effective)",
type: "array"
.option("create-build-manifest", {
describe: "Store build metadata in a '.ui5' directory in the build destination, " +
"allowing reuse of the build result in other builds",
default: false,
type: "boolean"
})
.option("include-task", {
describe: "A list of specific tasks to be included to the default/dev set",
describe: "A list of tasks to be added to the default execution set. " +
"This option takes precedence over any excludes.",
type: "array"
})
.option("exclude-task", {
describe: "A list of specific tasks to be excluded from default/dev set",
describe: "A list of tasks to be excluded from the default task execution set",
type: "array"
})
.option("framework-version", {
Expand All @@ -108,6 +103,8 @@ build.builder = function(cli) {
type: "boolean"
})
.example("ui5 build", "Preload build for project without dependencies")

// TODO 3.0: Update examples
.example("ui5 build self-contained --all", "Self-contained build for project including dependencies")
.example("ui5 build --all --exclude-task=* --include-task=createDebugFiles generateAppPreload",
"Build project and dependencies but only apply the createDebugFiles- and generateAppPreload tasks")
Expand All @@ -120,56 +117,49 @@ build.builder = function(cli) {
.example("ui5 build dev",
"Build project and dependencies in dev mode. Only a set of essential tasks is executed.")
.example("ui5 build --experimental-css-variables",
"Preload build for project without dependencies but with CSS variable artefacts");
"Preload build for project without dependencies but with CSS variable artifacts");
};

async function handleBuild(argv) {
const normalizer = require("@ui5/project").normalizer;
const builder = require("@ui5/builder").builder;
const logger = require("@ui5/logger");
const {generateProjectGraph, builder} = require("@ui5/project");

const command = argv._[argv._.length - 1];
logger.setShowProgress(true);

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,
rootConfigPath: argv.config,
versionOverride: argv.frameworkVersion
};
});
} else {
graph = await generateProjectGraph.usingNodePackageDependencies({
rootConfigPath: argv.config,
versionOverride: argv.frameworkVersion
});
}

const tree = await normalizer.generateProjectTree(normalizerOptions);
const buildSettings = (tree.builder && tree.builder.settings) || {};

const {includedDependencies, excludedDependencies} = buildHelper.createDependencyLists({
tree: tree,
includeDependency: argv["include-dependency"],
includeDependencyRegExp: argv["include-dependency-regexp"],
includeDependencyTree: argv["include-dependency-tree"],
excludeDependency: argv["exclude-dependency"],
excludeDependencyRegExp: argv["exclude-dependency-regexp"],
excludeDependencyTree: argv["exclude-dependency-tree"],
defaultIncludeDependency: buildSettings.includeDependency,
defaultIncludeDependencyRegExp: buildSettings.includeDependencyRegExp,
defaultIncludeDependencyTree: buildSettings.includeDependencyTree
});
const buildAll = buildHelper.alignWithBuilderApi(argv.all, includedDependencies, excludedDependencies);

await builder.build({
tree: tree,
const buildSettings = graph.getRoot().getBuilderSettings() || {};
await builder({
graph,
destPath: argv.dest,
cleanDest: argv["clean-dest"],
buildDependencies: buildAll,
includedDependencies: includedDependencies,
excludedDependencies: excludedDependencies,
dev: command === "dev",
createBuildManifest: argv["create-build-manifest"],
complexDependencyIncludes: {
includeAllDependencies: argv["include-all-dependencies"],
includeDependency: argv["include-dependency"],
includeDependencyRegExp: argv["include-dependency-regexp"],
includeDependencyTree: argv["include-dependency-tree"],
excludeDependency: argv["exclude-dependency"],
excludeDependencyRegExp: argv["exclude-dependency-regexp"],
excludeDependencyTree: argv["exclude-dependency-tree"],
defaultIncludeDependency: buildSettings.includeDependency,
defaultIncludeDependencyRegExp: buildSettings.includeDependencyRegExp,
defaultIncludeDependencyTree: buildSettings.includeDependencyTree
},
selfContained: command === "self-contained",
jsdoc: command === "jsdoc",
devExcludeProject: argv["dev-exclude-project"],
includedTasks: argv["include-task"],
excludedTasks: argv["exclude-task"],
cssVariables: argv["experimental-css-variables"]
Expand Down
8 changes: 4 additions & 4 deletions lib/cli/commands/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ removeCommand.handler = async function(argv) {
return libraryNames.indexOf(libraryName) === index;
});

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

const libraries = libraryNames.map((name) => {
Expand All @@ -38,7 +38,7 @@ removeCommand.handler = async function(argv) {
});

const {yamlUpdated} = await require("../../framework/remove")({
normalizerOptions,
projectGraphOptions,
libraries
});

Expand Down
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");
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
Loading

0 comments on commit 945b82b

Please sign in to comment.