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

Ported to ES6 and rewrote some duplicate code #17

Closed
wants to merge 5 commits into from
Closed

Ported to ES6 and rewrote some duplicate code #17

wants to merge 5 commits into from

Conversation

rafaelklaessen
Copy link

Ported to ES6 and rewrote some duplicate code. See commits for more details.

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.
@rajikaimal rajikaimal mentioned this pull request Nov 8, 2016

const program = require('commander');

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

Copy link
Author

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 () {

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?

Copy link
Author

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++) {

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.

Copy link
Author

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

Choose a reason for hiding this comment

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

Please indent properly.

Copy link
Author

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

Choose a reason for hiding this comment

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

Typo in answers.

Copy link
Author

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.

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.

Copy link
Author

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.

Copy link
Contributor

@rajikaimal rajikaimal left a 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');
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 any reason for changing const / let to var ?

@rafaelklaessen
Copy link
Author

Yeah that's true. But as we're using react (es6), does compiling make sense at all?

@rajikaimal
Copy link
Contributor

Compiling makes sense, but maintaining compiled files doesn't. So let's go head with the suggestion shall we ? Any other suggestions ?

@rafaelklaessen
Copy link
Author

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?

@dhruvdutt
Copy link

dhruvdutt commented Nov 8, 2016

Please take a look at this table before removing the compiled ES5 code.
It seems NodeJS v6 doesn't support ES6 completely.
http://node.green/

@rafaelklaessen
Copy link
Author

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?

@dhruvdutt
Copy link

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

@rajikaimal
Copy link
Contributor

What I'm concerned is not about ES6 compatibility, I want to clarify why we include compiled/transpiled files into our repository. We can do the process of compilation/transpilation while we are testing this tool or adding new version to npm registry. Any comments ?

@rajikaimal
Copy link
Contributor

I'm assuming that src contains all ES6 code so that it gets transpiled through babel to dist folder

@rafaelklaessen
Copy link
Author

No, I'm just compiling everything from ./src to ./ with Babel

@rafaelklaessen
Copy link
Author

rafaelklaessen commented Nov 8, 2016

@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 npm test didn't test all code.) If we decide to keep the compiling process, we should indeed remove the compiled files and add them when testing or putting it on npm.

@rajikaimal
Copy link
Contributor

rajikaimal commented Nov 10, 2016

So if we keep compiled files in our repository it means something like, keeping compiled java file .class files in repository in the case of a java project, right ?

@rafaelklaessen
Copy link
Author

rafaelklaessen commented Nov 10, 2016

Kinda, the point is that we don't have to compile it (but you do have to compile Java).

@rajikaimal
Copy link
Contributor

Alright so, if we have ES6 code now, we do have to compile for sure right ?

@rafaelklaessen
Copy link
Author

I'd say that we'd just skip the whole compiling thing as nodeJS v6 supports ES6 almost completely.

@rafaelklaessen
Copy link
Author

You see, it compiles to ES5, but it's just not necessary.

@rajikaimal
Copy link
Contributor

rajikaimal commented Nov 10, 2016

Okay, so one question, do you have any compiled files here ES3 / ES5 in this PR

@rafaelklaessen
Copy link
Author

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.

@rajikaimal
Copy link
Contributor

If we remove babel it will remove backward compatibility. So the point is to write code in ES6 and compile the source into ES5 for backward compatibility.

@rafaelklaessen
Copy link
Author

Yes, but we're talking about a scaffolder that generates ES6 for ReactJS.

@rafaelklaessen
Copy link
Author

So, why wouldn't a scaffolder that generates ES6 be written in ES6 as well?

@rajikaimal
Copy link
Contributor

I'm referring to the source code of this tool itself not the code that this tool generates.

@rafaelklaessen
Copy link
Author

I know, but I mean, using ES5 for a tool that generates ES6 doesn't make sense.

@rafaelklaessen
Copy link
Author

As the user that uses it has to have node v6 or higher anyways.

@rajikaimal
Copy link
Contributor

rajikaimal commented Nov 10, 2016

Like I mentioned earlier we need backward compatibility.

@rajikaimal
Copy link
Contributor

For an example if a developer is using this tool on Node v4.

@rafaelklaessen
Copy link
Author

rafaelklaessen commented Nov 10, 2016

If a developer is using Node v4 he can't use the generated React code either, so the tool's still useless.

@rafaelklaessen
Copy link
Author

So the tool'd work, but he still wouldn't be able to use it.

@rajikaimal
Copy link
Contributor

The code generated by this tool again should be compiled to ES5 through babel.

@rafaelklaessen
Copy link
Author

But why aren't we adding a babel config for it then?

@rajikaimal
Copy link
Contributor

rajikaimal commented Nov 10, 2016

Take a look at here.
We are using webpack, and it's loader for babel.

@rafaelklaessen
Copy link
Author

Okay, let's remove the compiled files then.

@rafaelklaessen
Copy link
Author

How are we gonna let it autocompile on test or when putting on npm registery?

@rafaelklaessen
Copy link
Author

And how are we going to do that? Merge this PR and then add the autocompile stuff or...?

@rajikaimal
Copy link
Contributor

Like I said, lets add the prepublish command on package.json, so that it will compile before publishing a new version to npm registry.
You can still commit to the same branch and it'll automatically update this same PR.

@rajikaimal
Copy link
Contributor

I created a separate branch on this repo called es6 can you create a PR on that instead. Let's add es6 stuff there, before we go for a stable release.

@rafaelklaessen
Copy link
Author

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

@rajikaimal
Copy link
Contributor

Exactly, so let's go ahead with that plan shall we ?

@rafaelklaessen
Copy link
Author

Yes, I'll create a pull request.

@rajikaimal
Copy link
Contributor

Moved this PR to es6 branch with PR #19

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.

3 participants