microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
gulpfile.js
134lines · 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 gulp = require('gulp'); |
| 5 | var log = require('gulp-util').log; |
| 6 | var sourcemaps = require('gulp-sourcemaps'); |
| 7 | var path = require('path'); |
| 8 | var runSequence = require("run-sequence"); |
| 9 | var ts = require('gulp-typescript'); |
| 10 | var mocha = require('gulp-mocha'); |
| 11 | var GulpExtras = require("./tools/gulp-extras"); |
| 12 | var copyright = GulpExtras.checkCopyright; |
| 13 | var imports = GulpExtras.checkImports; |
| 14 | var executeCommand = GulpExtras.executeCommand; |
| 15 | |
| 16 | var srcPath = 'src'; |
| 17 | var outPath = 'out'; |
| 18 | |
| 19 | var sources = [ |
| 20 | srcPath, |
| 21 | ].map(function (tsFolder) { return tsFolder + '/**/*.ts'; }) |
| 22 | .concat(['test/*.ts']); |
| 23 | |
| 24 | // TODO: The file property should point to the generated source (this implementation adds an extra folder to the path) |
| 25 | // We should also make sure that we always generate urls in all the path properties (We shouldn't have \\s. This seems to |
| 26 | // be an issue on Windows platforms) |
| 27 | gulp.task('build', ["check-imports", "check-copyright"], function () { |
| 28 | var tsProject = ts.createProject('tsconfig.json'); |
| 29 | return tsProject.src() |
| 30 | .pipe(sourcemaps.init()) |
| 31 | .pipe(ts(tsProject)) |
| 32 | .pipe(sourcemaps.write('.', { |
| 33 | includeContent: false, |
| 34 | sourceRoot: function (file) { |
| 35 | return path.relative(path.dirname(file.path), __dirname + '/src'); |
| 36 | } |
| 37 | })) |
| 38 | .pipe(gulp.dest(outPath)); |
| 39 | }); |
| 40 | |
| 41 | gulp.task('watch', ['build'], function (cb) { |
| 42 | log('Watching build sources...'); |
| 43 | return gulp.watch(sources, ['build']); |
| 44 | }); |
| 45 | |
| 46 | gulp.task('default', function (callback) { |
| 47 | runSequence("clean", "build", "tslint", callback); |
| 48 | }); |
| 49 | |
| 50 | var lintSources = [ |
| 51 | srcPath, |
| 52 | ].map(function (tsFolder) { return tsFolder + '/**/*.ts'; }); |
| 53 | lintSources = lintSources.concat([ |
| 54 | '!src/typings/**' |
| 55 | ]); |
| 56 | |
| 57 | var tslint = require('gulp-tslint'); |
| 58 | gulp.task('tslint', function () { |
| 59 | return gulp.src(lintSources, { base: '.' }) |
| 60 | .pipe(tslint()) |
| 61 | .pipe(tslint.report('verbose')); |
| 62 | }); |
| 63 | |
| 64 | function readArgument(argumentName) { |
| 65 | var argumentNameIndex = process.argv.indexOf("--" + argumentName); |
| 66 | var argumentValueIndex = argumentNameIndex + 1; |
| 67 | return argumentNameIndex > -1 && argumentValueIndex < process.argv.length |
| 68 | ? process.argv[argumentValueIndex] |
| 69 | : null; |
| 70 | } |
| 71 | |
| 72 | function test() { |
| 73 | // Defaults |
| 74 | var invert = true; |
| 75 | |
| 76 | // Check if arguments were passed |
| 77 | var pattern = readArgument("pattern"); |
| 78 | if (pattern !== null) { |
| 79 | invert = false; |
| 80 | console.log("\nTesting cases that match pattern: " + pattern); |
| 81 | } else { |
| 82 | pattern = "extensionContext"; |
| 83 | console.log("\nTesting cases that don't match pattern: " + pattern); |
| 84 | } |
| 85 | |
| 86 | return gulp.src(['out/test/**/*.test.js', '!out/test/extension/**']) |
| 87 | .pipe(mocha({ |
| 88 | ui: 'tdd', |
| 89 | useColors: true, |
| 90 | invert: invert, |
| 91 | grep: pattern |
| 92 | })); |
| 93 | } |
| 94 | |
| 95 | gulp.task('build-test', ['build'], test); |
| 96 | gulp.task('test', test); |
| 97 | |
| 98 | gulp.task('check-imports', function (cb) { |
| 99 | var tsProject = ts.createProject('tsconfig.json'); |
| 100 | return tsProject.src() |
| 101 | .pipe(imports()); |
| 102 | }); |
| 103 | |
| 104 | gulp.task('check-copyright', function (cb) { |
| 105 | return gulp.src([ |
| 106 | "**/*.ts", |
| 107 | "**/*.js", |
| 108 | "!**/*.d.ts", |
| 109 | "!node_modules/**/*.*", |
| 110 | "!SampleApplication/**/*.js" |
| 111 | ]) |
| 112 | .pipe(copyright()); |
| 113 | }); |
| 114 | |
| 115 | gulp.task('watch-build-test', ['build', 'build-test'], function () { |
| 116 | return gulp.watch(sources, ['build', 'build-test']); |
| 117 | }); |
| 118 | |
| 119 | gulp.task("clean", function () { |
| 120 | var del = require("del"); |
| 121 | var pathsToDelete = [ |
| 122 | outPath, |
| 123 | ".vscode-test" |
| 124 | ].map(function (folder) { |
| 125 | return folder + "/**"; |
| 126 | }); |
| 127 | return del(pathsToDelete, { force: true }); |
| 128 | }); |
| 129 | |
| 130 | gulp.task("package", function (callback) { |
| 131 | var command = path.join(__dirname, "node_modules", ".bin", "vsce" + (process.platform === "win32" ? ".cmd" : "")); |
| 132 | var args = ["package"]; |
| 133 | executeCommand(command, args, callback); |
| 134 | }); |