Skip to content

Commit 6c75777

Browse files
zhaoshengjunRandomByte
authored andcommitted
[FEATURE] Versions Command
Show versions of all UI5 Tooling packages. Fixes: #64
1 parent 253d8c0 commit 6c75777

File tree

3 files changed

+116
-60
lines changed

3 files changed

+116
-60
lines changed

README.md

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-tooling/master/docs/images/UI5_logo_wide.png)
22

33
# ui5-cli
4+
45
> UI5 Command Line Interface
56
> Part of the [UI5 Build and Development Tooling](https://github.com/SAP/ui5-tooling)
67
@@ -14,14 +15,18 @@
1415
**The UI5 Build and Development Tooling described here is not intended for productive use yet. Breaking changes are to be expected.**
1516

1617
## General Information
17-
- General information regarding the **UI5 Build and Development Tooling** project can be found **[here](https://github.com/SAP/ui5-tooling)**
18-
- Details regarding **project configuration** can be found **[here](https://github.com/SAP/ui5-project#configuration)**
18+
19+
- General information regarding the **UI5 Build and Development Tooling** project can be found **[here](https://github.com/SAP/ui5-tooling)**
20+
- Details regarding **project configuration** can be found **[here](https://github.com/SAP/ui5-project#configuration)**
1921

2022
## Installing the UI5 CLI
23+
2124
### Requirements
22-
- [Node.js](https://nodejs.org/) (**version 8.5 or higher** ⚠️)
25+
26+
- [Node.js](https://nodejs.org/) (**version 8.5 or higher** ⚠️)
2327

2428
### Installation
29+
2530
```sh
2631
npm install --global @ui5/cli
2732

@@ -30,7 +35,9 @@ ui5 --help
3035
```
3136

3237
## CLI Usage
38+
3339
### Overview
40+
3441
```
3542
Usage: ui5 <command> [options]
3643
@@ -56,8 +63,11 @@ Examples:
5663
The CLI automatically checks for updates using [update-notifier](https://github.com/yeoman/update-notifier). While this is skipped in CI environments, you might also opt-out manually by following the steps described [here](https://github.com/yeoman/update-notifier/blob/master/readme.md#user-settings).
5764

5865
### Commands
66+
5967
#### build
68+
6069
`ui5 build [options]` builds the project in the current directory.
70+
6171
```
6272
Commands:
6373
dev Dev build: Skips non-essential and time-intensive tasks during build
@@ -85,8 +95,11 @@ Examples:
8595
ui5 build dev --all --dev-exclude-project=sap.ui.core sap.m Build project and dependencies in dev mode, except "sap.ui.core" and "sap.m" (useful in combination with --include-task)
8696
ui5 build dev Build project and dependencies in dev mode. Only a set of essential tasks is executed.
8797
```
98+
8899
#### serve
100+
89101
`ui5 serve [options]` starts a webserver for the current project.
102+
90103
```
91104
Options:
92105
--help, -h Show help [boolean]
@@ -109,8 +122,11 @@ Examples:
109122
ui5 serve --translator static:/path/to/projectDependencies.yaml Use a "static" translator with translator parameters.
110123
ui5 serve --port 1337 --open tests/QUnit.html Listen to port 1337 and launch default browser with http://localhost:1337/test/QUnit.html
111124
```
125+
112126
#### tree
113-
`ui5 tree [options]` outputs the dependency tree of the current project to *stdout*. It takes all relevant parameters of ui5 build into account.
127+
128+
`ui5 tree [options]` outputs the dependency tree of the current project to _stdout_. It takes all relevant parameters of ui5 build into account.
129+
114130
```
115131
Options:
116132
--help, -h Show help [boolean]
@@ -128,7 +144,9 @@ Examples:
128144
```
129145

130146
#### init
147+
131148
`ui5 init [options]` initializes the UI5 Build and Development Tooling configuration for an application or library project.
149+
132150
```
133151
Options:
134152
--help, -h Show help [boolean]
@@ -139,7 +157,23 @@ Options:
139157
--loglevel Set the logging level (error|warn|info|verbose|silly). [string] [default: "info"]
140158
```
141159

160+
#### versions
161+
162+
`ui5 versions [options]` show the versions of all UI5 Build and Development Tooling packages.
163+
164+
```
165+
Options:
166+
--help, -h Show help [boolean]
167+
--version, -v Show version number [boolean]
168+
--config Path to config file [string]
169+
--translator, --t8r Translator to use. Including optional colon separated translator parameters. [string] [default: "npm"]
170+
--verbose Enable verbose logging. [boolean]
171+
--loglevel Set the logging level (error|warn|info|verbose|silly). [string] [default: "info"]
172+
173+
```
174+
142175
### Local vs. Global Installation
176+
143177
In general a global installation of the UI5 CLI (`npm install --global @ui5/cli`) is recommended.
144178

145179
However, it makes sense to add the UI5 CLI as a [devDependency](https://docs.npmjs.com/files/package.json#devdependencies) (`npm install --save-dev @ui5/cli`) for a project that is using `ui5`-commands in its build or test scripts or otherwise depends on the UI5 CLI for development workflows (like Continuous Integration).
@@ -151,24 +185,27 @@ This behavior can be disabled by setting the environment variable `UI5_CLI_NO_LO
151185
**Example**
152186
You have a project located at `/my-application`. The project has a devDependency to `@ui5/cli` and defines a start-script `"ui5 serve"`.
153187

154-
Current Working Directory | Command | Uses globally installed UI5 CLI | Uses locally installed UI5 CLI
155-
--- | --- | :---: | :---:
156-
`/``ui5 --version` | ✔️ |
157-
`/my-application``ui5 --version` | | ✔️
158-
`/my-application``ui5 serve` | | ✔️
159-
`/my-application``npm start` | | ✔️
160-
`/my-application``UI5_CLI_NO_LOCAL=X ui5 serve` | ✔️ |
161-
`/my-application``UI5_CLI_NO_LOCAL=X npm start` | | ✔️
162-
188+
| Current Working Directory | Command | Uses globally installed UI5 CLI | Uses locally installed UI5 CLI |
189+
| ------------------------- | ------------------------------- | :-----------------------------: | :----------------------------: |
190+
| `/` |  `ui5 --version` | ✔️ |
191+
| `/my-application` |  `ui5 --version` | | ✔️ |
192+
| `/my-application` |  `ui5 serve` | | ✔️ |
193+
| `/my-application` |  `npm start` | | ✔️ |
194+
| `/my-application` |  `UI5_CLI_NO_LOCAL=X ui5 serve` | ✔️ |
195+
| `/my-application` |  `UI5_CLI_NO_LOCAL=X npm start` | | ✔️ |
163196

164197
## Contributing
198+
165199
Please check our [Contribution Guidelines](https://github.com/SAP/ui5-tooling/blob/master/CONTRIBUTING.md).
166200

167201
## Support
202+
168203
Please follow our [Contribution Guidelines](https://github.com/SAP/ui5-tooling/blob/master/CONTRIBUTING.md#report-an-issue) on how to report an issue.
169204

170205
## Release History
206+
171207
See [CHANGELOG.md](CHANGELOG.md).
172208

173209
## License
210+
174211
This project is licensed under the Apache Software License, Version 2.0 except as noted otherwise in the [LICENSE](/LICENSE.txt) file.

lib/cli/commands/versions.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Versions
2+
const baseMiddleware = require("../middlewares/base.js");
3+
4+
const versions = {
5+
command: "versions",
6+
describe: "Show versions of all UI5 Tooling modules",
7+
middlewares: [baseMiddleware]
8+
};
9+
10+
const NOT_FOUND = "===(not installed)";
11+
const getVersion = (pkg) => {
12+
try {
13+
const packageInfo = require(`${pkg}/package.json`);
14+
return packageInfo.version || NOT_FOUND;
15+
} catch (err) {
16+
return NOT_FOUND;
17+
}
18+
};
19+
20+
versions.handler = (argv) => {
21+
try {
22+
const cliVersion =
23+
require("../../../package.json").version || NOT_FOUND;
24+
const builderVersion = getVersion("@ui5/builder");
25+
const serverVersion = getVersion("@ui5/server");
26+
const fsVersion = getVersion("@ui5/fs");
27+
const projectVersion = getVersion("@ui5/project");
28+
const loggerVersion = getVersion("@ui5/logger");
29+
console.log(`
30+
@ui5/cli: ${cliVersion}
31+
@ui5/builder: ${builderVersion}
32+
@ui5/server: ${serverVersion}
33+
@ui5/fs: ${fsVersion}
34+
@ui5/project: ${projectVersion}
35+
@ui5/logger: ${loggerVersion}
36+
`);
37+
} catch (err) {
38+
console.error(err);
39+
process.exit(1);
40+
}
41+
};
42+
43+
module.exports = versions;

0 commit comments

Comments
 (0)