eveningkid/reacto

Open project from command line

Opened this issue ยท 37 comments

Open project from command line

I truly have no idea how to do this. Do you have any leads?
Also, is this necessary at the moment?

This is a good thing to have, as other code editors supports it (e.g code path/to/file/or/project). I'm not quite sure on how these things works on Mac, though.

I found an article about that. I'll give it a try. Should the cli be called reacto? I feel like this would be good.

Sure, if you find any details about this and don't have time to implement it, share it there.
I can take care of it. :)
Let me know, so we can update this issue and make it available asap.

yeah, I did found out that you can use the app binary as a cli by calling /Application/Reacto.app/Contents/MacOS/Reacto and then handling the arguments on the main.js as explained here: https://discuss.atom.io/t/bundle-a-cli-app-inside-the-electron-app/40113/2
I'll be putting some time on this approach today.

Really interesting approach. What are your thoughts on such a CLI helper for Reacto?

I'm not really sure it is needed if we are doing only one thing without any options. But if we want this to a be a more complete solution and have more options, yargs is indeed a nice solution. Short story: we might not need now, but we'll surely need it later.

Correction, right now it'd already be useful by parsing the options and showing the version when we type reacto -v.

The only problem with this approach is that I don't really know how to test this in development. Do you have any ideas on how to test this without making a package?

If we only get the current version of Reacto, I don't think that a CLI is currently needed.
I guess you'll need to create a package even for testing. Simply set the bin attribute to where it should call the CLI from (quickly look this up this online, bin property of package.json). Your CLI will be just a node script I guess, right?

Ok, I agree that we do not need many options for now. The cli effectively is the own binary. We gotta handle the call from cli by parsing process.argv on main.js and checking if there's more arguments on it. If there is, than we check if the argument is a directory (I guess we should also open single files...) and then load the directory through the filetree function.
Is it only my machine that takes like 20+ minutes to pack the application?

I think your approach is correct and could work. I just have no idea how to actually do all the communication between a running reacto instance and what we get from the command line.

If you feel like spending time on this, please do some experiments and share your results here. I think that at this point, this is the only way to actually get answers. Maybe it won't work, maybe it will, haha.

And usually, I stop the build process when it says something like building "maps" or something. So usually, as soon as it updated the .dmg file, it's all good. Why asking? Do you need to pack it every single time for testing? :o

Ok. Did some progress here. Now I'm parsing the command line and getting the desired path to open. The quest is to make it open the project. I believe I should send a message with ipcMain to the render process to trigger the switchProject action with the directory path. Does that makes sense? Where should this logic live on the application? Should I add a listener on the open project component to take care of this?

Somewhere inside public/main.js, when something is caught from the command line, simply call mainWindow.webContents.send('switch-project', cwd).

Then, inside src/editor/events, create a file called switch-project.js, which simply dispatches the switchProject action (you can check other files in that folder, you'll quickly get the idea!).

Finally, add the listener to the src/editor/events/index.js file: import switch-project, add it to the events variable, and let the EventsManager listen to the switch-project event. Don't forget to pass it the cwd argument value.

I guess you have the whole recipe now! Thanks again for your help, I'm excited about this feature now!

Ok, I made it. It's opening a directory as project from the command line. Now I need to add a menu command to add reacto bin to PATH.
I can't test this on other OS (windows and linux). It might require some adjustments.

Amazing @julianorafael, please let us know when it's ready!!

I solved this by creating a symlink from the binary to /usr/local/bin on mac os. I added menu options to add and to delete this symlink and it only shows on darwin platforms for now. The only problem remainig is that the app remains attached to the console. I need to detach it, but I'm not sure how to do it yet.

@julianorafael could you please share your code so far so that could be easier to understand your issue at the moment?

Ok. I opened up a PR with the code. It appears that there has been some major changes on main.js and my code will need some changes. I couldn't find a way to do what I did on the ready event of the app with the sweet-electron. Also, as I said before, it opens from the terminal, but does not detach from it, which is quite annoying.

Thank you. I will add a .ready((is, mainWindow) => ...) method to sweet-electron tomorrow.
I guess it will be enough to adapt code from main.js. If not, please let me know and I'll add it as well. :)

For the menu, it should also be quite easy to fix the conflict, same for events.js.
Oh also, for the menu, I will add an instance of electron-is as .menu(...) first parameter so you'll be able to write is.macOS() inside menu.js.

For the terminal issue, is it different for Atom right now? If so, have you tried to find how they deal with it? ๐Ÿ‘€

Thank you again for all your energy and time, I definitely appreciate it.

Your welcome sir, pleasure is mine. I'm a bit short on time, but I'm doing whatever I can. I'll find a way to deal with it and I'll refactor the code as soon as the method is available. The refactor is quite simple. The only thing is the ready event.
Thank you for the help and the attention, this is one of my first contributions with actual code to OSS projects. :)

Alright, I've just added the .ready method on sweet() instance! You'll find an example here, but it is exactly as what I've explained in my previous message. :) (it should be fine, but if it's not, please let me know)

.ready((is, mainWindow) => ...)

Don't forget to upgrade sweet-electron to its latest version.

Also, I am extremely glad that this is your first contribution to an open-source project!

Keep me updated and keep it up!

I'm having problems with the ready method.
image

I'm on version 1.0.7 of the sweet-electron

The error you're having shows the Reacto icon instead of Electron's.
Are you sure all this is running in development mode?

no, is not. in development mode I disabled the open from cmd because it'd always open the reacto directory by default since we always start the development mode from the cmd

Have you tried small debugging like the following?

const electron = require('electron');
const sweet = require('sweet-electron')(electron);
console.log(sweet().ready);

Replacing all main.js's content with this short code and see what happens?
Because just now I've tried with a very basic project and the ready method works just fine.

The function is there. But I guess that's not really the problem. I believe I need to create the window on this method, right? How do I access window configuration on the ready function to be able do that?

Nope, sweet-electron already takes care of that.

image
This is what I get when I try to open in development mode.

@julianorafael, my apologies for the delay.
It should be working by now with the latest codebase.

If you still have the energy to look into this...well, I can't tell you how much I would appreciate it.
I feel it's a pity if we can't use all the effort you already put for this project.

Let me know if you run into any other issue.

I can make a push to finish it :)

Don't worry about the delay, I really understand it. I'll make this push in the next few days, probably on the weekend.

I'll post it here if I find any issues along the way.

Thank you, thank you. Thank you for your time!

Status update: I'm working on it. Should submit in a couple of days.