Skip to content

Commit

Permalink
updated check verison to return all local package versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorian1te committed Nov 7, 2023
1 parent f444b75 commit 975e6ec
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions scripts/checkVersionPublished.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ interface SimplePackageJson {
function getLatestVersion(packageName: string): string {
try {
return execSync(`npm show ${packageName} version`, { encoding: 'utf-8' }).trim()
} catch (e) {
} catch {
return 'unavailable'
}
}

const publishCommands: string[] = []
const localVersions: string[] = []

function compareVersions(packagePath: string, packageName: string, currentVersion: string): void {
const latestVersion = getLatestVersion(packageName)
Expand All @@ -27,18 +28,19 @@ function compareVersions(packagePath: string, packageName: string, currentVersio
if (currentVersion !== latestVersion) {
const relativePath = path.relative(process.cwd(), packagePath)
const publishCommand = `(cd ${relativePath} && npm publish)`

publishCommands.push(publishCommand)
console.log(
`Publish new version for ${packageName} in ${packagePath} from npm version ${latestVersion} to ${currentVersion}`,
`Publish new version for ${packageName} in ${packagePath} from npm version ${latestVersion} to ${currentVersion}`,
)
publishCommands.push(publishCommand)
}
}

function checkPackageJson(packagePath: string): void {
const packageJsonPath = path.join(packagePath, 'package.json')
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) as SimplePackageJson

const { name, version } = packageJson
localVersions.push(`${name}@${version}`)
compareVersions(packagePath, name, version)
}

Expand All @@ -63,9 +65,10 @@ function main(): void {
const packagesPath = path.join(__dirname, '..', 'packages')
const packagePaths = getPackagePaths(packagesPath)

for (const packagePath of packagePaths) {
checkPackageJson(packagePath)
}
packagePaths.forEach((packagePath) => checkPackageJson(packagePath))

console.log(localVersions.join('\n'))

if (publishCommands.length > 0) {
console.log('\nPublish Commands:')
console.log(publishCommands.join('\n'))
Expand Down

0 comments on commit 975e6ec

Please sign in to comment.