From 28979c8c795b869c8e93f3c6c4c52f80f0a84efc Mon Sep 17 00:00:00 2001 From: mihaisc Date: Thu, 23 Jun 2022 04:51:32 -0700 Subject: [PATCH] add version (#455) --- package.json | 3 ++- schema.graphql | 3 +++ scripts/replaceVersion.js | 17 +++++++++++++++++ src/mappings/utils/globalUtils.ts | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 scripts/replaceVersion.js diff --git a/package.json b/package.json index 6d999f6..ba71db1 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "lint:fix": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx . --fix", "format": "prettier --ignore-path .gitignore './**/*.{css,yml,js,ts,tsx,json,yaml}' --write", "type-check": "tsc --noEmit", + "replaceVersion": "node ./scripts/replaceVersion.js", "release": "release-it --non-interactive", "changelog": "auto-changelog -p" }, @@ -68,7 +69,7 @@ "license": "Apache-2.0", "release-it": { "hooks": { - "after:bump": "npm run changelog" + "after:bump": "npm run changelog && npm run replaceVersion" }, "plugins": {}, "git": { diff --git a/schema.graphql b/schema.graphql index dba47cc..90f6202 100644 --- a/schema.graphql +++ b/schema.graphql @@ -492,6 +492,9 @@ type GlobalStatistic @entity { "number of dispensers created" dispenserCount: Int! + + "current version" + version: String } type OPC @entity { diff --git a/scripts/replaceVersion.js b/scripts/replaceVersion.js new file mode 100644 index 0000000..be0f859 --- /dev/null +++ b/scripts/replaceVersion.js @@ -0,0 +1,17 @@ +const fs = require('fs') +const packageJson = require('../package.json') + +async function replaceVersion() { + let globalUtils = fs.readFileSync( + './src/mappings/utils/globalUtils.ts', + 'utf8' + ) + globalUtils = globalUtils.replace( + /.*globalStats\.version.*\n/, + " globalStats.version = '" + packageJson.version + "'\n" + ) + + fs.writeFileSync('./src/mappings/utils/globalUtils.ts', globalUtils, 'utf8') +} + +replaceVersion() diff --git a/src/mappings/utils/globalUtils.ts b/src/mappings/utils/globalUtils.ts index db2f4f7..ee5601a 100644 --- a/src/mappings/utils/globalUtils.ts +++ b/src/mappings/utils/globalUtils.ts @@ -14,6 +14,7 @@ export function getGlobalStats(): GlobalStatistic { let globalStats = GlobalStatistic.load(GLOBAL_ID) if (!globalStats) { globalStats = new GlobalStatistic(GLOBAL_ID) + globalStats.version = '1.2.0' globalStats.save() } return globalStats