@@ -72,27 +72,40 @@ function parseConf(conf) {
7272 } ;
7373}
7474
75- function getFiles ( { sync = false } ) {
75+ function getFiles ( { sync = false , conf } ) {
7676 const srcPath = '../src/' ;
7777 const vendorPath = '../vendor/' ;
7878
7979 const lPath = path . join ( __dirname , vendorPath , 'l.js' ) ;
8080 const ocClientPath = path . join ( __dirname , srcPath , 'oc-client.js' ) ;
81+ const replaceGlobals = x =>
82+ x
83+ . replaceAll (
84+ '__REGISTERED_TEMPLATES_PLACEHOLDER__' ,
85+ JSON . stringify ( conf . templates )
86+ )
87+ . replaceAll ( '__EXTERNALS__' , JSON . stringify ( conf . externals ) )
88+ . replaceAll ( '__DEFAULT_RETRY_LIMIT__' , conf . retryLimit )
89+ . replaceAll ( '__DEFAULT_RETRY_INTERVAL__' , conf . retryInterval )
90+ . replaceAll ( '__DEFAULT_DISABLE_LOADER__' , conf . disableLoader )
91+ . replaceAll ( '__DISABLE_LEGACY_TEMPLATES__' , conf . disableLegacyTemplates ) ;
8192
8293 if ( sync ) {
8394 const l = fs . readFileSync ( lPath , 'utf-8' ) ;
84- const ocClient = fs . readFileSync ( ocClientPath , 'utf-8' ) ;
95+ const ocClient = replaceGlobals ( fs . readFileSync ( ocClientPath , 'utf-8' ) ) ;
8596
8697 return [ l , ocClient ] ;
8798 } else {
8899 const lPromise = readFile ( lPath , 'utf-8' ) ;
89- const ocClientPromise = readFile ( ocClientPath , 'utf-8' ) ;
100+ const ocClientPromise = readFile ( ocClientPath , 'utf-8' ) . then (
101+ replaceGlobals
102+ ) ;
90103
91104 return Promise . all ( [ lPromise , ocClientPromise ] ) ;
92105 }
93106}
94107
95- function compileFiles ( l , ocClient , conf ) {
108+ function compileFiles ( l , ocClient ) {
96109 const version = packageJson . version ;
97110 const licenseLink =
98111 'https://github.com/opencomponents/oc-client-browser/tree/master/LICENSES' ;
@@ -103,16 +116,6 @@ function compileFiles(l, ocClient, conf) {
103116 sourceMap : {
104117 filename : 'oc-client.min.js' ,
105118 url : 'oc-client.min.map'
106- } ,
107- compress : {
108- global_defs : {
109- __DISABLE_LEGACY_TEMPLATES__ : conf . disableLegacyTemplates ,
110- __DEFAULT_DISABLE_LOADER__ : conf . disableLoader ,
111- __DEFAULT_RETRY_INTERVAL__ : conf . retryInterval ,
112- __DEFAULT_RETRY_LIMIT__ : conf . retryLimit ,
113- __EXTERNALS__ : conf . externals ,
114- __REGISTERED_TEMPLATES_PLACEHOLDER__ : conf . templates
115- }
116119 }
117120 } ) ;
118121
@@ -123,14 +126,14 @@ function compileFiles(l, ocClient, conf) {
123126
124127async function compile ( conf = { } ) {
125128 const parsedConf = parseConf ( conf ) ;
126- const [ l , ocClient ] = await getFiles ( { sync : false } ) ;
127- return compileFiles ( l , ocClient , parsedConf ) ;
129+ const [ l , ocClient ] = await getFiles ( { sync : false , conf : parsedConf } ) ;
130+ return compileFiles ( l , ocClient ) ;
128131}
129132
130133function compileSync ( conf = { } ) {
131134 const parsedConf = parseConf ( conf ) ;
132- const [ l , ocClient ] = getFiles ( { sync : true } ) ;
133- return compileFiles ( l , ocClient , parsedConf ) ;
135+ const [ l , ocClient ] = getFiles ( { sync : true , conf : parsedConf } ) ;
136+ return compileFiles ( l , ocClient ) ;
134137}
135138
136139module . exports = {
0 commit comments