-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(whats-new): add script for generating whats new pages
- Loading branch information
Showing
4 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,25 @@ | ||
import dotenv from 'dotenv'; | ||
import { WhatsNewCreator } from './whats-new-creator.js'; | ||
|
||
dotenv.config({ path: '.env.local' }); | ||
|
||
const reactFlowCreator = await WhatsNewCreator({ | ||
site: 'reactflow.dev', | ||
packageName: 'reactflow', | ||
}); | ||
const reactFlowUpdated = await reactFlowCreator.start(); | ||
|
||
if (reactFlowUpdated) { | ||
console.log('updated React Flow'); | ||
} | ||
|
||
// no Svelte Flow releases yet | ||
// const svelteFlowCreator = await WhatsNewCreator({ | ||
// site: 'svelteflow.dev', | ||
// packageName: '@xyflow/svelte', | ||
// }); | ||
// const svelteFlowUpdated = await svelteFlowCreator.start(); | ||
|
||
// if (svelteFlowUpdated) { | ||
// console.log('updated Svelte Flow'); | ||
// } |
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,20 @@ | ||
{ | ||
"name": "create-whats-new", | ||
"version": "1.0.0", | ||
"private": true, | ||
"type": "module", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"keywords": [], | ||
"author": "xyflow", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@actions/exec": "^1.1.1", | ||
"dotenv": "^16.4.5", | ||
"envfile": "^7.1.0", | ||
"latest-version": "^9.0.0" | ||
} | ||
} |
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,80 @@ | ||
import { dirname, resolve } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { writeFile, stat } from 'fs/promises'; | ||
|
||
import latestVersion from 'latest-version'; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
/** | ||
* This is a helper function for checking the latest version on npm against the version in the .env file for a specific site. | ||
* You need to create the helper and then call the start method to check the version. | ||
*/ | ||
export async function WhatsNewCreator({ site, packageName }) { | ||
const sitePath = resolve(__dirname, `../../sites/${site}`); | ||
const latestNpmVersion = await latestVersion(packageName); | ||
const ghApiUrl = `https://api.github.com/repos/xyflow/xyflow/releases/tags/${latestNpmVersion}`; | ||
|
||
async function getReleaseNotes() { | ||
console.log('request release notes for', ghApiUrl); | ||
|
||
const releaseNotes = await fetch(ghApiUrl, { | ||
headers: { | ||
Authorization: process.env.GITHUB_TOKEN, | ||
Accept: 'application/vnd.github+json', | ||
}, | ||
}); | ||
const releaseJson = await releaseNotes.json(); | ||
|
||
return releaseJson.body; | ||
} | ||
|
||
async function writeWhatsNew(fileName, content) { | ||
console.log(`write whats new page for ${site}`); | ||
|
||
const whatsNewPath = resolve( | ||
sitePath, | ||
'src', | ||
'pages', | ||
'whats-new', | ||
`${fileName}.mdx`, | ||
); | ||
|
||
if (await fileExists(whatsNewPath)) { | ||
console.log( | ||
`Can't write file. What's new file ${fileName} already exists!`, | ||
); | ||
return null; | ||
} | ||
|
||
await writeFile(whatsNewPath, content); | ||
return true; | ||
} | ||
|
||
function getMdContent(date, body) { | ||
return `--- | ||
title: New Release ${latestNpmVersion} | ||
description: What's new in ${packageName} ${latestNpmVersion} | ||
authors: [moklick] | ||
date: ${date} | ||
--- | ||
# ${latestNpmVersion} | ||
${body}`; | ||
} | ||
|
||
return { | ||
async start() { | ||
const releaseNotes = await getReleaseNotes(); | ||
const today = new Date().toISOString().slice(0, 10); | ||
const mdContent = getMdContent(today, releaseNotes); | ||
const createdWhatsNew = await writeWhatsNew(today, mdContent); | ||
|
||
return createdWhatsNew; | ||
}, | ||
}; | ||
} | ||
|
||
const fileExists = async (pathName) => | ||
!!(await stat(pathName).catch((e) => false)); |