Application Structure with Modules

Posted on
  • I'm looking at building an application for my ESP32 with Espruino, and I'd like to organize my code in different javascript modules. I see that if I want to use a require() on a local file, it looks in whatever folder is assigned to my projects in the IDE. Then there is a modules subfolder there for including local js modules.

    My problem is I want to maintain code in different files, and also host it in a git repository. How can I do this without having to include the Espruino IDE project folder and all of the contents with it?

    Ultimately I'd like to have a folder anywhere on my local drive and that the require() statement would search inside the local folder holding my code rather than putting modules for all of my projects in the same folder. Can I do this?

  • You can host modules externally and they will be required. So you could use a Git provider and load the module directly using it's URI. Only downside is you obviously need connectivity.

  • What about just a config file with environment variables? I'd like to export an object that pulls in local environment variables from a file in my .gitignore that holds my Wifi name/password. How can I load a file locally to accomplish this?

    I don't want to have to put a config file in the ./modules folder, is there a way around this?

  • You could use the command-line tools? https://www.npmjs.com/package/espruino

    Sounds like with multiple files you're probably not going to be using the IDE editor much anyway. Use your favourite editor and then use the -w command in the tools to watch the file for changes and upload when it changes.

    I believe the CLI will pull modules out of node_modules by default, but you can always make some shell script that takes your JS, does whatever is needed to it, and then uses the CLI to upload it.

  • Thanks Gordon! I didn't realize I could build from the CLI package. I do like the Chrome extension, however I am finding a problem with hovering over text and a tooltip will popup and not go away. I keep having to close the IDE and open it again, but the one file is also a problem.

    I think I'll move over to Visual Studio Code and build like you mentioned.

  • I am finding a problem with hovering over text and a tooltip will popup and not go away

    I have had this once or twice too - I'm finding it very hard to track down though as it doesn't seem to happen reliably.

  • I have had this once or twice too - I'm finding it very hard to track down though as it doesn't seem to happen reliably.

    I'm working from Ubuntu Linux. I don't know if that info will help with tracking down the bug or not.

  • See this thread:

    http://forum.espruino.com/conversations/­298523

    Is there a way of tying the build into visual studio Code?

  • I've also looked at the parcel package for building code - although that does not intergrate with the sending to espruino part.

  • Thanks @Wilberforce for pointing me to that thread. I am familiar with rollup. I will check it out.

    I'm doing an Ionic app in VS Code. For tying the build into VS Code I just run npm from the internal terminal. I'm sure you can find some nice plugins with it. I like it so I can use TypeScript and ES6 stuff with IDE styles and formatting and linting.

  • There's a bug in the plugin that has been pushed to npm - lodash forEach - you have to edit that to get it to build which is a real pain.

    There has also been some changes to the espruino (confusing name - the npm code that talks to a connected board) that allows you to specify the port as "tcp://1.2.3.4" where 1.2.3.4 is your ip - this sends over tcp rather than serial ansis about a million times quicker.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Application Structure with Modules

Posted by Avatar for chrsbvr @chrsbvr

Actions