@@ -53,52 +53,46 @@ function parseConf(conf) {
5353 global : 'jQuery' ,
5454 url : 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js'
5555 } ;
56+ const disableLegacyTemplates = Boolean ( conf . disableLegacyTemplates ?? true ) ;
57+ const transformedTemplates = transformTemplates ( conf . templates ) ;
58+ const templates = disableLegacyTemplates
59+ ? {
60+ 'oc-template-es6' : baseTemplates [ 'oc-template-es6' ] ,
61+ ...transformedTemplates
62+ }
63+ : { ...baseTemplates , ...transformedTemplates } ;
5664
5765 return {
5866 externals : [ jQueryExternal ] . concat ( conf . externals || [ ] ) ,
5967 retryLimit : conf . retryLimit || 30 ,
6068 retryInterval : conf . retryInterval || 5000 ,
69+ disableLegacyTemplates : disableLegacyTemplates ,
6170 disableLoader : Boolean ( conf . disableLoader ?? false ) ,
62- templates : {
63- ...baseTemplates ,
64- ...transformTemplates ( conf . templates )
65- }
71+ templates
6672 } ;
6773}
6874
69- function getFiles ( { sync = false , conf } ) {
75+ function getFiles ( { sync = false } ) {
7076 const srcPath = '../src/' ;
7177 const vendorPath = '../vendor/' ;
7278
7379 const lPath = path . join ( __dirname , vendorPath , 'l.js' ) ;
7480 const ocClientPath = path . join ( __dirname , srcPath , 'oc-client.js' ) ;
75- const replaceTemplates = x =>
76- x
77- . replaceAll (
78- '__REGISTERED_TEMPLATES_PLACEHOLDER__' ,
79- JSON . stringify ( conf . templates )
80- )
81- . replaceAll ( '__EXTERNALS__' , JSON . stringify ( conf . externals ) )
82- . replaceAll ( '__DEFAULT_RETRY_LIMIT__' , conf . retryLimit )
83- . replaceAll ( '__DEFAULT_RETRY_INTERVAL__' , conf . retryInterval )
84- . replaceAll ( '__DEFAULT_DISABLE_LOADER__' , conf . disableLoader ) ;
8581
8682 if ( sync ) {
8783 const l = fs . readFileSync ( lPath , 'utf-8' ) ;
88- const ocClient = replaceTemplates ( fs . readFileSync ( ocClientPath , 'utf-8' ) ) ;
84+ const ocClient = fs . readFileSync ( ocClientPath , 'utf-8' ) ;
8985
9086 return [ l , ocClient ] ;
9187 } else {
9288 const lPromise = readFile ( lPath , 'utf-8' ) ;
93- const ocClientPromise = readFile ( ocClientPath , 'utf-8' ) . then (
94- replaceTemplates
95- ) ;
89+ const ocClientPromise = readFile ( ocClientPath , 'utf-8' ) ;
9690
9791 return Promise . all ( [ lPromise , ocClientPromise ] ) ;
9892 }
9993}
10094
101- function compileFiles ( l , ocClient ) {
95+ function compileFiles ( l , ocClient , conf ) {
10296 const version = packageJson . version ;
10397 const licenseLink =
10498 'https://github.com/opencomponents/oc-client-browser/tree/master/LICENSES' ;
@@ -109,6 +103,16 @@ function compileFiles(l, ocClient) {
109103 sourceMap : {
110104 filename : 'oc-client.min.js' ,
111105 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+ }
112116 }
113117 } ) ;
114118
@@ -119,13 +123,13 @@ function compileFiles(l, ocClient) {
119123
120124async function compile ( conf = { } ) {
121125 const parsedConf = parseConf ( conf ) ;
122- const [ l , ocClient ] = await getFiles ( { sync : false , conf : parsedConf } ) ;
126+ const [ l , ocClient ] = await getFiles ( { sync : false } ) ;
123127 return compileFiles ( l , ocClient , parsedConf ) ;
124128}
125129
126130function compileSync ( conf = { } ) {
127131 const parsedConf = parseConf ( conf ) ;
128- const [ l , ocClient ] = getFiles ( { sync : true , conf : parsedConf } ) ;
132+ const [ l , ocClient ] = getFiles ( { sync : true } ) ;
129133 return compileFiles ( l , ocClient , parsedConf ) ;
130134}
131135
0 commit comments