Code Monkey home page Code Monkey logo

Comments (8)

aa900031 avatar aa900031 commented on September 18, 2024 5

Hi @azat-io, currently is pending, because I waiting for those PR's to merge

from changelogen.

pi0 avatar pi0 commented on September 18, 2024 2

Are the values in workspaces in the config file the same as package.json workspaces ?

I think we might return an object from resolveWorkspace like { root: '', type: '', workspaces: string[] }

Why there is this usecase? or user how to use that?

Subdir can be used by CLI to run changelog update against each package. Also manually by user to read config from root but update changeloges in a subdir only (even without workspace support)

I think there is another feature that can be implemented - "A filter for monorepos".
Here is the usecase:
We are using pnpm to manage a monorepo, but we only want to automatically generate changelogs for certain packages. Specifically, we need to generate changelogs for awesome-pkg, @awesome-pkg/core, and @awesome-pkg/shared, but not for playground or example.

Yes this also 👍🏼

from changelogen.

aa900031 avatar aa900031 commented on September 18, 2024 1

Configurable git commit template

I believe that this feature has been completed in this PR #68

from changelogen.

aa900031 avatar aa900031 commented on September 18, 2024

Expose a new workspaces config object (auto-detected with resolveWorkspace from pkg-types)

Are the values in workspaces in the config file the same as package.json workspaces ?

from changelogen.

aa900031 avatar aa900031 commented on September 18, 2024

A new subDir config defaulting to / and when is set, filters commits only relevant to this subpath and also operates package.json and CHANGELOG.md in {rootDir}/{subDir} for updating

Why there is this usecase? or user how to use that?

from changelogen.

aa900031 avatar aa900031 commented on September 18, 2024

I think there is another feature that can be implemented - "A filter for monorepos".

Here is the usecase:

We are using pnpm to manage a monorepo, but we only want to automatically generate changelogs for certain packages. Specifically, we need to generate changelogs for awesome-pkg, @awesome-pkg/core, and @awesome-pkg/shared, but not for playground or example.

from changelogen.

azat-io avatar azat-io commented on September 18, 2024

Any progress?
Is it works with pnpm workspaces?

from changelogen.

LouisMazel avatar LouisMazel commented on September 18, 2024

Tips

To manage my monorepo versions and have the advantages of changelogen (beautiful changelog and release publish to github), I use lerna at first, and then I use changelogen to generate and publish the changelog:

  1. Bump version without changelog generation with lerna: lerna version (lerna will bump the version in package.json files if needed, create a commit to push it, create and push the new tag). My lerna config bellow
  2. Then, generate the new changelog with changelogen in a custom script, amend the previous commit of lerna and push it to github to create a new release. Script bellow.

lerna.json

{
  "loglevel": "verbose",
  "version": "0.47.26",
  "yes": true,
  "command": {
    "version": {
      "allowBranch": ["master"],
      "message": "chore(release): bump version %v",
      "conventionalCommits": true,
      "forceGitTag": false,
      "changelog": false,
      "push": true,
      "gitTagVersion": true,
      "tagVersionPrefix": "v",
      "commitHooks": true
    }
  },
  "npmClient": "pnpm",
  "$schema": "node_modules/lerna/schemas/lerna-schema.json"
}

``

import { exec } from 'node:child_process'
import { existsSync, promises as fsp } from 'node:fs'
import { generateMarkDown, getGitDiff, parseCommits, loadChangelogConfig, syncGithubRelease } from 'changelogen'

async function execPromise(command: string): Promise<{ stdout: string; stderr: string }> {
  return await new Promise((resolve, reject) => {
    exec(command, (error, stdout, stderr) => {
      if (error) {
        console.error(`🔴 [cli](${command}) Execution failed - ${error.message}.`)
        reject(error)
      } else {
        resolve({ stdout, stderr })
      }
    })
  })
}

async function updateChangelog() {
  const { stdout: lastTag } = await execPromise("git tag --sort=-v:refname | sed -n '1p'")
  const { stdout: penultimateTag } = await execPromise("git tag --sort=-v:refname | sed -n '2p'")

  const lastTagTrimed = lastTag.trim()
  const penultimateTagTrimed = penultimateTag.trim()

  const config = await loadChangelogConfig(process.cwd(), {
    from: penultimateTagTrimed,
    to: lastTagTrimed,
  })

  const rawCommits = await getGitDiff(penultimateTagTrimed, lastTagTrimed)
  const commits = parseCommits(rawCommits, config).filter((commit) => {
    return (
      config.types[commit.type] &&
      !(commit.type === 'chore' && (commit.scope === 'deps' || commit.scope === 'release') && !commit.isBreaking)
    )
  })

  const newChangelog = await generateMarkDown(commits, config)

  let changelogMD: string

  if (typeof config.output === 'string' && existsSync(config.output)) {
    changelogMD = await fsp.readFile(config.output, 'utf8')
  } else {
    changelogMD = '# Changelog\n\n'
  }

  const lastEntry = changelogMD.match(/^###?\s+.*$/m)

  if (lastEntry) {
    changelogMD = changelogMD.slice(0, lastEntry.index) + newChangelog + '\n\n' + changelogMD.slice(lastEntry.index)
  } else {
    changelogMD += '\n' + newChangelog + '\n\n'
  }

  await fsp.writeFile(config.output as string, changelogMD)

  const changelogWithoutTitle = newChangelog.split('\n').slice(2).join('\n')

  console.log(changelogWithoutTitle)

  await execPromise(`git add -u`)
  await execPromise(`git commit --amend --no-edit`)
  await execPromise(`git push origin HEAD --force`)

  try {
    await syncGithubRelease(config, {
      version: lastTagTrimed.replace('v', ''),
      body: changelogWithoutTitle,
    })

    console.log('Release pushed to GitHub.')
  } catch (error: any) {
    console.error('error', error)
  }
}

updateChangelog()

package.json

{
  "scripts": {
    "release": "pnnp release:bump-version && pnpm release:changelogen",
    "release:bump-version": "lerna version",
    "release:changelogen": "ts-node ./changelog-generate.ts"
  },
}

You have to run

pnpm release

from changelogen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.