WEB IDE require(ish) or

Posted on
  • Hi Gordon,

    I'm not using an SD card with my espruino but most of my projects are made in an IDE other then web IDE. As I prefer to have an object oriented workflow, I often have multiple smaller files which I have to combine when I want to upload them to the espruino.

    I was wondering if it would be possible to link to a few files with the web IDE, change their order and have the webIDE grab their contents and upload the combined package to the espruino.

    So you could write some code like:

    var deployment = "espruino";
    
    require("C:\Webstorm\EspruinoProject\coo­lObjectOne.js");
    require("C:\Webstorm\EspruinoProject\coo­lObjectTwo.js");
    require("C:\Webstorm\EspruinoProject\coo­lObjectThree.js");
    require("C:\Webstorm\EspruinoProject\coo­lObjectFour.js");
    require("C:\Webstorm\EspruinoProject\mai­nProgram.js");
    
    function onInit() {
     mainProgram(); // this would be a function in mainProgram.js
    }
    
    

    The only thing the javascript files have are something like:

    
    // mainProgram.js
    
    function mainProgram() {
       ... do stuff
    }
    
    

    No exports or anything. A browser also has the <script type="text/javascript" src="mainProgram.js"></script> tags with the links to javascript files. I think it would be great for organizing bigger projects on the espruino!

    From my understanding, the require function in espruino only gets modules from the SD card and is used to lazyload modules when needed. If that's not correct and it already does what I'm describing... then I'm and idiot and I'm sorry :)

    Regards,

    Alex

  • Well, it sort of does what you want already - although Chrome Web Apps impose some limitations (for safety) so it can't access arbitrary files.

    The old way would have been for you to have put a webserver on your PC and simply typed the URL into require()... Hell, you could even use github as long as you gave the 'raw' URL.

    But @JumJum's made the 'project' plugin. Go into Settings, and follow the tutorial. You can then put modules into the folder that you define and it should all work :)

    There's also the command-line Espruino programmer for Node.js, but I don't know if that supports modules. I have plans to pull the guts out of the Web IDE into a library, and to make that available in a command-line app (possibly node-espruino).

  • Well, it sort of does what you want already - although Chrome Web Apps impose some limitations (for safety) so it can't access arbitrary files.

    ... and a demon appeared before me, and it wore that unhallowed discus, a symbol of his Master's dominion over the realm. He held out his hand - or claw. He did not speak - I saw no mouth at all on his visage - but he placed a terrifying vision in my mind, of my future... I sat coding, coding for months on end, writing the same program over and over, like Sisyphus rolling a rock up a hill... I opened my eyes, and he stared back at me (or maybe into the prisim he wore in front of his eye), and presented his offer to me... that I need write code but once, and across the world, all could use it.... I was seduced by his visions, and signed my name to him in blood and code. Perhaps I should have thought harder - for that demon was Chrome, minion of Google, and he exacts a terrible price

    (I was inspired... I think the chrome web app is right way to go, but there are some odd limits...)

  • I see :) great work guys. Thanks a lot!

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

WEB IDE require(ish) or

Posted by Avatar for Alex @Alex

Actions