<commit_before>import * as fs from 'fs-extra';
import { shellEscape } from '../utils';

const path = require('path') as typeof import('path');
const cp = require('child_process') as typeof import('child_process');

function execFile(cmd, args) {
	return new Promise<void>(function (resolve, reject) {
		cp.execFile(cmd, args, function (err, _stdout, stderr) {
			if (err || stderr) {
				return reject(err || stderr);
			}
			resolve();
		});
	});
}

export async function buildInnoSetup(options: {
	installerDir: string;
	outDir: string;
	version: string;
	gameUID: string;
	certFile: string;
	certPw: string;
}) {
	const vendorDir = path.resolve(__dirname, 'vendor');
	let script = await fs.readFile(path.join(vendorDir, 'gamejolt.iss'), {
		encoding: 'utf8',
	});

	// Version in innosetup isnt semver compatible. it expects a value in the form of 4 numbers separated by dot.
	const versionStuff = options.version.match(/^v?(\d+)\.(\d+)\.(\d+)/);
	if (!versionStuff) {
		throw new Error('Version is invalid');
	}
	const installerVersion = versionStuff.join('.') + '.0';

	script = script
		.replace(/\{\{ICON_DIR\}\}/g, shellEscape(path.resolve(__dirname, 'icons')))
		.replace(/\{\{APP_DIR\}\}/g, shellEscape(options.installerDir))
		.replace(/\{\{OUT_DIR\}\}/g, shellEscape(options.outDir))
		.replace(/\{\{GAME_UID\}\}/g, options.gameUID)
		.replace(/\{\{APP_VERSION\}\}/g, options.version)
		.replace(/\{\{INSTALLER_VERSION\}\}/g, installerVersion);

	const scriptFilepath = path.join(vendorDir, 'tmp-gamejolt.iss');
	await fs.writeFile(scriptFilepath, script, { encoding: 'utf8' });

	await execFile('iscc.exe', [
		'/Ssigntool=' +
			shellEscape(path.join(vendorDir, 'signtool.exe')) +
			' sign /f ' +
			shellEscape(options.certFile) +
			' /p ' +
			options.certPw +
			' /t http://timestamp.digicert.com $f',
		'/Q',
		scriptFilepath,
	]);
}
<commit_msg>Trying to fix builds with the cert timestamp server<commit_after>import * as fs from 'fs-extra';
import { shellEscape } from '../utils';

const path = require('path') as typeof import('path');
const cp = require('child_process') as typeof import('child_process');

function execFile(cmd, args) {
	return new Promise<void>(function (resolve, reject) {
		cp.execFile(cmd, args, function (err, _stdout, stderr) {
			if (err || stderr) {
				return reject(err || stderr);
			}
			resolve();
		});
	});
}

export async function buildInnoSetup(options: {
	installerDir: string;
	outDir: string;
	version: string;
	gameUID: string;
	certFile: string;
	certPw: string;
}) {
	const vendorDir = path.resolve(__dirname, 'vendor');
	let script = await fs.readFile(path.join(vendorDir, 'gamejolt.iss'), {
		encoding: 'utf8',
	});

	// Version in innosetup isnt semver compatible. it expects a value in the form of 4 numbers separated by dot.
	const versionStuff = options.version.match(/^v?(\d+)\.(\d+)\.(\d+)/);
	if (!versionStuff) {
		throw new Error('Version is invalid');
	}
	const installerVersion = versionStuff.join('.') + '.0';

	script = script
		.replace(/\{\{ICON_DIR\}\}/g, shellEscape(path.resolve(__dirname, 'icons')))
		.replace(/\{\{APP_DIR\}\}/g, shellEscape(options.installerDir))
		.replace(/\{\{OUT_DIR\}\}/g, shellEscape(options.outDir))
		.replace(/\{\{GAME_UID\}\}/g, options.gameUID)
		.replace(/\{\{APP_VERSION\}\}/g, options.version)
		.replace(/\{\{INSTALLER_VERSION\}\}/g, installerVersion);

	const scriptFilepath = path.join(vendorDir, 'tmp-gamejolt.iss');
	await fs.writeFile(scriptFilepath, script, { encoding: 'utf8' });

	await execFile('iscc.exe', [
		'/Ssigntool=' +
			shellEscape(path.join(vendorDir, 'signtool.exe')) +
			' sign /f ' +
			shellEscape(options.certFile) +
			' /p ' +
			options.certPw +
			' /tr http://timestamp.digicert.com $f',
		'/Q',
		scriptFilepath,
	]);
}

{'fraction_non_alphanumeric': 0.1860588391200636, 'fraction_numerical': 0.0021203286509408957, 'mean_word_length': 4.120759837177747, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3818316', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1319, 'n_words': 290}