vscode/build/gulpfile.vscode.js

273 lines
12 KiB
JavaScript
Raw Normal View History

2015-11-23 19:28:42 +00:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
2016-07-20 08:52:46 +00:00
'use strict';
const gulp = require('gulp');
const fs = require('fs');
const path = require('path');
const es = require('event-stream');
const azure = require('gulp-azure-storage');
const electron = require('gulp-atom-electron');
const symdest = require('gulp-symdest');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const filter = require('gulp-filter');
const json = require('gulp-json-editor');
const _ = require('underscore');
const util = require('./lib/util');
const buildfile = require('../src/buildfile');
const common = require('./gulpfile.common');
const nlsDev = require('vscode-nls-dev');
const root = path.dirname(__dirname);
const build = path.join(root, '.build');
const commit = util.getVersion(root);
2016-07-20 09:00:43 +00:00
const packageJson = require('../package.json');
const product = require('../product.json');
const shrinkwrap = require('../npm-shrinkwrap.json');
2016-07-20 08:52:46 +00:00
const dependencies = Object.keys(shrinkwrap.dependencies);
const baseModules = Object.keys(process.binding('natives')).filter(n => !/^_|\//.test(n));
const nodeModules = ['electron', 'original-fs']
.concat(dependencies)
.concat(baseModules);
2015-11-23 19:28:42 +00:00
// Build
2016-07-20 08:52:46 +00:00
const vscodeEntryPoints = _.flatten([
2015-11-23 19:28:42 +00:00
buildfile.entrypoint('vs/workbench/workbench.main'),
buildfile.base,
buildfile.editor,
buildfile.languages,
buildfile.workbench,
buildfile.code
2015-11-23 19:28:42 +00:00
]);
2016-07-20 08:52:46 +00:00
const vscodeResources = [
2016-02-09 14:09:03 +00:00
'out-build/main.js',
2016-02-12 11:08:19 +00:00
'out-build/cli.js',
2015-11-23 19:28:42 +00:00
'out-build/bootstrap.js',
2016-02-09 14:09:03 +00:00
'out-build/bootstrap-amd.js',
2016-05-04 09:01:10 +00:00
'out-build/paths.js',
2015-11-23 19:28:42 +00:00
'out-build/vs/**/*.{svg,png,cur}',
'out-build/vs/base/node/{stdForkStart.js,terminateProcess.sh}',
'out-build/vs/base/worker/workerMainCompatibility.html',
'out-build/vs/base/worker/workerMain.{js,js.map}',
'out-build/vs/base/browser/ui/octiconLabel/octicons/**',
2015-11-23 19:28:42 +00:00
'out-build/vs/workbench/browser/media/*-theme.css',
'out-build/vs/workbench/electron-browser/index.html',
'out-build/vs/workbench/parts/debug/**/*.json',
'out-build/vs/workbench/parts/execution/**/*.scpt',
'out-build/vs/workbench/parts/git/**/*.html',
'out-build/vs/workbench/parts/git/**/*.sh',
'out-build/vs/workbench/parts/html/browser/webview.html',
'out-build/vs/workbench/parts/extensions/electron-browser/media/markdown.css',
2015-11-23 19:28:42 +00:00
'out-build/vs/workbench/parts/tasks/**/*.json',
'out-build/vs/workbench/parts/terminal/electron-browser/terminalProcess.js',
2015-11-23 19:28:42 +00:00
'out-build/vs/workbench/services/files/**/*.exe',
'out-build/vs/workbench/services/files/**/*.md',
'!**/test/**'
];
2016-07-20 08:52:46 +00:00
const BUNDLED_FILE_HEADER = [
2015-11-23 19:28:42 +00:00
'/*!--------------------------------------------------------',
' * Copyright (C) Microsoft Corporation. All rights reserved.',
' *--------------------------------------------------------*/'
].join('\n');
gulp.task('clean-optimized-vscode', util.rimraf('out-vscode'));
2016-03-08 09:56:52 +00:00
gulp.task('optimize-vscode', ['clean-optimized-vscode', 'compile-build', 'compile-extensions-build'], common.optimizeTask({
2015-11-23 19:28:42 +00:00
entryPoints: vscodeEntryPoints,
otherSources: [],
resources: vscodeResources,
loaderConfig: common.loaderConfig(nodeModules),
2015-11-23 19:28:42 +00:00
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', true));
2015-11-23 19:28:42 +00:00
// Package
2016-07-20 08:52:46 +00:00
const darwinCreditsTemplate = product.darwinCredits && _.template(fs.readFileSync(path.join(root, product.darwinCredits), 'utf8'));
2015-11-23 19:28:42 +00:00
2016-07-20 08:52:46 +00:00
const config = {
2016-01-20 16:51:01 +00:00
version: packageJson.electronVersion,
2015-11-23 19:28:42 +00:00
productAppName: product.nameLong,
2016-01-20 16:36:31 +00:00
companyName: 'Microsoft Corporation',
2016-04-19 05:55:52 +00:00
copyright: 'Copyright (C) 2016 Microsoft. All rights reserved',
2016-01-20 16:36:31 +00:00
darwinIcon: 'resources/darwin/code.icns',
2015-11-23 19:28:42 +00:00
darwinBundleIdentifier: product.darwinBundleIdentifier,
2016-01-20 16:36:31 +00:00
darwinApplicationCategoryType: 'public.app-category.developer-tools',
darwinBundleDocumentTypes: [{
name: product.nameLong + ' document',
role: 'Editor',
ostypes: ["TEXT", "utxt", "TUTX", "****"],
2016-07-20 08:21:45 +00:00
extensions: ["ascx", "asp", "aspx", "bash", "bash_login", "bash_logout", "bash_profile", "bashrc", "bat", "bowerrc", "c", "cc", "clj", "cljs", "cljx", "clojure", "cmd", "coffee", "config", "cpp", "cs", "cshtml", "csproj", "css", "csx", "ctp", "cxx", "dockerfile", "dot", "dtd", "editorconfig", "edn", "eyaml", "eyml", "fs", "fsi", "fsscript", "fsx", "gemspec", "gitattributes", "gitconfig", "gitignore", "go", "h", "handlebars", "hbs", "hh", "hpp", "htm", "html", "hxx", "ini", "jade", "jav", "java", "js", "jscsrc", "jshintrc", "jshtm", "json", "jsp", "less", "lua", "m", "makefile", "markdown", "md", "mdoc", "mdown", "mdtext", "mdtxt", "mdwn", "mkd", "mkdn", "ml", "mli", "php", "phtml", "pl", "pl6", "pm", "pm6", "pod", "pp", "profile", "properties", "ps1", "psd1", "psgi", "psm1", "py", "r", "rb", "rhistory", "rprofile", "rs", "rt", "scss", "sh", "shtml", "sql", "svg", "svgz", "t", "ts", "txt", "vb", "wxi", "wxl", "wxs", "xaml", "xml", "yaml", "yml", "zlogin", "zlogout", "zprofile", "zsh", "zshenv", "zshrc"],
2016-01-20 16:36:31 +00:00
iconFile: 'resources/darwin/code_file.icns'
}],
2016-08-03 16:03:53 +00:00
darwinBundleURLTypes: [{
role: 'Viewer',
name: product.nameLong,
urlSchemes: ['vscode']
}],
2015-11-23 19:28:42 +00:00
darwinCredits: darwinCreditsTemplate ? new Buffer(darwinCreditsTemplate({ commit: commit, date: new Date().toISOString() })) : void 0,
2016-02-12 14:48:39 +00:00
linuxExecutableName: product.applicationName,
2016-01-20 16:36:31 +00:00
winIcon: 'resources/win32/code.ico',
2015-11-23 19:28:42 +00:00
token: process.env['GITHUB_TOKEN'] || void 0
};
2016-07-20 08:52:46 +00:00
gulp.task('electron', () => {
2015-11-23 19:28:42 +00:00
// Force windows to use ia32
2016-07-20 08:52:46 +00:00
const arch = process.env.VSCODE_ELECTRON_PLATFORM || (process.platform === 'win32' ? 'ia32' : process.arch);
2016-04-14 15:20:06 +00:00
return electron.dest(path.join(build, 'electron'), _.extend({}, config, { arch: arch, ffmpegChromium: true }));
2015-11-23 19:28:42 +00:00
});
2016-07-20 08:52:46 +00:00
const languages = ['chs', 'cht', 'jpn', 'kor', 'deu', 'fra', 'esn', 'rus', 'ita'];
2015-11-23 19:28:42 +00:00
function packageTask(platform, arch, opts) {
opts = opts || {};
2016-07-20 08:52:46 +00:00
const destination = path.join(path.dirname(root), 'VSCode') + (platform ? '-' + platform : '') + (arch ? '-' + arch : '');
2015-11-23 19:28:42 +00:00
platform = platform || process.platform;
arch = platform === 'win32' ? 'ia32' : arch;
2016-07-20 08:52:46 +00:00
return () => {
const out = opts.minified ? 'out-vscode-min' : 'out-vscode';
2015-11-23 19:28:42 +00:00
2016-07-20 08:52:46 +00:00
const src = gulp.src(out + '/**', { base: '.' })
2015-11-23 19:28:42 +00:00
.pipe(rename(function (path) { path.dirname = path.dirname.replace(new RegExp('^' + out), 'out'); }))
.pipe(util.setExecutableBit(['**/*.sh']));
2016-07-20 08:52:46 +00:00
const extensions = gulp.src([
2015-11-23 19:28:42 +00:00
'extensions/**',
'!extensions/*/src/**',
'!extensions/*/out/**/test/**',
2016-04-08 21:00:27 +00:00
'!extensions/*/test/**',
'!extensions/*/build/**',
2016-06-14 13:14:51 +00:00
'!extensions/*/{client,server}/src/**',
'!extensions/*/{client,server}/test/**',
'!extensions/*/{client,server}/out/**/test/**',
'!extensions/*/{client,server}/out/**/typings/**',
'!extensions/**/.vscode/**',
'!extensions/**/tsconfig.json',
'!extensions/typescript/bin/**',
2016-01-22 08:04:50 +00:00
'!extensions/vscode-api-tests/**',
2016-06-23 15:41:36 +00:00
'!extensions/vscode-colorize-tests/**'
2015-11-23 19:28:42 +00:00
], { base: '.' });
2016-07-20 08:52:46 +00:00
const sources = es.merge(src, extensions)
.pipe(nlsDev.createAdditionalLanguageFiles(languages, path.join(__dirname, '..', 'i18n')))
.pipe(filter(['**', '!**/*.js.map']))
.pipe(util.handleAzureJson({ platform: platform }));
2015-11-23 19:28:42 +00:00
2016-07-20 08:52:46 +00:00
let version = packageJson.version;
const quality = product.quality;
2016-01-20 16:51:01 +00:00
if (quality && quality !== 'stable') {
version += '-' + quality;
}
2016-07-20 08:52:46 +00:00
const name = product.nameShort;
const packageJsonStream = gulp.src(['package.json'], { base: '.' })
.pipe(json({ name, version }));
const date = new Date().toISOString();
const productJsonStream = gulp.src(['product.json'], { base: '.' })
.pipe(json({ commit, date }));
2015-11-23 19:28:42 +00:00
2016-07-20 08:52:46 +00:00
const license = gulp.src(['Credits_*', 'LICENSE.txt', 'ThirdPartyNotices.txt', 'licenses/**'], { base: '.' });
2015-11-23 19:28:42 +00:00
2016-07-20 08:52:46 +00:00
// TODO the API should be copied to `out` during compile, not here
const api = gulp.src('src/vs/vscode.d.ts').pipe(rename('out/vs/vscode.d.ts'));
const depsSrc = _.flatten(dependencies
2016-04-19 13:57:34 +00:00
.map(function (d) { return ['node_modules/' + d + '/**', '!node_modules/' + d + '/**/{test,tests}/**']; }));
2015-11-23 19:28:42 +00:00
2016-07-20 08:52:46 +00:00
const deps = gulp.src(depsSrc, { base: '.', dot: true })
.pipe(util.cleanNodeModule('fsevents', ['binding.gyp', 'fsevents.cc', 'build/**', 'src/**', 'test/**'], ['**/*.node']))
.pipe(util.cleanNodeModule('oniguruma', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], ['**/*.node']))
.pipe(util.cleanNodeModule('windows-mutex', ['binding.gyp', 'build/**', 'src/**'], ['**/*.node']))
.pipe(util.cleanNodeModule('native-keymap', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], ['**/*.node']))
.pipe(util.cleanNodeModule('pty.js', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], ['build/Release/**']));
2015-11-23 19:28:42 +00:00
2016-07-20 08:52:46 +00:00
let all = es.merge(
2016-01-20 16:51:01 +00:00
packageJsonStream,
2016-07-20 08:52:46 +00:00
productJsonStream,
2015-11-23 19:28:42 +00:00
license,
2016-07-20 08:52:46 +00:00
api,
2015-11-23 19:28:42 +00:00
sources,
2016-02-19 14:35:30 +00:00
deps
2016-02-12 14:31:54 +00:00
);
if (platform === 'win32') {
all = es.merge(all, gulp.src('resources/win32/code_file.ico', { base: '.' }));
} else if (platform === 'linux') {
all = es.merge(all, gulp.src('resources/linux/code.png', { base: '.' }));
2016-02-12 15:55:11 +00:00
} else if (platform === 'darwin') {
2016-07-20 08:52:46 +00:00
const shortcut = gulp.src('resources/darwin/bin/code.sh')
2016-02-12 15:55:11 +00:00
.pipe(rename('bin/code'));
all = es.merge(all, shortcut);
2016-02-12 14:31:54 +00:00
}
2015-11-23 19:28:42 +00:00
2016-07-20 08:52:46 +00:00
let result = all
2016-02-12 14:31:54 +00:00
.pipe(util.skipDirectories())
2015-11-23 19:28:42 +00:00
.pipe(util.fixWin32DirectoryPermissions())
2016-04-14 15:20:06 +00:00
.pipe(electron(_.extend({}, config, { platform: platform, arch: arch, ffmpegChromium: true })))
2015-12-15 12:00:05 +00:00
.pipe(filter(['**', '!LICENSE', '!LICENSES.chromium.html', '!version']));
2015-11-23 19:28:42 +00:00
if (platform === 'win32') {
2016-02-25 15:58:27 +00:00
result = es.merge(result, gulp.src('resources/win32/bin/code.js', { base: 'resources/win32' }));
2016-01-27 14:41:54 +00:00
2016-02-25 15:58:27 +00:00
result = es.merge(result, gulp.src('resources/win32/bin/code.cmd', { base: 'resources/win32' })
.pipe(replace('@@NAME@@', product.nameShort))
.pipe(rename(function (f) { f.basename = product.applicationName; })));
2016-02-25 15:58:27 +00:00
result = es.merge(result, gulp.src('resources/win32/bin/code.sh', { base: 'resources/win32' })
.pipe(replace('@@NAME@@', product.nameShort))
.pipe(rename(function (f) { f.basename = product.applicationName; f.extname = ''; })));
} else if (platform === 'linux') {
result = es.merge(result, gulp.src('resources/linux/bin/code.sh', { base: '.' })
.pipe(replace('@@NAME@@', product.applicationName))
.pipe(rename('bin/' + product.applicationName)));
2015-11-23 19:28:42 +00:00
}
2016-01-25 15:00:30 +00:00
return result.pipe(symdest(destination));
2015-11-23 19:28:42 +00:00
};
}
2016-07-20 08:52:46 +00:00
const buildRoot = path.dirname(root);
gulp.task('clean-vscode-win32', util.rimraf(path.join(buildRoot, 'VSCode-win32')));
gulp.task('clean-vscode-darwin', util.rimraf(path.join(buildRoot, 'VSCode-darwin')));
gulp.task('clean-vscode-linux-ia32', util.rimraf(path.join(buildRoot, 'VSCode-linux-ia32')));
gulp.task('clean-vscode-linux-x64', util.rimraf(path.join(buildRoot, 'VSCode-linux-x64')));
gulp.task('clean-vscode-linux-arm', util.rimraf(path.join(buildRoot, 'VSCode-linux-arm')));
2015-11-23 19:28:42 +00:00
gulp.task('vscode-win32', ['optimize-vscode', 'clean-vscode-win32'], packageTask('win32'));
2016-01-27 13:56:15 +00:00
gulp.task('vscode-darwin', ['optimize-vscode', 'clean-vscode-darwin'], packageTask('darwin'));
2015-11-23 19:28:42 +00:00
gulp.task('vscode-linux-ia32', ['optimize-vscode', 'clean-vscode-linux-ia32'], packageTask('linux', 'ia32'));
gulp.task('vscode-linux-x64', ['optimize-vscode', 'clean-vscode-linux-x64'], packageTask('linux', 'x64'));
2015-12-07 12:14:51 +00:00
gulp.task('vscode-linux-arm', ['optimize-vscode', 'clean-vscode-linux-arm'], packageTask('linux', 'arm'));
2015-11-23 19:28:42 +00:00
gulp.task('vscode-win32-min', ['minify-vscode', 'clean-vscode-win32'], packageTask('win32', null, { minified: true }));
gulp.task('vscode-darwin-min', ['minify-vscode', 'clean-vscode-darwin'], packageTask('darwin', null, { minified: true }));
gulp.task('vscode-linux-ia32-min', ['minify-vscode', 'clean-vscode-linux-ia32'], packageTask('linux', 'ia32', { minified: true }));
gulp.task('vscode-linux-x64-min', ['minify-vscode', 'clean-vscode-linux-x64'], packageTask('linux', 'x64', { minified: true }));
2015-12-07 12:14:51 +00:00
gulp.task('vscode-linux-arm-min', ['minify-vscode', 'clean-vscode-linux-arm'], packageTask('linux', 'arm', { minified: true }));
2015-11-23 19:28:42 +00:00
// Sourcemaps
2016-02-16 15:17:29 +00:00
gulp.task('upload-vscode-sourcemaps', ['minify-vscode'], function () {
2015-11-23 19:28:42 +00:00
return gulp.src('out-vscode-min/**/*.map')
.pipe(azure.upload({
account: process.env.AZURE_STORAGE_ACCOUNT,
key: process.env.AZURE_STORAGE_ACCESS_KEY,
container: 'sourcemaps',
prefix: commit + '/'
}));
});