-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathlanguages.ts
117 lines (106 loc) · 2.48 KB
/
languages.ts
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import fs from 'node:fs'
import LinguistLanguages from 'linguist-languages'
import type { SupportLanguage } from 'prettier'
const EXTRA_SH_LANGUAGES: SupportLanguage[] = [
{
name: 'JvmOptions',
since: '0.1.0',
parsers: ['sh'],
extensions: ['.vmoptions'],
filenames: ['jvm.options'],
vscodeLanguageIds: ['jvmoptions'],
},
{
name: 'hosts',
since: '0.1.0',
parsers: ['sh'],
filenames: ['hosts'],
vscodeLanguageIds: ['hosts'],
},
{
name: 'dotenv',
since: '0.1.0',
parsers: ['sh'],
extensions: ['.env'],
filenames: ['.env.*'],
vscodeLanguageIds: ['dotenv'],
},
{
name: 'nvmrc',
since: '0.14.0',
parsers: ['sh'],
extensions: ['.node-version', '.nvmrc'],
filenames: ['.node-version', '.nvmrc'],
},
]
const getSupportLanguages = (
parser: 'autocorrect' | 'sh' | 'sql' | 'toml',
aceModes: string[],
) =>
Object.values(LinguistLanguages).reduce<SupportLanguage[]>(
(
acc,
{
aceMode,
name,
type: _type,
color: _color,
languageId: linguistLanguageId,
...rest
},
) => {
if (!aceModes.includes('all') && !aceModes.includes(aceMode)) {
return acc
}
acc.push({
name,
aceMode,
since: '0.1.0',
parsers: [parser],
linguistLanguageId,
vscodeLanguageIds: [aceMode === 'sh' ? 'shellscript' : aceMode],
...rest,
})
return acc
},
[],
)
fs.writeFileSync(
'packages/autocorrect/src/languages.ts',
`import { SupportLanguage } from 'prettier'
export const languages = ${JSON.stringify(
getSupportLanguages('autocorrect', ['all']),
null,
2,
)} as SupportLanguage[]`,
)
fs.writeFileSync(
'packages/sh/src/languages.ts',
`import { SupportLanguage } from 'prettier'
export const languages = ${JSON.stringify(
[
...getSupportLanguages('sh', ['dockerfile', 'gitignore', 'sh']),
...EXTRA_SH_LANGUAGES,
],
null,
2,
)} as SupportLanguage[]`,
)
fs.writeFileSync(
'packages/sql/src/languages.ts',
`import { SupportLanguage } from 'prettier'
export const languages = ${JSON.stringify(
[...getSupportLanguages('sql', ['sql', 'pgsql'])],
null,
2,
)} as SupportLanguage[]`,
)
fs.writeFileSync(
'packages/toml/src/languages.ts',
`import { SupportLanguage } from 'prettier'
export const languages = ${JSON.stringify(
[...getSupportLanguages('toml', ['toml'])],
null,
2,
)} as SupportLanguage[]`,
)