microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
88422e97bf6ad0988a4230efff6c91e0cd504f0c

Branches

Tags

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

Clone

HTTPS

Download ZIP

gulpfile.js

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