-
Notifications
You must be signed in to change notification settings - Fork 141
Feature: Allow set specific template #171
Feature: Allow set specific template #171
Conversation
Working to fix broken unit test |
Codecov Report
@@ Coverage Diff @@
## master #171 +/- ##
==========================================
- Coverage 96.59% 96.11% -0.49%
==========================================
Files 13 13
Lines 529 540 +11
Branches 92 94 +2
==========================================
+ Hits 511 519 +8
- Misses 18 21 +3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #171 +/- ##
==========================================
- Coverage 96.59% 95.14% -1.46%
==========================================
Files 13 13
Lines 529 535 +6
Branches 92 94 +2
==========================================
- Hits 511 509 -2
- Misses 18 26 +8
Continue to review full report at Codecov.
|
package-lock.json
Outdated
@@ -0,0 +1,2039 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove the package-lock file? we use yarn.lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! (:
lib/fetch-template.js
Outdated
return parseTemplate(baseTemplate); | ||
} | ||
return getTemplatePath(request, templatesPath) | ||
.then((templatePath) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you combine it by this way
getTemplatePath(request, templatesPath)
.then(readFile)
.then(baseTemplate)
looks cleaner IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! (:
Thanks a lot for working on this. If you are interested, feel free to use https://github.com/ljharb/util.promisify to promisify the functions. We thought of using that package anyways. |
lib/fetch-template.js
Outdated
* @return {Promise} Template Path on success or TemplateError on fail | ||
*/ | ||
const getTemplatePath = (request, templatesPath) => new Promise((resolve, reject) => { | ||
fs.lstat( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're using node 8.x, you can use util.promisify
to make this code simpler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the code style of 'readFile' function, however we can change the both functions to promisify sintaxe. What do you think? Or do we open a new issue to discuss about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also do it in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok @vigneshshanmugam, I will open a issue about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vigneshshanmugam is |
@mroderick We still support node 6, so we can use that polyfill for node < 8 |
lib/fetch-template.js
Outdated
const templatePath = path.join(templatesPath, pathname) + '.html'; | ||
|
||
return readFile(templatePath) | ||
return getTemplatePath(request, templatesPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two problems with this approach
- the url parsing happens twice with this approach. In
getTemplatePath
when its a directory and insidebaseTemplateFn
. - You would also need to look at modify this logic
Line 63 in 8344613
const baseTemplatePath = path.join(templatesPath, templateName) + '.html';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I will check this points as soon as possible!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vigneshshanmugam I adjust the duplicated url parsing and refactoring the logic to factory the complete template path. Now I working for break the process in case of single file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vigneshshanmugam Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
return parseTemplate(baseTemplate); | ||
} | ||
return getTemplatePath(templatesPath, pathname) | ||
.then((templateStat) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a small change to keep the indentation depth minimal
.then({path} => readFile(path))
.then(baseTemplate => ....)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vigneshshanmugam I understand your point of view, however i use the templateStat object to break the template parse logic on resolve the readFile promise. In your logic this not working apparently:
.then(({path}) => readFile(path))
.then(baseTemplate => {
// templateStat is not defined
})
We can pass the complete object to readFile, add the baseTemplate to object and resolve the promise with the object. What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh thanks for pointing out. No this is fine then, We can do the cleanup as part of using util.promisify
library changes.
lets get this merged :)
👍 |
👍 |
Proposal to resolve issue #170