Skip to content
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

Merged
merged 2 commits into from
Feb 14, 2018
Merged

Conversation

virkt25
Copy link
Contributor

@virkt25 virkt25 commented Feb 13, 2018

use .template extension for templates. Rename during project generation. Removes copyright headers from templates.

Fixes #944

Checklist

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Related API Documentation was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in packages/example-* were updated

use `.template` extension for templates. Rename during project generation. Removes copyright headers from templates.

Fixes #944
Copy link
Contributor

@shimks shimks left a 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();
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor Author

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 ... )

Copy link
Contributor

@b-admike b-admike left a 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') {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@raymondfeng

Copy link
Contributor

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];
}

Copy link
Contributor

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.

Copy link
Contributor

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.)

Copy link
Contributor

@kjdelisle kjdelisle left a 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') {
Copy link
Contributor

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.

@virkt25
Copy link
Contributor Author

virkt25 commented Feb 13, 2018

@raymondfeng Feedback applied. PTAL. (Had to change the Regular Expression slightly to get the leading . for the extension).

@virkt25 virkt25 added this to the February 2018 milestone Feb 14, 2018
@virkt25 virkt25 merged commit c987b28 into master Feb 14, 2018
@virkt25 virkt25 deleted the cli-headers branch February 14, 2018 01:13
@bajtos
Copy link
Member

bajtos commented Feb 14, 2018

Nice!

Have you @virkt25 considered using .ejs instead of .template to allow editors and IDEs to apply EJS syntax highlighting?

@virkt25
Copy link
Contributor Author

virkt25 commented Feb 14, 2018

@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 .tenplate. I can create a follow up task for switch to .ejs as I can’t remember any reasons to not switch to it. Syntax highlighting would make it easier to work with the templates.

@bajtos
Copy link
Member

bajtos commented Feb 14, 2018

I can create a follow up task for switch to .ejs as I can’t remember any reasons to not switch to it.

Yes please!

(On a side on, I think we should allow more time for reviews. For example, I am listed as a CODEOWNER for cli and yet I haven't had a chance to comment on this pull request before it was landed. If I had, then we could have switched to .ejs as part of this pull request.)

@virkt25 virkt25 mentioned this pull request Feb 15, 2018
6 tasks
@virkt25
Copy link
Contributor Author

virkt25 commented Feb 15, 2018

@bajtos See #996 as a follow up PR to switch to .ejs. Figured it'd be easier to open a PR since it's a quick change rather than creating a issue.

I would've waited but this was meant to be a well-groomed task so I assumed .ejs wasn't the criteria for a reason in #944

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants