-
Notifications
You must be signed in to change notification settings - Fork 21
/
sync.js
44 lines (38 loc) · 1.16 KB
/
sync.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
const CSON = require("cson")
const request = require('request')
const chalk = require('chalk')
const fs = require('fs')
const join = require('path').join
let getCSONFile = (url, callback) => {
request(url, function (error, response, body) {
if (error == null && response.statusCode == 200) {
console.log(chalk.green.bold(`Downloaded ${url}`))
callback(body)
} else {
console.log(chalk.red.bold(`Download ${url} failed`))
}
})
}
let toJSON = (text, name) => {
let space = "\t"
try {
let parsed = CSON.parse(text)
console.log(chalk.green.bold(`Translated ${name}`))
return JSON.stringify(parsed, null, space)
} catch (error) {
console.log(chalk.red.bold(`Translate ${name} failed`))
return null
}
}
let translate = (name) => {
let url = `https://raw.githubusercontent.com/idris-hackers/atom-language-idris/master/grammars/language-${name}.cson`
getCSONFile(url, (csonFile) => {
let jsonFile = toJSON(csonFile, name)
if (jsonFile == null) return
let file = join(__dirname, `/syntaxes/${name}.json`)
fs.writeFileSync(file, jsonFile)
})
}
translate("idris")
translate("ipkg")
translate("idris.literate")