Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 6724a9f

Browse files
committed
Added axios and libraries.io request
1 parent 483665c commit 6724a9f

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
GITHUB_TOKEN=
1+
GITHUB_TOKEN=
2+
LIBRARIES_IO_KEY=

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"@types/react-test-renderer": "^17.0.0",
6161
"@typescript-eslint/eslint-plugin": "^4.8.2",
6262
"@typescript-eslint/parser": "^4.8.2",
63+
"axios": "^0.21.0",
6364
"babel-core": "^6.26.3",
6465
"babel-jest": "^26.6.3",
6566
"babel-plugin-dev-expression": "^0.2.2",

scripts/precommit.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { JSDOM } from "jsdom";
22
import * as marked from "marked";
3+
import * as dotenv from "dotenv-safe";
4+
import axios from "axios";
35

46
import * as pkg from "../package.json";
57
import {
@@ -14,6 +16,8 @@ import {
1416
getStagedFiles,
1517
} from "./helpers";
1618

19+
dotenv.config();
20+
1721
const changelogDest = join(ROOT_DIR, "CHANGELOG.md");
1822

1923
const readmeDest = join(ROOT_DIR, "README.md");
@@ -30,20 +34,30 @@ const getReadme = () => {
3034
return readFile(readmeDest, "utf-8");
3135
};
3236

33-
const getNextVersions = () => {
34-
const currentVersion = pkg.version;
37+
const getNextVersions = async () => {
38+
try {
39+
const { data } = await axios.get(
40+
`https://libraries.io/api/NPM/react-hash-scroll?api_key=${process.env.LIBRARIES_IO_KEY}`
41+
);
42+
43+
const currentVersion =
44+
data?.versions?.slice?.(-1)?.[0]?.number ?? pkg.version;
3545

36-
const match = currentVersion.match(semverRegex) as RegExpMatchArray;
46+
const match = currentVersion.match(semverRegex) as RegExpMatchArray;
3747

38-
const major = parseInt(match[1]),
39-
minor = parseInt(match[2]),
40-
patch = parseInt(match[3]);
48+
const major = parseInt(match[1]),
49+
minor = parseInt(match[2]),
50+
patch = parseInt(match[3]);
4151

42-
return [
43-
`${major + 1}.0.0`,
44-
`${major}.${minor + 1}.0`,
45-
`${major}.${minor}.${patch + 1}`,
46-
];
52+
return [
53+
`${major + 1}.0.0`,
54+
`${major}.${minor + 1}.0`,
55+
`${major}.${minor}.${patch + 1}`,
56+
];
57+
} catch (e) {
58+
console.log(e);
59+
process.exit(1);
60+
}
4761
};
4862

4963
const createDom = (changelog: string) => {
@@ -62,7 +76,7 @@ const checkChangelog = async () => {
6276

6377
const changelog = await getChangelog();
6478

65-
const versions = getNextVersions();
79+
const versions = await getNextVersions();
6680

6781
const { document } = createDom(changelog);
6882

0 commit comments

Comments
 (0)