diff --git a/lib/cli/base.js b/lib/cli/base.js index c6c77844..fb2275b8 100644 --- a/lib/cli/base.js +++ b/lib/cli/base.js @@ -5,6 +5,7 @@ export default function(cli) { cli.usage("Usage: ui5 [options]") .demandCommand(1, "Command required! Please have a look at the help documentation above.") .option("config", { + alias: "c", describe: "Path to project configuration file in YAML format", type: "string" }) @@ -13,6 +14,16 @@ export default function(cli) { "This option will disable resolution of node package dependencies.", type: "string" }) + .option("workspace-config", { + describe: "Path to workspace configuration file in YAML format", + type: "string" + }) + .option("workspace", { + alias: "w", + describe: "Name of the workspace configuration to use", + default: "default", + type: "string" + }) .option("loglevel", { alias: "log-level", describe: "Set the logging level (silent|error|warn|info|perf|verbose|silly).", @@ -37,7 +48,7 @@ export default function(cli) { }) .coerce([ // base.js - "config", "dependency-definition", "log-level", + "config", "dependency-definition", "workspace-config", "workspace", "log-level", // tree.js, build.js & serve.js "framework-version", @@ -66,10 +77,14 @@ export default function(cli) { .strict(true) .alias("help", "h") .alias("version", "v") - .example("ui5 --translator static:/path/to/projectDependencies.yaml", - "Execute command using a \"static\" translator with translator parameters") + .example("ui5 --dependency-definition /path/to/projectDependencies.yaml", + "Execute command using a static dependency tree instead of resolving node package dependencies") .example("ui5 --config /path/to/ui5.yaml", "Execute command using a project configuration from custom path") + .example("ui5 --workspace dolphin", + "Execute command using the 'dolphin' workspace of a ui5-workspace.yaml") + .example("ui5 --log-level silly", + "Execute command with the maximum log output") .fail(function(msg, err, yargs) { if (err) { // Exception diff --git a/lib/cli/commands/build.js b/lib/cli/commands/build.js index 8fe34b15..e7982a41 100644 --- a/lib/cli/commands/build.js +++ b/lib/cli/commands/build.js @@ -134,7 +134,9 @@ async function handleBuild(argv) { } else { graph = await graphFromPackageDependencies({ rootConfigPath: argv.config, - versionOverride: argv.frameworkVersion + versionOverride: argv.frameworkVersion, + workspaceConfigPath: argv.workspaceConfig, + workspaceName: argv.workspace === false ? null : argv.workspace, }); } const buildSettings = graph.getRoot().getBuilderSettings() || {}; diff --git a/lib/cli/commands/serve.js b/lib/cli/commands/serve.js index 1b6de16e..931f81cd 100644 --- a/lib/cli/commands/serve.js +++ b/lib/cli/commands/serve.js @@ -88,7 +88,9 @@ serve.handler = async function(argv) { } else { graph = await graphFromPackageDependencies({ rootConfigPath: argv.config, - versionOverride: argv.frameworkVersion + versionOverride: argv.frameworkVersion, + workspaceConfigPath: argv.workspaceConfig, + workspaceName: argv.workspace === false ? null : argv.workspace, }); } diff --git a/lib/cli/commands/tree.js b/lib/cli/commands/tree.js index f5129a79..1079731e 100644 --- a/lib/cli/commands/tree.js +++ b/lib/cli/commands/tree.js @@ -35,7 +35,9 @@ tree.handler = async function(argv) { } else { graph = await graphFromPackageDependencies({ rootConfigPath: argv.config, - versionOverride: argv.frameworkVersion + versionOverride: argv.frameworkVersion, + workspaceConfigPath: argv.workspaceConfig, + workspaceName: argv.workspace === false ? null : argv.workspace, }); } diff --git a/test/lib/cli/commands/build.js b/test/lib/cli/commands/build.js index 41d1481a..4b672c92 100644 --- a/test/lib/cli/commands/build.js +++ b/test/lib/cli/commands/build.js @@ -1,3 +1,4 @@ +import path from "node:path"; import test from "ava"; import sinon from "sinon"; import esmock from "esmock"; @@ -123,7 +124,9 @@ test.serial("ui5 build --framework-version", async (t) => { graphFromPackageDependenciesStub.getCall(0).args[0], { rootConfigPath: undefined, - versionOverride: "1.99.0" + versionOverride: "1.99.0", + workspaceConfigPath: undefined, + workspaceName: undefined, }, "generateProjectGraph.graphFromPackageDependencies got called with expected arguments" ); }); @@ -139,7 +142,64 @@ test.serial("ui5 build --config", async (t) => { graphFromPackageDependenciesStub.getCall(0).args[0], { rootConfigPath: "ui5-test.yaml", - versionOverride: undefined + versionOverride: undefined, + workspaceConfigPath: undefined, + workspaceName: undefined, + }, "generateProjectGraph.graphFromPackageDependencies got called with expected arguments" + ); +}); + +test.serial("ui5 build --workspace", async (t) => { + const {build, argv, graphFromPackageDependenciesStub} = t.context; + + argv.workspace = "dolphin"; + + await build.handler(argv); + + t.deepEqual( + graphFromPackageDependenciesStub.getCall(0).args[0], + { + rootConfigPath: undefined, + versionOverride: undefined, + workspaceConfigPath: undefined, + workspaceName: "dolphin", + }, "generateProjectGraph.graphFromPackageDependencies got called with expected arguments" + ); +}); + +test.serial("ui5 build --no-workspace", async (t) => { + const {build, argv, graphFromPackageDependenciesStub} = t.context; + + argv.workspace = false; + + await build.handler(argv); + + t.deepEqual( + graphFromPackageDependenciesStub.getCall(0).args[0], + { + rootConfigPath: undefined, + versionOverride: undefined, + workspaceConfigPath: undefined, + workspaceName: null, + }, "generateProjectGraph.graphFromPackageDependencies got called with expected arguments" + ); +}); + +test.serial("ui5 build --workspace-config", async (t) => { + const {build, argv, graphFromPackageDependenciesStub} = t.context; + + const fakePath = path.join("/", "path", "to", "ui5-workspace.yaml"); + argv.workspaceConfig = fakePath; + + await build.handler(argv); + + t.deepEqual( + graphFromPackageDependenciesStub.getCall(0).args[0], + { + rootConfigPath: undefined, + versionOverride: undefined, + workspaceConfigPath: fakePath, + workspaceName: undefined, }, "generateProjectGraph.graphFromPackageDependencies got called with expected arguments" ); }); @@ -156,7 +216,7 @@ test.serial("ui5 build --dependency-definition", async (t) => { { filePath: "dependencies.yaml", rootConfigPath: undefined, - versionOverride: undefined + versionOverride: undefined, }, "generateProjectGraph.graphFromStaticFile got called with expected arguments" ); }); @@ -174,7 +234,7 @@ test.serial("ui5 build --dependency-definition --config", async (t) => { { filePath: "dependencies.yaml", rootConfigPath: "ui5-test.yaml", - versionOverride: undefined + versionOverride: undefined, }, "generateProjectGraph.graphFromStaticFile got called with expected arguments" ); }); @@ -193,7 +253,7 @@ test.serial("ui5 build --dependency-definition --config --framework-version", as { filePath: "dependencies.yaml", rootConfigPath: "ui5-test.yaml", - versionOverride: "1.99.0" + versionOverride: "1.99.0", }, "generateProjectGraph.graphFromStaticFile got called with expected arguments" ); }); diff --git a/test/lib/cli/commands/serve.js b/test/lib/cli/commands/serve.js index 3daaf451..2767209a 100644 --- a/test/lib/cli/commands/serve.js +++ b/test/lib/cli/commands/serve.js @@ -1,3 +1,4 @@ +import path from "node:path"; import test from "ava"; import sinon from "sinon"; import esmock from "esmock"; @@ -83,9 +84,10 @@ test.serial("ui5 serve: default", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: http://localhost:8080 @@ -112,8 +114,8 @@ test.serial("ui5 serve --h2", async (t) => { const {argv, serve, graph, server, fakeGraph, sslUtil} = t.context; sslUtil.getSslCertificate.resolves({ - key: "randombyte-likes-ponies-key", - cert: "randombyte-likes-ponies-cert" + key: "random-key", + cert: "random-cert" }); server.serve.returns({ @@ -127,9 +129,10 @@ test.serial("ui5 serve --h2", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: https://localhost:8443 @@ -142,8 +145,8 @@ URL: https://localhost:8443 acceptRemoteConnections: false, changePortIfInUse: true, h2: true, - key: "randombyte-likes-ponies-key", - cert: "randombyte-likes-ponies-cert", + key: "random-key", + cert: "random-cert", port: 8443, sendSAPTargetCSP: false, serveCSPReports: false, @@ -167,9 +170,10 @@ test.serial("ui5 serve --accept-remote-connections", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, ` ${chalk.bold("⚠️ This server is accepting connections from all hosts on your network")} @@ -209,9 +213,10 @@ test.serial("ui5 serve --open", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: http://localhost:8080 @@ -248,9 +253,10 @@ test.serial("ui5 serve --open (opens default url)", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: http://localhost:8080 @@ -281,15 +287,17 @@ URL: http://localhost:8080 test.serial("ui5 serve --config", async (t) => { const {argv, serve, graph, server, fakeGraph} = t.context; - argv.config = "/path/to/ui5.yaml"; + const fakePath = path.join("/", "path", "to", "ui5.yaml"); + argv.config = fakePath; await serve.handler(argv); t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: "/path/to/ui5.yaml", versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: fakePath, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: http://localhost:8080 @@ -315,15 +323,16 @@ URL: http://localhost:8080 test.serial("ui5 serve --dependency-definition", async (t) => { const {argv, serve, graph, server, fakeGraph} = t.context; - argv.dependencyDefinition = "/path/to/dependencies.yaml"; + const fakePath = path.join("/", "path", "to", "dependencies.yaml"); + argv.dependencyDefinition = fakePath; await serve.handler(argv); t.is(graph.graphFromPackageDependencies.callCount, 0); t.is(graph.graphFromStaticFile.callCount, 1); - t.deepEqual(graph.graphFromStaticFile.getCall(0).args, [ - {filePath: "/path/to/dependencies.yaml", versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromStaticFile.getCall(0).args, [{ + filePath: fakePath, versionOverride: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: http://localhost:8080 @@ -341,7 +350,7 @@ URL: http://localhost:8080 port: 8080, sendSAPTargetCSP: false, serveCSPReports: false, - simpleIndex: false, + simpleIndex: false } ]); }); @@ -355,9 +364,116 @@ test.serial("ui5 serve --framework-version", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: "1.234.5"} + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: "1.234.5", + workspaceConfigPath: undefined, workspaceName: undefined, + }]); + + t.is(t.context.consoleOutput, `Server started +URL: http://localhost:8080 +`); + + t.is(server.serve.callCount, 1); + t.deepEqual(server.serve.getCall(0).args, [ + fakeGraph, + { + acceptRemoteConnections: false, + cert: undefined, + changePortIfInUse: true, + h2: false, + key: undefined, + port: 8080, + sendSAPTargetCSP: false, + serveCSPReports: false, + simpleIndex: false, + } + ]); +}); + +test.serial("ui5 serve --workspace", async (t) => { + const {argv, serve, graph, server, fakeGraph} = t.context; + + argv.workspace = "dolphin"; + + await serve.handler(argv); + + t.is(graph.graphFromStaticFile.callCount, 0); + t.is(graph.graphFromPackageDependencies.callCount, 1); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: "dolphin", + }]); + + t.is(t.context.consoleOutput, `Server started +URL: http://localhost:8080 +`); + + t.is(server.serve.callCount, 1); + t.deepEqual(server.serve.getCall(0).args, [ + fakeGraph, + { + acceptRemoteConnections: false, + cert: undefined, + changePortIfInUse: true, + h2: false, + key: undefined, + port: 8080, + sendSAPTargetCSP: false, + serveCSPReports: false, + simpleIndex: false, + } + ]); +}); + +test.serial("ui5 serve --no-workspace", async (t) => { + const {argv, serve, graph, server, fakeGraph} = t.context; + + argv.workspace = false; + + await serve.handler(argv); + + t.is(graph.graphFromStaticFile.callCount, 0); + t.is(graph.graphFromPackageDependencies.callCount, 1); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: null, + }]); + + t.is(t.context.consoleOutput, `Server started +URL: http://localhost:8080 +`); + + t.is(server.serve.callCount, 1); + t.deepEqual(server.serve.getCall(0).args, [ + fakeGraph, + { + acceptRemoteConnections: false, + cert: undefined, + changePortIfInUse: true, + h2: false, + key: undefined, + port: 8080, + sendSAPTargetCSP: false, + serveCSPReports: false, + simpleIndex: false, + } ]); +}); + +test.serial("ui5 serve --workspace-config", async (t) => { + const {argv, serve, graph, server, fakeGraph} = t.context; + + const fakePath = path.join("/", "path", "to", "ui5-workspace.yaml"); + argv.workspaceConfig = fakePath; + + await serve.handler(argv); + + t.is(graph.graphFromStaticFile.callCount, 0); + t.is(graph.graphFromPackageDependencies.callCount, 1); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: fakePath, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: http://localhost:8080 @@ -389,9 +505,10 @@ test.serial("ui5 serve --sap-csp-policies", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: http://localhost:8080 @@ -423,9 +540,10 @@ test.serial("ui5 serve --serve-csp-reports", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: http://localhost:8080 @@ -457,9 +575,10 @@ test.serial("ui5 serve --simple-index", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: http://localhost:8080 @@ -498,9 +617,10 @@ test.serial("ui5 serve with ui5.yaml port setting", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: http://localhost:3333 @@ -527,8 +647,8 @@ test.serial("ui5 serve --h2 with ui5.yaml port setting", async (t) => { const {argv, serve, graph, server, fakeGraph, sslUtil, getServerSettings} = t.context; sslUtil.getSslCertificate.resolves({ - key: "randombyte-likes-ponies-key", - cert: "randombyte-likes-ponies-cert" + key: "random-key", + cert: "random-cert" }); getServerSettings.returns({ @@ -546,9 +666,10 @@ test.serial("ui5 serve --h2 with ui5.yaml port setting", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: https://localhost:4444 @@ -561,8 +682,8 @@ URL: https://localhost:4444 acceptRemoteConnections: false, changePortIfInUse: false, h2: true, - key: "randombyte-likes-ponies-key", - cert: "randombyte-likes-ponies-cert", + key: "random-key", + cert: "random-cert", port: 4444, sendSAPTargetCSP: false, serveCSPReports: false, @@ -581,8 +702,8 @@ test.serial("ui5 serve --h2 with ui5.yaml port setting and port CLI argument", a const {argv, serve, graph, server, fakeGraph, sslUtil, getServerSettings} = t.context; sslUtil.getSslCertificate.resolves({ - key: "randombyte-likes-ponies-key", - cert: "randombyte-likes-ponies-cert" + key: "random-key", + cert: "random-cert" }); getServerSettings.returns({ @@ -601,9 +722,10 @@ test.serial("ui5 serve --h2 with ui5.yaml port setting and port CLI argument", a t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `Server started URL: https://localhost:5555 @@ -616,8 +738,8 @@ URL: https://localhost:5555 acceptRemoteConnections: false, changePortIfInUse: false, h2: true, - key: "randombyte-likes-ponies-key", - cert: "randombyte-likes-ponies-cert", + key: "random-key", + cert: "random-cert", port: 5555, sendSAPTargetCSP: false, serveCSPReports: false, diff --git a/test/lib/cli/commands/tree.js b/test/lib/cli/commands/tree.js index 1b1b5d87..b5c25272 100644 --- a/test/lib/cli/commands/tree.js +++ b/test/lib/cli/commands/tree.js @@ -1,3 +1,4 @@ +import path from "node:path"; import test from "ava"; import sinon from "sinon"; import esmock from "esmock"; @@ -67,9 +68,10 @@ test.serial("ui5 tree (Without dependencies)", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `${chalk.bold.underline("Dependencies (1):")} @@ -131,9 +133,10 @@ test.serial("ui5 tree", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `${chalk.bold.underline("Dependencies (4):")} @@ -194,9 +197,10 @@ test.serial("ui5 tree (With extensions)", async (t) => { "getExtension called with expected extension name"); t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `${chalk.bold.underline("Dependencies (1):")} @@ -211,7 +215,7 @@ ${chalk.dim.italic("/home/extension2")} `); }); -test.serial("ui5 tree --x-perf", async (t) => { +test.serial("ui5 tree --perf", async (t) => { const {argv, tree, traverseBreadthFirst, graph} = t.context; traverseBreadthFirst.callsFake(async (fn) => { @@ -237,9 +241,10 @@ test.serial("ui5 tree --x-perf", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `${chalk.bold.underline("Dependencies (1):")} @@ -275,9 +280,10 @@ test.serial("ui5 tree --framework-version", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: undefined, versionOverride: "1.234.5"} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: "1.234.5", + workspaceConfigPath: undefined, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `${chalk.bold.underline("Dependencies (1):")} @@ -292,7 +298,8 @@ ${chalk.italic("None")} test.serial("ui5 tree --config", async (t) => { const {argv, tree, traverseBreadthFirst, graph} = t.context; - argv.config = "/home/project1/config.yaml"; + const fakePath = path.join("/", "path", "to", "ui5.yaml"); + argv.config = fakePath; traverseBreadthFirst.callsFake(async (fn) => { await fn({ @@ -311,9 +318,122 @@ test.serial("ui5 tree --config", async (t) => { t.is(graph.graphFromStaticFile.callCount, 0); t.is(graph.graphFromPackageDependencies.callCount, 1); - t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [ - {rootConfigPath: "/home/project1/config.yaml", versionOverride: undefined} - ]); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: fakePath, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: undefined, + }]); + + t.is(t.context.consoleOutput, + `${chalk.bold.underline("Dependencies (1):")} +╰─ ${chalk.bold("project1")} ${chalk.inverse("test/project1")} ${chalk.dim("(1.0.0, application) ")}\ +${chalk.dim.italic("/home/project1")} + +${chalk.bold.underline("Extensions (0):")} +${chalk.italic("None")} +`); +}); + +test.serial("ui5 tree --workspace", async (t) => { + const {argv, tree, traverseBreadthFirst, graph} = t.context; + + argv.workspace = "dolphin"; + + traverseBreadthFirst.callsFake(async (fn) => { + await fn({ + project: { + getName: sinon.stub().returns("project1"), + getNamespace: sinon.stub().returns("test/project1"), + getVersion: sinon.stub().returns("1.0.0"), + getType: sinon.stub().returns("application"), + getRootPath: sinon.stub().returns("/home/project1") + }, + dependencies: [] + }); + }); + + await tree.handler(argv); + + t.is(graph.graphFromStaticFile.callCount, 0); + t.is(graph.graphFromPackageDependencies.callCount, 1); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: "dolphin", + }]); + + t.is(t.context.consoleOutput, + `${chalk.bold.underline("Dependencies (1):")} +╰─ ${chalk.bold("project1")} ${chalk.inverse("test/project1")} ${chalk.dim("(1.0.0, application) ")}\ +${chalk.dim.italic("/home/project1")} + +${chalk.bold.underline("Extensions (0):")} +${chalk.italic("None")} +`); +}); + +test.serial("ui5 tree --no-workspace", async (t) => { + const {argv, tree, traverseBreadthFirst, graph} = t.context; + + argv.workspace = false; + + traverseBreadthFirst.callsFake(async (fn) => { + await fn({ + project: { + getName: sinon.stub().returns("project1"), + getNamespace: sinon.stub().returns("test/project1"), + getVersion: sinon.stub().returns("1.0.0"), + getType: sinon.stub().returns("application"), + getRootPath: sinon.stub().returns("/home/project1") + }, + dependencies: [] + }); + }); + + await tree.handler(argv); + + t.is(graph.graphFromStaticFile.callCount, 0); + t.is(graph.graphFromPackageDependencies.callCount, 1); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: undefined, workspaceName: null, + }]); + + t.is(t.context.consoleOutput, + `${chalk.bold.underline("Dependencies (1):")} +╰─ ${chalk.bold("project1")} ${chalk.inverse("test/project1")} ${chalk.dim("(1.0.0, application) ")}\ +${chalk.dim.italic("/home/project1")} + +${chalk.bold.underline("Extensions (0):")} +${chalk.italic("None")} +`); +}); + +test.serial("ui5 tree --workspace-config", async (t) => { + const {argv, tree, traverseBreadthFirst, graph} = t.context; + + const fakePath = path.join("/", "path", "to", "ui5-workspace.yaml"); + argv.workspaceConfig = fakePath; + + traverseBreadthFirst.callsFake(async (fn) => { + await fn({ + project: { + getName: sinon.stub().returns("project1"), + getNamespace: sinon.stub().returns("test/project1"), + getVersion: sinon.stub().returns("1.0.0"), + getType: sinon.stub().returns("application"), + getRootPath: sinon.stub().returns("/home/project1") + }, + dependencies: [] + }); + }); + + await tree.handler(argv); + + t.is(graph.graphFromStaticFile.callCount, 0); + t.is(graph.graphFromPackageDependencies.callCount, 1); + t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{ + rootConfigPath: undefined, versionOverride: undefined, + workspaceConfigPath: fakePath, workspaceName: undefined, + }]); t.is(t.context.consoleOutput, `${chalk.bold.underline("Dependencies (1):")} @@ -328,7 +448,8 @@ ${chalk.italic("None")} test.serial("ui5 tree --dependency-definition", async (t) => { const {argv, tree, traverseBreadthFirst, graph} = t.context; - argv.dependencyDefinition = "/home/project1/dependencies.yaml"; + const fakePath = path.join("/", "path", "to", "dependencies.yaml"); + argv.dependencyDefinition = fakePath; traverseBreadthFirst.callsFake(async (fn) => { await fn({ @@ -348,7 +469,7 @@ test.serial("ui5 tree --dependency-definition", async (t) => { t.is(graph.graphFromPackageDependencies.callCount, 0); t.is(graph.graphFromStaticFile.callCount, 1); t.deepEqual(graph.graphFromStaticFile.getCall(0).args, [ - {filePath: "/home/project1/dependencies.yaml", versionOverride: undefined} + {filePath: fakePath, versionOverride: undefined} ]); t.is(t.context.consoleOutput,