vscode/build/gulpfile.vscode.win32.js

151 lines
5.7 KiB
JavaScript
Raw Normal View History

2016-07-20 11:17:52 +02:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
const gulp = require('gulp');
const path = require('path');
2018-06-21 01:29:06 +02:00
const fs = require('fs');
const assert = require('assert');
const cp = require('child_process');
2017-05-10 12:56:18 +02:00
const _7z = require('7zip')['7z'];
2016-07-20 11:17:52 +02:00
const util = require('./lib/util');
const pkg = require('../package.json');
const product = require('../product.json');
const vfs = require('vinyl-fs');
2018-09-24 15:41:16 +02:00
const rcedit = require('rcedit');
2018-06-21 01:29:06 +02:00
const mkdirp = require('mkdirp');
2016-07-20 11:17:52 +02:00
const repoPath = path.dirname(__dirname);
2017-05-18 15:40:58 +02:00
const buildPath = arch => path.join(path.dirname(repoPath), `VSCode-win32-${arch}`);
const zipDir = arch => path.join(repoPath, '.build', `win32-${arch}`, 'archive');
const zipPath = arch => path.join(zipDir(arch), `VSCode-win32-${arch}.zip`);
2018-06-20 16:22:42 +02:00
const setupDir = (arch, target) => path.join(repoPath, '.build', `win32-${arch}`, `${target}-setup`);
const issPath = path.join(__dirname, 'win32', 'code.iss');
const innoSetupPath = path.join(path.dirname(path.dirname(require.resolve('innosetup-compiler'))), 'bin', 'ISCC.exe');
2018-07-02 14:14:54 +02:00
const signPS1 = path.join(repoPath, 'build', 'tfs', 'win32', 'sign.ps1');
2016-07-20 11:17:52 +02:00
function packageInnoSetup(iss, options, cb) {
options = options || {};
const definitions = options.definitions || {};
2018-06-19 15:29:36 +02:00
if (process.argv.some(arg => arg === '--debug-inno')) {
2018-06-19 15:29:36 +02:00
definitions['Debug'] = 'true';
}
if (process.argv.some(arg => arg === '--sign')) {
definitions['Sign'] = 'true';
}
2016-07-28 09:07:22 +02:00
const keys = Object.keys(definitions);
2017-05-10 12:56:18 +02:00
keys.forEach(key => assert(typeof definitions[key] === 'string', `Missing value for '${key}' in Inno Setup package step`));
2016-07-28 09:07:22 +02:00
2017-05-10 12:56:18 +02:00
const defs = keys.map(key => `/d${key}=${definitions[key]}`);
2018-07-02 11:43:03 +02:00
const args = [
iss,
2018-07-02 14:14:54 +02:00
...defs,
`/sesrp=powershell.exe -ExecutionPolicy bypass ${signPS1} $f`
2018-07-02 11:43:03 +02:00
];
2018-06-21 01:29:06 +02:00
cp.spawn(innoSetupPath, args, { stdio: ['ignore', 'inherit', 'inherit'] })
.on('error', cb)
.on('exit', () => cb(null));
}
2018-06-20 16:22:42 +02:00
function buildWin32Setup(arch, target) {
if (target !== 'system' && target !== 'user') {
throw new Error('Invalid setup target');
}
2018-01-22 15:47:18 +01:00
return cb => {
2018-06-20 16:22:42 +02:00
const ia32AppId = target === 'system' ? product.win32AppId : product.win32UserAppId;
const x64AppId = target === 'system' ? product.win32x64AppId : product.win32x64UserAppId;
2017-06-22 17:36:17 +02:00
2018-06-21 01:29:06 +02:00
const sourcePath = buildPath(arch);
const outputPath = setupDir(arch, target);
mkdirp.sync(outputPath);
const originalProductJsonPath = path.join(sourcePath, 'resources/app/product.json');
const productJsonPath = path.join(outputPath, 'product.json');
const productJson = JSON.parse(fs.readFileSync(originalProductJsonPath, 'utf8'));
productJson['target'] = target;
fs.writeFileSync(productJsonPath, JSON.stringify(productJson, undefined, '\t'));
2017-05-18 15:40:58 +02:00
const definitions = {
NameLong: product.nameLong,
NameShort: product.nameShort,
DirName: product.win32DirName,
Version: pkg.version,
RawVersion: pkg.version.replace(/-\w+$/, ''),
2018-06-27 15:31:31 +02:00
NameVersion: product.win32NameVersion + (target === 'user' ? ' (User)' : ''),
2017-05-18 15:40:58 +02:00
ExeBasename: product.nameShort,
RegValueName: product.win32RegValueName,
ShellNameShort: product.win32ShellNameShort,
AppMutex: product.win32MutexName,
2017-06-22 17:36:17 +02:00
Arch: arch,
AppId: arch === 'ia32' ? ia32AppId : x64AppId,
IncompatibleTargetAppId: arch === 'ia32' ? product.win32AppId : product.win32x64AppId,
IncompatibleArchAppId: arch === 'ia32' ? x64AppId : ia32AppId,
2017-05-18 15:40:58 +02:00
AppUserId: product.win32AppUserModelId,
2017-06-22 17:36:17 +02:00
ArchitecturesAllowed: arch === 'ia32' ? '' : 'x64',
ArchitecturesInstallIn64BitMode: arch === 'ia32' ? '' : 'x64',
2018-06-21 01:29:06 +02:00
SourceDir: sourcePath,
2017-05-18 15:40:58 +02:00
RepoDir: repoPath,
2018-06-21 01:29:06 +02:00
OutputDir: outputPath,
InstallTarget: target,
ProductJsonPath: productJsonPath
2017-05-18 15:40:58 +02:00
};
2018-01-22 15:47:18 +01:00
packageInnoSetup(issPath, { definitions }, cb);
2017-05-18 15:40:58 +02:00
};
2016-07-20 11:17:52 +02:00
}
2018-06-20 16:22:42 +02:00
function defineWin32SetupTasks(arch, target) {
gulp.task(`clean-vscode-win32-${arch}-${target}-setup`, util.rimraf(setupDir(arch, target)));
gulp.task(`vscode-win32-${arch}-${target}-setup`, [`clean-vscode-win32-${arch}-${target}-setup`], buildWin32Setup(arch, target));
}
2017-05-10 12:56:18 +02:00
2018-06-20 16:22:42 +02:00
defineWin32SetupTasks('ia32', 'system');
defineWin32SetupTasks('x64', 'system');
defineWin32SetupTasks('ia32', 'user');
defineWin32SetupTasks('x64', 'user');
2017-05-10 12:56:18 +02:00
2017-05-18 15:40:58 +02:00
function archiveWin32Setup(arch) {
return cb => {
2018-06-27 15:21:55 +02:00
const args = ['a', '-tzip', zipPath(arch), '-x!CodeSignSummary*.md', '.', '-r'];
2017-05-18 15:40:58 +02:00
2017-06-15 08:49:08 +02:00
cp.spawn(_7z, args, { stdio: 'inherit', cwd: buildPath(arch) })
2017-05-18 15:40:58 +02:00
.on('error', cb)
.on('exit', () => cb(null));
};
2017-05-10 12:56:18 +02:00
}
2017-05-18 15:40:58 +02:00
gulp.task('clean-vscode-win32-ia32-archive', util.rimraf(zipDir('ia32')));
gulp.task('vscode-win32-ia32-archive', ['clean-vscode-win32-ia32-archive'], archiveWin32Setup('ia32'));
gulp.task('clean-vscode-win32-x64-archive', util.rimraf(zipDir('x64')));
gulp.task('vscode-win32-x64-archive', ['clean-vscode-win32-x64-archive'], archiveWin32Setup('x64'));
2018-01-22 15:47:18 +01:00
function copyInnoUpdater(arch) {
return () => {
return gulp.src('build/win32/{inno_updater.exe,vcruntime140.dll}', { base: 'build/win32' })
.pipe(vfs.dest(path.join(buildPath(arch), 'tools')));
2018-01-22 15:47:18 +01:00
};
}
gulp.task('vscode-win32-ia32-copy-inno-updater', copyInnoUpdater('ia32'));
2018-09-24 15:41:16 +02:00
gulp.task('vscode-win32-x64-copy-inno-updater', copyInnoUpdater('x64'));
function patchInnoUpdater(arch) {
return cb => {
const icon = path.join(repoPath, 'resources', 'win32', 'code.ico');
rcedit(path.join(buildPath(arch), 'tools', 'inno_updater.exe'), { icon }, cb);
};
}
gulp.task('vscode-win32-ia32-inno-updater', ['vscode-win32-ia32-copy-inno-updater'], patchInnoUpdater('ia32'));
gulp.task('vscode-win32-x64-inno-updater', ['vscode-win32-x64-copy-inno-updater'], patchInnoUpdater('x64'));