|
| 1 | +import { task, src, dest, series, parallel } from "gulp"; |
| 2 | +import mocha from "gulp-mocha"; |
| 3 | +import json2cson from "gulp-json2cson"; |
| 4 | +import yaml from "gulp-yaml"; |
| 5 | +import gulpTypescript from 'gulp-typescript'; |
| 6 | +const { createProject } = gulpTypescript; |
| 7 | +import { load } from "js-yaml"; |
| 8 | +import plist from 'plist'; |
| 9 | +const { build } = plist; |
| 10 | +import { readFileSync, existsSync, mkdirSync, writeFileSync } from "fs"; |
| 11 | +import { join } from "path"; |
| 12 | +import { exec } from "child_process"; |
| 13 | + |
| 14 | +const inputGrammar = "src/csharp.tmLanguage.yml"; |
| 15 | +const grammarsDirectory = "grammars/"; |
| 16 | +const jsOut = "out/"; |
| 17 | + |
| 18 | + |
| 19 | +function handleError(err) { |
| 20 | + console.log(err.toString()); |
| 21 | + process.exit(-1); |
| 22 | +} |
| 23 | + |
| 24 | +task('buildTmLanguage', done => { |
| 25 | + const text = readFileSync(inputGrammar); |
| 26 | + const jsonData = load(text); |
| 27 | + const plistData = build(jsonData); |
| 28 | + |
| 29 | + if (!existsSync(grammarsDirectory)) { |
| 30 | + mkdirSync(grammarsDirectory); |
| 31 | + } |
| 32 | + |
| 33 | + writeFileSync(join(grammarsDirectory, 'csharp.tmLanguage'), plistData); |
| 34 | + |
| 35 | + done(); |
| 36 | +}); |
| 37 | + |
| 38 | +task('buildVSCode', done => { |
| 39 | + const text = readFileSync(inputGrammar); |
| 40 | + const jsonData = load(text); |
| 41 | + |
| 42 | + if (!existsSync(grammarsDirectory)) { |
| 43 | + mkdirSync(grammarsDirectory); |
| 44 | + } |
| 45 | + |
| 46 | + // These fields aren't used. |
| 47 | + jsonData.uuid = undefined; |
| 48 | + jsonData.fileTypes = undefined; |
| 49 | + |
| 50 | + // Get the SHA of the last commit. |
| 51 | + exec("git rev-parse HEAD", (err, stdout, stderr) => { |
| 52 | + if (err) { |
| 53 | + handleErr(err); |
| 54 | + } |
| 55 | + |
| 56 | + const commitSha = stdout.trim(); |
| 57 | + |
| 58 | + // Add the additional properties used in the VSCode repo. |
| 59 | + const enhancedJson = { |
| 60 | + "information_for_contributors": [ |
| 61 | + "This file has been converted from https://github.com/dotnet/csharp-tmLanguage/blob/main/grammars/csharp.tmLanguage", |
| 62 | + "If you want to provide a fix or improvement, please create a pull request against the original repository.", |
| 63 | + "Once accepted there, we are happy to receive an update request." |
| 64 | + ], |
| 65 | + "version": `https://github.com/dotnet/csharp-tmLanguage/commit/${commitSha}`, |
| 66 | + ...jsonData |
| 67 | + } |
| 68 | + |
| 69 | + writeFileSync(join(grammarsDirectory, 'csharp.tmLanguage.json'), JSON.stringify(enhancedJson, null, '\t')); |
| 70 | + |
| 71 | + done(); |
| 72 | + }); |
| 73 | +}); |
| 74 | + |
| 75 | +task('buildAtom', () => { |
| 76 | + return src(inputGrammar) |
| 77 | + .pipe(yaml()) |
| 78 | + .pipe(json2cson()) |
| 79 | + .pipe(dest(grammarsDirectory)) |
| 80 | + .on("error", handleError); |
| 81 | +}); |
| 82 | + |
| 83 | +task('compile', () => { |
| 84 | + const tsProject = createProject("./tsconfig.json"); |
| 85 | + return tsProject.src() |
| 86 | + .pipe(tsProject()) |
| 87 | + .pipe(dest(jsOut)); |
| 88 | +}); |
| 89 | + |
| 90 | +task('test', series('compile', done => { |
| 91 | + const result = src(jsOut + "test/**/*.tests.js") |
| 92 | + .pipe(mocha()) |
| 93 | + .on("error", handleError); |
| 94 | + |
| 95 | + done(); |
| 96 | + |
| 97 | + return result; |
| 98 | +})); |
| 99 | + |
| 100 | +task('default', |
| 101 | + series( |
| 102 | + parallel('buildAtom', 'buildVSCode', 'buildTmLanguage'), |
| 103 | + 'test')); |
0 commit comments