mirror of
https://github.com/jakejarvis/website-stats.git
synced 2025-04-25 13:15:20 -04:00
symlink a "latest.json" file to the freshest stats
This commit is contained in:
parent
16e2a7f87b
commit
075d8968c4
15
.github/workflows/daily.yml
vendored
15
.github/workflows/daily.yml
vendored
@ -9,9 +9,14 @@ jobs:
|
||||
snapshot:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
- uses: actions/checkout@v4
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
node-version: 16
|
||||
- run: yarn install
|
||||
- run: yarn run snapshot
|
||||
version: 9
|
||||
run_install: false
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: 'pnpm'
|
||||
- run: pnpm install
|
||||
- run: pnpm run snapshot
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
||||
node_modules/
|
||||
yarn.lock
|
||||
|
@ -5,9 +5,8 @@
|
||||
"snapshot": "node scripts/snapshot.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"date-fns": "^2.28.0",
|
||||
"node-fetch": "^3.2.4",
|
||||
"simple-git": "^3.7.1",
|
||||
"write-json-file": "^5.0.0"
|
||||
"date-fns": "^4.1.0",
|
||||
"node-fetch": "^3.3.2",
|
||||
"simple-git": "^3.27.0"
|
||||
}
|
||||
}
|
||||
|
99
pnpm-lock.yaml
generated
Normal file
99
pnpm-lock.yaml
generated
Normal file
@ -0,0 +1,99 @@
|
||||
lockfileVersion: '6.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
dependencies:
|
||||
date-fns:
|
||||
specifier: ^4.1.0
|
||||
version: 4.1.0
|
||||
node-fetch:
|
||||
specifier: ^3.3.2
|
||||
version: 3.3.2
|
||||
simple-git:
|
||||
specifier: ^3.27.0
|
||||
version: 3.27.0
|
||||
|
||||
packages:
|
||||
|
||||
/@kwsites/file-exists@1.1.1:
|
||||
resolution: {integrity: sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==}
|
||||
dependencies:
|
||||
debug: 4.3.7
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/@kwsites/promise-deferred@1.1.1:
|
||||
resolution: {integrity: sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==}
|
||||
dev: false
|
||||
|
||||
/data-uri-to-buffer@4.0.1:
|
||||
resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==}
|
||||
engines: {node: '>= 12'}
|
||||
dev: false
|
||||
|
||||
/date-fns@4.1.0:
|
||||
resolution: {integrity: sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==}
|
||||
dev: false
|
||||
|
||||
/debug@4.3.7:
|
||||
resolution: {integrity: sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==}
|
||||
engines: {node: '>=6.0'}
|
||||
peerDependencies:
|
||||
supports-color: '*'
|
||||
peerDependenciesMeta:
|
||||
supports-color:
|
||||
optional: true
|
||||
dependencies:
|
||||
ms: 2.1.3
|
||||
dev: false
|
||||
|
||||
/fetch-blob@3.2.0:
|
||||
resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==}
|
||||
engines: {node: ^12.20 || >= 14.13}
|
||||
dependencies:
|
||||
node-domexception: 1.0.0
|
||||
web-streams-polyfill: 3.3.3
|
||||
dev: false
|
||||
|
||||
/formdata-polyfill@4.0.10:
|
||||
resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==}
|
||||
engines: {node: '>=12.20.0'}
|
||||
dependencies:
|
||||
fetch-blob: 3.2.0
|
||||
dev: false
|
||||
|
||||
/ms@2.1.3:
|
||||
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
|
||||
dev: false
|
||||
|
||||
/node-domexception@1.0.0:
|
||||
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
|
||||
engines: {node: '>=10.5.0'}
|
||||
dev: false
|
||||
|
||||
/node-fetch@3.3.2:
|
||||
resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
dependencies:
|
||||
data-uri-to-buffer: 4.0.1
|
||||
fetch-blob: 3.2.0
|
||||
formdata-polyfill: 4.0.10
|
||||
dev: false
|
||||
|
||||
/simple-git@3.27.0:
|
||||
resolution: {integrity: sha512-ivHoFS9Yi9GY49ogc6/YAi3Fl9ROnF4VyubNylgCkA+RVqLaKWnDSzXOVzya8csELIaWaYNutsEuAhZrtOjozA==}
|
||||
dependencies:
|
||||
'@kwsites/file-exists': 1.1.1
|
||||
'@kwsites/promise-deferred': 1.1.1
|
||||
debug: 4.3.7
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/web-streams-polyfill@3.3.3:
|
||||
resolution: {integrity: sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==}
|
||||
engines: {node: '>= 8'}
|
||||
dev: false
|
@ -1,10 +1,10 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import fetch from "node-fetch";
|
||||
import { format } from "date-fns";
|
||||
import simpleGit from "simple-git";
|
||||
import { writeJsonFile } from "write-json-file";
|
||||
|
||||
// https://github.com/jakejarvis/jarv.is/blob/main/pages/api/hits.ts#L101
|
||||
// https://github.com/jakejarvis/jarv.is/blob/main/pages/api/hits.ts
|
||||
const API_ENDPOINT = "https://jarv.is/api/hits/";
|
||||
|
||||
// formulate path to target .json file
|
||||
@ -16,6 +16,7 @@ const jsonPath = path.join(
|
||||
format(today, "MM"), // month
|
||||
`${format(today, "yyyy-MM-dd")}.json` // year-month-day.json
|
||||
);
|
||||
const latestPath = path.join(process.cwd(), "data", "latest.json");
|
||||
|
||||
// pull the latest stats from API
|
||||
console.info("📡 Fetching latest data from API...");
|
||||
@ -23,7 +24,13 @@ const data = await (await fetch(API_ENDPOINT)).json();
|
||||
|
||||
// write pretty JSON to timestamped file
|
||||
console.info(`📂 Writing data to ${jsonPath} ...`);
|
||||
await writeJsonFile(jsonPath, data.pages);
|
||||
fs.mkdirSync(path.dirname(jsonPath), { recursive: true });
|
||||
fs.writeFileSync(jsonPath, JSON.stringify(data.pages || data, null, "\t") + "\n");
|
||||
|
||||
// update latest.json symlink to newest timestamped file
|
||||
console.info(`🔗 Pointing latest.json to ${jsonPath} ...`);
|
||||
fs.rmSync(latestPath, { force: true });
|
||||
fs.symlinkSync(path.relative(path.dirname(latestPath), jsonPath), latestPath, "file");
|
||||
|
||||
// automatically push changes only if running from CI
|
||||
if (process.env.GITHUB_ACTION) {
|
||||
@ -38,7 +45,7 @@ if (process.env.GITHUB_ACTION) {
|
||||
git.addConfig("user.email", "41898282+github-actions[bot]@users.noreply.github.com");
|
||||
|
||||
// do the normal git stuff
|
||||
await git.add([jsonPath]);
|
||||
await git.add([jsonPath, latestPath]);
|
||||
await git.commit(`📈 Add new snapshot for ${format(today, "yyyy-MM-dd")}`);
|
||||
await git.push("origin", "main");
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user