Skip to content

Commit

Permalink
feat: add set-version option
Browse files Browse the repository at this point in the history
  • Loading branch information
saitho committed Feb 10, 2021
1 parent 5c05ffd commit 45ec2d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ With that setup the file is updated when `npm start` and `npm build` are run.
| --file | relative location of the output file (based on the root directory) | ./src/_version.ts | false |
| --git | relative location of the folder containing the .git folder (based on the root directory) | . |
| --pnpm | PNPM has a different folder structure, resulting in a different root level. Add this if you use PNPM to install your dependencies. If package.json is not found at the expected PNPM path, it will fall back to the default one. This setting is ignored if `--root` is an absolute path. | false |
| --set-version | Set this to override the value of the version string fetched from package.json (set in `version` property) | |

## Receiving the versions

Expand All @@ -68,11 +69,9 @@ export class AppComponent {
}
```

> backward compatibility with previous version is guarantee
The file will export an object with following variables:

* **version** is the version from the packages.json (e.g. v1.0.0)
* **version** is the version from packages.json (or value of `set-version` option if set)
* **name** is the name from the packages.json (e.g. 'sample-app')
* **description** is the description from the packages.json
* **versionDate** is the timestamp in ISO format when the compilation/package started.
Expand Down Expand Up @@ -138,4 +137,4 @@ Check out [the example/ directory](example/) for a working example Angular appli


## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fsaitho%2Fng-appversion.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fsaitho%2Fng-appversion?ref=badge_large)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fsaitho%2Fng-appversion.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fsaitho%2Fng-appversion?ref=badge_large)
14 changes: 10 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,20 @@ const outputFile = argv.hasOwnProperty('file') ? argv.file : path.join('src', '_
const versionFile = path.join(projectFolder, outputFile);

// pull version from package.json
const pkg = require(packageFile);
const appVersion = pkg.version;
const appName = pkg.name;
const appDescription = pkg.description;
const pkg = require(packageFile);
const appName = pkg.name || '';
const appDescription = pkg.description || '';

let appVersion = pkg.version || '';

console.log('[TsAppVersion] ' + colors.green('Application version (from package.json): ') + colors.yellow(appVersion));
console.log('[TsAppVersion] ' + colors.green('Application name (from package.json): ') + colors.yellow(appName));

if (argv.hasOwnProperty('set-version')) {
appVersion = argv['set-version']
console.log('[TsAppVersion] Setting fixed version ' + appVersion + ' from command option.');
}

let src = `export interface TsAppVersion {
version: string;
name: string;
Expand Down

0 comments on commit 45ec2d4

Please sign in to comment.