Skip to content

chore: change changesets config #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env-cmdrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"version": {
"IN_VERSION_SCRIPT": "true"
},
"version-ci": {
"IN_VERSION_CI_SCRIPT": "true"
},
"debug": {
"DEBUG": "eslint-plugin-svelte*"
}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
uses: changesets/action@v1
with:
# this expects you to have a npm script called version that runs some logic and then calls `changeset version`.
version: yarn version
version: yarn version:ci
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
commit: "chore: release eslint-plugin-svelte"
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.svelte-kit
.type-coverage
build
lib
/lib
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"ts": "node -r esbuild-register",
"typecov": "type-coverage",
"update": "yarn ts ./tools/update.ts && yarn format-for-gen-file",
"version": "env-cmd -e version yarn update && changeset version"
"version": "env-cmd -e version yarn update",
"version:ci": "env-cmd -e version-ci yarn update && changeset version"
},
"peerDependencies": {
"eslint": "^7.0.0 || ^8.0.0-0",
Expand Down Expand Up @@ -169,7 +170,7 @@
"access": "public"
},
"typeCoverage": {
"atLeast": 98.63,
"atLeast": 98.64,
"cache": true,
"detail": true,
"ignoreAsAssertion": true,
Expand Down
27 changes: 27 additions & 0 deletions tools/lib/changesets-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import assembleReleasePlan from "@changesets/assemble-release-plan"
import readChangesets from "@changesets/read"
import { read } from "@changesets/config"
import { getPackages } from "@manypkg/get-packages"
import { readPreState } from "@changesets/pre"
import path from "path"

const root = path.resolve(__dirname, "../..")

/** Get new version string from changesets */
export async function getNewVersion(): Promise<string> {
const packages = await getPackages(root)
const preState = await readPreState(root)
const config = await read(root, packages)
const changesets = await readChangesets(root)

const releasePlan = assembleReleasePlan(
changesets,
packages,
config,
preState,
)

return releasePlan.releases.find(
({ name }) => name === "eslint-plugin-svelte",
)!.newVersion
}
38 changes: 24 additions & 14 deletions tools/update-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "path"
import fs from "fs"
import { rules } from "../src/utils/rules"
import type { RuleModule } from "../src/types"
import { getNewVersion } from "./lib/changesets-util"

//eslint-disable-next-line require-jsdoc -- tools
function formatItems(items: string[]) {
Expand All @@ -24,7 +25,7 @@ function yamlValue(val: unknown) {
const ROOT = path.resolve(__dirname, "../docs/rules")

//eslint-disable-next-line require-jsdoc -- tools
function pickSince(content: string): string | null {
function pickSince(content: string): string | null | Promise<string> {
const fileIntro = /^---\n((?:.*\n)+)---\n*/.exec(content)
if (fileIntro) {
const since = /since: "?(v\d+\.\d+\.\d+)"?/.exec(fileIntro[1])
Expand All @@ -37,6 +38,10 @@ function pickSince(content: string): string | null {
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports -- ignore
return `v${require("../package.json").version}`
}
// eslint-disable-next-line no-process-env -- ignore
if (process.env.IN_VERSION_CI_SCRIPT) {
return getNewVersion().then((v) => `v${v}`)
}
return null
}

Expand All @@ -47,7 +52,7 @@ class DocFile {

private content: string

private readonly since: string | null
private readonly since: string | null | Promise<string>

public constructor(rule: RuleModule) {
this.rule = rule
Expand Down Expand Up @@ -135,15 +140,15 @@ class DocFile {
return this
}

public updateFooter() {
public async updateFooter() {
const { ruleName, extensionRule } = this.rule.meta.docs
const footerPattern =
/## (?:(?::mag:)? ?Implementation|:rocket: Version).+$/s
const footer = `${
this.since
? `## :rocket: Version

This rule was introduced in eslint-plugin-svelte ${this.since}
This rule was introduced in eslint-plugin-svelte ${await this.since}

`
: ""
Expand Down Expand Up @@ -203,15 +208,15 @@ ${
return this
}

public updateFileIntro() {
public async updateFileIntro() {
const { ruleId, description } = this.rule.meta.docs

const fileIntro = {
pageClass: "rule-details",
sidebarDepth: 0,
title: ruleId,
description,
...(this.since ? { since: this.since } : {}),
...(this.since ? { since: await this.since } : {}),
}
const computed = `---\n${Object.keys(fileIntro)
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- tool
Expand Down Expand Up @@ -239,12 +244,17 @@ ${
}
}

for (const rule of rules) {
DocFile.read(rule)
.updateHeader()
.updateFooter()
.updateCodeBlocks()
.updateFileIntro()
.adjustCodeBlocks()
.write()
void main()

/** main */
async function main() {
for (const rule of rules) {
const doc = DocFile.read(rule)
doc.updateHeader()
await doc.updateFooter()
doc.updateCodeBlocks()
await doc.updateFileIntro()
doc.adjustCodeBlocks()
doc.write()
}
}