This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
update.js
73 lines (58 loc) · 2.42 KB
/
update.js
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
const path = require('path')
const fs = require('fs')
const request = require('request')
const fetchTagDescriptions = require('./fetch-tag-docs')
const fetchGlobalAttributeDescriptions = require('./fetch-global-attribute-docs')
const TagsURL = 'https://raw.githubusercontent.com/adobe/brackets/master/src/extensions/default/HTMLCodeHints/HtmlTags.json'
const AttributesURL = 'https://raw.githubusercontent.com/adobe/brackets/master/src/extensions/default/HTMLCodeHints/HtmlAttributes.json'
const tagsPromise = new Promise((resolve) => {
request({json: true, url: TagsURL}, (error, response, tags) => {
if (error != null) {
console.error(error.message)
resolve(null)
}
if (response.statusCode !== 200) {
console.error(`Request for HtmlTags.json failed: ${response.statusCode}`)
resolve(null)
}
for (let tag in tags) {
const options = tags[tag]
if ((options.attributes != null ? options.attributes.length : undefined) === 0) { delete options.attributes }
}
resolve(tags)
})
})
const tagDescriptionsPromise = fetchTagDescriptions()
const attributesPromise = new Promise((resolve) => {
return request({json: true, url: AttributesURL}, (error, response, attributes) => {
if (error != null) {
console.error(error.message)
resolve(null)
}
if (response.statusCode !== 200) {
console.error(`Request for HtmlAttributes.json failed: ${response.statusCode}`)
resolve(null)
}
for (let attribute in attributes) {
const options = attributes[attribute]
if ((options.attribOption != null ? options.attribOption.length : undefined) === 0) { delete options.attribOption }
}
resolve(attributes)
})
})
const globalAttributeDescriptionsPromise = fetchGlobalAttributeDescriptions()
Promise.all([tagsPromise, tagDescriptionsPromise, attributesPromise, globalAttributeDescriptionsPromise]).then((values) => {
const tags = values[0]
const tagDescriptions = values[1]
const attributes = values[2]
const attributeDescriptions = values[3]
for (let tag in tags) {
tags[tag].description = tagDescriptions[tag]
}
for (let attribute in attributes) {
const options = attributes[attribute]
if (options.global) { attributes[attribute].description = attributeDescriptions[attribute] }
}
const completions = {tags, attributes}
fs.writeFileSync(path.join(__dirname, 'completions.json'), `${JSON.stringify(completions, null, ' ')}\n`)
})