Skip to content

Commit 92da081

Browse files
committed
feat: updating cargo.toml and package.json before version commit and tag
* Related #28
1 parent 3747725 commit 92da081

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@matrixai/quic",
3-
"version": "0.0.2-alpha.0",
3+
"version": "0.0.3-alpha.0",
44
"bin": {
55
"server": "dist/bin/server.js"
66
},
@@ -20,7 +20,7 @@
2020
"prepare": "tsc -p ./tsconfig.build.json",
2121
"prebuild": "node ./scripts/prebuild.js",
2222
"build": "rimraf ./dist && tsc -p ./tsconfig.build.json",
23-
"postversion": "node ./scripts/postversion.js",
23+
"version": "node ./scripts/version.js",
2424
"prepublishOnly": "node ./scripts/prepublishOnly.js",
2525
"ts-node": "ts-node",
2626
"test": "jest",

scripts/postversion.js renamed to scripts/version.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env node
22

33
/**
4-
* This runs after `npm version` command.
5-
* This will update the `package.json` optional native dependencies
4+
* This runs after `npm version` command updates the version but before changes are commited.
5+
* This will update the `cargo.toml` version to match the new `package.json` verson.
6+
* This will also update the `package.json` optional native dependencies
67
* to match the same version as the version of this package.
78
* This maintains the same version between this master package
89
* and the optional native dependencies.
@@ -12,6 +13,9 @@
1213
* to prevent `npm` from attempting to download unpublished packages.
1314
*/
1415

16+
const process = require('process');
17+
const path = require('path');
18+
const fs = require('fs');
1519
const os = require('os');
1620
const childProcess = require('child_process');
1721
const packageJSON = require('../package.json');
@@ -20,6 +24,27 @@ const platform = os.platform();
2024

2125
/* eslint-disable no-console */
2226
async function main() {
27+
28+
console.error(
29+
'Updating the cargo.toml version to match new version',
30+
);
31+
const projectRoot = path.join(__dirname, '..');
32+
const cargoTOMLPath = path.join(projectRoot, 'Cargo.toml');
33+
const cargoTOML = await fs.promises.readFile(cargoTOMLPath, 'utf-8');
34+
const cargoTOMLMatch = cargoTOML.match(/version\s*=\s*"(.*)"/);
35+
const cargoTOMLUpdated = cargoTOML.replace(cargoTOMLMatch[0], `version = "${packageJSON.version}"`);
36+
await fs.promises.writeFile(cargoTOMLPath, cargoTOMLUpdated, 'utf-8');
37+
38+
console.error(
39+
'Staging changes in git',
40+
);
41+
childProcess.execFileSync('git', ['add', cargoTOMLPath], {
42+
stdio: ['inherit', 'inherit', 'inherit'],
43+
windowsHide: true,
44+
encoding: 'utf-8',
45+
shell: platform === 'win32' ? true : false,
46+
});
47+
2348
console.error(
2449
'Updating the package.json with optional native dependencies and package-lock.json',
2550
);

0 commit comments

Comments
 (0)