caffco/yarn-workspace-packages-github-action

View on GitHub
src/main.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import path from 'path'
import {readJsonFile} from './fs'
import {
  getOptionsFromGithubActionInput,
  setGithubActionOutputFromResults
} from './github'

export default async function main(): Promise<void> {
  const options = getOptionsFromGithubActionInput()
  const resolveFunction = 'resolve'

  const rootPackage = (await readJsonFile(
    path[resolveFunction](options.repositoryRootPath, 'package.json')
  )) as {
    workspaces: {packages: string[]}
  }

  const packageFolderRelativePaths = rootPackage.workspaces.packages

  const packageNames = await Promise.all(
    packageFolderRelativePaths.map(async relativePath => {
      const packageJsonAbsolutePath = path[resolveFunction](
        options.repositoryRootPath,
        relativePath,
        'package.json'
      )
      const packageJson = (await readJsonFile(packageJsonAbsolutePath)) as {
        name: string
      }
      return packageJson.name
    })
  )

  setGithubActionOutputFromResults({
    packageNames
  })
}