Skip to content

Commit

Permalink
DEV: Update docs during build process (#12)
Browse files Browse the repository at this point in the history
closes #12
  • Loading branch information
dwhieb committed May 28, 2024
1 parent 2cee894 commit 921ebcb
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
6 changes: 3 additions & 3 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
authors:
- family-names: Hieber
given-names: Daniel W.
orcid: 'https://orcid.org/0000-0002-1411-3773'
given-names: Daniel W.
orcid: https://orcid.org/0000-0002-1411-3773
website: https://danielhieber.info
cff-version: 1.2.0
license: MIT
Expand All @@ -10,4 +10,4 @@ repository-code: https://github.com/digitallinguistics/tools
title: Tools for Linguistic Productivity (TooLiP)
type: software
url: https://tools.digitallinguistics.io
version: 0.1.0
version: 0.1.0
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Digital Linguistics
Copyright (c) 2013–2024 Daniel W. Hieber

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
50 changes: 50 additions & 0 deletions build/updateDocs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Updates the version number and dates in documentation.
* NOTE: This script is run using npm scripts rather than 11ty
* because it's not part of the website build, just the project build.
*/

import path from 'node:path'
import { readFile } from 'node:fs/promises'

import { outputFile, readJSON } from 'fs-extra/esm'

import {
parse as parseYAML,
stringify as stringifyYAML,
} from 'yaml'

const citationPath = path.resolve(import.meta.dirname, `../CITATION.cff`)
const licensePath = path.resolve(import.meta.dirname, `../LICENSE`)
const packagePath = path.resolve(import.meta.dirname, `../package.json`)

const yearRegExp = /(?<=[0-9]{4}\u2013)[0-9]{4}/v

async function updateCitation() {

const meta = await readJSON(packagePath)
const citationYAML = await readFile(citationPath, `utf8`)
const citationData = parseYAML(citationYAML)

citationData.version = meta.version

await outputFile(citationPath, stringifyYAML(citationData))

}

async function updateLicense() {

const currentYear = (new Date).getFullYear()
const licenseText = await readFile(licensePath, `utf8`)
const updatedText = licenseText.replace(yearRegExp, `${ currentYear }`)

await outputFile(licensePath, updatedText)

}

export default async function updateDocs() {
await updateCitation()
await updateLicense()
}

updateDocs()
15 changes: 14 additions & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"type": "module",
"scripts": {
"build": "eleventy",
"postbuild": "node build/updateDocs.js",
"start": "eleventy --serve"
},
"devDependencies": {
Expand All @@ -33,6 +34,7 @@
"@eslint/js": "^9.3.0",
"@stylistic/eslint-plugin-js": "^2.1.0",
"eslint": "^9.3.0",
"fs-extra": "^11.2.0"
"fs-extra": "^11.2.0",
"yaml": "^2.4.2"
}
}

0 comments on commit 921ebcb

Please sign in to comment.