-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
100 additions
and
122 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
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,75 @@ | ||
import { dirname, resolve } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { readFile, writeFile } from 'fs/promises'; | ||
import latestVersion from 'latest-version'; | ||
import { exec } from '@actions/exec'; | ||
import { parse as parseEnv, stringify as stringifyEnv } from 'envfile'; | ||
|
||
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 FlowLibUpdater({ siteName, packageName, envKey }) { | ||
const sitePath = resolve(__dirname, `../../sites/${siteName}`); | ||
const latestNpmVersion = await latestVersion(packageName); | ||
const envPath = resolve(sitePath, '.env'); | ||
const envContent = await readFile(envPath); | ||
const envParsed = parseEnv(envContent); | ||
const currentVersion = envParsed[envKey]; | ||
|
||
// writes the latest version from npm to the .env file | ||
async function updateEnv() { | ||
console.log(`update ${packageName} .env file`); | ||
|
||
if (!envParsed[envKey]) { | ||
console.log(`couldn't find ${envKey} in .env file ${packagePath}`); | ||
return; | ||
} | ||
|
||
envParsed[versionKey] = latestNpmVersion; | ||
|
||
const envUpdated = stringifyEnv(envParsed); | ||
|
||
await writeFile(envPath, envUpdated); | ||
} | ||
|
||
// updates all workspaces that use the package | ||
async function updatePkgs() { | ||
console.log(`update ${packageName} dependencies`); | ||
|
||
await exec(`pnpm`, [ | ||
`--recursive`, | ||
`-C=${__dirname}/../../`, | ||
'update', | ||
`${packageName}@${latestNpmVersion}`, | ||
]); | ||
} | ||
|
||
return { | ||
async start() { | ||
if (!areVersionsEqual(currentVersion, latestNpmVersion)) { | ||
await updatePkgs(); | ||
await updateEnv(); | ||
|
||
return latestNpmVersion; | ||
} | ||
|
||
return null; | ||
}, | ||
}; | ||
} | ||
|
||
// utils | ||
|
||
function areVersionsEqual(a, b) { | ||
if (!a || !b) { | ||
return false; | ||
} | ||
|
||
const versionA = a.replace('^', ''); | ||
const versionB = b.replace('^', ''); | ||
|
||
return versionA === versionB; | ||
} |
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,23 @@ | ||
import { FlowLibUpdater } from './flow-lib-updater.js'; | ||
|
||
const reactFlowUpdater = await FlowLibUpdater({ | ||
packageName: 'reactflow', | ||
envKey: 'NEXT_PUBLIC_REACT_FLOW_VERSION', | ||
siteName: 'reactflow.dev', | ||
}); | ||
const reactFlowUpdated = await reactFlowUpdater.start(); | ||
|
||
if (reactFlowUpdated) { | ||
console.log('updated reactflow'); | ||
} | ||
|
||
const svelteFlowUpdater = await FlowLibUpdater({ | ||
packageName: '@xyflow/svelte', | ||
envKey: 'NEXT_PUBLIC_SVELTE_FLOW_VERSION', | ||
siteName: 'svelteflow.dev', | ||
}); | ||
const svelteFlowUpdated = await svelteFlowUpdater.start(); | ||
|
||
if (svelteFlowUpdated) { | ||
console.log('updated @xyflow/svelte'); | ||
} |
2 changes: 1 addition & 1 deletion
2
scripts/check-libs/package.json → scripts/check-flow-libs/package.json
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,5 +1,5 @@ | ||
{ | ||
"name": "check-libs", | ||
"name": "check-flow-libs", | ||
"version": "1.0.0", | ||
"private": true, | ||
"type": "module", | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.