-
Notifications
You must be signed in to change notification settings - Fork 812
/
notarization.js
101 lines (93 loc) · 2.21 KB
/
notarization.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const util = require('util');
const execCore = util.promisify(require('child_process').exec);
function sleep(ms) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms);
});
}
async function exec(command) {
try {
return await execCore(command);
} catch (err) {
const stderr = err.message;
return {stderr};
}
}
async function notarizeApp(password) {
//
const command = `xcrun altool --notarize-app -t osx -f WizNote.zip --primary-bundle-id="cn.wiz.wiznoteformac" -u "[email protected]" -p ${password}`;
console.log(command);
//
const getUuidFromMessage = (stderr) => {
if (stderr) {
}
}
//
const { stdout, stderr} = await exec(command);
//
if (stderr) {
const info = 'The software asset has already been uploaded. The upload ID is ';
const index = stderr.indexOf(info);
if (index != -1) {
let uuid = stderr.substr(index + info.length);
const parts = uuid.split(' ');
uuid = parts[0];
if (uuid.endsWith('"')) {
uuid = uuid.substr(0, uuid.length - 1);
}
return uuid;
}
console.error(stderr);
return;
}
console.log('altool output:', stdout);
//
const index = stdout.indexOf('=');
if (index > -1) {
return stdout.substr(index + 1).trim();
}
//
return '';
}
//
async function doNotarize(password) {
const uuid = await notarizeApp(password);
if (!uuid) {
return;
}
//
console.log('uuid: ' + uuid);
//
while (true) {
//
console.log('wait 10 seconds');
await sleep(1000 * 10);
//
const command = `xcrun altool --notarization-info ${uuid} -u "[email protected]" -p "${password}"`;
console.log(command);
const {stdout, stderr} = await exec(command);
//
if (stderr) {
console.error(stderr);
return;
}
//
console.log(stdout);
//Status Message: Package Approved
if (stdout.indexOf('Status Message: Package Approved') != -1) {
break;
}
//
}
//
const command = `xcrun stapler staple "WizNote.app"`;
console.log(command);
const {stdout, stderr} = await exec(command);
if (stderr) {
console.error(stderr);
} else {
console.log(stdout);
}
}
const password = process.argv[2];
doNotarize(password);