vscode/build/gulpfile.vscode.js

544 lines
19 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 os = require('os');
const cp = require('child_process');
2016-07-20 08:52:46 +00:00
const path = require('path');
const es = require('event-stream');
const azure = require('gulp-azure-storage');
const electron = require('gulp-atom-electron');
2016-09-05 10:38:25 +00:00
const vfs = require('vinyl-fs');
2016-07-20 08:52:46 +00:00
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');
2019-02-12 14:13:43 +00:00
const task = require('./lib/task');
2016-07-20 08:52:46 +00:00
const buildfile = require('../src/buildfile');
const common = require('./lib/optimize');
2016-07-20 08:52:46 +00:00
const root = path.dirname(__dirname);
const commit = util.getVersion(root);
2016-07-20 09:00:43 +00:00
const packageJson = require('../package.json');
const product = require('../product.json');
2016-09-23 07:35:29 +00:00
const crypto = require('crypto');
const i18n = require('./lib/i18n');
const deps = require('./dependencies');
2019-10-16 13:35:53 +00:00
const { config } = require('./lib/electron');
2018-02-19 09:28:14 +00:00
const createAsar = require('./lib/asar').createAsar;
const minimist = require('minimist');
2019-02-05 09:03:46 +00:00
const { compileBuildTask } = require('./gulpfile.compile');
const { compileExtensionsBuildTask } = require('./gulpfile.extensions');
2016-07-20 08:52:46 +00:00
const productionDependencies = deps.getProductionDependencies(path.dirname(__dirname));
2016-07-20 08:52:46 +00:00
const baseModules = Object.keys(process.binding('natives')).filter(n => !/^_|\//.test(n));
const nodeModules = ['electron', 'original-fs']
.concat(Object.keys(product.dependencies || {}))
.concat(_.uniq(productionDependencies.map(d => d.name)))
2016-07-20 08:52:46 +00:00
.concat(baseModules);
2015-11-23 19:28:42 +00:00
// Build
2016-07-20 08:52:46 +00:00
const vscodeEntryPoints = _.flatten([
buildfile.entrypoint('vs/workbench/workbench.desktop.main'),
2015-11-23 19:28:42 +00:00
buildfile.base,
2019-08-27 12:59:31 +00:00
buildfile.workbenchDesktop,
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',
2018-04-04 10:15:04 +00:00
'out-build/driver.js',
2015-11-23 19:28:42 +00:00
'out-build/bootstrap.js',
'out-build/bootstrap-fork.js',
2016-02-09 14:09:03 +00:00
'out-build/bootstrap-amd.js',
'out-build/bootstrap-window.js',
2016-05-04 09:01:10 +00:00
'out-build/paths.js',
2019-07-14 11:36:46 +00:00
'out-build/vs/**/*.{svg,png,html}',
2019-04-11 10:32:34 +00:00
'!out-build/vs/code/browser/**/*.html',
'out-build/vs/base/common/performance.js',
'out-build/vs/base/node/languagePacks.js',
2019-04-11 23:10:52 +00:00
'out-build/vs/base/node/{stdForkStart.js,terminateProcess.sh,cpuUsage.sh,ps.sh}',
'out-build/vs/base/browser/ui/codiconLabel/codicon/**',
2015-11-23 19:28:42 +00:00
'out-build/vs/workbench/browser/media/*-theme.css',
'out-build/vs/workbench/contrib/debug/**/*.json',
'out-build/vs/workbench/contrib/externalTerminal/**/*.scpt',
'out-build/vs/workbench/contrib/webview/browser/pre/*.js',
'out-build/vs/workbench/contrib/webview/electron-browser/pre/*.js',
2016-09-28 14:58:13 +00:00
'out-build/vs/**/markdown.css',
'out-build/vs/workbench/contrib/tasks/**/*.json',
2019-07-10 18:55:44 +00:00
'out-build/vs/platform/files/**/*.exe',
'out-build/vs/platform/files/**/*.md',
'out-build/vs/code/electron-browser/workbench/**',
'out-build/vs/code/electron-browser/sharedProcess/sharedProcess.js',
'out-build/vs/code/electron-browser/issue/issueReporter.js',
2018-04-10 00:35:17 +00:00
'out-build/vs/code/electron-browser/processExplorer/processExplorer.js',
'out-build/vs/platform/auth/common/auth.css',
2015-11-23 19:28:42 +00:00
'!**/test/**'
];
2019-02-12 19:43:28 +00:00
const optimizeVSCodeTask = task.define('optimize-vscode', task.series(
util.rimraf('out-vscode'),
2019-02-05 17:08:41 +00:00
common.optimizeTask({
src: 'out-build',
entryPoints: vscodeEntryPoints,
resources: vscodeResources,
loaderConfig: common.loaderConfig(nodeModules),
out: 'out-vscode',
bundleInfo: undefined
})
2019-02-12 19:43:28 +00:00
));
gulp.task(optimizeVSCodeTask);
2019-02-05 17:08:41 +00:00
const sourceMappingURLBase = `https://ticino.blob.core.windows.net/sourcemaps/${commit}`;
const minifyVSCodeTask = task.define('minify-vscode', task.series(
2019-02-05 17:08:41 +00:00
optimizeVSCodeTask,
util.rimraf('out-vscode-min'),
2019-02-05 17:08:41 +00:00
() => {
const fullpath = path.join(process.cwd(), 'out-vscode/bootstrap-window.js');
const contents = fs.readFileSync(fullpath).toString();
const newContents = contents.replace('[/*BUILD->INSERT_NODE_MODULES*/]', JSON.stringify(nodeModules));
fs.writeFileSync(fullpath, newContents);
},
2019-02-05 17:08:41 +00:00
common.minifyTask('out-vscode', `${sourceMappingURLBase}/core`)
2019-02-12 19:43:28 +00:00
));
gulp.task(minifyVSCodeTask);
2015-11-23 19:28:42 +00:00
2016-09-23 07:35:29 +00:00
/**
* Compute checksums for some files.
*
* @param {string} out The out folder to read the file from.
* @param {string[]} filenames The paths to compute a checksum for.
* @return {Object} A map of paths to checksums.
*/
function computeChecksums(out, filenames) {
2020-01-02 19:35:07 +00:00
let result = {};
filenames.forEach(function (filename) {
2020-01-02 19:35:07 +00:00
let fullPath = path.join(process.cwd(), out, filename);
2016-09-23 07:35:29 +00:00
result[filename] = computeChecksum(fullPath);
});
return result;
}
/**
* Compute checksum for a file.
*
* @param {string} filename The absolute path to a filename.
* @return {string} The checksum for `filename`.
*/
function computeChecksum(filename) {
2020-01-02 19:35:07 +00:00
let contents = fs.readFileSync(filename);
2016-09-23 07:35:29 +00:00
2020-01-02 19:35:07 +00:00
let hash = crypto
2016-09-23 07:35:29 +00:00
.createHash('md5')
.update(contents)
.digest('base64')
.replace(/=+$/, '');
return hash;
}
2019-02-05 17:08:41 +00:00
function packageTask(platform, arch, sourceFolderName, destinationFolderName, opts) {
2017-05-18 14:02:40 +00:00
opts = opts || {};
2019-02-05 17:08:41 +00:00
const destination = path.join(path.dirname(root), destinationFolderName);
2015-11-23 19:28:42 +00:00
platform = platform || process.platform;
2016-07-20 08:52:46 +00:00
return () => {
2019-02-05 17:08:41 +00:00
const out = sourceFolderName;
2015-11-23 19:28:42 +00:00
2016-09-23 07:35:29 +00:00
const checksums = computeChecksums(out, [
'vs/workbench/workbench.desktop.main.js',
'vs/workbench/workbench.desktop.main.css',
'vs/code/electron-browser/workbench/workbench.html',
'vs/code/electron-browser/workbench/workbench.js'
2016-09-23 07:35:29 +00:00
]);
2016-07-20 08:52:46 +00:00
const src = gulp.src(out + '/**', { base: '.' })
.pipe(rename(function (path) { path.dirname = path.dirname.replace(new RegExp('^' + out), 'out'); }))
2019-07-14 19:21:29 +00:00
.pipe(util.setExecutableBit(['**/*.sh']));
2015-11-23 19:28:42 +00:00
2019-07-14 19:21:29 +00:00
const extensions = gulp.src('.build/extensions/**', { base: '.build', dot: true });
2019-07-14 19:21:29 +00:00
const sources = es.merge(src, extensions)
2019-07-14 19:48:29 +00:00
.pipe(filter(['**', '!**/*.js.map'], { dot: true }));
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 packageJsonUpdates = { name, version };
// for linux url handling
if (platform === 'linux') {
packageJsonUpdates.desktopName = `${product.applicationName}-url-handler.desktop`;
}
2016-07-20 08:52:46 +00:00
const packageJsonStream = gulp.src(['package.json'], { base: '.' })
.pipe(json(packageJsonUpdates));
2016-07-20 08:52:46 +00:00
const date = new Date().toISOString();
const productJsonUpdate = { commit, date, checksums };
if (shouldSetupSettingsSearch()) {
productJsonUpdate.settingsSearchBuildId = getSettingsSearchBuildId(packageJson);
}
2016-07-20 08:52:46 +00:00
const productJsonStream = gulp.src(['product.json'], { base: '.' })
.pipe(json(productJsonUpdate));
2015-11-23 19:28:42 +00:00
2019-03-19 08:39:57 +00:00
const license = gulp.src(['LICENSES.chromium.html', product.licenseFileName, 'ThirdPartyNotices.txt', 'licenses/**'], { base: '.', allowEmpty: true });
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 telemetry = gulp.src('.build/telemetry/**', { base: '.build/telemetry', dot: true });
2019-07-14 19:21:29 +00:00
const root = path.resolve(path.join(__dirname, '..'));
const dependenciesSrc = _.flatten(productionDependencies.map(d => path.relative(root, d.path)).map(d => [`${d}/**`, `!${d}/**/{test,tests}/**`]));
2015-11-23 19:28:42 +00:00
const deps = gulp.src(dependenciesSrc, { base: '.', dot: true })
2017-07-26 14:39:49 +00:00
.pipe(filter(['**', '!**/package-lock.json']))
2019-05-09 14:27:37 +00:00
.pipe(util.cleanNodeModules(path.join(__dirname, '.nativeignore')))
2018-02-19 09:28:14 +00:00
.pipe(createAsar(path.join(process.cwd(), 'node_modules'), ['**/*.node', '**/vscode-ripgrep/bin/*', '**/node-pty/build/Release/*'], 'app/node_modules.asar'));
2015-11-23 19:28:42 +00:00
2016-07-20 08:52:46 +00:00
let all = es.merge(
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,
telemetry,
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/bower.ico',
'resources/win32/c.ico',
'resources/win32/config.ico',
'resources/win32/cpp.ico',
'resources/win32/csharp.ico',
'resources/win32/css.ico',
'resources/win32/default.ico',
'resources/win32/go.ico',
'resources/win32/html.ico',
'resources/win32/jade.ico',
'resources/win32/java.ico',
'resources/win32/javascript.ico',
'resources/win32/json.ico',
'resources/win32/less.ico',
'resources/win32/markdown.ico',
'resources/win32/php.ico',
'resources/win32/powershell.ico',
'resources/win32/python.ico',
'resources/win32/react.ico',
'resources/win32/ruby.ico',
'resources/win32/sass.ico',
'resources/win32/shell.ico',
'resources/win32/sql.ico',
'resources/win32/typescript.ico',
'resources/win32/vue.ico',
'resources/win32/xml.ico',
'resources/win32/yaml.ico',
'resources/win32/code_70x70.png',
'resources/win32/code_150x150.png'
], { base: '.' }));
2016-02-12 14:31:54 +00:00
} 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())
.pipe(electron(_.extend({}, config, { platform, arch, ffmpegChromium: true })))
2019-06-27 14:37:33 +00:00
.pipe(filter(['**', '!LICENSE', '!LICENSES.chromium.html', '!version'], { dot: true }));
2015-11-23 19:28:42 +00:00
2019-08-12 06:49:19 +00:00
if (platform === 'linux') {
result = es.merge(result, gulp.src('resources/completions/bash/code', { base: '.' })
.pipe(replace('@@APPNAME@@', product.applicationName))
.pipe(rename(function (f) { f.basename = product.applicationName; })));
result = es.merge(result, gulp.src('resources/completions/zsh/_code', { base: '.' })
.pipe(replace('@@APPNAME@@', product.applicationName))
.pipe(rename(function (f) { f.basename = '_' + product.applicationName; })));
}
2015-11-23 19:28:42 +00:00
if (platform === 'win32') {
2019-02-06 09:15:36 +00:00
result = es.merge(result, gulp.src('resources/win32/bin/code.js', { base: 'resources/win32', allowEmpty: true }));
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))
2019-04-10 14:46:24 +00:00
.pipe(replace('@@PRODNAME@@', product.nameLong))
.pipe(replace('@@VERSION@@', version))
2018-11-08 20:59:23 +00:00
.pipe(replace('@@COMMIT@@', commit))
.pipe(replace('@@APPNAME@@', product.applicationName))
2019-05-29 21:18:39 +00:00
.pipe(replace('@@DATAFOLDER@@', product.dataFolderName))
2019-04-12 12:01:12 +00:00
.pipe(replace('@@QUALITY@@', quality))
.pipe(rename(function (f) { f.basename = product.applicationName; f.extname = ''; })));
result = es.merge(result, gulp.src('resources/win32/VisualElementsManifest.xml', { base: 'resources/win32' })
.pipe(rename(product.nameShort + '.VisualElementsManifest.xml')));
} else if (platform === 'linux') {
result = es.merge(result, gulp.src('resources/linux/bin/code.sh', { base: '.' })
2019-04-10 14:46:24 +00:00
.pipe(replace('@@PRODNAME@@', product.nameLong))
.pipe(replace('@@NAME@@', product.applicationName))
.pipe(rename('bin/' + product.applicationName)));
2015-11-23 19:28:42 +00:00
}
2018-09-05 14:58:50 +00:00
// submit all stats that have been collected
// during the build phase
if (opts.stats) {
result.on('end', () => {
const { submitAllStats } = require('./lib/stats');
2018-09-07 08:26:36 +00:00
submitAllStats(product, commit).then(() => console.log('Submitted bundle stats!'));
2018-09-05 14:58:50 +00:00
});
}
2016-09-05 10:38:25 +00:00
return result.pipe(vfs.dest(destination));
2015-11-23 19:28:42 +00:00
};
}
2016-07-20 08:52:46 +00:00
const buildRoot = path.dirname(root);
2019-02-05 17:08:41 +00:00
const BUILD_TARGETS = [
{ platform: 'win32', arch: 'ia32' },
{ platform: 'win32', arch: 'x64' },
{ platform: 'darwin', arch: null, opts: { stats: true } },
{ platform: 'linux', arch: 'ia32' },
{ platform: 'linux', arch: 'x64' },
{ platform: 'linux', arch: 'arm' },
{ platform: 'linux', arch: 'arm64' },
];
BUILD_TARGETS.forEach(buildTarget => {
const dashed = (str) => (str ? `-${str}` : ``);
const platform = buildTarget.platform;
const arch = buildTarget.arch;
const opts = buildTarget.opts;
['', 'min'].forEach(minified => {
const sourceFolderName = `out-vscode${dashed(minified)}`;
const destinationFolderName = `VSCode${dashed(platform)}${dashed(arch)}`;
const vscodeTaskCI = task.define(`vscode${dashed(platform)}${dashed(arch)}${dashed(minified)}-ci`, task.series(
util.rimraf(path.join(buildRoot, destinationFolderName)),
2019-02-05 17:08:41 +00:00
packageTask(platform, arch, sourceFolderName, destinationFolderName, opts)
2019-02-12 19:43:28 +00:00
));
gulp.task(vscodeTaskCI);
2019-07-01 10:24:33 +00:00
const vscodeTask = task.define(`vscode${dashed(platform)}${dashed(arch)}${dashed(minified)}`, task.series(
compileBuildTask,
2019-07-01 10:24:33 +00:00
compileExtensionsBuildTask,
minified ? minifyVSCodeTask : optimizeVSCodeTask,
vscodeTaskCI
2019-07-01 10:24:33 +00:00
));
2019-02-12 19:43:28 +00:00
gulp.task(vscodeTask);
2019-02-05 17:08:41 +00:00
});
});
2015-11-23 19:28:42 +00:00
// Transifex Localizations
2018-01-25 20:13:24 +00:00
const innoSetupConfig = {
'zh-cn': { codePage: 'CP936', defaultInfo: { name: 'Simplified Chinese', id: '$0804', } },
'zh-tw': { codePage: 'CP950', defaultInfo: { name: 'Traditional Chinese', id: '$0404' } },
'ko': { codePage: 'CP949', defaultInfo: { name: 'Korean', id: '$0412' } },
'ja': { codePage: 'CP932' },
'de': { codePage: 'CP1252' },
'fr': { codePage: 'CP1252' },
'es': { codePage: 'CP1252' },
'ru': { codePage: 'CP1251' },
'it': { codePage: 'CP1252' },
'pt-br': { codePage: 'CP1252' },
'hu': { codePage: 'CP1250' },
'tr': { codePage: 'CP1254' }
};
const apiHostname = process.env.TRANSIFEX_API_URL;
const apiName = process.env.TRANSIFEX_API_NAME;
const apiToken = process.env.TRANSIFEX_API_TOKEN;
2019-02-12 19:43:28 +00:00
gulp.task(task.define(
'vscode-translations-push',
2019-02-12 14:13:43 +00:00
task.series(
2019-07-11 07:44:52 +00:00
compileBuildTask,
compileExtensionsBuildTask,
2019-02-05 20:23:25 +00:00
optimizeVSCodeTask,
function () {
const pathToMetadata = './out-vscode/nls.metadata.json';
2019-09-04 06:05:36 +00:00
const pathToExtensions = '.build/extensions/*';
2019-02-05 20:23:25 +00:00
const pathToSetup = 'build/win32/**/{Default.isl,messages.en.isl}';
return es.merge(
gulp.src(pathToMetadata).pipe(i18n.createXlfFilesForCoreBundle()),
gulp.src(pathToSetup).pipe(i18n.createXlfFilesForIsl()),
gulp.src(pathToExtensions).pipe(i18n.createXlfFilesForExtensions())
).pipe(i18n.findObsoleteResources(apiHostname, apiName, apiToken)
).pipe(i18n.pushXlfFiles(apiHostname, apiName, apiToken));
}
)
2019-02-12 19:43:28 +00:00
));
2018-01-25 20:13:24 +00:00
2019-02-12 19:43:28 +00:00
gulp.task(task.define(
'vscode-translations-export',
2019-02-12 14:13:43 +00:00
task.series(
2019-07-11 07:44:52 +00:00
compileBuildTask,
compileExtensionsBuildTask,
2019-02-05 20:23:25 +00:00
optimizeVSCodeTask,
function () {
const pathToMetadata = './out-vscode/nls.metadata.json';
2019-09-04 06:05:36 +00:00
const pathToExtensions = '.build/extensions/*';
2019-02-05 20:23:25 +00:00
const pathToSetup = 'build/win32/**/{Default.isl,messages.en.isl}';
return es.merge(
gulp.src(pathToMetadata).pipe(i18n.createXlfFilesForCoreBundle()),
gulp.src(pathToSetup).pipe(i18n.createXlfFilesForIsl()),
gulp.src(pathToExtensions).pipe(i18n.createXlfFilesForExtensions())
).pipe(vfs.dest('../vscode-translations-export'));
}
)
2019-02-12 19:43:28 +00:00
));
2018-01-25 20:13:24 +00:00
gulp.task('vscode-translations-pull', function () {
return es.merge([...i18n.defaultLanguages, ...i18n.extraLanguages].map(language => {
2018-01-25 20:13:24 +00:00
let includeDefault = !!innoSetupConfig[language.id].defaultInfo;
return i18n.pullSetupXlfFiles(apiHostname, apiName, apiToken, language, includeDefault).pipe(vfs.dest(`../vscode-translations-import/${language.id}/setup`));
}));
});
2017-05-16 16:12:27 +00:00
gulp.task('vscode-translations-import', function () {
2020-01-02 19:35:07 +00:00
let options = minimist(process.argv.slice(2), {
string: 'location',
default: {
location: '../vscode-translations-import'
}
});
return es.merge([...i18n.defaultLanguages, ...i18n.extraLanguages].map(language => {
let id = language.transifexId || language.id;
return gulp.src(`${options.location}/${id}/setup/*/*.xlf`)
2018-01-25 20:13:24 +00:00
.pipe(i18n.prepareIslFiles(language, innoSetupConfig[language.id]))
.pipe(vfs.dest(`./build/win32/i18n`));
}));
});
// This task is only run for the MacOS build
2019-02-12 19:43:28 +00:00
const generateVSCodeConfigurationTask = task.define('generate-vscode-configuration', () => {
return new Promise((resolve, reject) => {
const buildDir = process.env['AGENT_BUILDDIRECTORY'];
if (!buildDir) {
return reject(new Error('$AGENT_BUILDDIRECTORY not set'));
}
2018-06-25 13:22:43 +00:00
if (process.env.VSCODE_QUALITY !== 'insider' && process.env.VSCODE_QUALITY !== 'stable') {
return resolve();
}
const userDataDir = path.join(os.tmpdir(), 'tmpuserdata');
const extensionsDir = path.join(os.tmpdir(), 'tmpextdir');
const appName = process.env.VSCODE_QUALITY === 'insider' ? 'Visual\\ Studio\\ Code\\ -\\ Insiders.app' : 'Visual\\ Studio\\ Code.app';
const appPath = path.join(buildDir, `VSCode-darwin/${appName}/Contents/Resources/app/bin/code`);
const codeProc = cp.exec(
`${appPath} --export-default-configuration='${allConfigDetailsPath}' --wait --user-data-dir='${userDataDir}' --extensions-dir='${extensionsDir}'`,
(err, stdout, stderr) => {
clearTimeout(timer);
if (err) {
console.log(`err: ${err} ${err.message} ${err.toString()}`);
reject(err);
}
if (stdout) {
console.log(`stdout: ${stdout}`);
}
if (stderr) {
console.log(`stderr: ${stderr}`);
}
resolve();
}
);
const timer = setTimeout(() => {
codeProc.kill();
reject(new Error('export-default-configuration process timed out'));
}, 12 * 1000);
codeProc.on('error', err => {
clearTimeout(timer);
reject(err);
});
});
2019-02-12 19:43:28 +00:00
});
2019-02-05 20:23:25 +00:00
const allConfigDetailsPath = path.join(os.tmpdir(), 'configuration.json');
2019-02-12 19:43:28 +00:00
gulp.task(task.define(
'upload-vscode-configuration',
2019-02-12 14:13:43 +00:00
task.series(
2019-02-05 20:23:25 +00:00
generateVSCodeConfigurationTask,
() => {
if (!shouldSetupSettingsSearch()) {
const branch = process.env.BUILD_SOURCEBRANCH;
console.log(`Only runs on master and release branches, not ${branch}`);
return;
}
if (!fs.existsSync(allConfigDetailsPath)) {
throw new Error(`configuration file at ${allConfigDetailsPath} does not exist`);
}
const settingsSearchBuildId = getSettingsSearchBuildId(packageJson);
if (!settingsSearchBuildId) {
throw new Error('Failed to compute build number');
}
return gulp.src(allConfigDetailsPath)
.pipe(azure.upload({
account: process.env.AZURE_STORAGE_ACCOUNT,
key: process.env.AZURE_STORAGE_ACCESS_KEY,
container: 'configuration',
prefix: `${settingsSearchBuildId}/${commit}/`
}));
}
)
2019-02-12 19:43:28 +00:00
));
2019-02-05 20:23:25 +00:00
function shouldSetupSettingsSearch() {
const branch = process.env.BUILD_SOURCEBRANCH;
return branch && (/\/master$/.test(branch) || branch.indexOf('/release/') >= 0);
}
function getSettingsSearchBuildId(packageJson) {
try {
const branch = process.env.BUILD_SOURCEBRANCH;
const branchId = branch.indexOf('/release/') >= 0 ? 0 :
/\/master$/.test(branch) ? 1 :
2; // Some unexpected branch
const out = cp.execSync(`git rev-list HEAD --count`);
const count = parseInt(out.toString());
// <version number><commit count><branchId (avoid unlikely conflicts)>
// 1.25.1, 1,234,567 commits, master = 1250112345671
return util.versionStringToNumber(packageJson.version) * 1e8 + count * 10 + branchId;
} catch (e) {
throw new Error('Could not determine build number: ' + e.toString());
}
}