Skip to content

Commit 4f342ad

Browse files
committed
✨ add version to rc file
1 parent 9bcac7b commit 4f342ad

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

packages/code-style/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
],
3939
"scripts": {
4040
"build": "concurrently --group --prefix none \"npm:build:*\"",
41-
"build:jsonschema": "typescript-json-schema src/config-types.ts CodeStyleSetupOptions > codestylerc.schema.json",
41+
"build:jsonschema": "typescript-json-schema src/config-types.ts CodeStyleRCFile > codestylerc.schema.json",
4242
"build:ts": "tsc",
4343
"lint": "eslint . --ext ts,mts,cts,js,json",
4444
"prepublishOnly": "npm run build",

packages/code-style/src/config-types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ export interface CodeStyleSetupOptions {
3434
/** Whether or not to overwrite files. */
3535
overwrite: boolean;
3636
}
37+
38+
export interface CodeStyleRCFile extends CodeStyleSetupOptions {
39+
/** The version of code-style that generated the rc file */
40+
version: string;
41+
}

packages/create-configs/src/rc-file.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { access, readFile, writeFile } from 'node:fs/promises';
22
import { URL } from 'node:url';
33
import { parse, stringify } from 'yaml';
4-
import type { CodeStyleSetupOptions } from '@code-style/code-style/config-types';
4+
import type {
5+
CodeStyleSetupOptions,
6+
CodeStyleRCFile,
7+
} from '@code-style/code-style/config-types';
8+
import { version } from './utils.js';
59

610
export const default_config_path = '.codestyleinitrc.yaml';
711

@@ -12,15 +16,15 @@ export interface LoadRCOptions {
1216
export async function load_rc({
1317
config_path = default_config_path,
1418
throw_no_config = false,
15-
}: LoadRCOptions = {}): Promise<Partial<CodeStyleSetupOptions>> {
19+
}: LoadRCOptions = {}): Promise<Partial<CodeStyleRCFile>> {
1620
const found = await access(config_path)
1721
.then(() => true)
1822
.catch(() => false);
1923
if (found) {
2024
return readFile(config_path)
2125
.then((buf) => buf.toString())
22-
.then<Partial<CodeStyleSetupOptions>>(
23-
(str) => (parse(str) ?? {}) as Partial<CodeStyleSetupOptions>,
26+
.then<Partial<CodeStyleRCFile>>(
27+
(str) => (parse(str) ?? {}) as Partial<CodeStyleRCFile>,
2428
)
2529
.catch((err: unknown) => {
2630
if (throw_no_config) throw err;
@@ -50,7 +54,7 @@ export async function save_rc(
5054
.then<string>((pkg) => pkg.version as string);
5155

5256
const header = `# yaml-language-server: $schema=https://github.com/dudeofawesome/code-style/releases/download/v${package_version}/codestylerc.schema.json`;
53-
const contents = `${header}\n\n${stringify(config)}`;
57+
const contents = `${header}\n\n${stringify({ version, ...config })}`;
5458

5559
await writeFile(config_path, contents);
5660
}

0 commit comments

Comments
 (0)