jsoverson / preprocess

Preprocess HTML, JavaScript, and other files with directives based off custom or ENV configuration
Other
366 stars 80 forks source link

Coffee/PHP/SHELL: alternative @echo usage with end delimiter #105

Closed kirly-af closed 4 years ago

kirly-af commented 8 years ago

Let's consider the following use case:

'use strict';

const pp = require('preprocess');
require('shelljs/global');
const context = {BAR: 'foobar'};

pp.preprocessFile('./in.js', './out.js', context, () => {
    echo('js:');
    console.log(cat('out.js'));
});

pp.preprocessFile('./in.coffee', './out.coffee', context, () => {
    echo('coffee:');
    console.log(cat('out.coffee'));
});
// in.js
var foo = "/* @echo BAR */";
# in.coffee
foo_undef = '# @echo BAR '
foo = # @echo BAR
foo_workaround = """
# @echo BAR
"""

This will produce the following output:

js:                    
var foo = "foobar";    

coffee:                
foo_undef = 'undefined 
foo = foobar           
foo_workaround = """   
foobar                 
"""

As shown with the 1st coffee example (foo_undef), Coffeescript syntax currently does not allow to preprocess strings with @echo on a single line.

An alternative syntax for convenience could be:

foo = ' ### @echo BAR ###'    # output: foo = 'foobar'