gulpfile.vscode.win32.js 5.4 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  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');
9
const path = require('path');
J
Joao Moreno 已提交
10
const fs = require('fs');
11 12
const assert = require('assert');
const cp = require('child_process');
J
Joao Moreno 已提交
13
const _7z = require('7zip')['7z'];
J
Joao Moreno 已提交
14
const util = require('./lib/util');
E
Erich Gamma 已提交
15
// @ts-ignore Microsoft/TypeScript#21262 complains about a require of a JSON file
16
const pkg = require('../package.json');
E
Erich Gamma 已提交
17
// @ts-ignore Microsoft/TypeScript#21262 complains about a require of a JSON file
18
const product = require('../product.json');
19
const vfs = require('vinyl-fs');
J
Joao Moreno 已提交
20
const mkdirp = require('mkdirp');
J
Joao Moreno 已提交
21

22
const repoPath = path.dirname(__dirname);
J
Joao Moreno 已提交
23 24 25
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`);
J
Joao Moreno 已提交
26
const setupDir = (arch, target) => path.join(repoPath, '.build', `win32-${arch}`, `${target}-setup`);
27 28
const issPath = path.join(__dirname, 'win32', 'code.iss');
const innoSetupPath = path.join(path.dirname(path.dirname(require.resolve('innosetup-compiler'))), 'bin', 'ISCC.exe');
J
Joao Moreno 已提交
29
const signPS1 = path.join(repoPath, 'build', 'tfs', 'win32', 'sign.ps1');
J
Joao Moreno 已提交
30

31 32 33 34
function packageInnoSetup(iss, options, cb) {
	options = options || {};

	const definitions = options.definitions || {};
J
Joao Moreno 已提交
35 36 37 38 39 40
	const debug = process.argv.some(arg => arg === '--debug-inno');

	if (debug) {
		definitions['Debug'] = 'true';
	}

J
Joao Moreno 已提交
41
	const keys = Object.keys(definitions);
42

J
Joao Moreno 已提交
43
	keys.forEach(key => assert(typeof definitions[key] === 'string', `Missing value for '${key}' in Inno Setup package step`));
J
Joao Moreno 已提交
44

J
Joao Moreno 已提交
45
	const defs = keys.map(key => `/d${key}=${definitions[key]}`);
J
Joao Moreno 已提交
46 47
	const args = [
		iss,
J
Joao Moreno 已提交
48 49
		...defs,
		`/sesrp=powershell.exe -ExecutionPolicy bypass ${signPS1} $f`
J
Joao Moreno 已提交
50
	];
51

J
Joao Moreno 已提交
52
	cp.spawn(innoSetupPath, args, { stdio: ['ignore', 'inherit', 'inherit'] })
53 54 55 56
		.on('error', cb)
		.on('exit', () => cb(null));
}

J
Joao Moreno 已提交
57 58 59 60 61
function buildWin32Setup(arch, target) {
	if (target !== 'system' && target !== 'user') {
		throw new Error('Invalid setup target');
	}

J
Joao Moreno 已提交
62
	return cb => {
J
Joao Moreno 已提交
63 64
		const ia32AppId = target === 'system' ? product.win32AppId : product.win32UserAppId;
		const x64AppId = target === 'system' ? product.win32x64AppId : product.win32x64UserAppId;
J
Joao Moreno 已提交
65

J
Joao Moreno 已提交
66 67 68 69 70 71 72 73 74 75
		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'));

J
Joao Moreno 已提交
76 77 78 79 80 81
		const definitions = {
			NameLong: product.nameLong,
			NameShort: product.nameShort,
			DirName: product.win32DirName,
			Version: pkg.version,
			RawVersion: pkg.version.replace(/-\w+$/, ''),
J
Joao Moreno 已提交
82
			NameVersion: product.win32NameVersion + (target === 'user' ? ' (User)' : ''),
J
Joao Moreno 已提交
83 84 85 86
			ExeBasename: product.nameShort,
			RegValueName: product.win32RegValueName,
			ShellNameShort: product.win32ShellNameShort,
			AppMutex: product.win32MutexName,
J
Joao Moreno 已提交
87 88
			Arch: arch,
			AppId: arch === 'ia32' ? ia32AppId : x64AppId,
89 90
			IncompatibleTargetAppId: arch === 'ia32' ? product.win32AppId : product.win32x64AppId,
			IncompatibleArchAppId: arch === 'ia32' ? x64AppId : ia32AppId,
J
Joao Moreno 已提交
91
			AppUserId: product.win32AppUserModelId,
J
Joao Moreno 已提交
92 93
			ArchitecturesAllowed: arch === 'ia32' ? '' : 'x64',
			ArchitecturesInstallIn64BitMode: arch === 'ia32' ? '' : 'x64',
J
Joao Moreno 已提交
94
			SourceDir: sourcePath,
J
Joao Moreno 已提交
95
			RepoDir: repoPath,
J
Joao Moreno 已提交
96 97 98
			OutputDir: outputPath,
			InstallTarget: target,
			ProductJsonPath: productJsonPath
J
Joao Moreno 已提交
99
		};
100

J
Joao Moreno 已提交
101
		packageInnoSetup(issPath, { definitions }, cb);
J
Joao Moreno 已提交
102
	};
J
Joao Moreno 已提交
103 104
}

J
Joao Moreno 已提交
105 106 107 108
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));
}
J
Joao Moreno 已提交
109

J
Joao Moreno 已提交
110 111 112 113
defineWin32SetupTasks('ia32', 'system');
defineWin32SetupTasks('x64', 'system');
defineWin32SetupTasks('ia32', 'user');
defineWin32SetupTasks('x64', 'user');
J
Joao Moreno 已提交
114

J
Joao Moreno 已提交
115 116
function archiveWin32Setup(arch) {
	return cb => {
J
Joao Moreno 已提交
117
		const args = ['a', '-tzip', zipPath(arch), '-x!CodeSignSummary*.md', '.', '-r'];
J
Joao Moreno 已提交
118

J
Joao Moreno 已提交
119
		cp.spawn(_7z, args, { stdio: 'inherit', cwd: buildPath(arch) })
J
Joao Moreno 已提交
120 121 122
			.on('error', cb)
			.on('exit', () => cb(null));
	};
J
Joao Moreno 已提交
123 124
}

J
Joao Moreno 已提交
125 126 127 128 129
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'));
J
Joao Moreno 已提交
130 131 132

function copyInnoUpdater(arch) {
	return () => {
133 134
		return gulp.src('build/win32/{inno_updater.exe,vcruntime140.dll}', { base: 'build/win32' })
			.pipe(vfs.dest(path.join(buildPath(arch), 'tools')));
J
Joao Moreno 已提交
135 136 137 138 139
	};
}

gulp.task('vscode-win32-ia32-copy-inno-updater', copyInnoUpdater('ia32'));
gulp.task('vscode-win32-x64-copy-inno-updater', copyInnoUpdater('x64'));