-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathbuild.js
81 lines (62 loc) · 2 KB
/
build.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
'use strict';
const fs = require( 'node:fs' );
const path = require( 'node:path' );
const archiver = require( 'archiver' );
const manifest = require( './manifest.json' );
const version = manifest.version.replace( /\./g, '_' );
delete manifest.$schema;
( async() =>
{
await ArchiveChromium();
await ArchiveFirefox();
} )();
function ArchiveChromium()
{
const zipPath = path.join( __dirname, `steamdb_ext_${version}.zip` );
const archive = PrepareArchive( zipPath );
const chromeManifest = structuredClone( manifest );
delete chromeManifest.background.scripts;
delete chromeManifest.browser_specific_settings;
const json = JSON.stringify( chromeManifest, null, '\t' );
archive.append( json, { name: 'manifest.json' } );
return archive.finalize();
}
function ArchiveFirefox()
{
const zipPath = path.join( __dirname, `steamdb_ext_${version}_firefox.zip` );
const archive = PrepareArchive( zipPath );
const firefoxManifest = structuredClone( manifest );
delete firefoxManifest.background.service_worker;
const json = JSON.stringify( firefoxManifest, null, '\t' );
archive.append( json, { name: 'manifest.json' } );
return archive.finalize();
}
/**
* @param {string} zipPath
*/
function PrepareArchive( zipPath )
{
console.log( `Packaging to ${zipPath}` );
const output = fs.createWriteStream( zipPath );
const archive = archiver( 'zip' );
output.on( 'close', () =>
{
console.log( `Written ${archive.pointer()} total bytes to ${zipPath}` );
} );
archive.on( 'warning', err =>
{
throw err;
} );
archive.on( 'error', err =>
{
throw err;
} );
archive.pipe( output );
archive.file( path.join( __dirname, 'LICENSE' ), { name: 'LICENSE' } );
archive.directory( path.join( __dirname, 'icons/' ), 'icons' );
archive.directory( path.join( __dirname, 'options/' ), 'options' );
archive.directory( path.join( __dirname, 'scripts/' ), 'scripts' );
archive.directory( path.join( __dirname, 'styles/' ), 'styles' );
archive.directory( path.join( __dirname, '_locales/' ), '_locales' );
return archive;
}