microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a593f339aaef614caa22033ca067884a7c0aa038

Branches

Tags

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

Clone

HTTPS

Download ZIP

gulpfile.js

176lines · 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');
14var os = require("os");
15var fs = require("fs");
16var Q = require("q");
17
18var copyright = GulpExtras.checkCopyright;
19var imports = GulpExtras.checkImports;
20var executeCommand = GulpExtras.executeCommand;
21
22var srcPath = 'src';
23var outPath = 'out';
24
25var sources = [
26 srcPath,
27].map(function (tsFolder) { return tsFolder + '/**/*.ts'; })
28 .concat(['test/*.ts']);
29
30var knownOptions = {
31 string: 'env',
32 default: { env: 'production' }
33};
34
35var options = minimist(process.argv.slice(2), knownOptions);
36
37// TODO: The file property should point to the generated source (this implementation adds an extra folder to the path)
38// We should also make sure that we always generate urls in all the path properties (We shouldn't have \\s. This seems to
39// be an issue on Windows platforms)
40gulp.task('build', ["check-imports", "check-copyright"], function (callback) {
41 var tsProject = ts.createProject('tsconfig.json');
42 var isProd = options.env === 'production';
43 var preprocessorContext = isProd ? { PROD: true } : { DEBUG: true };
44 log(`Building with preprocessor context: ${JSON.stringify(preprocessorContext)}`);
45 return tsProject.src()
46 .pipe(preprocess({ context: preprocessorContext })) //To set environment variables in-line
47 .pipe(sourcemaps.init())
48 .pipe(ts(tsProject))
49 .on('error', function (e) {
50 callback(e);
51 })
52 .pipe(sourcemaps.write('.', {
53 includeContent: false,
54 sourceRoot: function (file) {
55 return path.relative(path.dirname(path.dirname(file.path)), __dirname + '/src');
56 }
57 }))
58 .pipe(gulp.dest(outPath));
59});
60
61gulp.task('watch', ['build'], function (cb) {
62 log('Watching build sources...');
63 return gulp.watch(sources, ['build']);
64});
65
66gulp.task('default', function (callback) {
67 runSequence("clean", "build", "tslint", callback);
68});
69
70var lintSources = [
71 srcPath,
72].map(function (tsFolder) { return tsFolder + '/**/*.ts'; });
73lintSources = lintSources.concat([
74 '!src/typings/**',
75 '!src/test/resources/sampleReactNative022Project/**',
76]);
77
78var tslint = require('gulp-tslint');
79gulp.task('tslint', function () {
80 return gulp.src(lintSources, { base: '.' })
81 .pipe(tslint())
82 .pipe(tslint.report('verbose'));
83});
84
85function test() {
86 // Check if arguments were passed
87 if (options.pattern) {
88 console.log("\nTesting cases that match pattern: " + options.pattern);
89 } else {
90 console.log("\nTesting cases that don't match pattern: extensionContext");
91 }
92
93 return gulp.src(['out/test/**/*.test.js', '!out/test/extension/**'])
94 .pipe(mocha({
95 ui: 'tdd',
96 useColors: true,
97 invert: !options.pattern,
98 grep: options.pattern || "extensionContext"
99 }));
100}
101
102gulp.task('test', ['build', 'tslint'], test);
103gulp.task('test-no-build', test);
104
105gulp.task('check-imports', function (cb) {
106 var tsProject = ts.createProject('tsconfig.json');
107 return tsProject.src()
108 .pipe(imports());
109});
110
111gulp.task('check-copyright', function (cb) {
112 return gulp.src([
113 "**/*.ts",
114 "**/*.js",
115 "!**/*.d.ts",
116 "!node_modules/**",
117 "!SampleApplication/**",
118 "!src/test/resources/sampleReactNative022Project/**/*.js",
119 ])
120 .pipe(copyright());
121});
122
123gulp.task('watch-build-test', ['build', 'build-test'], function () {
124 return gulp.watch(sources, ['build', 'build-test']);
125});
126
127gulp.task("clean", function () {
128 var del = require("del");
129 var pathsToDelete = [
130 outPath,
131 ".vscode-test"
132 ].map(function (folder) {
133 return folder + "/**";
134 });
135 return del(pathsToDelete, { force: true });
136});
137
138gulp.task("package", function (callback) {
139 var command = path.join(__dirname, "node_modules", ".bin", "vsce");
140 var args = ["package"];
141 executeCommand(command, args, callback);
142});
143
144gulp.task("release", ["build"], function () {
145 var licenseFiles = ["LICENSE.txt", "ThirdPartyNotices.txt"];
146 var backupFolder = path.resolve(path.join(os.tmpdir(), 'vscode-react-native'));
147 if (!fs.existsSync(backupFolder)) {
148 fs.mkdirSync(backupFolder);
149 }
150
151 return Q({})
152 .then(function () {
153 /* back up LICENSE.txt, ThirdPartyNotices.txt, README.md */
154 console.log("Backing up license files to " + backupFolder + "...");
155 licenseFiles.forEach(function (fileName) {
156 fs.writeFileSync(path.join(backupFolder, fileName), fs.readFileSync(fileName));
157 });
158
159 /* copy over the release package license files */
160 console.log("Preparing license files for release...");
161 fs.writeFileSync('LICENSE.txt', fs.readFileSync('release/LICENSE.txt'));
162 fs.writeFileSync('ThirdPartyNotices.txt', fs.readFileSync('release/ThirdPartyNotices.txt'));
163 }).then(()=>{
164 console.log("Creating release package...");
165 var deferred = Q.defer();
166 // NOTE: vsce must see npm 3.X otherwise it will not correctly strip out dev dependencies.
167 executeCommand('vsce', ['package'], function (arg) { if (arg) { deferred.reject(arg);} deferred.resolve()} , {cwd: path.resolve(__dirname)});
168 return deferred.promise;
169 }).finally(function () {
170 /* restore backed up files */
171 console.log("Restoring modified files...");
172 licenseFiles.forEach(function (fileName) {
173 fs.writeFileSync(path.join(__dirname, fileName), fs.readFileSync(path.join(backupFolder, fileName)));
174 });
175 });
176})
177