Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #99

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"env": {
"es6": true,
"node": true
},
"parserOptions": {
"ecmaVersion": "2022"
},
"extends": ["eslint:recommended", "aenondynamics"]
}
}
13 changes: 3 additions & 10 deletions bin/nodemcu-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

// load utils
const _pkg = require('../package.json');
const _cli = require('commander');
const { Command } = require('commander');
const _cli = new Command();
const _progressbar = require('cli-progress');
const _colors = require('colors');
const _prompt = require('../lib/cli/prompt');
Expand All @@ -26,7 +27,7 @@ _nodemcutool.onOutput(function(message){
function asyncWrapper(promise){
return function(...args){
// extract options (last argument)
_optionsManager.parse(args.pop())
_optionsManager.parse(args.pop(), _cli.opts())

// trigger command
.then(options => {
Expand Down Expand Up @@ -318,14 +319,6 @@ _cli

}));

_cli
.command('*')
.action((cmd) => {
_logger.error('Unknown command "' + cmd + '"');
_cli.outputHelp();
process.exit(1);
});

// run the commander dispatcher
_cli.parse(process.argv);

Expand Down
23 changes: 7 additions & 16 deletions lib/cli/glob-expression.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
const _isGlob = require('is-glob');
const _glob = require('glob');
const _util = require('util');

// promisify glob
const _globResolver = _util.promisify(_glob);

async function expandExpression(args){
const {glob} = require('glob');

async function expandExpression(args) {
// resolve glob expressions async
const resolvedExpressions = await Promise.all(args.map( expr => {
const resolvedExpressions = await Promise.all(args.map(async expr => {
// glob expression ?
if (_isGlob(expr)){

// expand expression
return _globResolver(expr, {});
return await glob(expr, {});

// passthrough (e.g. bash/zsh automatically expand glob expressions)
}else{
return Promise.resolve(expr);
}
}));

// flatten array - Array.flat is only availble in Node.js >= 11
return resolvedExpressions.reduce((aggregator, value) => {
return aggregator.concat(value);
}, []);
return resolvedExpressions.flat(resolvedExpressions.length);
}

module.exports = {
expand: expandExpression
}
}
7 changes: 4 additions & 3 deletions lib/cli/nodemcu-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async function upload(localFiles, options, onProgess){
// the index of the current uploaded file
let fileUploadIndex = 0;

async function uploadFile(localFile, remoteFilename){
async function uploadFile(localFile, remoteFilenameRelative){

// increment upload index
fileUploadIndex++;
Expand All @@ -142,10 +142,10 @@ async function upload(localFiles, options, onProgess){
}

// display filename
_logger.log('Uploading "' + localFile + '" >> "' + remoteFilename + '"...');
_logger.log('Uploading "' + localFile + '" >> "' + remoteFilenameRelative + '"...');

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

// delete old file (may existent)
await _nodeMcuConnector.remove(remoteFilename);
Expand Down Expand Up @@ -204,6 +204,7 @@ async function upload(localFiles, options, onProgess){
const remoteFile = (options.keeppath ? localFile : _path.basename(localFile));

// trigger upload
// eslint-disable-next-line no-await-in-loop
await uploadFile(localFile, remoteFile);
}

Expand Down
18 changes: 8 additions & 10 deletions lib/cli/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@ const _fs = require('fs-magic');
const _path = require('path');
const _configFilename = _path.join(process.cwd(), '.nodemcutool');

async function parseOptions(options){
// default
options = options || {};
async function parseOptions(options = {}, opts){

// debug mode enabled by flag ?
if (options.parent.debug===true){
if (opts.debug===true){
// enable silent mode (decrease logging level)
_logger.notice('debug mode enabled');
_loggingFacility.setBackend(_loggingFacility.LOGGER.FANCY(_loggingFacility.LEVEL.DEBUG));

// io debug mode ?
if (options.parent.ioDebug===true){
if (opts.ioDebug===true){
_logger.notice('io-debug mode enabled - rx/tx messages are passed to logger');
_serialport.debug(true);
}

// silent mode enabled by flag ?
// silent mode enabled by json output format ?
// silent mode enabled by json raw format ?
} else if (options.parent.silent===true || options.json === true || options.raw === true){
} else if (opts.silent===true || options.json === true || options.raw === true){
// enable silent mode (decrease logging level)
_loggingFacility.setBackend(_loggingFacility.LOGGER.FANCY(_loggingFacility.LEVEL.WARNING));
}else{
Expand Down Expand Up @@ -71,9 +69,9 @@ async function parseOptions(options){

// merge global flags, command flags and global defaults
// config file + cli args
config.baudrate = mergeOptions(options.parent.baud, configFile.baudrate, '115200');
config.port = mergeOptions(options.parent.port, configFile.port, '/dev/ttyUSB0');
config.connectionDelay = mergeOptions(options.parent.connectionDelay, configFile.connectionDelay, 0);
config.baudrate = mergeOptions(opts.baud, configFile.baudrate, '115200');
config.port = mergeOptions(opts.port, configFile.port, '/dev/ttyUSB0');
config.connectionDelay = mergeOptions(opts.connectionDelay, configFile.connectionDelay, 0);
config.minify = mergeOptions(options.minify, configFile.minify, false);
config.compile = mergeOptions(options.compile, configFile.compile, false);
config.keeppath = mergeOptions(options.keeppath, configFile.keeppath, false);
Expand All @@ -95,7 +93,7 @@ async function parseOptions(options){
});

// dump config in debug mode
if (options.parent.debug===true){
if (opts.debug===true){
for (const key in config){
_logger.log(`${key.padEnd(20,' ')} = ${config[key]} (type:${typeof config[key]})`);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/connector/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function download(remoteName){
_logger.log('Transfer-Encoding: ' + tEncoding);

// decode file content + detect encoding
data = new Buffer.from(response, tEncoding);
data = Buffer.from(response, tEncoding);
}catch(e){
_logger.debug(e);
throw new Error('Cannot read remote file content');
Expand Down
4 changes: 2 additions & 2 deletions lib/connector/fsinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const _virtualTerminal = require('../transport/scriptable-serial-terminal');
const _luaCommandBuilder = require('../lua/command-builder');

function toKB(s){
return parseInt((parseInt(s)/1024));
return (Math.ceil((parseInt(s)/1024)));
}

// show filesystem information
Expand Down Expand Up @@ -50,4 +50,4 @@ async function fsinfo(){
return {metadata: meta, files: files}
}

module.exports = fsinfo;
module.exports = fsinfo;
4 changes: 2 additions & 2 deletions lib/lua/minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const _luamin = require('luamin');

// strip comments and whitespaces from lua content
function minifyLuaContent(rawContent){
// apply minification
// apply minification
const t = _luamin.minify((rawContent.toString('utf-8')));

// re-convert to buffer
return new Buffer.from(t, 'utf-8');
return Buffer.from(t, 'utf-8');
}

module.exports = {
Expand Down
6 changes: 3 additions & 3 deletions lib/transport/serialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function requireConnection(){
}
}

function connect(devicename, baudrate=115200, onData=null, onError=null){
function connect(devicename, baudrate='115200', onData=null, onError=null){
// wrap into promise
return new Promise(function(resolve, reject){

Expand All @@ -25,7 +25,7 @@ function connect(devicename, baudrate=115200, onData=null, onError=null){
path: devicename,
baudRate: parseInt(baudrate),
autoOpen: false
});
});

// new delimiter parser
const parser = _device.pipe(new _delimiterParser({ delimiter: Buffer.from(_delimiterSequence) }));
Expand Down Expand Up @@ -171,4 +171,4 @@ module.exports = {
list: list,
isConnected: isConnected,
debug: enableDebug
};
};
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
"author": "Andi Dittrich (https://andidittrich.de)",
"license": "MIT",
"dependencies": {
"async-magic": "^1.3.0",
"cli-progress": "^3.1.0",
"async-magic": "1.5.0",
"cli-progress": "3.12.0",
"colors": "^1.1.2",
"commander": "^2.14.0",
"fs-magic": "^2.1.1",
"glob": "^7.1.6",
"is-glob": "^4.0.1",
"commander": "12.1.0",
"fs-magic": "2.1.3",
"glob": "10.4.4",
"is-glob": "4.0.3",
"logging-facility": "^2.0.1",
"luamin": "^1.0.4",
"prompt": "1.3.0",
"serialport": "12.0.0"
},
"devDependencies": {
"eslint": "^4.18.0",
"eslint": "8.57.0",
"eslint-config-aenondynamics": "^0.2.0"
}
}
Loading