espruino / EspruinoTools

JavaScript library of tools for Espruino - used for the Web IDE, CLI, etc.
Apache License 2.0
150 stars 89 forks source link

Trayng to import my on module #108

Closed Maksss2018 closed 4 years ago

Maksss2018 commented 5 years ago

Good day I have wrote some small module to make IRreciver code readeble , and then export it with all known methods (module.exports). But result is ERROR cannot find module "./some_module". To save code on board I'm using command espruino --port /dev/somePort -w ~/code/dir/code.js or espruino --port /dev/somePort -m ~/code/dir/code.js -e "save()" . Do I need to load both files or only one of them ? Can I use webpack to generate code writen in es6,8,10 to generate bundle.js - witch I will load on board?

gfwilliams commented 5 years ago

Please can you post up a simple code example that exhibits the problem?

I just tried this and it works:

modules/bar.js

exports = 42;

foo.js

var a = require("bar");

print(a);

Command (so without connecting to a board):

espruino --board PUCKJS foo.js -o out.js
gfwilliams commented 5 years ago

And yes, you can use webpack or other tools like that if you want, but you need to be careful that they don't add loads of 'wrapper' code which will eat up all your RAM

Maksss2018 commented 5 years ago

here it's

module.exports = function(trg){
    var result;
    switch (trg) {
        case "0100010101111111111111111000101111": result = "power";break;
        case "10001010111111111111111100011111": result = "minus";break;
           .........
       case "100011111111111111110000010001111": result = "z";break;
        default:  result = null;
    }
    return result;
};

and to connecting it use this way : var s = require("./ir-code-names")

gfwilliams commented 5 years ago

try removing ./ in the name?

Maksss2018 commented 5 years ago

I've tried that. it's not working

gfwilliams commented 5 years ago

what is your ir-code-names filename?

Maksss2018 commented 5 years ago

~/some-dir/ir-code-names.js

gfwilliams commented 4 years ago

Tried:

//t.js
var s = require("ir-code-names")
// modules/ir-code-names.js
module.exports = function(trg){
    var result;
    switch (trg) {
        case "0100010101111111111111111000101111": result = "power";break;
        case "10001010111111111111111100011111": result = "minus";break;
       case "100011111111111111110000010001111": result = "z";break;
        default:  result = null;
    }
    return result;
};

works great. closing