This repository was archived by the owner on Nov 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathupdate-lib-flat-configs.ts
More file actions
85 lines (78 loc) · 2.36 KB
/
update-lib-flat-configs.ts
File metadata and controls
85 lines (78 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
This script updates `lib/configs/flat/*.js` files from rule's meta data.
*/
import fs from 'fs/promises'
import path from 'path'
import { format, Options } from 'prettier'
import prettierConfig from '../.prettierrc'
import { categories, TCategory } from './utils/categories'
import {
extendsCategories,
STORIES_GLOBS,
MAIN_JS_FILE,
formatRules,
formatSingleRule,
} from './utils/updates'
function formatCategory(category: TCategory) {
const extendsCategoryId = extendsCategories[category.categoryId]
if (extendsCategoryId == null) {
return `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content, execute "pnpm run update-all"
*/
export = [
{
name: 'storybook:${category.categoryId}:setup',
plugins: {
get storybook() {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require('../../index')
}
}
},
{
name: 'storybook:${category.categoryId}:stories-rules',
files: [${STORIES_GLOBS.join(', ')}],
rules: ${formatRules(category.rules, ['storybook/no-uninstalled-addons'])}
},
{
name: 'storybook:${category.categoryId}:main-rules',
files: [${MAIN_JS_FILE.join(', ')}],
rules: ${formatSingleRule(category.rules, 'storybook/no-uninstalled-addons')}
}
]
`
}
return `/*
* IMPORTANT!
* This file has been automatically generated,
* in order to update its content, execute "pnpm run update-all"
*/
import config from './${extendsCategoryId}'
export = [
...config,
{
name: 'storybook:${category.categoryId}:rules',
files: [${STORIES_GLOBS.join(', ')}],
rules: ${formatRules(category.rules)}
}
]
`
}
const FLAT_CONFIG_DIR = path.resolve(__dirname, '../lib/configs/flat')
export async function update() {
// setup config directory
await fs.mkdir(FLAT_CONFIG_DIR)
// Update/add rule files
await Promise.all(
categories.map(async (category) => {
const filePath = path.join(FLAT_CONFIG_DIR, `${category.categoryId}.ts`)
const content = await format(formatCategory(category), {
parser: 'typescript',
...(prettierConfig as Options),
})
await fs.writeFile(filePath, content)
})
)
}