-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
101 lines (82 loc) · 2.79 KB
/
gulpfile.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
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
const gulp = require("gulp");
const mocha = require("gulp-mocha");
const json2cson = require("gulp-json2cson");
const yaml = require("gulp-yaml");
const ts = require("gulp-typescript");
const js_yaml = require("js-yaml");
const plist = require("plist");
const fs = require("fs");
const path = require("path");
const exec = require("child_process").exec;
const inputGrammar = "src/vein.tmLanguage.yml";
const grammarsDirectory = "grammars/";
const jsOut = "out/";
function handleError(err) {
console.log(err.toString());
process.exit(-1);
}
gulp.task('buildTmLanguage', done => {
const text = fs.readFileSync(inputGrammar);
const jsonData = js_yaml.load(text);
const plistData = plist.build(jsonData);
if (!fs.existsSync(grammarsDirectory)) {
fs.mkdirSync(grammarsDirectory);
}
fs.writeFileSync(path.join(grammarsDirectory, 'vein.tmLanguage'), plistData);
done();
});
gulp.task('buildVSCode', done => {
const text = fs.readFileSync(inputGrammar);
const jsonData = js_yaml.load(text);
if (!fs.existsSync(grammarsDirectory)) {
fs.mkdirSync(grammarsDirectory);
}
// These fields aren't used.
jsonData.uuid = undefined;
jsonData.fileTypes = undefined;
// Get the SHA of the last commit.
exec("git rev-parse HEAD", (err, stdout, stderr) => {
if (err) {
handleErr(err);
}
const commitSha = stdout.trim();
const enhancedJson = {
"information_for_contributors": [
"This file has been converted from https://github.com/vein-lang/tmLanguage/blob/master/grammars/vein.tmLanguage",
"If you want to provide a fix or improvement, please create a pull request against the original repository.",
"Once accepted there, we are happy to receive an update request."
],
"version": `https://github.com/vein-lang/tmLanguage/commit/${commitSha}`,
...jsonData
}
fs.writeFileSync(path.join(grammarsDirectory, 'vein.tmLanguage.json'), JSON.stringify(enhancedJson, null, '\t'));
done();
});
});
gulp.task('buildAtom', () => {
return gulp.src(inputGrammar)
.pipe(yaml())
.pipe(json2cson())
.pipe(gulp.dest(grammarsDirectory))
.on("error", handleError);
});
/*
gulp.task('compile', () => {
const tsProject = ts.createProject("./tsconfig.json");
return tsProject.src()
.pipe(tsProject())
.pipe(gulp.dest(jsOut));
});
*/
//gulp.task('test', gulp.series('compile', done => {
// const result = gulp.src(jsOut + "test/**/*.tests.js")
// .pipe(mocha())
// .on("error", handleError);
//
// done();
//
// return result;
//}));
gulp.task('default',
gulp.series(
gulp.parallel('buildAtom', 'buildVSCode', 'buildTmLanguage')));