Skip to content

Commit

Permalink
get version const from tools package
Browse files Browse the repository at this point in the history
  • Loading branch information
rsek committed Dec 8, 2023
1 parent b0db4eb commit bd04ee2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "datasworn-tools",
"name": "@datasworn/tools",
"version": "0.0.5",
"description": "",
"type": "module",
Expand All @@ -9,21 +9,28 @@
"build:schema": "ts-node ./src/scripts/schema/buildSchema.ts",
"build:jtd": "ts-node ./src/scripts/json-typedef/index.ts",
"build:dts": "ts-node ./src/scripts/codegen/writeTypescriptTypes.ts",
"build:tools": "tsc --project tsconfig.json ; tsc-alias -p tsconfig.json ./dist",
"build:json": "ts-node ./src/scripts/datasworn/writeDatasworn.ts",
"build:pkg": "ts-node ./src/scripts/pkg/nodejs/buildPackages.ts",
"build": "ts-node ./src/scripts/pkg/nodejs/updatePackageVersions.ts && npm run build:schema && npm run build:jtd && npm run build:dts && npm run build:json && npm run build:pkg",
"pkg:node": "ts-node ./src/scripts/pkg/nodejs/publishPackages.ts"
},
"files": ["docs", "img", "markdown"],
"files": [
"docs",
"img",
"markdown"
],
"directories": {
"doc": "./docs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rsek/datasworn.git"
},
"keywords": ["ironsworn", "starforged", "TTRPG"],
"keywords": [
"ironsworn",
"starforged",
"TTRPG"
],
"author": {
"name": "rsek",
"email": "r.sekouri@gmail.com",
Expand Down Expand Up @@ -77,4 +84,4 @@
"winston": "^3.11.0",
"yaml": "^2.3.4"
}
}
}
7 changes: 6 additions & 1 deletion src/scripts/const.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import path from 'path'
import fs from 'fs-extra'

const toolsPkg = fs.readJSONSync(path.join(process.cwd(), 'package.json')) as {
version: string
}

export const PKG_NAME = 'Datasworn'

export const VERSION = '0.0.5'
export const VERSION = toolsPkg.version

export const PKG_SCOPE_OFFICIAL = '@datasworn'
export const PKG_SCOPE_COMMUNITY = '@datasworn-community-content'
Expand Down
43 changes: 22 additions & 21 deletions src/scripts/pkg/nodejs/updatePackageVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,32 @@ export async function updatePackageVersions(
const pattern =
/^(?<headerText># .+? v)(?<version>(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)/

for (const filePath of [...pkgs, path.join(process.cwd(), 'package.json')])
toWrite.push(
fs.readJSON(filePath).then(async (json) => {
const oldVersion = json?.version as string


for (const filePath of pkgs)
toWrite.push(
fs.readJSON(filePath).then(async (json) => {
const oldVersion = json?.version as string

if (oldVersion !== newVersion) {
Log.info(
`Updating from v${oldVersion} to v${newVersion} in ./${path.relative(
process.cwd(),
filePath
)}`
)
json.version = newVersion
}
if (oldVersion !== newVersion) {
Log.info(
`Updating from v${oldVersion} to v${newVersion} in ./${path.relative(
process.cwd(),
filePath
)}`
)
json.version = newVersion
}

const newDependencies = mapValues(json.dependencies as Record<string, string>, (value, key) => key.startsWith('@datasworn/') ? newVersion : value)
const newDependencies = mapValues(
json.dependencies as Record<string, string>,
(value, key) => (key.startsWith('@datasworn/') ? newVersion : value)
)

if (!isEqual(json.dependencies, newDependencies))
json.dependencies = newDependencies
if (!isEqual(json.dependencies, newDependencies))
json.dependencies = newDependencies

return writeJSON(filePath, json)
})
)
return writeJSON(filePath, json)
})
)

for (const filePath of readmes) {
toWrite.push(
Expand Down

0 comments on commit bd04ee2

Please sign in to comment.