Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] Adapt to Project Graph APIs #413

Merged
merged 25 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d035a5c
[INTERNAL] Enhance tree and build commands with project graph options
RandomByte Feb 14, 2021
2964124
[INTERNAL] tree: Also show project namespace
RandomByte Feb 22, 2021
92cb40b
[INTERNAL] build: Adapt to new ProjectGraph API
RandomByte Apr 23, 2022
ee8aa59
[INTERNAL] Fix build-all-dependencies CLI options
RandomByte May 3, 2022
03ef5b0
[INTERNAL] build: Remove obsolete parameter 'devExcludeProject'
RandomByte May 18, 2022
21dea1d
[INTERNAL] build: Alias old --all flag to new --include-all-dependencies
RandomByte May 20, 2022
5ca3f20
[INTERNAL] serve: Adapt to new ProjectGraph API
RandomByte May 20, 2022
abc2a91
[INTERNAL] tree: Remove legacy dependency tree implementation
RandomByte May 23, 2022
5ae2a5c
[INTERNAL] Remove buildHelper: Module moved to ui5-project
RandomByte May 24, 2022
8edd137
[INTERNAL] Remove obsolete 'translator' option
RandomByte May 24, 2022
2d1b34f
[INTERNAL] add/remove/use: Adapt to new ProjectGraph API
RandomByte May 24, 2022
b70fd3c
[INTERNAL] utils: Do not add framework deps to graph
RandomByte May 24, 2022
8fc8c52
[INTERNAL] updateYaml: Add config path override
RandomByte May 24, 2022
e8150f9
[INTERNAL] Update framework/* tests
RandomByte May 25, 2022
6cf7592
Start updating unit tests for commands/build
matz3 Jun 2, 2022
860a217
Update all commands/build tests
matz3 Jun 2, 2022
ab94966
Start updating unit tests for commands/tree
matz3 Jun 2, 2022
4c48ee5
commands/tree unit tests
matz3 Jun 7, 2022
267b36f
Finish tree tests
matz3 Jun 7, 2022
0796776
Update serve command tests
matz3 Jun 8, 2022
d4f907e
Remove unused dependency treeify
matz3 Jun 8, 2022
2c56c5b
Add missing dependency pretty-hrtime
matz3 Jun 8, 2022
9157b16
[INTERNAL] Make build command 'archive' an option 'create-build-descr…
RandomByte Jun 8, 2022
372631a
Rename build description to build manifest
RandomByte Jun 10, 2022
a9ae0db
build: pass --config arg to generateProjectGraph.usingStaticFile
matz3 Jun 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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