Skip to content

Commit c363583

Browse files
author
Jonathan
committed
fixes release version updating
1 parent 63c1edb commit c363583

File tree

4 files changed

+75
-83
lines changed

4 files changed

+75
-83
lines changed

.github/workflows/release/action.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ inputs:
1515
runs:
1616
using: composite
1717
steps:
18+
- name: Build
19+
shell: bash
20+
run: npm run release
1821
- name: Create new release
1922
shell: bash
20-
run: npm run release:version ${{ inputs.VERSION }}
23+
run: npm run version ${{ inputs.VERSION }}
2124
# - name: SonarCloud Scan
2225
# uses: sonarsource/sonarcloud-github-action@master
2326
# env:

build/change-version.js

Lines changed: 68 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,85 @@
1-
#!/usr/bin/env node
2-
3-
/*!
4-
* Script to update version number references in the project.
5-
* Copyright 2017-2021 The Bootstrap Authors
6-
* Copyright 2017-2021 Twitter, Inc.
7-
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
8-
*/
9-
10-
'use strict';
11-
12-
const pkg = require('../package.json');
13-
14-
const fs = require('fs').promises;
1+
const fs = require('fs');
152
const path = require('path');
163
const globby = require('globby');
174

18-
const VERBOSE = process.argv.includes('--verbose');
19-
const DRY_RUN =
20-
process.argv.includes('--dry') || process.argv.includes('--dry-run');
21-
22-
// These are the filetypes we only care about replacing the version
23-
const GLOB = [
24-
'**/*.{css,js,json,md,scss,txt,yml,ts,nuspec,properties}',
25-
'**/shell.html',
26-
'**/installing.html',
27-
'**/templates/index.html',
28-
'!**/change-log*',
29-
];
30-
const GLOBBY_OPTIONS = {
31-
cwd: path.join(__dirname, '..'),
32-
gitignore: true,
33-
};
34-
35-
// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
36-
function regExpQuote(string) {
37-
return string.replace(/[$()*+-.?[\\\]^{|}]/g, '\\$&');
38-
}
39-
40-
function regExpQuoteReplacement(string) {
41-
return string.replace(/\$/g, '$$');
42-
}
43-
44-
async function replaceRecursively(file, oldVersion, newVersion) {
45-
const originalString = await fs.readFile(file, 'utf8');
46-
const newString = originalString.replace(
47-
new RegExp(regExpQuote(oldVersion), 'g'),
48-
regExpQuoteReplacement(newVersion)
49-
);
50-
51-
// No need to move any further if the strings are identical
52-
if (originalString === newString) {
53-
return;
54-
}
55-
56-
//if (VERBOSE) {
57-
console.log(`FILE: ${file}`);
58-
//}
5+
// Function to update version in a file
6+
function updateVersionInFile(filePath, oldVersion, newVersion) {
7+
try {
8+
const content = fs.readFileSync(filePath, 'utf8');
9+
const updated = content.replace(
10+
new RegExp(oldVersion.replace(/\./g, '\\.'), 'g'),
11+
newVersion
12+
);
5913

60-
if (DRY_RUN) {
61-
return;
14+
if (content !== updated) {
15+
fs.writeFileSync(filePath, updated, 'utf8');
16+
console.log(`Updated version in ${filePath}`);
17+
}
18+
} catch (error) {
19+
console.error(`Error processing ${filePath}:`, error);
6220
}
63-
64-
await fs.writeFile(file, newString, 'utf8');
6521
}
6622

67-
async function main(args) {
68-
let newVersion = args[0];
69-
let oldVersion = pkg.version;
70-
71-
if (!newVersion) {
72-
console.error(
73-
'USAGE: change-version new_version [--verbose] [--dry[-run]]'
23+
async function updateVersions(newVersion) {
24+
try {
25+
// Read current version from package.json
26+
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
27+
const currentVersion = packageJson.version;
28+
29+
if (!currentVersion) {
30+
throw new Error('Could not find version in package.json');
31+
}
32+
33+
// Update package.json
34+
packageJson.version = newVersion;
35+
fs.writeFileSync(
36+
'./package.json',
37+
JSON.stringify(packageJson, null, 2) + '\n'
7438
);
75-
console.error('Got arguments:', args);
76-
process.exit(1);
77-
}
39+
console.log('Updated version in package.json');
40+
41+
const GLOB = [
42+
'**/*.{json,md,nuspec,properties}',
43+
'src/js/tempus-dominus.ts',
44+
'**/shell.html',
45+
'**/installing.html',
46+
'**/templates/index.html',
47+
'!**/change-log*',
48+
'!test/**/*',
49+
];
50+
51+
const GLOBBY_OPTIONS = {
52+
cwd: path.join(__dirname, '..'),
53+
gitignore: true,
54+
};
7855

79-
// Strip any leading `v` from arguments because otherwise we will end up with duplicate `v`s
80-
[oldVersion, newVersion] = [oldVersion, newVersion].map((arg) =>
81-
arg.startsWith('v') ? arg.slice(1) : arg
82-
);
83-
84-
try {
8556
const files = await globby(GLOB, GLOBBY_OPTIONS);
8657

87-
await Promise.all(
88-
files.map((file) => replaceRecursively(file, oldVersion, newVersion))
58+
//make sure that the dist folder is included
59+
files.push(
60+
...(await globby(['dist/**/*'], {
61+
cwd: path.join(__dirname, '..'),
62+
}))
8963
);
64+
65+
// Update version in each file
66+
for (const file of files) {
67+
updateVersionInFile(file, currentVersion, newVersion);
68+
}
9069
} catch (error) {
91-
console.error(error);
70+
console.error('Error:', error);
9271
process.exit(1);
9372
}
9473
}
9574

96-
main(process.argv.slice(2)).then();
75+
// Get new version from command line argument
76+
const newVersion = process.argv[2];
77+
78+
if (!newVersion) {
79+
console.error('Please provide a new version number as an argument');
80+
console.error('Usage: node update-version.js <new-version>');
81+
process.exit(1);
82+
}
83+
84+
// Execute the update
85+
updateVersions(newVersion);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Jonathan Peterson"
44
},
55
"name": "@eonasdan/tempus-dominus",
6-
"version": "6.10.2",
6+
"version": "6.10.3",
77
"style": "dist/css/tempus-dominus.css",
88
"sass": "scss/tempus-dominus.scss",
99
"main": "dist/js/tempus-dominus.js",
@@ -35,7 +35,7 @@
3535
"docs": "node ./src/docs/make.js",
3636
"docs-watch": "node ./src/docs/make.js --watch",
3737
"release": "npm run eslint && npm run test:silent && npm run build",
38-
"release:version": "npm run release && node build/change-version.js",
38+
"version": "node build/change-version.js",
3939
"prepare": "husky install",
4040
"prettier": "prettier --ignore-unknown --write .",
4141
"eslint": "npm run prettier && npx eslint --ext .html,.ts ."

src/js/tempus-dominus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ const extend = function (plugin, option = undefined) {
681681
return tempusDominus;
682682
};
683683

684-
const version = '6.9.4';
684+
const version = '6.10.3';
685685

686686
const tempusDominus = {
687687
TempusDominus,

0 commit comments

Comments
 (0)