@@ -89,13 +89,16 @@ export function resetVirtualFiles() {
89
89
* processTemplate('prefix <%= name %> suffix', { name: 'foo' })
90
90
* // prefix foo suffix
91
91
*
92
+ * It's also possible to pass custom options to EJS render like changing the delimiter of tags.
93
+ *
92
94
* @param {string } _fileContent Template as a string
93
95
* @param {object } data Object of all the variables to repalce
96
+ * @param {ejs.Options } ejsOptions
94
97
* @returns {string } Template with all replacements
95
98
*/
96
- export function processTemplate ( _fileContent , data = { } ) {
99
+ export function processTemplate ( _fileContent , data = { } , ejsOptions = { } ) {
97
100
let fileContent = _fileContent ;
98
- fileContent = render ( fileContent , data , { debug : false , filename : 'template' } ) ;
101
+ fileContent = render ( fileContent , data , { debug : false , filename : 'template' , ... ejsOptions } ) ;
99
102
return fileContent ;
100
103
}
101
104
@@ -342,11 +345,12 @@ export function optionsToCommand(options, generatorName = '@open-wc') {
342
345
* @param {string } fromPath
343
346
* @param {string } toPath
344
347
* @param {object } data
348
+ * @param {ejs.Options } ejsOptions
345
349
*/
346
- export function copyTemplate ( fromPath , toPath , data ) {
350
+ export function copyTemplate ( fromPath , toPath , data , ejsOptions = { } ) {
347
351
const fileContent = readFileFromPath ( fromPath ) ;
348
352
if ( fileContent ) {
349
- const processed = processTemplate ( fileContent , data ) ;
353
+ const processed = processTemplate ( fileContent , data , ejsOptions ) ;
350
354
writeFileToPath ( toPath , processed ) ;
351
355
}
352
356
}
@@ -356,16 +360,17 @@ export function copyTemplate(fromPath, toPath, data) {
356
360
* @param {string } fromGlob
357
361
* @param {string } [toDir] Directory to copy into
358
362
* @param {object } data Replace parameters in files
363
+ * @param {ejs.Options } ejsOptions
359
364
*/
360
- export function copyTemplates ( fromGlob , toDir = process . cwd ( ) , data = { } ) {
365
+ export function copyTemplates ( fromGlob , toDir = process . cwd ( ) , data = { } , ejsOptions = { } ) {
361
366
return new Promise ( resolve => {
362
367
glob ( fromGlob , { dot : true } , ( er , files ) => {
363
368
const copiedFiles = [ ] ;
364
369
files . forEach ( filePath => {
365
370
if ( ! fs . lstatSync ( filePath ) . isDirectory ( ) ) {
366
371
const fileContent = readFileFromPath ( filePath ) ;
367
372
if ( fileContent !== false ) {
368
- const processed = processTemplate ( fileContent , data ) ;
373
+ const processed = processTemplate ( fileContent , data , ejsOptions ) ;
369
374
370
375
// find path write to (force / also on windows)
371
376
const replace = path . join ( fromGlob . replace ( / \* / g, '' ) ) . replace ( / \\ (? ! ) / g, '/' ) ;
@@ -386,18 +391,20 @@ export function copyTemplates(fromGlob, toDir = process.cwd(), data = {}) {
386
391
* @param {string } fromPath
387
392
* @param {string } toPath
388
393
* @param {object } data
394
+ * @param {ejs.Options } ejsOptions
389
395
*/
390
396
export function copyTemplateJsonInto (
391
397
fromPath ,
392
398
toPath ,
393
399
data = { } ,
394
400
{ mode = 'merge' } = { mode : 'merge' } ,
401
+ ejsOptions = { } ,
395
402
) {
396
403
const content = readFileFromPath ( fromPath ) ;
397
404
if ( content === false ) {
398
405
return ;
399
406
}
400
- const processed = processTemplate ( content , data ) ;
407
+ const processed = processTemplate ( content , data , ejsOptions ) ;
401
408
const mergeMeObj = JSON . parse ( processed ) ;
402
409
403
410
const overwriteMerge = ( destinationArray , sourceArray ) => sourceArray ;
0 commit comments