@tmlmobilidade/repo-version 20251006.1125.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +25 -0
  2. package/dist/index.js +53 -0
  3. package/package.json +31 -0
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ ### @tmlmobilidade/bump-version 🧼
2
+
3
+ Bump version is a small util to update the package.json version string using the current timestamp.
4
+
5
+ #### Usage:
6
+
7
+ ```
8
+ npx @tmlmobilidade/repo-version --output=<path-to-package.json | console> --format=<default | code> --prefix=<your-prefix>
9
+ ```
10
+
11
+ ##### `--format`
12
+ - "string" - Output as a formatted string (e.g. `20250101.1026.12`)
13
+ - "code" - Output as number (e.g. `20250101102612`)
14
+
15
+ ##### `--prefix`
16
+ - an optional value to prepend to the version string (only in default format)
17
+
18
+ ##### `--suffix`
19
+ - an optional value to append to the version string (only in default format)
20
+
21
+ ##### `--output`
22
+ - "<path-to-package.json>" - Modify the package.json.
23
+ - "console" - Output to the console. This will hide any other logs.
24
+
25
+ :)
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ /* * */
3
+ import { Dates } from '@tmlmobilidade/utils';
4
+ import fs from 'node:fs';
5
+ /* * */
6
+ //
7
+ // Parse command-line arguments
8
+ const args = process.argv.slice(2);
9
+ const prefixArg = args.find(arg => arg.startsWith('--prefix='));
10
+ const prefix = prefixArg ? prefixArg.split('=')[1] : '';
11
+ const suffixArg = args.find(arg => arg.startsWith('--suffix='));
12
+ const suffix = suffixArg ? suffixArg.split('=')[1] : '';
13
+ const formatArg = args.find(arg => arg.startsWith('--format='));
14
+ const format = formatArg ? formatArg.split('=')[1] : '';
15
+ const outputArg = args.find(arg => arg.startsWith('--output='));
16
+ const output = outputArg ? outputArg.split('=')[1] : '';
17
+ //
18
+ // Generate the new version based on the current date and time
19
+ const dateValue = Dates.now('Europe/Lisbon');
20
+ //
21
+ // Format the version string.
22
+ // For "default" format: [prefix]YYYYMMDD.HHMM.SS
23
+ // For "code" format: YYYYMMDDHHMMSS (as a single number, no prefix)
24
+ let futurePackageVersion = '';
25
+ if (!format || format === 'default') {
26
+ futurePackageVersion = `${prefix}${dateValue.toFormat('yyyyMMdd.HHmm.ss')}${suffix}`;
27
+ }
28
+ if (format === 'code') {
29
+ futurePackageVersion = String(Number(dateValue.toFormat('yyyyMMddHHmmss')));
30
+ }
31
+ //
32
+ // If the ouput is set to "console",
33
+ // just print the version to the console and exit.
34
+ if (output === 'console') {
35
+ console.log(futurePackageVersion);
36
+ process.exit(0);
37
+ }
38
+ //
39
+ // If there is a package.json path argument,
40
+ // read the file and parse its content.
41
+ if (!output) {
42
+ console.error('✘ Error: No path to package.json provided.');
43
+ process.exit(1);
44
+ }
45
+ const packageJsonFile = fs.readFileSync(output, 'utf8');
46
+ const packageJsonData = JSON.parse(packageJsonFile);
47
+ //
48
+ // Update the package.json file with the new version
49
+ // and log the change to the console.
50
+ const currentPackageVersion = packageJsonData.version;
51
+ packageJsonData.version = futurePackageVersion;
52
+ fs.writeFileSync(output, JSON.stringify(packageJsonData, null, '\t'));
53
+ console.log(`✓ Package Version updated from "${currentPackageVersion}" to "${futurePackageVersion}".`);
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@tmlmobilidade/repo-version",
3
+ "description": "A CLI tool to bump the version of a NodeJS package.",
4
+ "version": "20251006.1125.28",
5
+ "author": "João de Vasconcelos & Jusi Monteiro",
6
+ "license": "AGPL-3.0-or-later",
7
+ "type": "module",
8
+ "files": [
9
+ "dist/"
10
+ ],
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "scripts": {
14
+ "build": "tsc && resolve-tspaths",
15
+ "lint": "eslint .",
16
+ "lint:fix": "eslint . --fix",
17
+ "start": "tsc && resolve-tspaths && node dist/index.js"
18
+ },
19
+ "bin": {
20
+ "repo-version": "./dist/index.js"
21
+ },
22
+ "dependencies": {
23
+ "@tmlmobilidade/utils": "*"
24
+ },
25
+ "devDependencies": {
26
+ "@carrismetropolitana/eslint": "20250622.1204.50",
27
+ "@types/node": "24.7.0",
28
+ "resolve-tspaths": "0.8.23",
29
+ "typescript": "5.9.3"
30
+ }
31
+ }