diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 1ca5122..acff0be 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -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 diff --git a/.gitignore b/.gitignore index 23d67fc..c2658d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ node_modules/ -yarn.lock diff --git a/package.json b/package.json index 8bf69fb..f058f81 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..1653eb1 --- /dev/null +++ b/pnpm-lock.yaml @@ -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 diff --git a/scripts/snapshot.js b/scripts/snapshot.js index 6c4fdcd..eddf353 100644 --- a/scripts/snapshot.js +++ b/scripts/snapshot.js @@ -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 {