microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
18d8ad2abfdce9bcdb96cc3fe6fb491da873c8f6

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

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
4var gulp = require('gulp');
5var log = require('gulp-util').log;
6var sourcemaps = require('gulp-sourcemaps');
7var path = require('path');
8var runSequence = require("run-sequence");
9var ts = require('gulp-typescript');
10var mocha = require('gulp-mocha');
11var GulpExtras = require("./tools/gulp-extras");
12var copyright = GulpExtras.checkCopyright;
13var imports = GulpExtras.checkImports;
14var executeCommand = GulpExtras.executeCommand;
15
16var srcPath = 'src';
17var outPath = 'out';
18
19var 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)
27gulp.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
41gulp.task('watch', ['build'], function (cb) {
42 log('Watching build sources...');
43 return gulp.watch(sources, ['build']);
44});
45
46gulp.task('default', function (callback) {
47 runSequence("clean", "build", "tslint", callback);
48});
49
50var lintSources = [
51 srcPath,
52].map(function (tsFolder) { return tsFolder + '/**/*.ts'; });
53lintSources = lintSources.concat([
54 '!src/typings/**'
55]);
56
57var tslint = require('gulp-tslint');
58gulp.task('tslint', function () {
59 return gulp.src(lintSources, { base: '.' })
60 .pipe(tslint())
61 .pipe(tslint.report('verbose'));
62});
63
64function 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
72function 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
95gulp.task('build-test', ['build'], test);
96gulp.task('test', test);
97
98gulp.task('check-imports', function (cb) {
99 var tsProject = ts.createProject('tsconfig.json');
100 return tsProject.src()
101 .pipe(imports());
102});
103
104gulp.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
115gulp.task('watch-build-test', ['build', 'build-test'], function () {
116 return gulp.watch(sources, ['build', 'build-test']);
117});
118
119gulp.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
130gulp.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});