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

feat: updating cargo.toml and package.json before version commit #29

Merged
merged 4 commits into from
May 24, 2023
Merged
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quic"
version = "0.0.1"
version = "0.0.4-alpha.0"
authors = ["Roger Qiu <[email protected]>"]
license-file = "LICENSE"
edition = "2021"
Expand Down
4 changes: 2 additions & 2 deletions benches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import fs from 'fs';
import path from 'path';
import si from 'systeminformation';
import Stream1KB from './stream_1KB';
// import Dummy from './dummy';
// Import Dummy from './dummy';

async function main(): Promise<void> {
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
// Running benches
await Stream1KB();
// await Dummy();
// Await Dummy();
const resultFilenames = await fs.promises.readdir(
path.join(__dirname, 'results'),
);
Expand Down
16 changes: 10 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@matrixai/quic",
"version": "0.0.2-alpha.0",
"version": "0.0.4-alpha.0",
"bin": {
"server": "dist/bin/server.js"
},
Expand All @@ -20,7 +20,7 @@
"prepare": "tsc -p ./tsconfig.build.json",
"prebuild": "node ./scripts/prebuild.js",
"build": "rimraf ./dist && tsc -p ./tsconfig.build.json",
"postversion": "node ./scripts/postversion.js",
"version": "node ./scripts/version.js",
"prepublishOnly": "node ./scripts/prepublishOnly.js",
"ts-node": "ts-node",
"test": "jest",
Expand All @@ -40,10 +40,10 @@
"ip-num": "^1.5.0"
},
"optionalDependencies": {
"@matrixai/quic-linux-x64": "0.0.1",
"@matrixai/quic-win32-x64": "0.0.1",
"@matrixai/quic-darwin-x64": "0.0.1",
"@matrixai/quic-darwin-arm64": "0.0.1"
"@matrixai/quic-darwin-arm64": "0.0.4-alpha.0",
"@matrixai/quic-darwin-x64": "0.0.4-alpha.0",
"@matrixai/quic-linux-x64": "0.0.4-alpha.0",
"@matrixai/quic-win32-x64": "0.0.4-alpha.0"
},
"devDependencies": {
"@fast-check/jest": "^1.1.0",
Expand Down
38 changes: 36 additions & 2 deletions scripts/postversion.js → scripts/version.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env node

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

const path = require('path');
const fs = require('fs');
const os = require('os');
const childProcess = require('child_process');
const packageJSON = require('../package.json');
Expand All @@ -20,6 +23,37 @@ const platform = os.platform();

/* eslint-disable no-console */
async function main() {
console.error('Updating the cargo.toml version to match new version');
const projectRoot = path.join(__dirname, '..');
const cargoTOMLPath = path.join(projectRoot, 'Cargo.toml');
const cargoTOML = await fs.promises.readFile(cargoTOMLPath, 'utf-8');
const cargoTOMLMatch = cargoTOML.match(/version\s*=\s*"(.*)"/);
const cargoTOMLUpdated = cargoTOML.replace(
cargoTOMLMatch[0],
`version = "${packageJSON.version}"`,
);
await fs.promises.writeFile(cargoTOMLPath, cargoTOMLUpdated, 'utf-8');

console.error('updating cargo lock file with change');
childProcess.execFileSync('cargo', ['update', '--package', 'quic'], {
stdio: ['inherit', 'inherit', 'inherit'],
windowsHide: true,
encoding: 'utf-8',
shell: platform === 'win32' ? true : false,
});

console.error('Staging changes in git');
childProcess.execFileSync(
'git',
['add', cargoTOMLPath, path.join(projectRoot, 'Cargo.lock')],
{
stdio: ['inherit', 'inherit', 'inherit'],
windowsHide: true,
encoding: 'utf-8',
shell: platform === 'win32' ? true : false,
},
);

console.error(
'Updating the package.json with optional native dependencies and package-lock.json',
);
Expand Down