-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #326 from ashik-75/work
Add Npm packages and update diff checker
- Loading branch information
Showing
26 changed files
with
2,064 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Fetch Latest packages | ||
|
||
on: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
fetch-news: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: automation-scripts/npm-packages | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "18.16.1" | ||
|
||
- name: Install Yarn | ||
run: | | ||
corepack enable | ||
corepack prepare yarn@stable --activate | ||
- name: Install dependencies | ||
run: yarn install --immutable | ||
|
||
- name: Run | ||
run: yarn start | ||
|
||
- name: Move packages.json | ||
run: |- | ||
git add news.json | ||
git mv -f news.json ../../api/packages.json | ||
- name: Commit and push if changed | ||
run: |- | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "GitHub Actions" | ||
git commit -m "Update packages.json" || true | ||
git push |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ | |
# Documentation here: https://yarnpkg.com/features/zero-installs | ||
!.yarn/cache | ||
#.pnp.* | ||
.yarn | ||
|
||
node_modules |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
# Swap the comments on the following lines if you don't wish to use zero-installs | ||
# Documentation here: https://yarnpkg.com/features/zero-installs | ||
!.yarn/cache | ||
#.pnp.* | ||
.yarn | ||
|
||
node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: node-modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
# TODO | ||
```shell | ||
yarn init -2 | ||
|
||
yarn add --dev typescript | ||
yarn add --dev ts-node | ||
yarn add --dev nodemon | ||
yarn add fs | ||
|
||
mkdir src | ||
cd src | ||
touch index.ts | ||
``` | ||
|
||
```shell | ||
yarn start | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "npm-packages", | ||
"packageManager": "[email protected]", | ||
"scripts": { | ||
"start": "ts-node src/index.ts", | ||
"dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts", | ||
"build": "tsc", | ||
"watch": "tsc -w" | ||
}, | ||
"dependencies": { | ||
"fs": "^0.0.1-security", | ||
"semver": "^7.5.4" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.6.3", | ||
"@types/semver": "^7.5.2", | ||
"nodemon": "^3.0.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.2.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import fs from "fs"; | ||
import semver from "semver"; | ||
|
||
interface PackageType { | ||
key: string; | ||
url: string; | ||
version: string; | ||
new: boolean; | ||
} | ||
|
||
interface ResponseType { | ||
packages: PackageType[]; | ||
lastDate: number; | ||
} | ||
|
||
async function fetchData(url: string) { | ||
try { | ||
const response = await fetch(url); | ||
const data = await response.json(); | ||
|
||
return data; | ||
} catch (error) { | ||
console.log("something went wrong"); | ||
} | ||
} | ||
|
||
function compareMajorVersion(latestVersion: string, previousVesrion: string) { | ||
const latestMajor = semver.major(latestVersion); | ||
const prevMajor = semver.major(previousVesrion); | ||
|
||
return latestMajor > prevMajor; | ||
} | ||
|
||
async function fetchPackages(packageNames: string[]) { | ||
try { | ||
const packageList: PackageType[] = []; | ||
let prevData = (await fetchData( | ||
"https://raw.githubusercontent.com/lifeparticle/binarytree/main/api/packages.json" | ||
)) as ResponseType; | ||
|
||
for (const packageName of packageNames) { | ||
const packageUrl = `https://registry.npmjs.org/${packageName}/latest`; | ||
const latestPackage = await fetchData(packageUrl); | ||
|
||
if (latestPackage) { | ||
const prevPackage = prevData?.packages.find( | ||
(info) => info.key === packageName | ||
); | ||
|
||
const isNew = | ||
!prevPackage || | ||
compareMajorVersion(latestPackage.version, prevPackage.version); | ||
|
||
const result = { | ||
key: packageName, | ||
url: `https://www.npmjs.com/package/${packageName}`, | ||
version: latestPackage.version, | ||
new: isNew, | ||
}; | ||
|
||
packageList.push(result); | ||
} | ||
} | ||
|
||
return { | ||
packages: packageList, | ||
lastDate: Date.now(), | ||
}; | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
async function saveDataToFile(data: any, filename: string): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
fs.writeFile(filename, JSON.stringify(data), (err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
async function main() { | ||
const packages = ["react", "svelte", "remix", "gatsby", "next", "vue"]; | ||
if (!packages) { | ||
throw new Error("No package found"); | ||
} | ||
const articles = await fetchPackages(packages); | ||
await saveDataToFile(articles, "packages.json"); | ||
console.log("Data saved to packages.json"); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"strict": true, | ||
"esModuleInterop": true | ||
}, | ||
"types": ["node"] | ||
} |
Oops, something went wrong.