|
3 | 3 |
|
4 | 4 | import path from 'node:path' |
5 | 5 | import { execSync } from 'node:child_process' |
| 6 | +import { existsSync, readdirSync } from 'node:fs' |
6 | 7 | import chalk from 'chalk' |
7 | 8 | import * as semver from 'semver' |
8 | 9 | import currentGitBranch from 'current-git-branch' |
@@ -365,6 +366,41 @@ export const publish = async (options) => { |
365 | 366 | ) |
366 | 367 | } |
367 | 368 |
|
| 369 | + if (existsSync(path.resolve(rootDir, 'examples'))) { |
| 370 | + console.info('Updating examples to use new package versions...') |
| 371 | + const examplePkgJsonArray = /** @type {string[]} */ ( |
| 372 | + readdirSync(path.resolve(rootDir, 'examples'), { |
| 373 | + recursive: true, |
| 374 | + }).filter( |
| 375 | + (file) => |
| 376 | + typeof file === 'string' && |
| 377 | + file.includes('package.json') && |
| 378 | + !file.includes('node_modules'), |
| 379 | + ) |
| 380 | + ) |
| 381 | + if (examplePkgJsonArray.length !== 0) { |
| 382 | + for (const examplePkgJson of examplePkgJsonArray) { |
| 383 | + await updatePackageJson( |
| 384 | + path.resolve(rootDir, 'examples', examplePkgJson), |
| 385 | + (config) => { |
| 386 | + for (const pkg of changedPackages) { |
| 387 | + if (config.dependencies?.[pkg.name]) { |
| 388 | + config.dependencies[pkg.name] = `^${version}` |
| 389 | + } |
| 390 | + if (config.devDependencies?.[pkg.name]) { |
| 391 | + config.devDependencies[pkg.name] = `^${version}` |
| 392 | + } |
| 393 | + } |
| 394 | + }, |
| 395 | + ) |
| 396 | + } |
| 397 | + if (existsSync(path.resolve(rootDir, 'pnpm-lock.yaml'))) { |
| 398 | + console.info('Updating examples to use new package versions...') |
| 399 | + execSync('pnpm install') |
| 400 | + } |
| 401 | + } |
| 402 | + } |
| 403 | + |
368 | 404 | if (!process.env.CI) { |
369 | 405 | console.warn( |
370 | 406 | `This is a dry run for version ${version}. Push to CI to publish for real or set CI=true to override!`, |
|
0 commit comments