@wtf/release-replace
v6.1.1
Published
Text replaced in the files of a repo, of no release tool, each function by the folder of the repo and the platform it is given: what a replacement is (.), each match of a RegExp of each file git tracks of paths, globs and negations replaced, and of a text
Maintainers
Readme
@wtf/release-replace
Text replaced in the files of a repo, with no release tool: each match of each replacement, in each
file git tracks of paths or globs, as the version of a release written into the badge of a README,
so the release commit commits it. A badge that names a version is wrong from the next release, and
nothing fails then. The library of
@wtf/semantic-release-replace, with no dependency on
semantic-release; each function reads and writes the files of the folder of the repo, a handle of
the File System standard, and runs git by the platform, as @wtf/release
has them, which its caller gives it.
As a library
A replacement replaces each match of from, the source of a RegExp, of its flags but g, which
it always has, by to, a text or a function:
- a text reads
$1,$2… and$<name>, each group of the match, asString.prototype.replacereads them, and${nextRelease.version}, each value of the context by its dotted path, as the message of@semantic-release/gitwrites one: a path the context has not fails withEVALUE.escapewrites each value as it is,none, the default; as the text of a badge of shields.io,shields, each-and_doubled; or as a component of a URL,url; - a function is given the match, its text, groups, named groups and index, the file, and the context, and gives the text it is replaced by, or a promise of one.
files are the files git tracks of paths and globs, in order, from the root of the repo: a path
holds the file, or each file under the folder; a glob, of
picomatch, each file it matches, * and ? within a
name, ** across folders, […] a class, [^…] one not of it, and {a,b} each of a list; and an
entry of ! first leaves out what it matches of what the entries before it hold.
A template is a replacement of a name, of templates: a replacement names it alone, as 'badge',
or with options over the template's own, as { template: 'badge', escape: 'none' }; a name of none
fails with ETEMPLATE, naming those there are. mergeTemplates merges sets of them in order, by
name, as a repo's own over those a package shares.
import type { RepoContext } from '@wtf/release'
import { replaceFiles } from '@wtf/release-replace/replace'
import { mergeTemplates } from '@wtf/release-replace/templates'
/** The version of a badge of shields.io, of any colour, as a package of templates shares it. */
const shared = {
badge: {
from: '(img\\.shields\\.io/badge/version-)[^)\\s"\'?#]*?(-[0-9A-Za-z]+(?:\\.svg)?(?=[)\\s"\'?#]|$))',
to: '$1${nextRelease.version}$2',
escape: 'shields' as const
}
}
export function replaceVersion({ root, platform }: RepoContext, version: string) {
return replaceFiles({
files: ['packages/**/README.md', '!packages/shared/**', 'src/version.ts'],
templates: mergeTemplates([
shared,
{ version: { from: '(VERSION = ")[^"]*(")', to: '$1${nextRelease.version}$2' } }
]),
replacements: [
'badge',
'version',
{ from: 'UNRELEASED', to: (_match, file) => `${version} of ${file}` }
],
context: { nextRelease: { version } },
root,
platform
})
}Only a file whose text changes is written; replaceFiles gives each it wrote.
| Export | What it is |
| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| @wtf/release-replace | The types of a replacement: Replacement, ReplacementSpec, Templates, ReplaceFunction |
| @wtf/release-replace/replace | replaceFiles, each file of paths or globs replaced; replaceText, a text; regExpOf |
| @wtf/release-replace/files | filesMatcher, the files of paths, globs and negations |
| @wtf/release-replace/values | textOf, the values of a context in the text of a replacement; escapeValue, valueAt |
| @wtf/release-replace/templates | resolveReplacements, the replacement of each template named; mergeTemplates, sets merged; noTemplate, the error of a name of none |
| @wtf/release-replace/errors | ReplaceError, the class of its errors, and their codes, REPLACE_ERRORS |
See Configuring trains.
License
MIT
