gulpfile.editor.js 6.0 KB
Newer Older
I
isidor 已提交
1 2 3 4 5 6 7 8 9 10
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

var gulp = require('gulp');
var path = require('path');
var _ = require('underscore');
var util = require('./lib/util');
var common = require('./gulpfile.common');
A
Alex Dima 已提交
11
var es = require('event-stream');
12
var File = require('vinyl');
I
isidor 已提交
13 14

var root = path.dirname(__dirname);
A
Alex Dima 已提交
15 16 17
var sha1 = util.getVersion(root);
var semver = require('./monaco/package.json').version;
var headerVersion = semver + '(' + sha1 + ')';
I
isidor 已提交
18 19 20

// Build

21 22 23 24 25 26 27 28 29 30 31 32
var editorEntryPoints = [
	{
		name: 'vs/editor/editor.main',
		include: [],
		exclude: [ 'vs/css', 'vs/nls' ]
	},
	{
		name: 'vs/base/common/worker/simpleWorker',
		include: [ 'vs/editor/common/services/editorSimpleWorker' ],
		exclude: [ 'vs/css', 'vs/nls' ]
	},
]
I
isidor 已提交
33 34 35

var editorResources = [
	'out-build/vs/{base,editor}/**/*.{svg,png}',
36 37 38
	'!out-build/vs/base/browser/ui/splitview/**/*',
	'!out-build/vs/base/browser/ui/toolbar/**/*',
	'!out-build/vs/base/browser/ui/octiconLabel/**/*',
39
	'!out-build/vs/editor/contrib/defineKeybinding/**/*',
I
isidor 已提交
40 41 42 43 44 45 46
	'out-build/vs/base/worker/workerMain.{js,js.map}',
	'!out-build/vs/workbench/**',
	'!**/test/**'
];

var editorOtherSources = [
	'out-build/vs/css.js',
A
Alex Dima 已提交
47
	'out-build/vs/nls.js'
I
isidor 已提交
48 49 50 51
];

var BUNDLED_FILE_HEADER = [
	'/*!-----------------------------------------------------------',
A
Alex Dima 已提交
52
	' * Copyright (c) Microsoft Corporation. All rights reserved.',
A
Alex Dima 已提交
53
	' * Version: ' + headerVersion,
I
isidor 已提交
54 55 56 57 58 59
	' * Released under the MIT license',
	' * https://github.com/Microsoft/vscode/blob/master/LICENSE.txt',
	' *-----------------------------------------------------------*/',
	''
].join('\n');

60
function editorLoaderConfig() {
I
isidor 已提交
61 62
	var result = common.loaderConfig();

63 64
	// never ship octicons in editor
	result.paths['vs/base/browser/ui/octiconLabel/octiconLabel'] = 'out-build/vs/base/browser/ui/octiconLabel/octiconLabel.mock';
I
isidor 已提交
65

66 67
	// force css inlining to use base64 -- see https://github.com/Microsoft/monaco-editor/issues/148
	result['vs/css'] = { inlineResources: 'base64' };
68

I
isidor 已提交
69 70 71 72
	return result;
}

gulp.task('clean-optimized-editor', util.rimraf('out-editor'));
A
Alex Dima 已提交
73
gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-build'], common.optimizeTask({
I
isidor 已提交
74 75 76
	entryPoints: editorEntryPoints,
	otherSources: editorOtherSources,
	resources: editorResources,
77
	loaderConfig: editorLoaderConfig(),
I
isidor 已提交
78
	header: BUNDLED_FILE_HEADER,
A
Alex Dima 已提交
79
	bundleInfo: true,
I
isidor 已提交
80 81 82 83
	out: 'out-editor'
}));

gulp.task('clean-minified-editor', util.rimraf('out-editor-min'));
J
Joao Moreno 已提交
84
gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor'));
A
Alex Dima 已提交
85 86

gulp.task('clean-editor-distro', util.rimraf('out-monaco-editor-core'));
A
Alex Dima 已提交
87
gulp.task('editor-distro', ['clean-editor-distro', 'minify-editor', 'optimize-editor'], function() {
A
Alex Dima 已提交
88 89 90 91 92 93 94 95
	return es.merge(
		// other assets
		es.merge(
			gulp.src('build/monaco/LICENSE'),
			gulp.src('build/monaco/ThirdPartyNotices.txt'),
			gulp.src('src/vs/monaco.d.ts')
		).pipe(gulp.dest('out-monaco-editor-core')),

96 97 98 99 100 101 102 103 104 105
		// package.json
		gulp.src('build/monaco/package.json')
			.pipe(es.through(function(data) {
				var json = JSON.parse(data.contents.toString());
				json.private = false;
				data.contents = new Buffer(JSON.stringify(json, null, '  '));
				this.emit('data', data);
			}))
			.pipe(gulp.dest('out-monaco-editor-core')),

106 107 108 109 110 111 112 113 114 115 116
		// README.md
		gulp.src('build/monaco/README-npm.md')
			.pipe(es.through(function(data) {
				this.emit('data', new File({
					path: data.path.replace(/README-npm\.md/, 'README.md'),
					base: data.base,
					contents: data.contents
				}));
			}))
			.pipe(gulp.dest('out-monaco-editor-core')),

A
Alex Dima 已提交
117 118 119 120 121 122 123 124 125 126
		// dev folder
		es.merge(
			gulp.src('out-editor/**/*')
		).pipe(gulp.dest('out-monaco-editor-core/dev')),

		// min folder
		es.merge(
			gulp.src('out-editor-min/**/*')
		).pipe(filterStream(function(path) {
			// no map files
127
			return !/(\.js\.map$)|(nls\.metadata\.json$)|(bundleInfo\.json$)/.test(path);
A
Alex Dima 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
		})).pipe(es.through(function(data) {
			// tweak the sourceMappingURL
			if (!/\.js$/.test(data.path)) {
				this.emit('data', data);
				return;
			}

			var relativePathToMap = path.relative(path.join(data.relative), path.join('min-maps', data.relative + '.map'));

			var strContents = data.contents.toString();
			var newStr = '//# sourceMappingURL=' + relativePathToMap.replace(/\\/g, '/');
			strContents = strContents.replace(/\/\/\# sourceMappingURL=[^ ]+$/, newStr);

			data.contents = new Buffer(strContents);
			this.emit('data', data);
		})).pipe(gulp.dest('out-monaco-editor-core/min')),

		// min-maps folder
		es.merge(
			gulp.src('out-editor-min/**/*')
		).pipe(filterStream(function(path) {
			// no map files
A
Alex Dima 已提交
150
			return /\.js\.map$/.test(path);
A
Alex Dima 已提交
151 152 153 154
		})).pipe(gulp.dest('out-monaco-editor-core/min-maps'))
	);
});

A
Alex Dima 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
gulp.task('analyze-editor-distro', function() {
	var bundleInfo = require('../out-editor/bundleInfo.json');
	var graph = bundleInfo.graph;
	var bundles = bundleInfo.bundles;

	var inverseGraph = {};
	Object.keys(graph).forEach(function(module) {
		var dependencies = graph[module];
		dependencies.forEach(function(dep) {
			inverseGraph[dep] = inverseGraph[dep] || [];
			inverseGraph[dep].push(module);
		});
	});

	var detailed = {};
	Object.keys(bundles).forEach(function(entryPoint) {
		var included = bundles[entryPoint];
		var includedMap = {};
		included.forEach(function(included) {
			includedMap[included] = true;
		});

		var explanation = [];
		included.map(function(included) {
			if (included.indexOf('!') >= 0) {
				return;
			}

			var reason = (inverseGraph[included]||[]).filter(function(mod) {
				return !!includedMap[mod];
			});
			explanation.push({
				module: included,
				reason: reason
			});
		});

		detailed[entryPoint] = explanation;
	});

	console.log(JSON.stringify(detailed, null, '\t'));
});

A
Alex Dima 已提交
198 199 200 201 202 203 204 205
function filterStream(testFunc) {
	return es.through(function(data) {
		if (!testFunc(data.relative)) {
			return;
		}
		this.emit('data', data);
	});
}