Skip to content

Commit a4f5f20

Browse files
v3.0.1
1 parent 95ba050 commit a4f5f20

File tree

5 files changed

+102
-601
lines changed

5 files changed

+102
-601
lines changed

bump.ts

Lines changed: 68 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { readFile, writeFile } from 'fs';
1+
import { readFile, writeFile } from 'fs/promises'; // Use promises version of fs methods
22
import { execSync } from "child_process";
3+
import chalk from "chalk";//chalk commonJs
4+
import type { ForegroundColorName, BackgroundColorName } from "chalk";
5+
type Msg = [string, ForegroundColorName | 'white', BackgroundColorName | null];
6+
37
// Define the package semver and app version
48
const packageSemver = "3.0.1"; // Replace with your desired package semver
59
const appVersion = "1.8.4"; // Replace with your desired app version
@@ -10,106 +14,88 @@ const manifestFilePath = './manifest.json';
1014
const packageFilePath = './package.json';
1115

1216
// Function to update versions.json
13-
function updateVersionsFile() {
14-
readFile(versionsFilePath, 'utf8', (err, data) => {
15-
if (err) {
16-
console.error('Error reading versions.json:', err);
17-
return;
18-
}
19-
20-
try {
21-
const versions = JSON.parse(data);
22-
versions[packageSemver] = appVersion;
23-
24-
const updatedJson = JSON.stringify(versions, null, '\t');
25-
writeFile(versionsFilePath, updatedJson, 'utf8', (writeErr) => {
26-
if (writeErr) {
27-
console.error('Error writing to versions.json:', writeErr);
28-
} else {
29-
console.log(`Successfully added "${packageSemver}: ${appVersion}" to versions.json`);
30-
}
31-
});
32-
} catch (parseErr) {
33-
console.error('Error parsing versions.json:', parseErr);
34-
}
35-
});
17+
async function updateVersionsFile() {
18+
try {
19+
const data = await readFile(versionsFilePath, 'utf8');
20+
const versions = JSON.parse(data);
21+
versions[packageSemver] = appVersion;
22+
const updatedJson = JSON.stringify(versions, null, '\t');
23+
await writeFile(versionsFilePath, updatedJson, 'utf8');
24+
console.log(logInsert([`>> added "${packageSemver}: ${appVersion}" to versions.json. ✓✓`, "blue", null]));
25+
} catch (err) {
26+
console.error('Error updating versions.json:', err);
27+
}
3628
}
3729

3830
// Function to update manifest.json
39-
function updateManifestFile() {
40-
readFile(manifestFilePath, 'utf8', (err, data) => {
41-
if (err) {
42-
console.error('Error reading manifest.json:', err);
43-
return;
44-
}
45-
46-
try {
47-
const manifest = JSON.parse(data);
48-
manifest.version = packageSemver; // Update the version field
49-
manifest.minAppVersion = appVersion; // Update the minAppVersion field
50-
51-
const updatedJson = JSON.stringify(manifest, null, '\t');
52-
writeFile(manifestFilePath, updatedJson, 'utf8', (writeErr) => {
53-
if (writeErr) {
54-
console.error('Error writing to manifest.json:', writeErr);
55-
} else {
56-
console.log(`Successfully updated manifest.json: version="${packageSemver}", minAppVersion="${appVersion}"`);
57-
}
58-
});
59-
} catch (parseErr) {
60-
console.error('Error parsing manifest.json:', parseErr);
61-
}
62-
});
31+
async function updateManifestFile() {
32+
try {
33+
const data = await readFile(manifestFilePath, 'utf8');
34+
const manifest = JSON.parse(data);
35+
manifest.version = packageSemver; // Update the version field
36+
manifest.minAppVersion = appVersion; // Update the minAppVersion field
37+
const updatedJson = JSON.stringify(manifest, null, '\t');
38+
await writeFile(manifestFilePath, updatedJson, 'utf8');
39+
console.log(logInsert([`>> updated manifest.json: version="${packageSemver}", minAppVersion="${appVersion}". ✓✓`, "blue", null]));
40+
} catch (err) {
41+
console.error('Error updating manifest.json:', err);
42+
}
6343
}
64-
// Function to update package.json
65-
function updatePackageJsonFile() {
66-
readFile(packageFilePath, 'utf8', (err, data) => {
67-
if (err) {
68-
console.error('Error reading package.json:', err);
69-
return;
70-
}
71-
72-
try {
73-
const packageJson = JSON.parse(data);
74-
packageJson.version = packageSemver; // Update the version field
7544

76-
const updatedJson = JSON.stringify(packageJson, null, '\t');
77-
writeFile(packageFilePath, updatedJson, 'utf8', (writeErr) => {
78-
if (writeErr) {
79-
console.error('Error writing to package.json:', writeErr);
80-
} else {
81-
console.log(`Successfully updated package.json: version="${packageSemver}"`);
82-
}
83-
});
84-
} catch (parseErr) {
85-
console.error('Error parsing manifest.json:', parseErr);
86-
}
87-
});
45+
// Function to update package.json
46+
async function updatePackageJsonFile() {
47+
try {
48+
const data = await readFile(packageFilePath, 'utf8');
49+
const packageJson = JSON.parse(data);
50+
packageJson.version = packageSemver; // Update the version field
51+
const updatedJson = JSON.stringify(packageJson, null, '\t');
52+
await writeFile(packageFilePath, updatedJson, 'utf8');
53+
console.log(logInsert([`>> updated package.json: version="${packageSemver}. ✓✓"`, "blue", null]));
54+
} catch (err) {
55+
console.error('Error updating package.json:', err);
56+
}
8857
}
8958

9059
// Function to perform Git operations
9160
function gitCommitAndTag() {
9261
try {
9362
// Stage all changes
9463
execSync('git add .');
95-
console.log('Successfully staged all changes.');
96-
64+
console.log();
65+
console.log(logInsert(['-- staged all changes. ✓✓', "greenBright", null]));
9766
// Commit with the packageSemver as the message
9867
execSync(`git commit -m "v${packageSemver}"`);
99-
console.log(`Successfully committed changes with message: "v${packageSemver}".`);
68+
console.log(logInsert([`-- committed changes with message: "v${packageSemver}". ✓✓`, "greenBright", null]));
10069

10170
// Create a Git tag with the packageSemver
102-
execSync(`git tag v${packageSemver}`);
103-
console.log(`Successfully created Git tag: v${packageSemver}.`);
71+
execSync(`git tag ${packageSemver}`);
72+
console.log(logInsert([`-- created Git tag: ${packageSemver}. ✓✓`, "greenBright", null]));
73+
console.log();
10474

105-
console.log('Bump process completed successfully!');
10675
} catch (gitErr) {
10776
console.error('Error during Git operations:', gitErr.message || gitErr);
10877
}
10978
}
11079

111-
// Run both functions
112-
updateVersionsFile();
113-
updateManifestFile();
114-
updatePackageJsonFile();
115-
gitCommitAndTag();
80+
export function logInsert(msgArr: Msg) {
81+
const msg = {
82+
msg: msgArr[0],
83+
color: msgArr[1],
84+
bgColor: msgArr[2]
85+
}
86+
if (msg.bgColor !== null) {
87+
return chalk[msg.color][msg.bgColor](msg.msg)
88+
89+
}
90+
return chalk[msg.color](msg.msg)
91+
}
92+
// Main function to run all steps in sequence
93+
async function main() {
94+
await updateVersionsFile();
95+
await updateManifestFile();
96+
await updatePackageJsonFile();
97+
gitCommitAndTag(); // This will only run after all file updates are complete
98+
}
99+
100+
// Run the main function
101+
main();

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "cluster",
33
"name": "Cluster",
4-
"version": "3.0.0",
4+
"version": "3.0.1",
55
"minAppVersion": "1.8.4",
66
"description": "Make the notes clustering simpler on mobile devices and work well on PCs ether, Notes Clustering is the process of creating hierarchical notes structures.",
77
"author": "Lorens Osman",

0 commit comments

Comments
 (0)