Skip to content

Commit

Permalink
feat: Update example dependencies when publishing (#35)
Browse files Browse the repository at this point in the history
* feat: Update example dependencies when publishing

* Improve console messages
  • Loading branch information
lachlancollins authored Feb 2, 2024
1 parent 35ed35b commit 6dacd4f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import path from 'node:path'
import { execSync } from 'node:child_process'
import { existsSync, readdirSync } from 'node:fs'
import chalk from 'chalk'
import * as semver from 'semver'
import currentGitBranch from 'current-git-branch'
Expand Down Expand Up @@ -365,6 +366,41 @@ export const publish = async (options) => {
)
}

if (existsSync(path.resolve(rootDir, 'examples'))) {
console.info('Updating examples to use new package versions...')
const examplePkgJsonArray = /** @type {string[]} */ (
readdirSync(path.resolve(rootDir, 'examples'), {
recursive: true,
}).filter(
(file) =>
typeof file === 'string' &&
file.includes('package.json') &&
!file.includes('node_modules'),
)
)
if (examplePkgJsonArray.length !== 0) {
for (const examplePkgJson of examplePkgJsonArray) {
await updatePackageJson(
path.resolve(rootDir, 'examples', examplePkgJson),
(config) => {
for (const pkg of changedPackages) {
if (config.dependencies?.[pkg.name]) {
config.dependencies[pkg.name] = `^${version}`
}
if (config.devDependencies?.[pkg.name]) {
config.devDependencies[pkg.name] = `^${version}`
}
}
},
)
}
if (existsSync(path.resolve(rootDir, 'pnpm-lock.yaml'))) {
console.info('Updating examples to use new package versions...')
execSync('pnpm install')
}
}
}

if (!process.env.CI) {
console.warn(
`This is a dry run for version ${version}. Push to CI to publish for real or set CI=true to override!`,
Expand Down

0 comments on commit 6dacd4f

Please sign in to comment.