forked from live-codes/livecodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvscode-intellisense.js
More file actions
69 lines (63 loc) · 1.93 KB
/
Copy pathvscode-intellisense.js
File metadata and controls
69 lines (63 loc) · 1.93 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
const fs = require('fs');
const path = require('path');
/**
* Add new custom data attributes for HTML intellisense here.
*
* To add new translatable attributes, add the attribute name to `I18nAttributes` in `src/livecodes/i18n/locales/models.ts`.
*/
const customDataSchema = {
version: 1.1,
globalAttributes: [
{
name: 'data-i18n',
description: 'The key of the translation for current element.',
},
{
name: 'data-i18n-prop',
description: 'Attributes of the element that should be translated, separated by space.',
valueSet: 'i18nProps',
},
{
name: 'data-hint',
description: 'The tooltip of the element.',
},
],
valueSets: [],
};
const generateHTMLIntellisense = async () => {
const generateI18nPropsValueSet = () => {
return new Promise((resolve, reject) => {
fs.readFile('src/livecodes/i18n/locales/models.ts', 'utf8', (err, data) => {
if (err) {
console.error(err);
reject(err);
} else {
const i18nProps = data
.match(/I18nAttributes.+?{([\s\S]*?)}/)[1]
.split('\n')
.map(
(line) =>
line
.trim()
.replace(/['|;?]/g, '')
.split(':')[0],
)
.filter((line) => line !== '');
customDataSchema.valueSets.push({
name: customDataSchema.globalAttributes[1].valueSet,
values: i18nProps.map((value) => ({ name: value })),
});
resolve();
}
});
});
};
await generateI18nPropsValueSet();
const schemaPath = path.resolve(__dirname, '../.vscode/html.html-data.json');
fs.writeFileSync(schemaPath, JSON.stringify(customDataSchema, null, 2));
console.log(`HTML Intellisense schema generated at ${schemaPath}`);
};
module.exports = { generateHTMLIntellisense };
if (require.main === module) {
generateHTMLIntellisense();
}