Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readme suggestion on Advanced integration #30

Open
rijuma opened this issue Mar 3, 2024 · 1 comment
Open

readme suggestion on Advanced integration #30

rijuma opened this issue Mar 3, 2024 · 1 comment

Comments

@rijuma
Copy link

rijuma commented Mar 3, 2024

I'm working on a module package that generates text files, and I'm appending the current module version to the generated files. This package helped me to deal with reading the package.json file as expected, I'm really grateful for it.

I'm using TypeScript, and wanted to, as the "Advanced Integration" documentation suggests, generate the version file after the patch.

I've tried to use a postversion.sh as indicated but this caused some issues. For example, this scripts requires you to fiddle with the git tags after creating, and also for my case of using Typescript it wasn't so useful because at this step the code has already been built and this file wasn't there in the process.

I've found a practical way to use it, which I think other people might find useful, which is:

  1. create a "gv" script to generate the file and add it to the build process:
// file: package.json

{
  ...
  "scripts": {
  ...
    "gv": "genversion --esm --property name,version,homepage src/constants/project.ts",
    "build": npm run gv && tsc"
  ...
  }
}
  1. Add a "version" script which runs after the version was bumped but before the tagging which I use to build the module and to add the generated file to the commit:
// file: package.json

{
  ...
  "scripts": {
  ...
    "gv": "genversion --esm --property name,version,homepage src/constants/project.ts",
    "build": npm run gv && tsc",
    "version": "npm run build && git add -A",
  ...
  }
}

And now, each time you run npm version patch for example, the file is generated and pushed along with the package.json update. Besides that, you've already built the project with the recently generated version, so you can just publish it right away.

I'm not an expert on this, so I might have overlooked something, but this was really helpful on my project, and I didn't had to create a shell file, made it executable and so on, it just works right out of the clone.

Cheers!

@axelpale
Copy link
Owner

Thanks for the approach, definitely worth it. I might adapt this into the advanced integration docs at some point. Related to #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants