1
- import { postProcess , rollupScript } from './utils/build.js' ;
1
+ import { bundle } from './utils/build.js' ;
2
2
import { parseArgs , write } from '../../scripts/script-utils.js' ;
3
- import { camelcase } from '../src/utils.js' ;
4
-
5
- const contentScopePath = 'src/content-scope-features.js' ;
6
- const contentScopeName = 'contentScopeFeatures' ;
7
3
8
4
/**
9
5
* @typedef Build
10
6
* @property {string } input
11
7
* @property {string[] } output
12
- * @property {boolean } [postProcess] - optional value to post-process an output file
13
8
*
14
9
* @typedef {Record<NonNullable<ImportMeta['injectName']>, Build> } BuildManifest
15
10
*/
@@ -22,7 +17,6 @@ const builds = {
22
17
} ,
23
18
apple : {
24
19
input : 'entry-points/apple.js' ,
25
- postProcess : true ,
26
20
output : [ '../Sources/ContentScopeScripts/dist/contentScope.js' ] ,
27
21
} ,
28
22
'apple-isolated' : {
@@ -34,11 +28,11 @@ const builds = {
34
28
output : [ '../build/android/contentScope.js' ] ,
35
29
} ,
36
30
'android-broker-protection' : {
37
- input : 'entry-points/android' ,
31
+ input : 'entry-points/android.js ' ,
38
32
output : [ '../build/android/brokerProtection.js' ] ,
39
33
} ,
40
34
'android-autofill-password-import' : {
41
- input : 'entry-points/android' ,
35
+ input : 'entry-points/android.js ' ,
42
36
output : [ '../build/android/autofillPasswordImport.js' ] ,
43
37
} ,
44
38
windows : {
@@ -57,65 +51,33 @@ const builds = {
57
51
input : 'entry-points/extension-mv3.js' ,
58
52
output : [ '../build/chrome-mv3/inject.js' ] ,
59
53
} ,
60
- chrome : {
61
- input : 'entry-points/chrome.js' ,
62
- output : [ '../build/chrome/inject.js' ] ,
63
- } ,
64
54
} ;
65
55
66
- async function initOther ( injectScriptPath , platformName ) {
67
- const identName = `inject${ camelcase ( platformName ) } ` ;
68
- const injectScript = await rollupScript ( {
69
- scriptPath : injectScriptPath ,
70
- name : identName ,
71
- platform : platformName ,
72
- } ) ;
73
- const outputScript = injectScript ;
74
- return outputScript ;
75
- }
76
-
77
- /**
78
- * @param {string } entry
79
- * @param {string } platformName
80
- */
81
- async function initChrome ( entry , platformName ) {
82
- const replaceString = '/* global contentScopeFeatures */' ;
83
- const injectScript = await rollupScript ( { scriptPath : entry , platform : platformName } ) ;
84
- const contentScope = await rollupScript ( {
85
- scriptPath : contentScopePath ,
86
- name : contentScopeName ,
87
- platform : platformName ,
88
- } ) ;
89
- // Encode in URI format to prevent breakage (we could choose to just escape ` instead)
90
- // NB: .replace(/\r\n/g, "\n") is needed because in Windows rollup generates CRLF line endings
91
- const encodedString = encodeURI ( contentScope . toString ( ) . replace ( / \r \n / g, '\n' ) ) ;
92
- const outputScript = injectScript . toString ( ) . replace ( replaceString , '${decodeURI("' + encodedString + '")}' ) ;
93
- return outputScript ;
94
- }
95
-
96
56
async function init ( ) {
97
57
// verify the input
98
- const requiredFields = [ 'platform' ] ;
58
+ const requiredFields = [ ] ;
99
59
const args = parseArgs ( process . argv . slice ( 2 ) , requiredFields ) ;
100
- const build = builds [ args . platform ] ;
101
-
102
- if ( ! build ) {
103
- throw new Error ( 'unsupported platform: ' + args . platform ) ;
104
- }
105
60
106
- let output ;
107
- if ( args . platform === 'chrome' ) {
108
- output = await initChrome ( build . input , args . platform ) ;
109
- } else {
110
- output = await initOther ( build . input , args . platform ) ;
111
- if ( build . postProcess ) {
112
- const processResult = await postProcess ( output ) ;
113
- output = processResult . code ;
61
+ // if a platform was given as an argument, just build that platform
62
+ if ( args . platform ) {
63
+ const build = builds [ args . platform ] ;
64
+ if ( ! build ) {
65
+ throw new Error ( 'unsupported platform: ' + args . platform ) ;
114
66
}
67
+ const output = await bundle ( { scriptPath : build . input , platform : args . platform } ) ;
68
+
69
+ // bundle and write the output
70
+ write ( [ build . output ] , output ) ;
71
+
72
+ return ;
115
73
}
116
74
117
- // bundle and write the output
118
- write ( [ build . output ] , output ) ;
75
+ // otherwise, just build them all
76
+ for ( const [ injectName , build ] of Object . entries ( builds ) ) {
77
+ const output = await bundle ( { scriptPath : build . input , platform : injectName } ) ;
78
+ write ( build . output , output ) ;
79
+ console . log ( '✅' , injectName , build . output [ 0 ] ) ;
80
+ }
119
81
}
120
82
121
83
init ( ) ;
0 commit comments