-
Notifications
You must be signed in to change notification settings - Fork 34
/
gulpfile.mjs
103 lines (82 loc) · 2.95 KB
/
gulpfile.mjs
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
102
103
import { task, src, dest, series, parallel } from "gulp";
import mocha from "gulp-mocha";
import json2cson from "gulp-json2cson";
import yaml from "gulp-yaml";
import gulpTypescript from 'gulp-typescript';
const { createProject } = gulpTypescript;
import { load } from "js-yaml";
import plist from 'plist';
const { build } = plist;
import { readFileSync, existsSync, mkdirSync, writeFileSync } from "fs";
import { join } from "path";
import { exec } from "child_process";
const inputGrammar = "src/csharp.tmLanguage.yml";
const grammarsDirectory = "grammars/";
const jsOut = "out/";
function handleError(err) {
console.log(err.toString());
process.exit(-1);
}
task('buildTmLanguage', done => {
const text = readFileSync(inputGrammar);
const jsonData = load(text);
const plistData = build(jsonData);
if (!existsSync(grammarsDirectory)) {
mkdirSync(grammarsDirectory);
}
writeFileSync(join(grammarsDirectory, 'csharp.tmLanguage'), plistData);
done();
});
task('buildVSCode', done => {
const text = readFileSync(inputGrammar);
const jsonData = load(text);
if (!existsSync(grammarsDirectory)) {
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();
// Add the additional properties used in the VSCode repo.
const enhancedJson = {
"information_for_contributors": [
"This file has been converted from https://github.com/dotnet/csharp-tmLanguage/blob/main/grammars/csharp.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/dotnet/csharp-tmLanguage/commit/${commitSha}`,
...jsonData
}
writeFileSync(join(grammarsDirectory, 'csharp.tmLanguage.json'), JSON.stringify(enhancedJson, null, '\t'));
done();
});
});
task('buildAtom', () => {
return src(inputGrammar)
.pipe(yaml())
.pipe(json2cson())
.pipe(dest(grammarsDirectory))
.on("error", handleError);
});
task('compile', () => {
const tsProject = createProject("./tsconfig.json");
return tsProject.src()
.pipe(tsProject())
.pipe(dest(jsOut));
});
task('test', series('compile', done => {
const result = src(jsOut + "test/**/*.tests.js")
.pipe(mocha())
.on("error", handleError);
done();
return result;
}));
task('default',
series(
parallel('buildAtom', 'buildVSCode', 'buildTmLanguage'),
'test'));