@@ -2,6 +2,7 @@ import path from "path"
2
2
import fs from "fs"
3
3
import { rules } from "../src/utils/rules"
4
4
import type { RuleModule } from "../src/types"
5
+ import { getNewVersion } from "./lib/changesets-util"
5
6
6
7
//eslint-disable-next-line require-jsdoc -- tools
7
8
function formatItems ( items : string [ ] ) {
@@ -24,7 +25,7 @@ function yamlValue(val: unknown) {
24
25
const ROOT = path . resolve ( __dirname , "../docs/rules" )
25
26
26
27
//eslint-disable-next-line require-jsdoc -- tools
27
- function pickSince ( content : string ) : string | null {
28
+ function pickSince ( content : string ) : string | null | Promise < string > {
28
29
const fileIntro = / ^ - - - \n ( (?: .* \n ) + ) - - - \n * / . exec ( content )
29
30
if ( fileIntro ) {
30
31
const since = / s i n c e : " ? ( v \d + \. \d + \. \d + ) " ? / . exec ( fileIntro [ 1 ] )
@@ -37,6 +38,10 @@ function pickSince(content: string): string | null {
37
38
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports -- ignore
38
39
return `v${ require ( "../package.json" ) . version } `
39
40
}
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
+ }
40
45
return null
41
46
}
42
47
@@ -47,7 +52,7 @@ class DocFile {
47
52
48
53
private content : string
49
54
50
- private readonly since : string | null
55
+ private readonly since : string | null | Promise < string >
51
56
52
57
public constructor ( rule : RuleModule ) {
53
58
this . rule = rule
@@ -135,15 +140,15 @@ class DocFile {
135
140
return this
136
141
}
137
142
138
- public updateFooter ( ) {
143
+ public async updateFooter ( ) {
139
144
const { ruleName, extensionRule } = this . rule . meta . docs
140
145
const footerPattern =
141
146
/ # # (?: (?: : 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
142
147
const footer = `${
143
148
this . since
144
149
? `## :rocket: Version
145
150
146
- This rule was introduced in eslint-plugin-svelte ${ this . since }
151
+ This rule was introduced in eslint-plugin-svelte ${ await this . since }
147
152
148
153
`
149
154
: ""
203
208
return this
204
209
}
205
210
206
- public updateFileIntro ( ) {
211
+ public async updateFileIntro ( ) {
207
212
const { ruleId, description } = this . rule . meta . docs
208
213
209
214
const fileIntro = {
210
215
pageClass : "rule-details" ,
211
216
sidebarDepth : 0 ,
212
217
title : ruleId ,
213
218
description,
214
- ...( this . since ? { since : this . since } : { } ) ,
219
+ ...( this . since ? { since : await this . since } : { } ) ,
215
220
}
216
221
const computed = `---\n${ Object . keys ( fileIntro )
217
222
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- tool
239
244
}
240
245
}
241
246
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
+ }
250
260
}
0 commit comments