-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedge-package.js
138 lines (112 loc) · 3.81 KB
/
edge-package.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const path = require('path');
const fs = require('fs');
const rimraf = require('rimraf');
const { exec } = require('child_process');
const manifold = path.resolve('node_modules/.bin/manifoldjs');
const manifestPath = path.resolve('build/manifest.json');
const identityFilePath = path.resolve('.edgepackagerc');
const manifoldManifestPath = path.resolve('PixelGrid/edgeextension/manifest/');
const manifoldAppManifestPath = path.resolve(
'PixelGrid/edgeextension/manifest/appxmanifest.xml'
);
start()
.then(() => {
console.log('Done');
})
.catch((e) => {
console.log('Error during packaging Edge extension.');
console.error(e);
});
async function start() {
// https://docs.microsoft.com/en-us/microsoft-edge/extensions/guides/packaging/using-manifoldjs-to-package-extensions
if (!fs.existsSync(identityFilePath)) {
throw new Error('ERROR: .edgepackagerc does not exist');
}
// Cleanup
rimraf.sync(path.resolve('PixelGrid'));
rimraf.sync(path.resolve('build-appx'));
rimraf.sync(path.resolve('package/edge'));
// Prepare package
await run(
`${manifold} -l debug -p edgeextension -f edgeextension -m ${manifestPath}`
);
// Update manifest with actual identifier data
replaceManifestIdentity(
manifoldAppManifestPath,
JSON.parse(fs.readFileSync(identityFilePath, 'utf-8'))
);
// Copy images
fs.copyFileSync(
path.resolve('assets/pixelgrid-edge-44x44.png'),
path.resolve(
'PixelGrid/edgeextension/manifest/Assets/Square44x44Logo.png'
)
);
fs.copyFileSync(
path.resolve('assets/pixelgrid-edge-150x150.png'),
path.resolve(
'PixelGrid/edgeextension/manifest/Assets/Square150x150Logo.png'
)
);
fs.copyFileSync(
path.resolve('assets/pixelgrid-edge-store.png'),
path.resolve('PixelGrid/edgeextension/manifest/Assets/StoreLogo.png')
);
// Build package with Microsoft cloud service
await run(
`${manifold} -l debug -p edgeextension package ${manifoldManifestPath}`
);
// Copy result to package directory
if (!fs.existsSync(path.resolve('package'))) {
fs.mkdirSync(path.resolve('package'));
}
if (!fs.existsSync(path.resolve('package/edge'))) {
fs.mkdirSync(path.resolve('package/edge'));
}
fs.copyFileSync(
path.resolve('PixelGrid/edgeextension/manifest/appxmanifest.xml'),
path.resolve('package/edge/pixelgrid.appx')
);
// Cleanup
rimraf.sync(path.resolve('PixelGrid'));
rimraf.sync(path.resolve('build-appx'));
// Result
console.log(
`Final package: ${path.resolve('package/edge/pixelgrid.appx')}`
);
}
function run(command, callback) {
return new Promise((resolve, reject) => {
exec(command, function(error, stdout, stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: ' + error.code);
console.log('Signal received: ' + error.signal);
console.log(stdout);
console.log(stderr);
reject();
} else {
console.log(stdout);
console.log(stderr);
resolve();
}
});
});
}
function replaceManifestIdentity(path, values) {
const data = fs
.readFileSync(path, 'utf-8')
.replace(
'INSERT-YOUR-PACKAGE-IDENTITY-NAME-HERE',
values.packageIdentityName
)
.replace(
'CN=INSERT-YOUR-PACKAGE-IDENTITY-PUBLISHER-HERE',
values.packageIdentityPublisher
)
.replace(
'INSERT-YOUR-PACKAGE-PROPERTIES-PUBLISHERDISPLAYNAME-HERE',
values.publisherDisplayName
);
fs.writeFileSync(path, data);
}