gulpfile.vscode.win32.js 3.9 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 10 11
const path = require('path');
const assert = require('assert');
const cp = require('child_process');
J
Joao Moreno 已提交
12
const _7z = require('7zip')['7z'];
J
Joao Moreno 已提交
13
const util = require('./lib/util');
14 15
const pkg = require('../package.json');
const product = require('../product.json');
16
const vfs = require('vinyl-fs');
J
Joao Moreno 已提交
17

18
const repoPath = path.dirname(__dirname);
J
Joao Moreno 已提交
19 20 21 22
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`);
const setupDir = arch => path.join(repoPath, '.build', `win32-${arch}`, 'setup');
23 24
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 已提交
25

26 27 28 29
function packageInnoSetup(iss, options, cb) {
	options = options || {};

	const definitions = options.definitions || {};
J
Joao Moreno 已提交
30
	const keys = Object.keys(definitions);
31

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

J
Joao Moreno 已提交
34
	const defs = keys.map(key => `/d${key}=${definitions[key]}`);
J
Joao Moreno 已提交
35
	const args = [iss].concat(defs);
36 37 38 39 40 41

	cp.spawn(innoSetupPath, args, { stdio: 'inherit' })
		.on('error', cb)
		.on('exit', () => cb(null));
}

J
Joao Moreno 已提交
42 43
function buildWin32Setup(arch) {
	return cb => {
J
Joao Moreno 已提交
44 45 46
		const ia32AppId = product.win32AppId;
		const x64AppId = product.win32x64AppId;

J
Joao Moreno 已提交
47 48 49 50 51 52 53 54 55 56 57
		const definitions = {
			NameLong: product.nameLong,
			NameShort: product.nameShort,
			DirName: product.win32DirName,
			Version: pkg.version,
			RawVersion: pkg.version.replace(/-\w+$/, ''),
			NameVersion: product.win32NameVersion,
			ExeBasename: product.nameShort,
			RegValueName: product.win32RegValueName,
			ShellNameShort: product.win32ShellNameShort,
			AppMutex: product.win32MutexName,
J
Joao Moreno 已提交
58 59 60
			Arch: arch,
			AppId: arch === 'ia32' ? ia32AppId : x64AppId,
			IncompatibleAppId: arch === 'ia32' ? x64AppId : ia32AppId,
J
Joao Moreno 已提交
61
			AppUserId: product.win32AppUserModelId,
J
Joao Moreno 已提交
62 63
			ArchitecturesAllowed: arch === 'ia32' ? '' : 'x64',
			ArchitecturesInstallIn64BitMode: arch === 'ia32' ? '' : 'x64',
J
Joao Moreno 已提交
64 65 66 67
			SourceDir: buildPath(arch),
			RepoDir: repoPath,
			OutputDir: setupDir(arch)
		};
68

J
Joao Moreno 已提交
69
		packageInnoSetup(issPath, { definitions }, cb);
J
Joao Moreno 已提交
70
	};
J
Joao Moreno 已提交
71 72
}

J
Joao Moreno 已提交
73 74
gulp.task('clean-vscode-win32-ia32-setup', util.rimraf(setupDir('ia32')));
gulp.task('vscode-win32-ia32-setup', ['clean-vscode-win32-ia32-setup'], buildWin32Setup('ia32'));
J
Joao Moreno 已提交
75

J
Joao Moreno 已提交
76 77
gulp.task('clean-vscode-win32-x64-setup', util.rimraf(setupDir('x64')));
gulp.task('vscode-win32-x64-setup', ['clean-vscode-win32-x64-setup'], buildWin32Setup('x64'));
J
Joao Moreno 已提交
78

J
Joao Moreno 已提交
79 80
function archiveWin32Setup(arch) {
	return cb => {
81
		const args = ['a', '-tzip', zipPath(arch), '.', '-r', '-x!inno_updater.exe'];
J
Joao Moreno 已提交
82

J
Joao Moreno 已提交
83
		cp.spawn(_7z, args, { stdio: 'inherit', cwd: buildPath(arch) })
J
Joao Moreno 已提交
84 85 86
			.on('error', cb)
			.on('exit', () => cb(null));
	};
J
Joao Moreno 已提交
87 88
}

J
Joao Moreno 已提交
89 90 91 92 93
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 已提交
94 95 96 97 98 99 100 101 102 103

function copyInnoUpdater(arch) {
	return () => {
		return gulp.src('build/win32/inno_updater.exe', { base: 'build/win32' })
			.pipe(vfs.dest(buildPath(arch)));
	};
}

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