Skip to content

Commit

Permalink
Merge pull request #23 from PolymeshAssociation/fix/update-readme
Browse files Browse the repository at this point in the history
fix: 🐛 Modify updateReadme script to update chain version
  • Loading branch information
prashantasdeveloper authored Apr 17, 2024
2 parents c257170 + 7cd662d commit 6c96de4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

## Polymesh version

This release is compatible with Polymesh v6.x.x and Polymesh Private v1.x.x
This release is compatible with Polymesh v6.0, v6.1, v6.2 and Polymesh Private v1.0

<!--- End of section --->

Expand Down
6 changes: 0 additions & 6 deletions scripts/consts.js

This file was deleted.

73 changes: 41 additions & 32 deletions scripts/updateReadme.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
/* eslint-disable @typescript-eslint/naming-convention */
const W3CWebSocket = require('websocket').w3cwebsocket;
const WebSocketAsPromised = require('websocket-as-promised');
/* eslint-enable @typescript-eslint/naming-convention */
/* eslint-disable */

const fs = require('fs');
const path = require('path');
const replace = require('replace-in-file');
const { NODE_URL, WS_PORT } = require('./consts');
const versionRegex = /This release is compatible with Polymesh v(.*) and Polymesh Private .*/;
const ppVersionRegex = /This release is compatible with Polymesh v.* and Polymesh Private v(.*)/;

const versionRegex = /This release is compatible with Polymesh v(\d+\.\d+\.\d+)/;
const getSupportedNodeVersion = path => {
const constantsFile = fs.readFileSync(path, {
encoding: 'utf8',
});

const regex = /export const SUPPORTED_NODE_VERSION_RANGE = '([^']+)';/g;

const match = regex.exec(constantsFile);

return match[1];
};

/**
* Replace the version number in the README
Expand All @@ -15,29 +25,28 @@ const createReplacementVersion = newVersion => (text, prevVersion) => {
return text.replace(prevVersion, newVersion);
};

// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => {
const wsp = new WebSocketAsPromised(`ws://${NODE_URL}:${WS_PORT}`, {
createWebSocket: url => new W3CWebSocket(url),
packMessage: data => JSON.stringify(data),
unpackMessage: data => JSON.parse(data.toString()),
attachRequestId: (data, requestId) => Object.assign({ id: requestId }, data),
extractRequestId: data => data && data.id,
});

await wsp.open();

const { result: version } = await wsp.sendRequest({
jsonrpc: '2.0',
method: 'system_version',
params: [],
});

replace.sync({
files: 'README.md',
from: versionRegex,
to: createReplacementVersion(version),
});

process.exit(0);
})();
const supportedNodeVersionString = supportedNodeVersion =>
supportedNodeVersion
.split('||')
.map(version => version.trim())
.join(', v');

const {
SUPPORTED_NODE_VERSION_RANGE: supportedNodeVersionForPolymesh,
} = require('@polymeshassociation/polymesh-sdk/utils/constants');

replace.sync({
files: 'README.md',
from: versionRegex,
to: createReplacementVersion(supportedNodeVersionString(supportedNodeVersionForPolymesh)),
});

const supportedNodeVersionForPolymeshPrivate = getSupportedNodeVersion(
path.resolve('src', 'utils', 'constants.ts')
);

replace.sync({
files: 'README.md',
from: ppVersionRegex,
to: createReplacementVersion(supportedNodeVersionString(supportedNodeVersionForPolymeshPrivate)),
});

0 comments on commit 6c96de4

Please sign in to comment.