AndiDittrich / NodeMCU-Tool

:wrench: Upload + Manage Lua files on NodeMCU
https://www.npmjs.com/package/nodemcu-tool
MIT License
316 stars 54 forks source link

Add the ability to provide remote destination filename or keep relative path in destination filename #5

Closed loicortola closed 8 years ago

loicortola commented 8 years ago

First, let me thank you for this awesome tool that you have provided. I use it a lot and I think it is a great replacement for the python tool.

For many use-cases (especially webservers and static files), it is important for an upload script to keep the paths in the filenames.

As you know, NodeMCU's filesystem is key/value based and it is possible to have slashes in a filename.

The default behaviour for this was to strip the path, and only keep the filename.

I propose this PR which gives the user two more options in the CLI: --keeppath and --remotename.

N.B: This changes the upload function signature a little. If you have important concerts about backward compatibility, thanks for letting me know, and I will rearrange the code to trick it.

AndiDittrich commented 8 years ago

Dear loicortola,

thank you for your contribtion! its a great addon - i will check the code and give you a feedback within the next week.

best reagrds, Andi

loicortola commented 8 years ago

Thanks, looking forward to it.

AndiDittrich commented 8 years ago

In lib/NodeMcuConnector.js line 21

compile: 'node.comgpile("?")'

is this a typo or a new NodeMCU core function ?

loicortola commented 8 years ago

Haha! Haven't seen that One. Must have been between the tests and the commit. I will change this right away

AndiDittrich commented 8 years ago

Thanks! i've just merged your pull request. a release will follow the next days after sucessful testing :)

AndiDittrich commented 8 years ago

Dear loicortola,

i've found a possible issue with the keeppath option: when having multiple projects and using relative paths these paths are transfered with their relative placeholders.

Example 1

./nodemcu-tool upload ../NodeMCU-Toolkit/wifi.lua --keeppath
[NodeMCU-Tool] Connected
[NodeMCU] Version: 0.9.5 | ChipID: 0xd1aa | FlashID: 0x1640e0
[NodeMCU-Tool] Uploading "../NodeMCU-Toolkit/wifi.lua" ...
[NodeMCU-Tool] Data Transfer complete!

./nodemcu-tool fsinfo
[NodeMCU-Tool] Connected
[NodeMCU] Version: 0.9.5 | ChipID: 0xd1aa | FlashID: 0x1640e0
[NodeMCU] Free Disk Space: 3343 KB | Total: 3346 KB | 1 Files
[NodeMCU] Files stored into Flash (SPIFFS)
          |- ../NodeMCU-Toolkit/wifi.lua (2151 Bytes)

Current Solution

I have added a simple filter which removes the relative parts - is this change in your interest ?

// filename defaults to original filename minus path.
// this behaviour can be overridden by --keeppath and --remotename options
var remoteFile = options.remotename ? options.remotename : (options.keeppath ? localFile : _path.basename(localFile));

// normalize the remote filename (strip relative parts)
remoteFile = remoteFile.replace(/\.\.\//g, '').replace(/\.\./g, '').replace(/^\.\//, '');

// display filenames
logStatus('NodeMCU-Tool', 'Uploading "' + localFile + '" >> "' + remoteFile + '"...');

Result

./nodemcu-tool upload ../NodeMCU-Toolkit/wifi.lua --keeppath
[NodeMCU-Tool] Connected
[NodeMCU] Version: 0.9.5 | ChipID: 0xd1aa | FlashID: 0x1640e0
[NodeMCU-Tool] Uploading "../NodeMCU-Toolkit/wifi.lua" ...
NodeMCU-Toolkit/wifi.lua
[NodeMCU-Tool] Data Transfer complete!

./nodemcu-tool fsinfo
[NodeMCU-Tool] Connected
[NodeMCU] Version: 0.9.5 | ChipID: 0xd1aa | FlashID: 0x1640e0
[NodeMCU] Free Disk Space: 3341 KB | Total: 3346 KB | 2 Files
[NodeMCU] Files stored into Flash (SPIFFS)
          |- NodeMCU-Toolkit/wifi.lua (2151 Bytes)

best regards, Andi

loicortola commented 8 years ago

Hi Andi, you are right, that may have posed a problem. Indeed, this change makes sense and it doesn't break anything on my side either, so perfect :)

Thanks for the input, best wishes,

Loïc

AndiDittrich commented 8 years ago

Great. I've published the v1.4 release :)