-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add update-deps #27
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,102 @@ | ||
/** | ||
* Dependencies Version Update Script | ||
* | ||
* Purpose: Automatically updates the version of all @univerjs and @univerjs-pro | ||
* related dependencies across all packages. | ||
* | ||
* Usage: | ||
* 1. Basic usage (will use latest version from @univerjs/core latest tag): | ||
* pnpm tsx scripts/update-dependencies.ts | ||
* | ||
* 2. Specify release channel: | ||
* RELEASE_CHANNEL=beta pnpm tsx scripts/update-dependencies.ts | ||
* | ||
* 3. Specify exact version: | ||
* NEW_VERSION=1.0.0 pnpm tsx scripts/update-dependencies.ts | ||
* | ||
* Environment Variables: | ||
* - RELEASE_CHANNEL: Release channel to use, defaults to 'latest'. | ||
* Can be 'beta', 'alpha', etc. | ||
* - NEW_VERSION: Target version to update to. If not specified, | ||
* will fetch latest version from specified RELEASE_CHANNEL | ||
* | ||
* Notes: | ||
* - Excluded packages: ${EXCLUDED_PACKAGES} | ||
* - Excluded versions: ${EXCLUDED_VERSIONS} | ||
*/ | ||
|
||
import { execSync } from 'node:child_process'; | ||
import * as path from 'node:path'; | ||
import process from 'node:process'; | ||
import fs from 'fs-extra'; | ||
|
||
const RELEASE_CHANNEL = process.env.RELEASE_CHANNEL || 'latest'; | ||
const NEW_VERSION = process.env.NEW_VERSION || getLatestTagVersion('@univerjs/core', RELEASE_CHANNEL); | ||
|
||
if (!NEW_VERSION) { | ||
console.error('Failed to get version'); | ||
process.exit(1); | ||
} | ||
|
||
const PACKAGES_DIR = path.resolve(__dirname, '../packages'); | ||
|
||
const EXCLUDED_PACKAGES = ['@univerjs/protocol']; | ||
const EXCLUDED_VERSIONS = ['workspace:*']; | ||
|
||
function getLatestTagVersion(packageName: string, tag: string = 'latest') { | ||
try { | ||
const version = execSync(`npm view ${packageName}@${tag} version`, { encoding: 'utf-8' }).trim(); | ||
return version; | ||
} | ||
catch (error) { | ||
console.error(`Failed to get version for ${packageName}@${tag}`); | ||
throw error; | ||
} | ||
} | ||
|
||
function updateDependencies() { | ||
const packages = fs.readdirSync(PACKAGES_DIR).filter(file => | ||
fs.statSync(path.join(PACKAGES_DIR, file)).isDirectory(), | ||
); | ||
|
||
packages.forEach((packageDir) => { | ||
const packageJsonPath = path.join(PACKAGES_DIR, packageDir, 'package.json'); | ||
|
||
if (!fs.existsSync(packageJsonPath)) { | ||
return; | ||
} | ||
|
||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); | ||
let hasUpdates = false; | ||
|
||
const dependencyTypes = ['dependencies', 'devDependencies', 'peerDependencies']; | ||
|
||
dependencyTypes.forEach((depType) => { | ||
if (!packageJson[depType]) | ||
return; | ||
|
||
Object.entries(packageJson[depType] as [string, string]).forEach(([pkg, version]) => { | ||
if ( | ||
(pkg.startsWith('@univerjs/') || pkg.startsWith('@univerjs-pro/')) | ||
&& !EXCLUDED_PACKAGES.includes(pkg) | ||
&& !EXCLUDED_VERSIONS.includes(version) | ||
) { | ||
packageJson[depType][pkg] = NEW_VERSION; | ||
hasUpdates = true; | ||
console.log(`Updated ${pkg} to ${NEW_VERSION} in ${packageDir}`); | ||
} | ||
}); | ||
}); | ||
|
||
if (hasUpdates) { | ||
fs.writeJSONSync(packageJsonPath, packageJson, { spaces: 4 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EOL is required |
||
} | ||
}); | ||
|
||
console.log('Running pnpm install to update lock file...'); | ||
execSync('pnpm install', { stdio: 'inherit' }); | ||
|
||
console.log('Dependencies update completed!'); | ||
} | ||
|
||
updateDependencies(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an ESM project, there's no need to
import *
.