@@ -2,6 +2,7 @@ import path from "path"
22import fs from "fs"
33import { rules } from "../src/utils/rules"
44import type { RuleModule } from "../src/types"
5+ import { getNewVersion } from "./lib/changesets-util"
56
67//eslint-disable-next-line require-jsdoc -- tools
78function formatItems ( items : string [ ] ) {
@@ -24,7 +25,7 @@ function yamlValue(val: unknown) {
2425const ROOT = path . resolve ( __dirname , "../docs/rules" )
2526
2627//eslint-disable-next-line require-jsdoc -- tools
27- function pickSince ( content : string ) : string | null {
28+ function pickSince ( content : string ) : string | null | Promise < string > {
2829 const fileIntro = / ^ - - - \n ( (?: .* \n ) + ) - - - \n * / . exec ( content )
2930 if ( fileIntro ) {
3031 const since = / s i n c e : " ? ( v \d + \. \d + \. \d + ) " ? / . exec ( fileIntro [ 1 ] )
@@ -37,6 +38,10 @@ function pickSince(content: string): string | null {
3738 // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports -- ignore
3839 return `v${ require ( "../package.json" ) . version } `
3940 }
41+ // eslint-disable-next-line no-process-env -- ignore
42+ if ( process . env . IN_VERSION_CI_SCRIPT ) {
43+ return getNewVersion ( ) . then ( ( v ) => `v${ v } ` )
44+ }
4045 return null
4146}
4247
@@ -47,7 +52,7 @@ class DocFile {
4752
4853 private content : string
4954
50- private readonly since : string | null
55+ private readonly since : string | null | Promise < string >
5156
5257 public constructor ( rule : RuleModule ) {
5358 this . rule = rule
@@ -135,15 +140,15 @@ class DocFile {
135140 return this
136141 }
137142
138- public updateFooter ( ) {
143+ public async updateFooter ( ) {
139144 const { ruleName, extensionRule } = this . rule . meta . docs
140145 const footerPattern =
141146 / # # (?: (?: : m a g : ) ? ? I m p l e m e n t a t i o n | : r o c k e t : V e r s i o n ) .+ $ / s
142147 const footer = `${
143148 this . since
144149 ? `## :rocket: Version
145150
146- This rule was introduced in eslint-plugin-svelte ${ this . since }
151+ This rule was introduced in eslint-plugin-svelte ${ await this . since }
147152
148153`
149154 : ""
203208 return this
204209 }
205210
206- public updateFileIntro ( ) {
211+ public async updateFileIntro ( ) {
207212 const { ruleId, description } = this . rule . meta . docs
208213
209214 const fileIntro = {
210215 pageClass : "rule-details" ,
211216 sidebarDepth : 0 ,
212217 title : ruleId ,
213218 description,
214- ...( this . since ? { since : this . since } : { } ) ,
219+ ...( this . since ? { since : await this . since } : { } ) ,
215220 }
216221 const computed = `---\n${ Object . keys ( fileIntro )
217222 // eslint-disable-next-line @typescript-eslint/no-explicit-any -- tool
239244 }
240245}
241246
242- for ( const rule of rules ) {
243- DocFile . read ( rule )
244- . updateHeader ( )
245- . updateFooter ( )
246- . updateCodeBlocks ( )
247- . updateFileIntro ( )
248- . adjustCodeBlocks ( )
249- . write ( )
247+ void main ( )
248+
249+ /** main */
250+ async function main ( ) {
251+ for ( const rule of rules ) {
252+ const doc = DocFile . read ( rule )
253+ doc . updateHeader ( )
254+ await doc . updateFooter ( )
255+ doc . updateCodeBlocks ( )
256+ await doc . updateFileIntro ( )
257+ doc . adjustCodeBlocks ( )
258+ doc . write ( )
259+ }
250260}
0 commit comments