-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathbuild.js
More file actions
92 lines (77 loc) · 2.46 KB
/
build.js
File metadata and controls
92 lines (77 loc) · 2.46 KB
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
'use strict';
const fs = require( 'node:fs' );
const path = require( 'node:path' );
const yazl = require( 'yazl' );
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 chromeManifest = structuredClone( manifest );
delete chromeManifest.$schema;
delete chromeManifest.background.scripts;
delete chromeManifest.browser_specific_settings;
const json = JSON.stringify( chromeManifest, null, '\t' );
return CreateArchive( zipPath, json );
}
function ArchiveFirefox()
{
const zipPath = path.join( __dirname, `steamdb_ext_${version}_firefox.zip` );
const firefoxManifest = structuredClone( manifest );
delete firefoxManifest.$schema;
delete firefoxManifest.background.service_worker;
const json = JSON.stringify( firefoxManifest, null, '\t' );
return CreateArchive( zipPath, json );
}
/**
* @param {string} zipPath
* @param {string} manifestJson
*/
function CreateArchive( zipPath, manifestJson )
{
console.log( `Packaging to ${zipPath}` );
const zip = new yazl.ZipFile();
zip.addBuffer( Buffer.from( manifestJson ), 'manifest.json' );
zip.addFile( path.join( __dirname, 'LICENSE' ), 'LICENSE' );
AddDirectory( zip, path.join( __dirname, 'icons' ), 'icons' );
AddDirectory( zip, path.join( __dirname, 'options' ), 'options' );
AddDirectory( zip, path.join( __dirname, 'scripts' ), 'scripts' );
AddDirectory( zip, path.join( __dirname, 'styles' ), 'styles' );
AddDirectory( zip, path.join( __dirname, '_locales' ), '_locales' );
return new Promise( ( resolve, reject ) =>
{
const output = fs.createWriteStream( zipPath );
output.on( 'close', () =>
{
console.log( `Written ${output.bytesWritten} total bytes to ${zipPath}` );
resolve();
} );
zip.outputStream.pipe( output );
zip.outputStream.on( 'error', reject );
zip.end();
} );
}
/**
* @param {yazl.ZipFile} zip
* @param {string} dirPath
* @param {string} prefix
*/
function AddDirectory( zip, dirPath, prefix )
{
for( const entry of fs.readdirSync( dirPath, { withFileTypes: true, recursive: true } ) )
{
if( !entry.isFile() )
{
continue;
}
const fullPath = path.join( entry.parentPath, entry.name );
const zipName = path.join( prefix, path.relative( dirPath, fullPath ) ).replace( /\\/g, '/' );
zip.addFile( fullPath, zipName );
}
}