Skip to content

Commit 6f42933

Browse files
authored
feat: add EJS as template engine and force all label to be filled
1 parent 4b51f1a commit 6f42933

File tree

4 files changed

+6082
-5977
lines changed

4 files changed

+6082
-5977
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"command-line-args": "^5.0.2",
4545
"dedent": "^0.7.0",
4646
"deepmerge": "^4.2.2",
47+
"ejs": "^3.1.5",
4748
"glob": "^7.1.3",
4849
"prompts": "^2.1.0",
4950
"semver": "^6.1.0"

src/core.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console, import/no-cycle */
2-
2+
import { render } from 'ejs';
33
import { spawn } from 'child_process';
44
import deepmerge from 'deepmerge';
55
import fs from 'fs';
@@ -95,9 +95,7 @@ export function resetVirtualFiles() {
9595
*/
9696
export function processTemplate(_fileContent, data = {}) {
9797
let fileContent = _fileContent;
98-
Object.keys(data).forEach(key => {
99-
fileContent = fileContent.replace(new RegExp(`<%= ${key} %>`, 'g'), data[key]);
100-
});
98+
fileContent = render(fileContent, data, { debug: false });
10199
return fileContent;
102100
}
103101

test/core.test.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ describe('processTemplate', () => {
3333
);
3434
});
3535

36-
it('ignores <%= keyName %> in source if not provided as data', async () => {
37-
expect(processTemplate('prefix <%= name %> suffix', { foo: 'foo' })).to.equal(
38-
'prefix <%= name %> suffix',
39-
);
36+
it('should throw an error if variable is not defined as data for source <%= keyName %> ', async () => {
37+
try {
38+
processTemplate('prefix <%= name %> suffix', { foo: 'foo' });
39+
} catch (e) {
40+
expect(e).to.be.an.instanceof(ReferenceError);
41+
}
4042
});
4143
});
4244

0 commit comments

Comments
 (0)