Skip to content

Commit 5dced21

Browse files
committed
Compression tools added.
1 parent aada102 commit 5dced21

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ $ esp file list
3333
1321 bytes test.lua
3434
```
3535

36-
#### file remove <remote_filename>
37-
Removes a file from the module.
38-
```
39-
$ esp file remove test.lua
40-
```
41-
4236
#### file write <local_filename> [<remote_filename>]
4337
Writes a file from the local file system to the module. If a second filename is given, the local file will be renamed to this value on the device, else it will keep its local name.
4438
```
4539
$ esp file write ./webserver.lua init.lua
4640
```
4741

42+
#### file push <local_filename> [<remote_filename>]
43+
Alternative to `esp file write` that compress the file if they are of any of the following types: Lua, HTML, JavaScript, CSS.
44+
```
45+
$ esp file push ./webserver.lua init.lua
46+
```
47+
4848
#### file read <remote_filename>
4949
Displays the content of a file from the module.
5050
```
@@ -59,6 +59,12 @@ $ esp file execute hello-world.lua
5959
Hello, world
6060
```
6161

62+
#### file remove <remote_filename>
63+
Removes a file from the module.
64+
```
65+
$ esp file remove test.lua
66+
```
67+
6268
#### restart
6369
Restarts the module.
6470
```

bin/cli.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,40 @@ var config = {
6262
});
6363
},
6464

65-
65+
66+
push: function (filename, destination) {
67+
var data = '' + fs.readFileSync(filename),
68+
pathLib = require('path'),
69+
basename = pathLib.basename(destination || filename),
70+
match = filename.match(/\.([^\.]+)$/);
71+
72+
if (match) {
73+
switch (match[1]) {
74+
case 'lua':
75+
data = require('luamin').minify(data);
76+
break;
77+
78+
case 'html':
79+
data = require('html-minifier').minify(data);
80+
break;
81+
82+
case 'js':
83+
data = require('uglify-js').minify(data, {fromString: true}).code;
84+
break;
85+
86+
case 'css':
87+
data = (new (require('clean-css'))).minify(data).styles;
88+
break;
89+
}
90+
}
91+
92+
new SerialComms(port).on('ready', function (comms) {
93+
new DeviceManager(comms).writeFile(basename, data)
94+
.then(comms.close.bind(comms));
95+
});
96+
},
97+
98+
6699
read: function (filename) {
67100
new SerialComms(port).on('ready', function (comms) {
68101
new DeviceManager(comms).readFile(filename)

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
"url": "https://github.com/paulcuth/esp8266-cli/issues"
2828
},
2929
"dependencies": {
30+
"clean-css": "^3.0.7",
3031
"es6-promise": "^2.0.0",
31-
"serialport": "^1.4.6"
32+
"html-minifier": "^0.6.9",
33+
"luamin": "^0.2.8",
34+
"serialport": "^1.4.6",
35+
"uglify-js": "^2.4.16"
3236
}
3337
}

0 commit comments

Comments
 (0)