Skip to content

readme suggestion on Advanced integration #30

Description

@rijuma

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions