Better editor build tasks
This commit is contained in:
parent
19888e6822
commit
046b87e067
|
@ -47,13 +47,27 @@ exports.loaderConfig = function (emptyPaths) {
|
|||
|
||||
var IS_OUR_COPYRIGHT_REGEXP = /Copyright \(C\) Microsoft Corporation/i;
|
||||
|
||||
function loader() {
|
||||
function loader(bundledFileHeader) {
|
||||
var isFirst = true;
|
||||
return gulp.src([
|
||||
'out-build/vs/loader.js',
|
||||
'out-build/vs/css.js',
|
||||
'out-build/vs/nls.js',
|
||||
'out-build/vs/text.js'
|
||||
], { base: 'out-build' })
|
||||
.pipe(es.through(function(data) {
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
this.emit('data', new File({
|
||||
path: 'fake',
|
||||
base: '',
|
||||
contents: new Buffer(bundledFileHeader)
|
||||
}));
|
||||
this.emit('data', data);
|
||||
} else {
|
||||
this.emit('data', data);
|
||||
}
|
||||
}))
|
||||
.pipe(util.loadSourcemaps())
|
||||
.pipe(concat('vs/loader.js'))
|
||||
.pipe(es.mapSync(function (f) {
|
||||
|
@ -62,66 +76,96 @@ function loader() {
|
|||
}));
|
||||
}
|
||||
|
||||
function toBundleStream(bundles) {
|
||||
return es.merge(bundles.map(function(bundle) {
|
||||
var useSourcemaps = /\.js$/.test(bundle.dest) && !/\.nls\.js$/.test(bundle.dest);
|
||||
var sources = bundle.sources.map(function(source) {
|
||||
var root = source.path ? path.dirname(__dirname).replace(/\\/g, '/') : '';
|
||||
var base = source.path ? root + '/out-build' : '';
|
||||
function toConcatStream(bundledFileHeader, sources, dest) {
|
||||
var useSourcemaps = /\.js$/.test(dest) && !/\.nls\.js$/.test(dest);
|
||||
|
||||
return new File({
|
||||
path: source.path ? root + '/' + source.path.replace(/\\/g, '/') : 'fake',
|
||||
base: base,
|
||||
contents: new Buffer(source.contents)
|
||||
});
|
||||
// If a bundle ends up including in any of the sources our copyright, then
|
||||
// insert a fake source at the beginning of each bundle with our copyright
|
||||
var containsOurCopyright = false;
|
||||
for (var i = 0, len = sources.length; i < len; i++) {
|
||||
var fileContents = sources[i].contents;
|
||||
if (IS_OUR_COPYRIGHT_REGEXP.test(fileContents)) {
|
||||
containsOurCopyright = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (containsOurCopyright) {
|
||||
sources.unshift({
|
||||
path: null,
|
||||
contents: bundledFileHeader
|
||||
});
|
||||
}
|
||||
|
||||
return es.readArray(sources)
|
||||
.pipe(useSourcemaps ? util.loadSourcemaps() : es.through())
|
||||
.pipe(concat(bundle.dest));
|
||||
var treatedSources = sources.map(function(source) {
|
||||
var root = source.path ? path.dirname(__dirname).replace(/\\/g, '/') : '';
|
||||
var base = source.path ? root + '/out-build' : '';
|
||||
|
||||
return new File({
|
||||
path: source.path ? root + '/' + source.path.replace(/\\/g, '/') : 'fake',
|
||||
base: base,
|
||||
contents: new Buffer(source.contents)
|
||||
});
|
||||
});
|
||||
|
||||
return es.readArray(treatedSources)
|
||||
.pipe(useSourcemaps ? util.loadSourcemaps() : es.through())
|
||||
.pipe(concat(dest));
|
||||
}
|
||||
|
||||
function toBundleStream(bundledFileHeader, bundles) {
|
||||
return es.merge(bundles.map(function(bundle) {
|
||||
return toConcatStream(bundledFileHeader, bundle.sources, bundle.dest);
|
||||
}));
|
||||
}
|
||||
|
||||
exports.optimizeTask = function(entryPoints, resources, loaderConfig, bundledFileHeader, out) {
|
||||
/**
|
||||
* opts:
|
||||
* - entryPoints (for AMD files, will get bundled and get Copyright treatment)
|
||||
* - otherSources (for non-AMD files that should get Copyright treatment)
|
||||
* - resources (svg, etc.)
|
||||
* - loaderConfig
|
||||
* - header (basically the Copyright treatment)
|
||||
* - out (out folder name)
|
||||
*/
|
||||
exports.optimizeTask = function(opts) {
|
||||
var entryPoints = opts.entryPoints;
|
||||
var otherSources = opts.otherSources;
|
||||
var resources = opts.resources;
|
||||
var loaderConfig = opts.loaderConfig;
|
||||
var bundledFileHeader = opts.header;
|
||||
var out = opts.out;
|
||||
return function() {
|
||||
var bundles = es.through();
|
||||
|
||||
bundle.bundle(entryPoints, loaderConfig, function(err, result) {
|
||||
if (err) { return bundles.emit('error', JSON.stringify(err)); }
|
||||
|
||||
// If a bundle ends up including in any of the sources our copyright, then
|
||||
// insert a fake source at the beginning of each bundle with our copyright
|
||||
result.forEach(function(b) {
|
||||
var containsOurCopyright = false;
|
||||
for (var i = 0, len = b.sources.length; i < len; i++) {
|
||||
var fileContents = b.sources[i].contents;
|
||||
if (IS_OUR_COPYRIGHT_REGEXP.test(fileContents)) {
|
||||
containsOurCopyright = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (containsOurCopyright) {
|
||||
b.sources.unshift({
|
||||
path: null,
|
||||
contents: bundledFileHeader
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
toBundleStream(result).pipe(bundles);
|
||||
toBundleStream(bundledFileHeader, result).pipe(bundles);
|
||||
});
|
||||
|
||||
var otherSourcesStream = es.through();
|
||||
(function() {
|
||||
var otherSourcesStreamArr = [];
|
||||
gulp.src(otherSources, { base: 'out-build' })
|
||||
.pipe(es.through(function write(data) {
|
||||
otherSourcesStreamArr.push(toConcatStream(bundledFileHeader, [data], data.relative));
|
||||
}, function end() {
|
||||
es.merge(otherSourcesStreamArr).pipe(otherSourcesStream);
|
||||
}))
|
||||
})();
|
||||
|
||||
var result = es.merge(
|
||||
loader(),
|
||||
loader(bundledFileHeader),
|
||||
bundles,
|
||||
otherSourcesStream,
|
||||
gulp.src(resources, { base: 'out-build' })
|
||||
);
|
||||
|
||||
return result
|
||||
.pipe(sourcemaps.write('./', {
|
||||
sourceRoot: null,
|
||||
addComment: false,
|
||||
addComment: true,
|
||||
includeContent: true
|
||||
}))
|
||||
.pipe(gulp.dest(out));
|
||||
|
@ -182,7 +226,7 @@ function uglifyWithCopyrights() {
|
|||
});
|
||||
}
|
||||
|
||||
exports.minifyTask = function (src) {
|
||||
exports.minifyTask = function (src, addSourceMapsComment) {
|
||||
return function() {
|
||||
var jsFilter = filter('**/*.js', { restore: true });
|
||||
var cssFilter = filter('**/*.css', { restore: true });
|
||||
|
@ -198,7 +242,7 @@ exports.minifyTask = function (src) {
|
|||
.pipe(sourcemaps.write('./', {
|
||||
sourceRoot: null,
|
||||
includeContent: true,
|
||||
addComment: false
|
||||
addComment: addSourceMapsComment
|
||||
}))
|
||||
.pipe(gulp.dest(src + '-min'));
|
||||
};
|
||||
|
|
|
@ -27,11 +27,7 @@ var editorEntryPoints = _.flatten([
|
|||
]);
|
||||
|
||||
var editorResources = [
|
||||
'out-build/vs/css.js',
|
||||
'out-build/vs/nls.js',
|
||||
'out-build/vs/text.js',
|
||||
'out-build/vs/{base,editor}/**/*.{svg,png}',
|
||||
'out-build/vs/editor/css/*.css',
|
||||
'out-build/vs/base/worker/workerMainCompatibility.html',
|
||||
'out-build/vs/base/worker/workerMain.{js,js.map}',
|
||||
'out-build/vs/languages/typescript/common/lib/lib.{d.ts,es6.d.ts}',
|
||||
|
@ -39,6 +35,13 @@ var editorResources = [
|
|||
'!**/test/**'
|
||||
];
|
||||
|
||||
var editorOtherSources = [
|
||||
'out-build/vs/css.js',
|
||||
'out-build/vs/nls.js',
|
||||
'out-build/vs/text.js',
|
||||
'out-build/vs/editor/css/*.css'
|
||||
];
|
||||
|
||||
var BUNDLED_FILE_HEADER = [
|
||||
'/*!-----------------------------------------------------------',
|
||||
' * Copyright (C) Microsoft Corporation. All rights reserved.',
|
||||
|
@ -63,54 +66,42 @@ function editorLoaderConfig(removeAllOSS) {
|
|||
}
|
||||
|
||||
gulp.task('clean-optimized-editor', util.rimraf('out-editor'));
|
||||
gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-build'], common.optimizeTask(
|
||||
editorEntryPoints,
|
||||
editorResources,
|
||||
editorLoaderConfig(false),
|
||||
BUNDLED_FILE_HEADER,
|
||||
'out-editor'
|
||||
));
|
||||
gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-build'], common.optimizeTask({
|
||||
entryPoints: editorEntryPoints,
|
||||
otherSources: editorOtherSources,
|
||||
resources: editorResources,
|
||||
loaderConfig: editorLoaderConfig(false),
|
||||
header: BUNDLED_FILE_HEADER,
|
||||
out: 'out-editor'
|
||||
}));
|
||||
|
||||
gulp.task('clean-minified-editor', util.rimraf('out-editor-min'));
|
||||
gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor'));
|
||||
|
||||
// OSS Free
|
||||
gulp.task('clean-optimized-editor-ossfree', util.rimraf('out-editor-ossfree'));
|
||||
gulp.task('optimize-editor-ossfree', ['clean-optimized-editor-ossfree', 'compile-build'], common.optimizeTask(
|
||||
editorEntryPoints,
|
||||
editorResources,
|
||||
editorLoaderConfig(true),
|
||||
BUNDLED_FILE_HEADER,
|
||||
'out-editor-ossfree'
|
||||
));
|
||||
|
||||
gulp.task('clean-minified-editor-ossfree', util.rimraf('out-editor-ossfree-min'));
|
||||
gulp.task('minify-editor-ossfree', ['clean-minified-editor-ossfree', 'optimize-editor-ossfree'], common.minifyTask('out-editor-ossfree'));
|
||||
gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor', true));
|
||||
|
||||
// Package
|
||||
|
||||
var root = path.dirname(__dirname);
|
||||
|
||||
function editorTask(out, dest) {
|
||||
function copyTask(src, dest, FILTER) {
|
||||
return function () {
|
||||
return gulp.src(out + '/**', { base: out })
|
||||
.pipe(filter(['**', '!**/*.js.map']))
|
||||
.pipe(gulp.dest(dest));
|
||||
return (
|
||||
gulp.src(src + '/**', { base: src })
|
||||
.pipe(FILTER ? filter(FILTER) : es.through())
|
||||
.pipe(gulp.dest(dest))
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
gulp.task('clean-editor', util.rimraf(path.join(path.dirname(root), 'Monaco-Editor-Build')));
|
||||
gulp.task('editor', ['clean-editor', 'optimize-editor'],
|
||||
editorTask('out-editor', path.join(path.dirname(root), 'Monaco-Editor-Build')));
|
||||
var DISTRO_DEV_FOLDER_PATH = path.join(path.dirname(root), 'Monaco-Editor');
|
||||
gulp.task('clean-editor-distro-dev', util.rimraf(DISTRO_DEV_FOLDER_PATH));
|
||||
gulp.task('editor-distro-dev', ['clean-editor-distro-dev', 'optimize-editor'], copyTask('out-editor', DISTRO_DEV_FOLDER_PATH));
|
||||
|
||||
gulp.task('clean-editor-min', util.rimraf(path.join(path.dirname(root), 'Monaco-Editor-Build-Min')));
|
||||
gulp.task('editor-min', ['clean-editor-min', 'minify-editor'],
|
||||
editorTask('out-editor-min', path.join(path.dirname(root), 'Monaco-Editor-Build-Min')));
|
||||
var DISTRO_MIN_FOLDER_PATH = path.join(path.dirname(root), 'Monaco-Editor-Min');
|
||||
gulp.task('clean-editor-distro-min', util.rimraf(DISTRO_MIN_FOLDER_PATH));
|
||||
gulp.task('editor-distro-min', ['clean-editor-distro-min', 'minify-editor'], copyTask('out-editor-min', DISTRO_MIN_FOLDER_PATH, ['**', '!**/*.js.map', '!nls.metadata.json']));
|
||||
|
||||
gulp.task('clean-editor-ossfree', util.rimraf(path.join(path.dirname(root), 'Monaco-Editor-Build-OSS-Free')));
|
||||
gulp.task('editor-ossfree', ['clean-editor-ossfree', 'optimize-editor-ossfree'],
|
||||
editorTask('out-editor-ossfree', path.join(path.dirname(root), 'Monaco-Editor-Build-OSS-Free')));
|
||||
var DISTRO_MIN_SOURCEMAPS_FOLDER_PATH = path.join(path.dirname(root), 'Monaco-Editor-Min-SourceMaps');
|
||||
gulp.task('clean-editor-distro-min-sourcemaps', util.rimraf(DISTRO_MIN_SOURCEMAPS_FOLDER_PATH));
|
||||
gulp.task('editor-distro-min-sourcemaps', ['clean-editor-distro-min-sourcemaps', 'minify-editor'], copyTask('out-editor-min', DISTRO_MIN_SOURCEMAPS_FOLDER_PATH, ['**/*.js.map']));
|
||||
|
||||
gulp.task('clean-editor-ossfree-min', util.rimraf(path.join(path.dirname(root), 'Monaco-Editor-Build-OSS-Free-Min')));
|
||||
gulp.task('editor-ossfree-min', ['clean-editor-ossfree-min', 'minify-editor-ossfree'],
|
||||
editorTask('out-editor-ossfree-min', path.join(path.dirname(root), 'Monaco-Editor-Build-OSS-Free-Min')));
|
||||
gulp.task('editor-distro', ['editor-distro-min', 'editor-distro-min-sourcemaps', 'editor-distro-dev']);
|
||||
|
|
|
@ -78,16 +78,17 @@ var BUNDLED_FILE_HEADER = [
|
|||
].join('\n');
|
||||
|
||||
gulp.task('clean-optimized-vscode', util.rimraf('out-vscode'));
|
||||
gulp.task('optimize-vscode', ['clean-optimized-vscode', 'compile-build', 'compile-plugins'], common.optimizeTask(
|
||||
vscodeEntryPoints,
|
||||
vscodeResources,
|
||||
common.loaderConfig(baseModules),
|
||||
BUNDLED_FILE_HEADER,
|
||||
'out-vscode'
|
||||
));
|
||||
gulp.task('optimize-vscode', ['clean-optimized-vscode', 'compile-build', 'compile-plugins'], common.optimizeTask({
|
||||
entryPoints: vscodeEntryPoints,
|
||||
otherSources: [],
|
||||
resources: vscodeResources,
|
||||
loaderConfig: common.loaderConfig(baseModules),
|
||||
header: BUNDLED_FILE_HEADER,
|
||||
out: 'out-vscode'
|
||||
}));
|
||||
|
||||
gulp.task('clean-minified-vscode', util.rimraf('out-vscode-min'));
|
||||
gulp.task('minify-vscode', ['clean-minified-vscode', 'optimize-vscode'], common.minifyTask('out-vscode'));
|
||||
gulp.task('minify-vscode', ['clean-minified-vscode', 'optimize-vscode'], common.minifyTask('out-vscode', false));
|
||||
|
||||
// Package
|
||||
var product = JSON.parse(fs.readFileSync(path.join(root, 'product.json'), 'utf8'));
|
||||
|
|
Loading…
Reference in a new issue