microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
ccf6a728181cfc0e2ddcf743bf86a697c5d94eb2

Branches

Tags

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

Clone

HTTPS

Download ZIP

gulpfile.js

152lines · 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]);
82
83var tslint = require('gulp-tslint');
84gulp.task('tslint', function () {
85 return gulp.src(lintSources, { base: '.' })
86 .pipe(tslint())
87 .pipe(tslint.report('verbose'));
88});
89
90function test() {
91 // Defaults
92 var invert = true;
93
94 // Check if arguments were passed
95 var pattern = readArgument("pattern");
96 if (pattern !== null) {
97 invert = false;
98 console.log("\nTesting cases that match pattern: " + pattern);
99 } else {
100 pattern = "extensionContext";
101 console.log("\nTesting cases that don't match pattern: " + pattern);
102 }
103
104 return gulp.src(['out/test/**/*.test.js', '!out/test/extension/**'])
105 .pipe(mocha({
106 ui: 'tdd',
107 useColors: true,
108 invert: invert,
109 grep: pattern
110 }));
111}
112
113gulp.task('build-test', ['build'], test);
114gulp.task('test', test);
115
116gulp.task('check-imports', function (cb) {
117 var tsProject = ts.createProject('tsconfig.json');
118 return tsProject.src()
119 .pipe(imports());
120});
121
122gulp.task('check-copyright', function (cb) {
123 return gulp.src([
124 "**/*.ts",
125 "**/*.js",
126 "!**/*.d.ts",
127 "!node_modules/**/*.*",
128 "!SampleApplication/**/*.js"
129 ])
130 .pipe(copyright());
131});
132
133gulp.task('watch-build-test', ['build', 'build-test'], function () {
134 return gulp.watch(sources, ['build', 'build-test']);
135});
136
137gulp.task("clean", function () {
138 var del = require("del");
139 var pathsToDelete = [
140 outPath,
141 ".vscode-test"
142 ].map(function (folder) {
143 return folder + "/**";
144 });
145 return del(pathsToDelete, { force: true });
146});
147
148gulp.task("package", function (callback) {
149 var command = path.join(__dirname, "node_modules", ".bin", "vsce" + (process.platform === "win32" ? ".cmd" : ""));
150 var args = ["package"];
151 executeCommand(command, args, callback);
152});