|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +const gulp = require("gulp"); |
| 7 | + |
| 8 | +const ts = require("gulp-typescript"); |
| 9 | +const sourcemaps = require("gulp-sourcemaps"); |
| 10 | +const typescript = require("typescript"); |
| 11 | +const del = require("del"); |
| 12 | +const es = require("event-stream"); |
| 13 | +const vsce = require("vsce"); |
| 14 | +const nls = require("vscode-nls-dev"); |
| 15 | + |
| 16 | +const tsProject = ts.createProject("./tsconfig.json", { typescript }); |
| 17 | + |
| 18 | +const inlineMap = true; |
| 19 | +const inlineSource = false; |
| 20 | +const outDest = "out"; |
| 21 | + |
| 22 | +// A list of all locales supported by VSCode can be found here: https://code.visualstudio.com/docs/getstarted/locales |
| 23 | +const languages = [{ folderName: "en", id: "en" }]; |
| 24 | + |
| 25 | +gulp.task("clean", () => { |
| 26 | + return del( |
| 27 | + ["out/**", "package.nls.*.json", "../../dist/*0.0.0-UNTRACKEDVERSION.vsix"], |
| 28 | + { force: true } |
| 29 | + ); |
| 30 | +}); |
| 31 | + |
| 32 | +const pythonToMove = ["./src/adafruit_circuitplayground/*.*", "./src/*.py"]; |
| 33 | + |
| 34 | +gulp.task("python-compile", () => { |
| 35 | + // the base option sets the relative root for the set of files, |
| 36 | + // preserving the folder structure |
| 37 | + return gulp.src(pythonToMove, { base: "./src/" }).pipe(gulp.dest("out")); |
| 38 | +}); |
| 39 | + |
| 40 | +gulp.task("internal-compile", () => { |
| 41 | + return compile(false); |
| 42 | +}); |
| 43 | + |
| 44 | +gulp.task("internal-nls-compile", () => { |
| 45 | + return compile(true); |
| 46 | +}); |
| 47 | + |
| 48 | +gulp.task("add-locales", () => { |
| 49 | + return gulp |
| 50 | + .src(["package.nls.json"]) |
| 51 | + .pipe(nls.createAdditionalLanguageFiles(languages, "locales")) |
| 52 | + .pipe(gulp.dest(".")); |
| 53 | +}); |
| 54 | + |
| 55 | +gulp.task("vsce:publish", () => { |
| 56 | + return vsce.publish(); |
| 57 | +}); |
| 58 | + |
| 59 | +gulp.task("vsce:package", () => { |
| 60 | + return vsce.createVSIX({ |
| 61 | + packagePath: "../../dist/pacifica-0.0.0-UNTRACKEDVERSION.vsix" |
| 62 | + }); |
| 63 | +}); |
| 64 | + |
| 65 | +gulp.task( |
| 66 | + "compile", |
| 67 | + gulp.series("clean", "internal-compile", "python-compile", callback => { |
| 68 | + callback(); |
| 69 | + }) |
| 70 | +); |
| 71 | + |
| 72 | +gulp.task( |
| 73 | + "build", |
| 74 | + gulp.series( |
| 75 | + "clean", |
| 76 | + "internal-nls-compile", |
| 77 | + "python-compile", |
| 78 | + "add-locales", |
| 79 | + callback => { |
| 80 | + callback(); |
| 81 | + } |
| 82 | + ) |
| 83 | +); |
| 84 | + |
| 85 | +gulp.task( |
| 86 | + "publish", |
| 87 | + gulp.series("compile", "vsce:publish", callback => { |
| 88 | + callback(); |
| 89 | + }) |
| 90 | +); |
| 91 | + |
| 92 | +gulp.task( |
| 93 | + "package", |
| 94 | + gulp.series("compile", "vsce:package", callback => { |
| 95 | + callback(); |
| 96 | + }) |
| 97 | +); |
| 98 | + |
| 99 | +//---- internal |
| 100 | + |
| 101 | +function compile(buildNls) { |
| 102 | + var r = tsProject |
| 103 | + .src() |
| 104 | + .pipe(sourcemaps.init()) |
| 105 | + .pipe(tsProject()) |
| 106 | + .js.pipe(buildNls ? nls.rewriteLocalizeCalls() : es.through()) |
| 107 | + .pipe( |
| 108 | + buildNls |
| 109 | + ? nls.createAdditionalLanguageFiles(languages, "locales", "out") |
| 110 | + : es.through() |
| 111 | + ); |
| 112 | + |
| 113 | + if (inlineMap && inlineSource) { |
| 114 | + r = r.pipe(sourcemaps.write()); |
| 115 | + } else { |
| 116 | + r = r.pipe( |
| 117 | + sourcemaps.write("../out", { |
| 118 | + // no inlined source |
| 119 | + includeContent: inlineSource, |
| 120 | + // Return relative source map root directories per file. |
| 121 | + sourceRoot: "../src" |
| 122 | + }) |
| 123 | + ); |
| 124 | + } |
| 125 | + |
| 126 | + return r.pipe(gulp.dest(outDest)); |
| 127 | +} |
0 commit comments