forked from Thinkmill/keystatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-prism.cts
82 lines (79 loc) · 1.49 KB
/
build-prism.cts
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
import fs from 'fs/promises';
const languages = [
'clike',
'c',
'cpp',
'arduino',
'bash',
'csharp',
'markup',
'css',
'diff',
'go',
'ini',
'java',
'regex',
'javascript',
'jsx',
'json',
'kotlin',
'less',
'lua',
'makefile',
'yaml',
'markdown',
'objectivec',
'perl',
'markup-templating',
'php',
'python',
'r',
'ruby',
'rust',
'sass',
'scss',
'sql',
'swift',
'typescript',
'tsx',
'basic',
'vbnet',
];
(async () => {
const otherLanguages = (
await Promise.all(
languages.map(lang =>
fs.readFile(require.resolve(`prismjs/components/prism-${lang}`), 'utf8')
)
)
).join('\n\n');
const prism = (await fs.readFile(require.resolve('prismjs'), 'utf8'))
.replace(
`if (typeof module !== 'undefined' && module.exports) {
\tmodule.exports = Prism;
}
// hack for components to work correctly in node.js
if (typeof global !== 'undefined') {
\tglobal.Prism = Prism;
}`,
''
)
.replace(
`var _self = (typeof window !== 'undefined')
? window // if in browser
: (
(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
? self // if in worker
: {} // if in node js
);`,
`var _self = globalThis;`
);
await fs.writeFile(
`${__dirname}/../src/form/fields/document/DocumentEditor/prism.js`,
'/* eslint-disable */\nglobalThis.Prism = { manual: true };\n' +
prism +
'\n' +
otherLanguages +
'\nexport default Prism;'
);
})();