microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
gulpfile.js
81lines · 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 | |
| 13 | var srcPath = 'src'; |
| 14 | var outPath = 'out'; |
| 15 | |
| 16 | var sources = [ |
| 17 | srcPath, |
| 18 | ].map(function (tsFolder) { return tsFolder + '/**/*.ts'; }) |
| 19 | .concat(['test/*.ts']); |
| 20 | |
| 21 | // TODO: The file property should point to the generated source (this implementation adds an extra folder to the path) |
| 22 | // We should also make sure that we always generate urls in all the path properties (We shouldn't have \\s. This seems to |
| 23 | // be an issue on Windows platforms) |
| 24 | gulp.task('build', function () { |
| 25 | var tsProject = ts.createProject('tsconfig.json'); |
| 26 | return tsProject.src() |
| 27 | .pipe(sourcemaps.init()) |
| 28 | .pipe(ts(tsProject)) |
| 29 | .pipe(sourcemaps.write('.', { |
| 30 | includeContent: false, |
| 31 | sourceRoot: function (file) { |
| 32 | return path.relative(path.dirname(file.path), __dirname + '/src'); |
| 33 | } |
| 34 | })) |
| 35 | .pipe(gulp.dest(outPath)); |
| 36 | }); |
| 37 | |
| 38 | gulp.task('watch', ['build'], function (cb) { |
| 39 | log('Watching build sources...'); |
| 40 | return gulp.watch(sources, ['build']); |
| 41 | }); |
| 42 | |
| 43 | gulp.task('default', function (callback) { |
| 44 | runSequence("clean", "build", "tslint", callback); |
| 45 | }); |
| 46 | |
| 47 | var lintSources = [ |
| 48 | srcPath, |
| 49 | ].map(function (tsFolder) { return tsFolder + '/**/*.ts'; }); |
| 50 | lintSources = lintSources.concat([ |
| 51 | '!src/typings/**' |
| 52 | ]); |
| 53 | |
| 54 | var tslint = require('gulp-tslint'); |
| 55 | gulp.task('tslint', function () { |
| 56 | return gulp.src(lintSources, { base: '.' }) |
| 57 | .pipe(tslint()) |
| 58 | .pipe(tslint.report('verbose')); |
| 59 | }); |
| 60 | |
| 61 | function test() { |
| 62 | throw new Error('To run tests, open the extension in VS Code and hit F5 with the "Launch Tests" configuration. Alternatively, on Mac OS, you can run "npm test" on the command line.'); |
| 63 | } |
| 64 | |
| 65 | gulp.task('build-test', ['build'], test); |
| 66 | gulp.task('test', test); |
| 67 | |
| 68 | gulp.task('watch-build-test', ['build', 'build-test'], function () { |
| 69 | return gulp.watch(sources, ['build', 'build-test']); |
| 70 | }); |
| 71 | |
| 72 | gulp.task("clean", function () { |
| 73 | var del = require("del"); |
| 74 | var pathsToDelete = [ |
| 75 | outPath, |
| 76 | ".vscode-test" |
| 77 | ].map(function (folder) { |
| 78 | return folder + "/**"; |
| 79 | }); |
| 80 | return del(pathsToDelete, { force: true }); |
| 81 | }); |