This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
99 lines (85 loc) · 2.48 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
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 inputGrammar = 'src/apex.tmLanguage.yml';
const inputSoqlGrammarTemplate = 'src/soql.tmLanguage.template.yml';
const grammarsDirectory = 'grammars/';
const jsOut = 'out/';
function handleError(err) {
console.log(err.toString());
process.exit(-1);
}
gulp.task('buildTmLanguage', function (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, 'apex.tmLanguage'), plistData);
done();
});
gulp.task('buildAtom', function () {
return gulp
.src(inputGrammar)
.pipe(yaml())
.pipe(json2cson())
.pipe(gulp.dest(grammarsDirectory))
.on('error', handleError);
});
gulp.task('buildSoqlTmLanguage', function (done) {
const soqlGrammar = js_yaml.load(fs.readFileSync(inputSoqlGrammarTemplate));
const apexGrammar = js_yaml.load(fs.readFileSync(inputGrammar));
if (!fs.existsSync(grammarsDirectory)) {
fs.mkdirSync(grammarsDirectory);
}
// Merge the repository of rules from Apex grammar
soqlGrammar['repository'] = Object.assign(
{},
apexGrammar.repository,
soqlGrammar['repository']
);
// Remove the comments rule SOQL query expression
const apexGrammarSoqlExpressionPatterns =
apexGrammar['repository']['soql-query-expression']['patterns'];
soqlGrammar['repository']['soql-query-expression']['patterns'] =
apexGrammarSoqlExpressionPatterns.filter(
(pattern) => pattern.include !== '#comment'
);
fs.writeFileSync(
path.join(grammarsDirectory, 'soql.tmLanguage'),
plist.build(soqlGrammar)
);
done();
});
gulp.task('compile', function () {
const tsProject = ts.createProject('./tsconfig.json');
return tsProject
.src()
.pipe(tsProject())
.pipe(gulp.dest(jsOut + 'test'));
});
gulp.task(
'test',
gulp.series(['compile'], () => {
return gulp
.src(jsOut + 'test/**/*.tests.js')
.pipe(mocha())
.on('error', handleError);
})
);
gulp.task(
'default',
gulp.series(
['buildAtom', 'buildTmLanguage', 'buildSoqlTmLanguage'],
function (done) {
done();
}
)
);