Skip to content

Commit

Permalink
fix(cli): cli commands not working (#1660)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Aug 3, 2023
1 parent 8f15557 commit 1bea132
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"type": "git",
"url": "git://github.com/mqttjs/MQTT.js.git"
},
"main": "./build/src/mqtt.js",
"main": "./build/mqtt.js",
"bin": {
"mqtt_pub": "./build/bin/pub.js",
"mqtt_sub": "./build/bin/sub.js",
Expand All @@ -30,29 +30,29 @@
"dist/",
"CONTRIBUTING.md",
"LICENSE.md",
"doc/",
"help/",
"build/",
"src/"
],
"exports": {
".": "./build/src/mqtt.js",
".": "./build/mqtt.js",
"./package.json": "./package.json",
"./*.map": "./build/*.js.map",
"./*": "./build/*.js"
},
"types": "build/src/mqtt.d.ts",
"types": "build/mqtt.d.ts",
"typesVersions": {
"*": {
"*": [
"./build/src/mqtt.d.ts"
"./build/mqtt.d.ts"
]
}
},
"scripts": {
"lint": "eslint --ext .ts .",
"lint-fix": "eslint --fix --ext .ts .",
"build:ts": "rimraf build/ && tsc -p tsconfig.build.json",
"build:browser": "rimraf dist/ && mkdirp dist/ && browserify build/src/mqtt.js --standalone mqtt > dist/mqtt.js && terser dist/mqtt.js --compress --mangle --output dist/mqtt.min.js",
"build:browser": "rimraf dist/ && mkdirp dist/ && browserify build/mqtt.js --standalone mqtt > dist/mqtt.js && terser dist/mqtt.js --compress --mangle --output dist/mqtt.min.js",
"build": "npm run build:ts && npm run build:browser",
"prepare": "npm run build",
"unit-test:node": "node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/mocha/bin/_mocha -r ts-node/register test/*.ts --exit",
Expand Down Expand Up @@ -94,7 +94,7 @@
"node": ">=16.0.0"
},
"browser": {
"./mqtt.js": "./build/src/mqtt.js",
"./mqtt.js": "./build/mqtt.js",
"fs": false,
"tls": false,
"net": false
Expand Down
17 changes: 12 additions & 5 deletions src/bin/mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,26 @@
* See LICENSE for more information
*/
import path from 'path'
import commist from 'commist'
import helpMe from 'help-me'
import { version } from '../../package.json'
import Commist from 'commist'
import help from 'help-me'
import publish from './pub'
import subscribe from './sub'

helpMe({
dir: path.join(path.dirname(require.main.filename), '/../doc'),
// eslint-disable-next-line @typescript-eslint/no-var-requires
const version = require('../../package.json').version

const helpMe = help({
dir: path.join(__dirname, '../../', 'help'),
ext: '.txt',
})

const commist = Commist()

commist.register('publish', publish)
commist.register('pub', publish)

commist.register('subscribe', subscribe)
commist.register('sub', subscribe)

commist.register('version', () => {
console.log('MQTT.js version:', version)
Expand Down
13 changes: 8 additions & 5 deletions src/bin/pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import { Writable } from 'readable-stream'
import path from 'path'
import fs from 'fs'
import concat from 'concat-stream'
import helpMe from 'help-me'
import help from 'help-me'

import minimist, { ParsedArgs } from 'minimist'
import split2 from 'split2'
import { connect } from '../mqtt'
import { IClientOptions, IClientPublishOptions } from 'src/lib/client'
import { pipeline } from 'stream'

helpMe({
dir: path.join(__dirname, '..', 'doc'),
const helpMe = help({
dir: path.join(__dirname, '../../', 'help'),
})

function send(args: ParsedArgs) {
Expand Down Expand Up @@ -142,8 +143,10 @@ export default function start(args: string[]) {
parsedArgs.rejectUnauthorized = false
}

parsedArgs.topic = (parsedArgs.topic || parsedArgs._.shift()).toString()
parsedArgs.message = (parsedArgs.message || parsedArgs._.shift()).toString()
parsedArgs.topic = (parsedArgs.topic || parsedArgs._.shift())?.toString()
parsedArgs.message = (
parsedArgs.message || parsedArgs._.shift()
)?.toString()

if (!parsedArgs.topic) {
console.error('missing topic\n')
Expand Down
6 changes: 3 additions & 3 deletions src/bin/sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import path from 'path'
import fs from 'fs'
import minimist from 'minimist'
import helpMe from 'help-me'
import help from 'help-me'
import { connect } from '../mqtt'
import { IClientOptions } from 'src/lib/client'

helpMe({
dir: path.join(__dirname, '..', 'doc'),
const helpMe = help({
dir: path.join(__dirname, '../../', 'help'),
})

export default function start(args: string[]) {
Expand Down

0 comments on commit 1bea132

Please sign in to comment.