typeorm-model-generator icon indicating copy to clipboard operation
typeorm-model-generator copied to clipboard

Custom entity.mst so to achieve general preferences and avoid double quotes

Open lixaotec opened this issue 6 years ago • 5 comments

Hello there.

First of all, congratulations for the tool, it helps alot.

It would be nice to have a way to custom entity.mst file so I can change some preferred formatting without fork the tool.

The main issue that leads me here to ask is because my project is rules by standard npm and it requires single quotes instead of double (that is used in entity.mst).

Does it make sense? I am not very experienced on node so forgive me in advance if I missed something.

Thanks.

lixaotec avatar Nov 15 '18 17:11 lixaotec

For now customizing entity.mst would require to lock on specific typeorm-model-generator version. There is too much going on there and some fixes require changes in that file. I want to rewrite part of package to add additional layer and remove unnecessary logic from this file - it would allow to customize template. Unfortunately I didn't have enough time lately to do that.

Right now I can think of two temporary solutions:

  • Process output of model generator by tools like prettier or use replace function provided by npm packages/code editors.
  • Make your changes in entity.mst and remember to copy your own version before generating model and to use always exactly the same version of typeorm-model-generator(or check if entity.mst was changed in each release).

Kononnable avatar Nov 19 '18 21:11 Kononnable

@lixaotec while it is volatile (since a fresh node_modules install would delete your changes), but if you use npx to run the tool (and possibly with a global install?) you can easily just modify the entity.mst that is located in the node_modules folder and those changes will be taken in to effect when you run the tool. While not a "perfect" solution it solves a problem without adding something to @Kononnable's plate for something that is relatively easy!

Jared-Dev avatar Dec 19 '18 04:12 Jared-Dev

Dear fellows, I´ve been dealing the way you told and I did progress. *thank you for that

However I´ve been challenging with tslint rules. I´m using a configuration that entity.mst is not preperaed. So I´m changing it all.

I don´t know if it is a good pratice to follow these tslint rules, but I´m trying to.

I´m sharing here th tslint if you wish to follow, also i´ll share entity.mst after I got it working if you wish.

{ "extends": "tslint:recommended", "rules": { "max-line-length": [ true, 160 ], "no-unnecessary-initializer": false, "no-var-requires": true, "no-null-keyword": true, "no-consecutive-blank-lines": true, "quotemark": [ true, "single", "avoid-escape" ], "interface-name": false, "no-empty-interface": false, "no-namespace": false, "ordered-imports": false, "object-literal-sort-keys": false, "arrow-parens": false, "member-ordering": [ true, { "order": [ "public-static-field", "public-static-method", "protected-static-field", "protected-static-method", "private-static-field", "private-static-method", "public-instance-field", "protected-instance-field", "private-instance-field", "public-constructor", "protected-constructor", "private-constructor", "public-instance-method", "protected-instance-method", "private-instance-method" ] } ], "no-console": [ true, "debug", "info", "time", "timeEnd", "trace" ], "no-inferrable-types": [ true, "ignore-params" ], "no-switch-case-fall-through": true, "typedef": [ true, "call-signature", "parameter" ], "trailing-comma": [ true, { "multiline": { "objects": "always", "arrays": "always", "functions": "never", "typeLiterals": "ignore" }, "singleline": "never" } ], "align": [ true, "parameters" ], "class-name": true, "curly": true, "eofline": true, "jsdoc-format": true, "member-access": true, "no-arg": true, "no-construct": true, "no-duplicate-variable": true, "no-empty": true, "no-eval": true, "no-internal-module": true, "no-string-literal": true, "no-trailing-whitespace": true, "no-unused-expression": true, "no-var-keyword": true, "one-line": [ true, "check-open-brace", "check-catch", "check-else", "check-finally", "check-whitespace" ], "semicolon": true, "switch-default": true, "triple-equals": [ true, "allow-null-check" ], "typedef-whitespace": [ true, { "call-signature": "nospace", "index-signature": "nospace", "parameter": "nospace", "property-declaration": "nospace", "variable-declaration": "nospace" } ], "variable-name": false, "whitespace": [ true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type" ] } }

lixaotec avatar Feb 21 '19 11:02 lixaotec

I forgot to say that also the unused imports becomes a pain.

How should I work araund?

Thanks

lixaotec avatar Feb 21 '19 12:02 lixaotec

Assuming you are implementing the no-unused-variable? Just run the fixer and be done with it. I agree that this would be nice to have built into the generator, but tslint provides tooling baked in for this so I wouldn't worry about working it into the generator. Just my $.02.

You can view the specifics at https://palantir.github.io/tslint/rules/no-unused-variable/ but since it is flagged as Has Fixer you shouldn't need to do any work surrounding this.

Jared-Dev avatar Feb 22 '19 15:02 Jared-Dev