-
Notifications
You must be signed in to change notification settings - Fork 14
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
Ported to ES6 and rewrote some duplicate code #17
Conversation
Ported to ES6. TODO: improve code quality.
Fixed bugs and removed some duplicate code. I've tested it and all commands were working properly.
Fixed bugs and removed some duplicate code. I forgot to include these files as I edited them while writing the commit which unchecked them (but I didn't notice that).
Improved error checking. This means that if an error occurs, you can do cb({success: false, msg: error}). The error will be logged. If code succeeds, you can do cb({success: true}). Also fixed file checking. Try/catch is no longer required in order to determine if a file exists or not (therefore, I could rewrite some code). Also fixed that some files weren't actually checked because react.js or .js wasn't added after the name. Now they are actually checked. Also improved checking if .reactclirc exists. If it doesn't, an error will be shown.
Rewritten if/else blocks. First they were if else blocks with a try/catch block in them. Now they are a try/catch block with a if/else block in them. Also fixed a bug in view.js that would crash the scaffolder if the directory that client is set to (in .reactclirc) doesn't exist. Also fixed thata functions were actually arrow functions in config.js, checkspaces.js and checkduplicates.js. Removed unneeded require from test/generate.js.
|
||
const program = require('commander'); |
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.
Why using var
here? 'const` seems fine as far as it's not redefined anywhere else in the module.
You can read more about it here.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
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.
This is a compiled file, ES6 files are in src/.
else { | ||
setTimeout(() => { | ||
} else { | ||
setTimeout(function () { |
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.
Any special reason for removing the arrow functions?
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.
This is a compiled file, ES6 files are in src/
|
||
for(let count=0; count<numberOfPropTypes; count++) { | ||
let propTypeChoice = { | ||
for (var count = 0; count < numberOfPropTypes; count++) { |
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.
Using var
here would make the variable count
exposed outside the for loop which should not happen. Please consider using let
in such cases.
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.
This is a compiled file, ES6 files are in src/.
|
||
/** | ||
* createComponentFacade | ||
* @param {string} module - module name to create a component |
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.
Please indent properly.
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.
This is a compiled file, ES6 files are in src/. This is caused by the compiler.
* createComponentFacade | ||
* @param {string} module - module name to create a component | ||
* @param {string} componentName - component name | ||
* @param {string} asnwers - options provided when creating component |
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.
Typo in answers
.
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.
This typo was already here and I didn't see it, my bad.
/** | ||
* promiseShortcut() function | ||
* Helper method. Created in order to shorten 2 almost the same promise calls. | ||
* @param {init} t Reference to this. Won't work if you just use this, you have to get the reference from a function parameter. |
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.
What is {init}
? There is no such data type in JavaScript.
You can consider using null
or object
as a data type for this
reference.
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.
Init is the current instance of the init class. Normally, this would be this
.
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 we have ES6 code under src
, there is no use in adding compiled files under source control (git). Therefore let's remove compiled js
files and add a npm
command to compile ES6 code before publishing to npm
registry.
|
||
const program = require('commander'); |
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 any reason for changing const
/ let
to var
?
Yeah that's true. But as we're using react (es6), does compiling make sense at all? |
Compiling makes sense, but maintaining compiled files doesn't. So let's go head with the suggestion shall we ? Any other suggestions ? |
Well as said, we are generating reactJS components that use ES6 as well (without any babel config), and we're targetting NodeJS v6 or higher, which supports ES6, so why does compiling make sense? |
Please take a look at this table before removing the compiled ES5 code. |
NodeJS v6 seems to support ES6 for 99%. The only unsupported things (2) aren't being used in the ES6 code. I think it's best to remove the compiled code. Shall we do this? |
@rafaelklaessen Sure! But, I think @rajikaimal would make the final call. And we should keep in mind about that 1%. I can help adding gulp task (if needed) or current npm scripts are fine too. |
What I'm concerned is not about |
I'm assuming that |
No, I'm just compiling everything from ./src to ./ with Babel |
@dhruvdutt Yea, that 1% that's unsupported is just 2 things that I've never heard of, so I'd say it's safe to just use ES6. And once again, ReactJS itself uses ES6 as well. @rajikaimal The compiled files are included because I didn't want to mess up stuff with the original folsers. In the way it is now, it just works as before. (Btw: I've tested the tool by putting it in my global node_modules folder as |
So if we keep compiled files in our repository it means something like, keeping compiled java file |
Kinda, the point is that we don't have to compile it (but you do have to compile Java). |
Alright so, if we have |
I'd say that we'd just skip the whole compiling thing as nodeJS v6 supports ES6 almost completely. |
You see, it compiles to ES5, but it's just not necessary. |
Okay, so one question, do you have any compiled files here |
Yes, in the current PR everything from ./src is compiled to ./. I think that we should put everything that's currently in ./src to ./ and remove the babel config. |
If we remove |
Yes, but we're talking about a scaffolder that generates ES6 for ReactJS. |
So, why wouldn't a scaffolder that generates ES6 be written in ES6 as well? |
I'm referring to the source code of this tool itself not the code that this tool generates. |
I know, but I mean, using ES5 for a tool that generates ES6 doesn't make sense. |
As the user that uses it has to have node v6 or higher anyways. |
Like I mentioned earlier we need backward compatibility. |
For an example if a developer is using this tool on Node |
If a developer is using Node v4 he can't use the generated React code either, so the tool's still useless. |
So the tool'd work, but he still wouldn't be able to use it. |
The code generated by this tool again should be compiled to |
But why aren't we adding a babel config for it then? |
Okay, let's remove the compiled files then. |
How are we gonna let it autocompile on test or when putting on npm registery? |
And how are we going to do that? Merge this PR and then add the autocompile stuff or...? |
Like I said, lets add the prepublish command on package.json, so that it will compile before publishing a new version to npm registry. |
I created a separate branch on this repo called |
Okey, but just to be sure, you do realise that at the moment, it's compiling to ES5, and that the only thing we need to do is to remove the compiled files (and create prepublish commands etc)? |
Exactly, so let's go ahead with that plan shall we ? |
Yes, I'll create a pull request. |
Moved this PR to |
Ported to ES6 and rewrote some duplicate code. See commits for more details.