Skip to content

Commit

Permalink
[FEATURE] Add --framework-version option (#306)
Browse files Browse the repository at this point in the history
Co-authored-by: Merlin Beutlberger <m.beutlberger@sap.com>
  • Loading branch information
matz3 and RandomByte authored Mar 10, 2020
1 parent e4d93db commit ae7932b
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 4 deletions.
16 changes: 14 additions & 2 deletions lib/cli/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ build.builder = function(cli) {
describe: "A list of specific tasks to be excluded from default/dev set",
type: "array"
})
.option("framework-version", {
describe: "Overrides the framework version defined by the project",
type: "string"
})
.example("ui5 build --all", "Preload build for project and dependencies to \"./dist\"")
.example("ui5 build --all --exclude-task=* --include-task=createDebugFiles generateAppPreload",
"Build project and dependencies but only apply the createDebugFiles- and generateAppPreload tasks")
Expand All @@ -78,10 +82,18 @@ async function handleBuild(argv) {
const command = argv._[argv._.length - 1];
logger.setShowProgress(true);

const tree = await normalizer.generateProjectTree({
const normalizerOptions = {
translatorName: argv.translator,
configPath: argv.config
});
};

if (argv.frameworkVersion) {
normalizerOptions.frameworkOptions = {
versionOverride: argv.frameworkVersion
};
}

const tree = await normalizer.generateProjectTree(normalizerOptions);
await builder.build({
tree: tree,
destPath: argv.dest,
Expand Down
16 changes: 14 additions & 2 deletions lib/cli/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ serve.builder = function(cli) {
default: false,
type: "boolean"
})
.option("framework-version", {
describe: "Overrides the framework version defined by the project",
type: "string"
})
.example("ui5 serve", "Start a web server for the current project")
.example("ui5 serve --h2", "Enable the HTTP/2 protocol for the web server (requires SSL certificate)")
.example("ui5 serve --config /path/to/ui5.yaml", "Use the project configuration from a custom path")
Expand All @@ -64,10 +68,18 @@ serve.handler = async function(argv) {
const ui5Server = require("@ui5/server");
const server = ui5Server.server;

const tree = await normalizer.generateProjectTree({
const normalizerOptions = {
translatorName: argv.translator,
configPath: argv.config
});
};

if (argv.frameworkVersion) {
normalizerOptions.frameworkOptions = {
versionOverride: argv.frameworkVersion
};
}

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

Expand Down
17 changes: 17 additions & 0 deletions lib/cli/commands/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ tree.builder = function(cli) {
default: false,
type: "boolean"
})
.option("framework-version", {
describe: "Overrides the framework version defined by the project. Only supported in combination with --full",
type: "string"
}).check((argv) => {
if (argv.frameworkVersion && !argv.full) {
throw new Error(`"framework-version" can only be used in combination with option "--full"`);
} else {
return true;
}
})
.example("ui5 tree > tree.txt", "Pipes the dependency tree into a new file \"tree.txt\"")
.example("ui5 tree --json > tree.json", "Pipes the dependency tree into a new file \"tree.json\"");
};
Expand All @@ -37,6 +47,13 @@ tree.handler = async function(argv) {
},
configPath: argv.config
};

if (argv.frameworkVersion ) {
options.frameworkOptions = {
versionOverride: argv.frameworkVersion
};
}

let projectTree;
if (argv.full) {
projectTree = await normalizer.generateProjectTree(options);
Expand Down
23 changes: 23 additions & 0 deletions test/lib/cli/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,26 @@ test.serial("ui5 build jsdoc", async (t) => {
"JSDoc build called with expected arguments"
);
});

test.serial("ui5 build --framework-version 1.99", async (t) => {
normalizerStub.resolves({
metadata:
{
name: "Sample"
}
});

args._ = ["build"];
args.frameworkVersion = "1.99.0";
await build.handler(args);
t.deepEqual(
normalizerStub.getCall(0).args[0],
{
configPath: undefined,
translatorName: "npm",
frameworkOptions: {
versionOverride: "1.99.0"
}
}, "generateProjectTree got called with expected arguments"
);
});
23 changes: 23 additions & 0 deletions test/lib/cli/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,26 @@ test.serial("ui5 serve --h2 with ui5.yaml port setting and port CLI argument", a
t.deepEqual(injectedServerConfig.port, 5555, "https port setting from CLI argument was used");
t.deepEqual(injectedServerConfig.changePortIfInUse, false, "changePortIfInUse is set to false");
});

test.serial("ui5 serve: --framework-version", async (t) => {
normalizerStub.resolves(projectTree);
serverStub.resolves({h2: false, port: 8080});

// loads project tree
const pPrepareServerConfig = await serve.handler(
Object.assign({}, defaultInitialHandlerArgs, {frameworkVersion: "1.2.3"})
);
// preprocess project config, skipping cert load
const pServeServer = await pPrepareServerConfig;
// serve server using config
await pServeServer;

t.is(normalizerStub.called, true);
t.deepEqual(normalizerStub.getCall(0).args, [{
configPath: undefined,
translatorName: "npm",
frameworkOptions: {
versionOverride: "1.2.3"
}
}]);
});
16 changes: 16 additions & 0 deletions test/lib/cli/commands/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ test.serial("ui5 tree --dedupe=true", async (t) => {
}), true, "includeDeduped passed as expected");
});

test.serial("ui5 tree --full --framework-version", async (t) => {
normalizer.generateProjectTree.resolves({});
await tree.handler({full: true, frameworkVersion: "1.2.3"});
t.is(normalizer.generateProjectTree.called, true, "project tree output");
t.deepEqual(normalizer.generateProjectTree.getCall(0).args, [{
configPath: undefined,
translatorName: undefined,
translatorOptions: {
includeDeduped: true
},
frameworkOptions: {
versionOverride: "1.2.3"
}
}]);
});

// test.serial("Error: throws on error during processing", async (t) => {
// normalizer.generateDependencyTree.rejects(new Error("Some error happened ..."));
// const processExitStub = sinon.stub(process, "exit");
Expand Down

0 comments on commit ae7932b

Please sign in to comment.