microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
gulpfile.js
108lines · 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 | var GulpExtras = require("./tools/gulp-extras"); |
| 14 | var copyright = GulpExtras.checkCopyright; |
| 15 | var imports = GulpExtras.checkImports; |
| 16 | |
| 17 | var srcPath = 'src'; |
| 18 | var outPath = 'out'; |
| 19 | |
| 20 | var sources = [ |
| 21 | srcPath, |
| 22 | ].map(function (tsFolder) { return tsFolder + '/**/*.ts'; }) |
| 23 | .concat(['test/*.ts']); |
| 24 | |
| 25 | // TODO: The file property should point to the generated source (this implementation adds an extra folder to the path) |
| 26 | // We should also make sure that we always generate urls in all the path properties (We shouldn't have \\s. This seems to |
| 27 | // be an issue on Windows platforms) |
| 28 | gulp.task('build', ["check-imports", "check-copyright"], function () { |
| 29 | var tsProject = ts.createProject('tsconfig.json'); |
| 30 | return tsProject.src() |
| 31 | .pipe(sourcemaps.init()) |
| 32 | .pipe(ts(tsProject)) |
| 33 | .pipe(sourcemaps.write('.', { |
| 34 | includeContent: false, |
| 35 | sourceRoot: function (file) { |
| 36 | return path.relative(path.dirname(file.path), __dirname + '/src'); |
| 37 | } |
| 38 | })) |
| 39 | .pipe(gulp.dest(outPath)); |
| 40 | }); |
| 41 | |
| 42 | gulp.task('watch', ['build'], function (cb) { |
| 43 | log('Watching build sources...'); |
| 44 | return gulp.watch(sources, ['build']); |
| 45 | }); |
| 46 | |
| 47 | gulp.task('default', function (callback) { |
| 48 | runSequence("clean", "build", "tslint", callback); |
| 49 | }); |
| 50 | |
| 51 | var lintSources = [ |
| 52 | srcPath, |
| 53 | ].map(function (tsFolder) { return tsFolder + '/**/*.ts'; }); |
| 54 | lintSources = lintSources.concat([ |
| 55 | '!src/typings/**' |
| 56 | ]); |
| 57 | |
| 58 | var tslint = require('gulp-tslint'); |
| 59 | gulp.task('tslint', function () { |
| 60 | return gulp.src(lintSources, { base: '.' }) |
| 61 | .pipe(tslint()) |
| 62 | .pipe(tslint.report('verbose')); |
| 63 | }); |
| 64 | |
| 65 | function test() { |
| 66 | return gulp.src(['out/test/**/*.test.js', '!out/test/extension/**']) |
| 67 | .pipe(mocha({ |
| 68 | ui: 'tdd', |
| 69 | useColors: true, |
| 70 | invert: true, |
| 71 | grep: "extensionContext" // Do not run tests intended for the extensionContext |
| 72 | })); |
| 73 | } |
| 74 | |
| 75 | gulp.task('build-test', ['build'], test); |
| 76 | gulp.task('test', test); |
| 77 | |
| 78 | gulp.task('check-imports', function (cb) { |
| 79 | var tsProject = ts.createProject('tsconfig.json'); |
| 80 | return tsProject.src() |
| 81 | .pipe(imports()); |
| 82 | }); |
| 83 | |
| 84 | gulp.task('check-copyright', function (cb) { |
| 85 | return gulp.src([ |
| 86 | "**/*.ts", |
| 87 | "**/*.js", |
| 88 | "!**/*.d.ts", |
| 89 | "!node_modules/**/*.*", |
| 90 | "!SampleApplication/**/*.js" |
| 91 | ]) |
| 92 | .pipe(copyright()); |
| 93 | }); |
| 94 | |
| 95 | gulp.task('watch-build-test', ['build', 'build-test'], function () { |
| 96 | return gulp.watch(sources, ['build', 'build-test']); |
| 97 | }); |
| 98 | |
| 99 | gulp.task("clean", function () { |
| 100 | var del = require("del"); |
| 101 | var pathsToDelete = [ |
| 102 | outPath, |
| 103 | ".vscode-test" |
| 104 | ].map(function (folder) { |
| 105 | return folder + "/**"; |
| 106 | }); |
| 107 | return del(pathsToDelete, { force: true }); |
| 108 | }); |
| 109 | |