Skip to content

Commit b58a4ff

Browse files
v5.0.6 - cleanup to code
1 parent 66feafe commit b58a4ff

File tree

9 files changed

+332
-260
lines changed

9 files changed

+332
-260
lines changed

.github/scripts/release.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const jsonfile = require('jsonfile');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const packageFile = './package.json';
6+
const packageData = jsonfile.readFileSync(packageFile);
7+
const currentVersion = packageData.version;
8+
const authorName = packageData.author;
9+
const versionParts = currentVersion.split('.');
10+
let [major, minor, patch] = versionParts.map(Number);
11+
const incrementType = process.argv[2];
12+
switch (incrementType) {
13+
case '-minor':
14+
minor += 1;
15+
patch = 0;
16+
break;
17+
case '-patch':
18+
patch += 1;
19+
break;
20+
case '-major':
21+
major += 1;
22+
minor = 0;
23+
patch = 0;
24+
break;
25+
default:
26+
console.log('Invalid increment type. Please use -minor, -patch, or -major.');
27+
process.exit(1);
28+
}
29+
const newVersion = `${major}.${minor}.${patch}`;
30+
packageData.version = newVersion;
31+
jsonfile.writeFileSync(packageFile, packageData, { spaces: 2 });
32+
33+
const filesToUpdate = [
34+
"./docs/dist/docsify-sidebar.js",
35+
"./docs/dist/docsify-sidebar.min.js",
36+
"./dist/docsify-sidebar.min.js"
37+
];
38+
39+
filesToUpdate.forEach(filePath => {
40+
const fileName = getFileName(filePath);
41+
const header = `/*! ${fileName} ${newVersion} | (c) ${authorName} */\n`;
42+
const fileContent = fs.readFileSync(filePath, 'utf8');
43+
const headerRegex = /^\/\*![\s\S]*?\*\//; // Regular expression to match the header comment
44+
const contentWithoutHeader = fileContent.replace(headerRegex, '');
45+
const updatedContent = header + contentWithoutHeader.trimStart();
46+
fs.writeFileSync(filePath, updatedContent, 'utf8');
47+
console.log(`Header added to ${filePath}.`);
48+
});
49+
50+
console.log('Header added successfully to all files.');
51+
52+
const changelogPath = './CHANGELOG.md';
53+
const changelogContent = generateChangelog(newVersion, incrementType);
54+
fs.writeFileSync(changelogPath, changelogContent, 'utf8');
55+
console.log('Changelog generated successfully.');
56+
57+
function generateChangelog(version, incrementType) {
58+
const currentDate = new Date().toDateString();
59+
const changeDescription = getChangeDescription(incrementType);
60+
61+
// Read the existing changelog content if it exists
62+
let existingChangelog = '';
63+
if (fs.existsSync(changelogPath)) {
64+
existingChangelog = fs.readFileSync(changelogPath, 'utf8');
65+
}
66+
const newChangelogEntry = `\n## ${version} - ${currentDate}\n\n${changeDescription}\n`;
67+
return newChangelogEntry + existingChangelog;
68+
}
69+
70+
function getChangeDescription(incrementType) {
71+
switch (incrementType) {
72+
case '-minor':
73+
return '### Added\n\n- Add your change description here.';
74+
case '-patch':
75+
return '### Fixed\n\n- Fix your change description here.';
76+
case '-major':
77+
return '### Breaking Changes\n\n- Describe any breaking changes here.';
78+
default:
79+
return '';
80+
}
81+
}
82+
83+
function getFileName(filePath) {
84+
const fileNameWithExtension = path.basename(filePath);
85+
const fileName = fileNameWithExtension.split('.')[0];
86+
return fileName;
87+
}

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
.DS_Store
2-
.markdownlintrc
31
.vscode
2+
.markdownlint.json
3+
.DS_Store
4+
*babel.js
45
*.min.js
56
!docs/dist
67
!docs/dist/*.min.js
7-
*.babel.js

.npmignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
.DS_Store
2-
.markdownlintrc
31
.vscode
4-
!dist
5-
docs
2+
.markdownlint.json
3+
.github
4+
.gitattributes
5+
.DS_Store
66
*babel.js
7-
!docs/README.md
7+
docs

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
## 5.0.6 - Mon May 22 2023
3+
4+
### Fixed
5+
6+
- Published to incorrect package manager
7+
8+
## 5.0.5 - Mon May 22 2023
9+
10+
### Fixed
11+
12+
- Namespace issue - wrapped the script into its own local environment to avoid clashing
13+
- Addition into Docsify.js plugin list more inline with the documentation

dist/docsify-sidebar.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)