microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
gulpfile.js
112lines · modeblame
b8ecee4ddigeff10 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. | |
8ba55f4cJimmy Thomson10 years ago | 3 | |
| 4 | var child_process = require('child_process'); | |
| 5 | var gulp = require('gulp'); | |
3fb37ad5unknown10 years ago | 6 | var log = require('gulp-util').log; |
8ba55f4cJimmy Thomson10 years ago | 7 | var sourcemaps = require('gulp-sourcemaps'); |
| 8 | var os = require('os'); | |
| 9 | var path = require('path'); | |
3fb37ad5unknown10 years ago | 10 | var runSequence = require("run-sequence"); |
| 11 | var ts = require('gulp-typescript'); | |
d500558fJimmy Thomson10 years ago | 12 | var mocha = require('gulp-mocha'); |
8ba55f4cJimmy Thomson10 years ago | 13 | |
89973b41dlebu10 years ago | 14 | var srcPath = 'src'; |
| 15 | var outPath = 'out'; | |
| 16 | | |
8ba55f4cJimmy Thomson10 years ago | 17 | var sources = [ |
89973b41dlebu10 years ago | 18 | srcPath, |
ee16550eGuillaume Jenkins10 years ago | 19 | ].map(function (tsFolder) { return tsFolder + '/**/*.ts'; }) |
3fb37ad5unknown10 years ago | 20 | .concat(['test/*.ts']); |
8ba55f4cJimmy Thomson10 years ago | 21 | |
c55d31ecdigeff10 years ago | 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) | |
9508f4d8digeff10 years ago | 25 | gulp.task('build', ['checkImports', 'checkCopyright'], function () { |
c55d31ecdigeff10 years ago | 26 | var tsProject = ts.createProject('tsconfig.json'); |
8ba55f4cJimmy Thomson10 years ago | 27 | return tsProject.src() |
| 28 | .pipe(sourcemaps.init()) | |
| 29 | .pipe(ts(tsProject)) | |
c55d31ecdigeff10 years ago | 30 | .pipe(sourcemaps.write('.', { |
| 31 | includeContent: false, | |
ee16550eGuillaume Jenkins10 years ago | 32 | sourceRoot: function (file) { |
c55d31ecdigeff10 years ago | 33 | return path.relative(path.dirname(file.path), __dirname + '/src'); |
| 34 | } | |
| 35 | })) | |
89973b41dlebu10 years ago | 36 | .pipe(gulp.dest(outPath)); |
8ba55f4cJimmy Thomson10 years ago | 37 | }); |
| 38 | | |
ee16550eGuillaume Jenkins10 years ago | 39 | gulp.task('watch', ['build'], function (cb) { |
8ba55f4cJimmy Thomson10 years ago | 40 | log('Watching build sources...'); |
| 41 | return gulp.watch(sources, ['build']); | |
| 42 | }); | |
| 43 | | |
ee16550eGuillaume Jenkins10 years ago | 44 | gulp.task('default', function (callback) { |
89973b41dlebu10 years ago | 45 | runSequence("clean", "build", "tslint", callback); |
3fb37ad5unknown10 years ago | 46 | }); |
8ba55f4cJimmy Thomson10 years ago | 47 | |
| 48 | var lintSources = [ | |
89973b41dlebu10 years ago | 49 | srcPath, |
ee16550eGuillaume Jenkins10 years ago | 50 | ].map(function (tsFolder) { return tsFolder + '/**/*.ts'; }); |
3fde2079Jimmy Thomson10 years ago | 51 | lintSources = lintSources.concat([ |
| 52 | '!src/typings/**' | |
| 53 | ]); | |
8ba55f4cJimmy Thomson10 years ago | 54 | |
| 55 | var tslint = require('gulp-tslint'); | |
ee16550eGuillaume Jenkins10 years ago | 56 | gulp.task('tslint', function () { |
3fb37ad5unknown10 years ago | 57 | return gulp.src(lintSources, { base: '.' }) |
8ba55f4cJimmy Thomson10 years ago | 58 | .pipe(tslint()) |
| 59 | .pipe(tslint.report('verbose')); | |
| 60 | }); | |
| 61 | | |
| 62 | function test() { | |
d500558fJimmy Thomson10 years ago | 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 | })); | |
8ba55f4cJimmy Thomson10 years ago | 70 | } |
| 71 | | |
| 72 | gulp.task('build-test', ['build'], test); | |
| 73 | gulp.task('test', test); | |
| 74 | | |
7d0d8776digeff10 years ago | 75 | function runCustomVerification(pathInTools, errorMessage, cb) { |
| 76 | var checkProcess = child_process.fork(path.join(__dirname, "tools", pathInTools), | |
| 77 | { | |
| 78 | cwd: path.resolve(__dirname, "src"), | |
| 79 | stdio: "inherit" | |
379834c9Jimmy Thomson10 years ago | 80 | }); |
7d0d8776digeff10 years ago | 81 | checkProcess.on("error", cb); |
| 82 | checkProcess.on("exit", function (code, signal) { | |
| 83 | if (code || signal) { | |
| 84 | cb(new Error(errorMessage)); | |
| 85 | } else { | |
| 86 | cb(); | |
| 87 | } | |
379834c9Jimmy Thomson10 years ago | 88 | }); |
9508f4d8digeff10 years ago | 89 | } |
| 90 | | |
7d0d8776digeff10 years ago | 91 | gulp.task('checkImports', function (cb) { |
| 92 | runCustomVerification("checkCasing.js", "Mismatches found in import casing", cb); | |
| 93 | }); | |
| 94 | | |
| 95 | gulp.task('checkCopyright', function (cb) { | |
| 96 | runCustomVerification("checkCopyright.js", "Some source code files don't have the expected copyright notice", cb); | |
| 97 | }); | |
379834c9Jimmy Thomson10 years ago | 98 | |
ee16550eGuillaume Jenkins10 years ago | 99 | gulp.task('watch-build-test', ['build', 'build-test'], function () { |
8ba55f4cJimmy Thomson10 years ago | 100 | return gulp.watch(sources, ['build', 'build-test']); |
| 101 | }); | |
89973b41dlebu10 years ago | 102 | |
ee16550eGuillaume Jenkins10 years ago | 103 | gulp.task("clean", function () { |
89973b41dlebu10 years ago | 104 | var del = require("del"); |
ee16550eGuillaume Jenkins10 years ago | 105 | var pathsToDelete = [ |
| 106 | outPath, | |
| 107 | ".vscode-test" | |
| 108 | ].map(function (folder) { | |
| 109 | return folder + "/**"; | |
| 110 | }); | |
| 111 | return del(pathsToDelete, { force: true }); | |
8edb50b4Jimmy Thomson10 years ago | 112 | }); |