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

Convert templates in packages #219

Merged
merged 17 commits into from
Feb 27, 2020
Merged

Conversation

fmvilas
Copy link
Member

@fmvilas fmvilas commented Feb 8, 2020

Fixes #214
Fixes #198

TODO

  • Publish packages
  • Update documentation

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not validate if provided template exists and now problem is that when I do node cli.js -o ./output ./test/docs/streetlights.yml test new dir in provided or default templates locaton is created with package-lock.json file

{
  "lockfileVersion": 1
}

It is not fault of installTemplate function but simply because we do not have the nonexisting template validation. If I'm getting the basics of the generator correct so far, the needed validation would only have to: check if in a given templates directory, a directory with given template name exists (test in my case) and if it contains .tp-config.json file.

Most important is though that nodejs template works like a charm with Node.js v13.7.0
And also I think we do not really need lerna for packages installation thanks to npmi

cli.js Outdated Show resolved Hide resolved
cli.js Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated
-d, --disable-hook <hookName> disable a specific hook
-n, --no-overwrite <glob> glob or path of the file(s) to skip when regenerating
-p, --param <name=value> additional param to pass to templates
-t, --templates <templateDir> directory where templates are located (default: Internal template folder)
-t, --templates <templateDir> directory where templates are located (defaults to internal templates directory)
--force-install forces the installation of the template dependencies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added those suggestions to explain the flag as at first it was weird for me that there is a --force-install flag but I did not pass it and dependencies were installed anyway (at first run). Maybe the name is confusing, maybe reinstall or something 🤔

btw, why no -f flag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -f flag will be a generic --force flag. It would "force" everything. Including, for instance, the generation when the repo has unstaged changes. It's useful but it's probably another flag and another PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeap, since last release we have --force-write so --force-install now nicely adds to the list and then as you wrote we can have -f god to apply all force flags

lib/generator.js Show resolved Hide resolved
@@ -485,6 +490,8 @@ class Generator {
const targetFile = path.resolve(this.targetDir, relativeSourceFile);
const relativeTargetFile = path.relative(this.targetDir, targetFile);

if (shouldIgnoreFile(relativeSourceFile)) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add code comment here what we are protecting from here as I couldn't figure out why,
I ran all templates and was never able to get true for any file. I see proper protection is here https://github.com/asyncapi/generator/blob/master/lib/generator.js#L379

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the only place where generateFile is called, that's why. I should probably remove it from the line you mentioned.

@fmvilas fmvilas requested a review from derberg February 27, 2020 14:01
@fmvilas
Copy link
Member Author

fmvilas commented Feb 27, 2020

This PR is of your interest, @damaru-inc.

@derberg
Copy link
Member

derberg commented Feb 27, 2020

@fmvilas

  1. We are pretty inconsistent when writing about "default"
    here https://github.com/asyncapi/generator/pull/219/files#diff-04c6e90faac2675aa89e2176d2eec7d8R49 and here https://github.com/asyncapi/generator/pull/219/files#diff-2cce40143051e25f811b56c79d619bf5R68
    We use forms like:

    • defaults
    • default is
    • By default -> this one with error as without comma at the end

    Would be awesome if you could address it :D, or just fix comman in the ones that you added
  2. What about Convert templates in packages #219 (review) ?

@fmvilas
Copy link
Member Author

fmvilas commented Feb 27, 2020

Good catch. It's fixed now.

Regarding the "defaults", I unified everything except the --force-install one, which I think it makes sense to have a longer sentence.

@derberg
Copy link
Member

derberg commented Feb 27, 2020

Would be almost super cool but I have to be picky on this error message that we show when I provide a name of the template that doesn't exist:
Template "my_custom_template" does not exist.

Code behind this error message only checks if directory exists and not if it is a template. If I would have a directory with my_custom_template the installation would go forward.

2 options here:

  1. Change the error message to just say that directory doesn't exist
  2. At least check if package.json & tp-config.json files exist

2 is better but I can live with 1 too :)

@fmvilas
Copy link
Member Author

fmvilas commented Feb 27, 2020

Implemented 2. However, the .tp-config.json file is not required so I'm not going to check for it. Also, when #228 is implemented there will only be package.json files.

@derberg
Copy link
Member

derberg commented Feb 27, 2020

LGTM. Awesome stuff!!! merge and release and let us go forward with rest of improvements

@fmvilas fmvilas merged commit b260e53 into master Feb 27, 2020
@fmvilas fmvilas deleted the feature/make-templates-packages branch February 27, 2020 16:17
@fmvilas
Copy link
Member Author

fmvilas commented Feb 27, 2020

Thanks for the great review mate!

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