Skip to content

Commit d4ce784

Browse files
authored
chore: change changesets config (#237)
1 parent 634ba94 commit d4ce784

File tree

6 files changed

+59
-18
lines changed

6 files changed

+59
-18
lines changed

.env-cmdrc

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"version": {
33
"IN_VERSION_SCRIPT": "true"
44
},
5+
"version-ci": {
6+
"IN_VERSION_CI_SCRIPT": "true"
7+
},
58
"debug": {
69
"DEBUG": "eslint-plugin-svelte*"
710
}

.github/workflows/Release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
uses: changesets/action@v1
3030
with:
3131
# this expects you to have a npm script called version that runs some logic and then calls `changeset version`.
32-
version: yarn version
32+
version: yarn version:ci
3333
# This expects you to have a script called release which does a build for your packages and calls changeset publish
3434
publish: yarn release
3535
commit: "chore: release eslint-plugin-svelte"

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.svelte-kit
22
.type-coverage
33
build
4-
lib
4+
/lib

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"ts": "node -r esbuild-register",
5252
"typecov": "type-coverage",
5353
"update": "yarn ts ./tools/update.ts && yarn format-for-gen-file",
54-
"version": "env-cmd -e version yarn update && changeset version"
54+
"version": "env-cmd -e version yarn update",
55+
"version:ci": "env-cmd -e version-ci yarn update && changeset version"
5556
},
5657
"peerDependencies": {
5758
"eslint": "^7.0.0 || ^8.0.0-0",
@@ -169,7 +170,7 @@
169170
"access": "public"
170171
},
171172
"typeCoverage": {
172-
"atLeast": 98.63,
173+
"atLeast": 98.64,
173174
"cache": true,
174175
"detail": true,
175176
"ignoreAsAssertion": true,

tools/lib/changesets-util.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import assembleReleasePlan from "@changesets/assemble-release-plan"
2+
import readChangesets from "@changesets/read"
3+
import { read } from "@changesets/config"
4+
import { getPackages } from "@manypkg/get-packages"
5+
import { readPreState } from "@changesets/pre"
6+
import path from "path"
7+
8+
const root = path.resolve(__dirname, "../..")
9+
10+
/** Get new version string from changesets */
11+
export async function getNewVersion(): Promise<string> {
12+
const packages = await getPackages(root)
13+
const preState = await readPreState(root)
14+
const config = await read(root, packages)
15+
const changesets = await readChangesets(root)
16+
17+
const releasePlan = assembleReleasePlan(
18+
changesets,
19+
packages,
20+
config,
21+
preState,
22+
)
23+
24+
return releasePlan.releases.find(
25+
({ name }) => name === "eslint-plugin-svelte",
26+
)!.newVersion
27+
}

tools/update-docs.ts

+24-14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "path"
22
import fs from "fs"
33
import { rules } from "../src/utils/rules"
44
import type { RuleModule } from "../src/types"
5+
import { getNewVersion } from "./lib/changesets-util"
56

67
//eslint-disable-next-line require-jsdoc -- tools
78
function formatItems(items: string[]) {
@@ -24,7 +25,7 @@ function yamlValue(val: unknown) {
2425
const 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 = /since: "?(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
/## (?:(?::mag:)? ?Implementation|:rocket: Version).+$/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
: ""
@@ -203,15 +208,15 @@ ${
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
@@ -239,12 +244,17 @@ ${
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

Comments
 (0)