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

Add script for updating package version #1794

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,22 @@ _[Read more about this](https://github.com/meilisearch/integration-guides/blob/m

#### Version update

Make a PR modifying the following files with the right version:
Make a PR after running the following command:

[`package.json`](/package.json):
```javascript
"version": "X.X.X",
```
```sh
# for patch bumps
yarn update-version
# or
yarn update-version -p

# for minor bumps
yarn update-version -m

# for major bumps
yarn update-version -M

[`src/package-version`](/src/package-version.ts)
```javascript
export const PACKAGE_VERSION = 'X.X.X'
# if exact version is desired
yarn update-version -e X.X.X
```

#### Github publish
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"url": "https://github.com/meilisearch/meilisearch-js"
},
"scripts": {
"update-version": "node scripts/update-version.js",
"playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript start",
"cleanup": "shx rm -rf dist/",
"build": "yarn cleanup && rollup -c && rollup -c --environment NODE_ENV:production",
Expand Down
50 changes: 50 additions & 0 deletions scripts/update-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { parseArgs } = require("node:util");
const { writeFileSync } = require("node:fs");
const { resolve } = require("node:path");

const {
values: { minor, major, exact },
} = parseArgs({
options: {
patch: { type: "boolean", short: "p", default: false },
minor: { type: "boolean", short: "m", default: false },
major: { type: "boolean", short: "M", default: false },
exact: { type: "string", short: "e" },
},
});

const pkg = require("../package.json");
let [M, m, p] = (exact !== undefined ? exact : pkg.version)
.split(".")
.map(Number);

console.log("old version: ", pkg.version);

if (exact === undefined) {
if (major) {
M += 1;
m = 0;
p = 0;
} else if (minor) {
m += 1;
p = 0;
} else {
p += 1;
}
}

const version = `${M}.${m}.${p}`;

console.log("new version: ", version);

pkg.version = version;
const packageJSONPath = resolve(__dirname, "../package.json");
writeFileSync(packageJSONPath, JSON.stringify(pkg, null, 2) + "\n");
console.log("written to: ", packageJSONPath);

const packageVersionPath = resolve(__dirname, "../src/package-version.ts");
writeFileSync(
packageVersionPath,
`export const PACKAGE_VERSION = "${version}";\n`,
);
console.log("written to: ", packageVersionPath);
Loading