-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cli): remove copyright header from generated app #991
Conversation
use `.template` extension for templates. Rename during project generation. Removes copyright headers from templates. Fixes #944
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.
LGTM just one question
@@ -55,6 +56,24 @@ module.exports = class ProjectGenerator extends BaseGenerator { | |||
const isValid = utils.validate(this.args[0]); | |||
if (typeof isValid === 'string') throw new Error(isValid); | |||
} | |||
|
|||
this.setupRenameTransformer(); |
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.
Is this line of code needed? I thought functions defined in Yeoman index files get called in sequential order they're defined in.
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.
Yep. If I comment it out and run CLI, the transformer is not registered ...
*/ | ||
setupRenameTransformer() { | ||
this.registerTransformStream( | ||
rename(function(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.
Is there a function that can do this for us without having to import another package? I guess it's not a huge deal regardless though
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 write a function ourselves ... but I didn't want to re-invent the wheel. (And it requires dealing with streams ... )
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.
👍
setupRenameTransformer() { | ||
this.registerTransformStream( | ||
rename(function(file) { | ||
if (file.extname === '.template') { |
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.
It's probably better to narrow it to *.js.template
and *.ts.template
.
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.
file.extname
property only gives us access to the last .extname
in the basename of a file. I can do a check again file.basename
instead but I think that makes the code messy.
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 do the following:
const fileName = `${file.basename}.${file.extname}`;
const result = fileName.match(/(.+)\.(ts|js)\.template$/);
if (result) {
file.extname = result[2];
file.basename = result[1];
}
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 agree that we shouldn't lean on it being *.template
, since it means someone could put a non-TS/JS template in there and we would mistakenly rewrite the results as a .ts
or .js
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.
(I don't know how much we really should worry or care about that, but the cost of not letting others be silly in that way is minimal.)
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.
One comment, otherwise LGTM.
setupRenameTransformer() { | ||
this.registerTransformStream( | ||
rename(function(file) { | ||
if (file.extname === '.template') { |
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 agree that we shouldn't lean on it being *.template
, since it means someone could put a non-TS/JS template in there and we would mistakenly rewrite the results as a .ts
or .js
file.
@raymondfeng Feedback applied. PTAL. (Had to change the Regular Expression slightly to get the leading |
Nice! Have you @virkt25 considered using |
@bajtos I did, it was proposed by you in the original task as well and would’ve been my preferred approach but the final task requirements in #944 asked the templates be switched to a |
Yes please! (On a side on, I think we should allow more time for reviews. For example, I am listed as a CODEOWNER for |
use
.template
extension for templates. Rename during project generation. Removes copyright headers from templates.Fixes #944
Checklist
npm test
passes on your machinepackages/cli
were updatedpackages/example-*
were updated