|
1 | | -import { sign as windowsSign, SignOptions } from "@electron/windows-sign"; |
2 | | -import { spawn } from 'child_process'; |
3 | | - |
4 | | -import { log } from "./logger"; |
5 | | -import { ProgramOptions } from "./types"; |
6 | | - |
7 | | -const run = async (executable: string, args: Array<string>) => { |
8 | | - return new Promise<string>((resolve, reject) => { |
9 | | - const proc = spawn(executable, args, {}); |
10 | | - log.debug(`Calling ${executable} with args`, args); |
11 | | - |
12 | | - const cleanOutData = (data: any) => { |
13 | | - return data |
14 | | - .toString() |
15 | | - .replace(/\r/g, '') |
16 | | - .replace(/\\\\/g, '\\') |
17 | | - .split('\n') |
18 | | - } |
19 | | - |
20 | | - let stdout = ""; |
21 | | - proc.stdout.on('data', (data) => { |
22 | | - stdout += data; |
23 | | - }); |
24 | | - |
25 | | - let stderr = ""; |
26 | | - proc.stderr.on('data', (data) => { |
27 | | - stderr += data; |
28 | | - }); |
29 | | - |
30 | | - proc.on('exit', (code: number) => { |
31 | | - log.debug(`stdout of ${executable}`, cleanOutData(stdout)); |
32 | | - if (code !== 0) { |
33 | | - log.error(`stderr of ${executable}`, false, cleanOutData(stderr)) |
34 | | - return reject(new Error(`Failed running ${executable} Exit Code: ${code} See previous errors for details`)) |
35 | | - } |
36 | | - return resolve(stdout); |
37 | | - }); |
38 | | - |
39 | | - proc.stdin.end(); |
40 | | - }) |
41 | | -} |
42 | | - |
43 | | -export const getCertPublisher = async (cert: string, cert_pass: string) => { |
44 | | - const args = []; |
45 | | - args.push('-p', cert_pass); |
46 | | - args.push('-dump', cert); |
47 | | - const certDump = await run('certutil', args); |
48 | | - const subjectRegex = /Subject:\s*(.*)/; |
49 | | - const match = certDump.match(subjectRegex); |
50 | | - const publisher = match ? match[1].trim() : null; |
51 | | - if(!publisher) { |
52 | | - log.error('Unable to find publisher in Cert'); |
53 | | - } |
54 | | - return publisher; |
55 | | -} |
56 | | - |
57 | | -export const priConfig = async (program: ProgramOptions) => { |
58 | | - const { makePri, priConfig, createPri } = program; |
59 | | - if(createPri) { |
60 | | - const args = ['createconfig', '/cf', priConfig, '/dq', 'en-US']; |
61 | | - log.debug('Creating pri config.') |
62 | | - await run(makePri, args); |
63 | | - } else { |
64 | | - log.debug('Skipping making pri config.'); |
65 | | - } |
66 | | -} |
67 | | - |
68 | | -export const pri = async (program: ProgramOptions) => { |
69 | | - const { makePri, priConfig, layoutDir, priFile, appManifestLayout, createPri } = program; |
70 | | - if(createPri) { |
71 | | - log.debug('Making pri.') |
72 | | - const args = ['new', '/pr', layoutDir, '/cf', priConfig, '/mn', appManifestLayout, '/of', priFile, '/v']; |
73 | | - await run(makePri, args); |
74 | | - } else { |
75 | | - log.debug('Skipping making pri.'); |
76 | | - } |
77 | | -} |
78 | | - |
79 | | -export const make = async (program: ProgramOptions) => { |
80 | | - const { makeMsix, layoutDir, msix, isSparsePackage} = program; |
81 | | - const args = [ |
82 | | - 'pack', |
83 | | - '/d', |
84 | | - layoutDir, |
85 | | - '/p', |
86 | | - msix, |
87 | | - '/o', |
88 | | - ]; |
89 | | - |
90 | | - if(isSparsePackage) { |
91 | | - args.push('/nv'); |
92 | | - } |
93 | | - await run(makeMsix, args); |
94 | | -} |
95 | | - |
96 | | -export const sign = async (program: ProgramOptions) => { |
97 | | - if(program.sign) { |
98 | | - const signOptions = program.windowsSignOptions; |
99 | | - log.debug('Signing with options', signOptions); |
100 | | - await windowsSign(signOptions as SignOptions); |
101 | | - } else { |
102 | | - log.debug('Skipping signing.'); |
103 | | - } |
104 | | -} |
| 1 | +import { sign as windowsSign, SignOptions } from "@electron/windows-sign"; |
| 2 | +import { spawn } from 'child_process'; |
| 3 | + |
| 4 | +import { log } from "./logger"; |
| 5 | +import { ProgramOptions } from "./types"; |
| 6 | + |
| 7 | +const run = async (executable: string, args: Array<string>) => { |
| 8 | + return new Promise<string>((resolve, reject) => { |
| 9 | + const proc = spawn(executable, args, {}); |
| 10 | + log.debug(`Calling ${executable} with args`, args); |
| 11 | + |
| 12 | + const cleanOutData = (data: any) => { |
| 13 | + return data |
| 14 | + .toString() |
| 15 | + .replace(/\r/g, '') |
| 16 | + .replace(/\\\\/g, '\\') |
| 17 | + .split('\n') |
| 18 | + } |
| 19 | + |
| 20 | + let stdout = ""; |
| 21 | + proc.stdout.on('data', (data) => { |
| 22 | + stdout += data; |
| 23 | + }); |
| 24 | + |
| 25 | + let stderr = ""; |
| 26 | + proc.stderr.on('data', (data) => { |
| 27 | + stderr += data; |
| 28 | + }); |
| 29 | + |
| 30 | + proc.on('exit', (code: number) => { |
| 31 | + if (code === 0) { |
| 32 | + log.debug(`stdout of ${executable}`, cleanOutData(stdout)); |
| 33 | + return resolve(stdout); |
| 34 | + } else { |
| 35 | + if (stderr !== '') { |
| 36 | + log.error(`stderr of ${executable}`, false, cleanOutData(stderr)); |
| 37 | + } |
| 38 | + |
| 39 | + if (stdout !== '') { |
| 40 | + log.error(`stdout of ${executable}`, false, cleanOutData(stdout)); |
| 41 | + } |
| 42 | + return reject( |
| 43 | + new Error( |
| 44 | + `Failed running ${executable} Exit Code: ${code} See previous errors for details` |
| 45 | + ) |
| 46 | + ); |
| 47 | + |
| 48 | + } |
| 49 | + }); |
| 50 | + |
| 51 | + proc.stdin.end(); |
| 52 | + }) |
| 53 | +} |
| 54 | + |
| 55 | +export const getCertPublisher = async (cert: string, cert_pass: string) => { |
| 56 | + const args = []; |
| 57 | + args.push('-p', cert_pass); |
| 58 | + args.push('-dump', cert); |
| 59 | + const certDump = await run('certutil', args); |
| 60 | + const subjectRegex = /Subject:\s*(.*)/; |
| 61 | + const match = certDump.match(subjectRegex); |
| 62 | + const publisher = match ? match[1].trim() : null; |
| 63 | + if(!publisher) { |
| 64 | + log.error('Unable to find publisher in Cert'); |
| 65 | + } |
| 66 | + return publisher; |
| 67 | +} |
| 68 | + |
| 69 | +export const priConfig = async (program: ProgramOptions) => { |
| 70 | + const { makePri, priConfig, createPri } = program; |
| 71 | + if(createPri) { |
| 72 | + const args = ['createconfig', '/cf', priConfig, '/dq', 'en-US']; |
| 73 | + log.debug('Creating pri config.') |
| 74 | + await run(makePri, args); |
| 75 | + } else { |
| 76 | + log.debug('Skipping making pri config.'); |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +export const pri = async (program: ProgramOptions) => { |
| 81 | + const { makePri, priConfig, layoutDir, priFile, appManifestLayout, createPri } = program; |
| 82 | + if(createPri) { |
| 83 | + log.debug('Making pri.') |
| 84 | + const args = ['new', '/pr', layoutDir, '/cf', priConfig, '/mn', appManifestLayout, '/of', priFile, '/v']; |
| 85 | + await run(makePri, args); |
| 86 | + } else { |
| 87 | + log.debug('Skipping making pri.'); |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +export const make = async (program: ProgramOptions) => { |
| 92 | + const { makeMsix, layoutDir, msix, isSparsePackage} = program; |
| 93 | + const args = [ |
| 94 | + 'pack', |
| 95 | + '/d', |
| 96 | + layoutDir, |
| 97 | + '/p', |
| 98 | + msix, |
| 99 | + '/o', |
| 100 | + ]; |
| 101 | + |
| 102 | + if(isSparsePackage) { |
| 103 | + args.push('/nv'); |
| 104 | + } |
| 105 | + await run(makeMsix, args); |
| 106 | +} |
| 107 | + |
| 108 | +export const sign = async (program: ProgramOptions) => { |
| 109 | + if(program.sign) { |
| 110 | + const signOptions = program.windowsSignOptions; |
| 111 | + log.debug('Signing with options', signOptions); |
| 112 | + await windowsSign(signOptions as SignOptions); |
| 113 | + } else { |
| 114 | + log.debug('Skipping signing.'); |
| 115 | + } |
| 116 | +} |
0 commit comments