microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
gulpfile.js
104lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. |
| 3 | |
| 4 | var child_process = require('child_process'); |
| 5 | var gulp = require('gulp'); |
| 6 | var log = require('gulp-util').log; |
| 7 | var sourcemaps = require('gulp-sourcemaps'); |
| 8 | var os = require('os'); |
| 9 | var path = require('path'); |
| 10 | var runSequence = require("run-sequence"); |
| 11 | var ts = require('gulp-typescript'); |
| 12 | var mocha = require('gulp-mocha'); |
| 13 | |
| 14 | var srcPath = 'src'; |
| 15 | var outPath = 'out'; |
| 16 | |
| 17 | var sources = [ |
| 18 | srcPath, |
| 19 | ].map(function (tsFolder) { return tsFolder + '/**/*.ts'; }) |
| 20 | .concat(['test/*.ts']); |
| 21 | |
| 22 | // TODO: The file property should point to the generated source (this implementation adds an extra folder to the path) |
| 23 | // We should also make sure that we always generate urls in all the path properties (We shouldn't have \\s. This seems to |
| 24 | // be an issue on Windows platforms) |
| 25 | gulp.task('build', ['checkImports'], function () { |
| 26 | var tsProject = ts.createProject('tsconfig.json'); |
| 27 | return tsProject.src() |
| 28 | .pipe(sourcemaps.init()) |
| 29 | .pipe(ts(tsProject)) |
| 30 | .pipe(sourcemaps.write('.', { |
| 31 | includeContent: false, |
| 32 | sourceRoot: function (file) { |
| 33 | return path.relative(path.dirname(file.path), __dirname + '/src'); |
| 34 | } |
| 35 | })) |
| 36 | .pipe(gulp.dest(outPath)); |
| 37 | }); |
| 38 | |
| 39 | gulp.task('watch', ['build'], function (cb) { |
| 40 | log('Watching build sources...'); |
| 41 | return gulp.watch(sources, ['build']); |
| 42 | }); |
| 43 | |
| 44 | gulp.task('default', function (callback) { |
| 45 | runSequence("clean", "build", "tslint", callback); |
| 46 | }); |
| 47 | |
| 48 | var lintSources = [ |
| 49 | srcPath, |
| 50 | ].map(function (tsFolder) { return tsFolder + '/**/*.ts'; }); |
| 51 | lintSources = lintSources.concat([ |
| 52 | '!src/typings/**' |
| 53 | ]); |
| 54 | |
| 55 | var tslint = require('gulp-tslint'); |
| 56 | gulp.task('tslint', function () { |
| 57 | return gulp.src(lintSources, { base: '.' }) |
| 58 | .pipe(tslint()) |
| 59 | .pipe(tslint.report('verbose')); |
| 60 | }); |
| 61 | |
| 62 | function test() { |
| 63 | return gulp.src(['out/test/**/*.test.js', '!out/test/extension/**']) |
| 64 | .pipe(mocha({ |
| 65 | ui: 'tdd', |
| 66 | useColors: true, |
| 67 | invert: true, |
| 68 | grep: "extensionContext" // Do not run tests intended for the extensionContext |
| 69 | })); |
| 70 | } |
| 71 | |
| 72 | gulp.task('build-test', ['build'], test); |
| 73 | gulp.task('test', test); |
| 74 | |
| 75 | gulp.task('checkImports', function (cb) { |
| 76 | var checkProcess = child_process.fork(path.join(__dirname, "tools", "checkCasing.js"), |
| 77 | { |
| 78 | cwd: path.resolve(__dirname, "src"), |
| 79 | stdio: "inherit" |
| 80 | }); |
| 81 | checkProcess.on("error", cb); |
| 82 | checkProcess.on("exit", function (code, signal) { |
| 83 | if (code || signal) { |
| 84 | cb(new Error("Mismatches found in import casing")); |
| 85 | } else { |
| 86 | cb(); |
| 87 | } |
| 88 | }); |
| 89 | }); |
| 90 | |
| 91 | gulp.task('watch-build-test', ['build', 'build-test'], function () { |
| 92 | return gulp.watch(sources, ['build', 'build-test']); |
| 93 | }); |
| 94 | |
| 95 | gulp.task("clean", function () { |
| 96 | var del = require("del"); |
| 97 | var pathsToDelete = [ |
| 98 | outPath, |
| 99 | ".vscode-test" |
| 100 | ].map(function (folder) { |
| 101 | return folder + "/**"; |
| 102 | }); |
| 103 | return del(pathsToDelete, { force: true }); |
| 104 | }); |
| 105 | |