hubot 7.0.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/hubot.js CHANGED
@@ -11,7 +11,7 @@ const switches = [
11
11
  ['-a', '--adapter ADAPTER', 'The Adapter to use, e.g. "shell" (to load the default hubot shell adapter)'],
12
12
  ['-f', '--file PATH', 'Path to adapter file, e.g. "./adapters/CustomAdapter.mjs"'],
13
13
  ['-c', '--create PATH', 'Create a deployable hubot'],
14
- ['-d', '--disable-httpd', 'Disable the HTTP server'],
14
+ ['-d', '--disable-httpd DISABLE_HTTPD', 'Disable the HTTP server'],
15
15
  ['-h', '--help', 'Display the help information'],
16
16
  ['-l', '--alias ALIAS', "Enable replacing the robot's name with alias"],
17
17
  ['-n', '--name NAME', 'The name of the robot in chat'],
@@ -98,21 +98,23 @@ if (options.file) {
98
98
  options.adapter = options.file.split('/').pop().split('.')[0]
99
99
  }
100
100
  const robot = Hubot.loadBot(options.adapter, options.enableHttpd, options.name, options.alias)
101
+ module.exports = robot
101
102
 
102
- function loadScripts () {
103
- robot.load(pathResolve('.', 'scripts'))
104
- robot.load(pathResolve('.', 'src', 'scripts'))
103
+ async function loadScripts () {
104
+ await robot.load(pathResolve('.', 'scripts'))
105
+ await robot.load(pathResolve('.', 'src', 'scripts'))
105
106
 
106
107
  loadExternalScripts()
107
108
 
108
- options.scripts.forEach((scriptPath) => {
109
+ const tasks = options.scripts.map((scriptPath) => {
109
110
  console.log('loadding', scriptPath)
110
111
  if (scriptPath[0] === '/') {
111
112
  return robot.load(scriptPath)
112
113
  }
113
114
 
114
- robot.load(pathResolve('.', scriptPath))
115
+ return robot.load(pathResolve('.', scriptPath))
115
116
  })
117
+ await Promise.all(tasks)
116
118
  }
117
119
 
118
120
  function loadExternalScripts () {
@@ -144,7 +146,7 @@ function loadExternalScripts () {
144
146
  }
145
147
 
146
148
  if (options.configCheck) {
147
- loadScripts()
149
+ await loadScripts()
148
150
  console.log('OK')
149
151
  process.exit(0)
150
152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hubot",
3
- "version": "7.0.0",
3
+ "version": "8.0.1",
4
4
  "author": "hubot",
5
5
  "keywords": [
6
6
  "github",
package/src/robot.js CHANGED
@@ -346,30 +346,47 @@ class Robot {
346
346
  })
347
347
  }
348
348
 
349
+ async loadmjs (filePath) {
350
+ const script = await import(filePath)
351
+ if (typeof script?.default === 'function') {
352
+ script.default(this)
353
+ } else {
354
+ this.logger.warning(`Expected ${filePath} to assign a function to export default, got ${typeof script}`)
355
+ }
356
+ }
357
+
358
+ async loadcoffee (filePath) {
359
+ return await this.loadjs(filePath)
360
+ }
361
+
362
+ async loadjs (filePath) {
363
+ const script = require(filePath)
364
+ if (typeof script === 'function') {
365
+ script(this)
366
+ } else {
367
+ this.logger.warning(`Expected ${filePath} to assign a function to module.exports, got ${typeof script}`)
368
+ }
369
+ }
370
+
349
371
  // Public: Loads a file in path.
350
372
  //
351
373
  // filepath - A String path on the filesystem.
352
374
  // filename - A String filename in path on the filesystem.
353
375
  //
354
376
  // Returns nothing.
355
- loadFile (filepath, filename) {
356
- const ext = path.extname(filename)
357
- const full = path.join(filepath, path.basename(filename, ext))
377
+ async loadFile (filepath, filename) {
378
+ const ext = path.extname(filename)?.replace('.', '')
379
+ const full = path.join(filepath, path.basename(filename))
358
380
 
359
381
  // see https://github.com/hubotio/hubot/issues/1355
360
- if (['.js', '.mjs', '.coffee'].indexOf(ext) == -1) { // eslint-disable-line
382
+ if (['js', 'mjs', 'coffee'].indexOf(ext) === -1) {
383
+ this.logger.debug(`Skipping unsupported file type ${full}`)
361
384
  return
362
385
  }
363
386
 
364
387
  try {
365
- const script = require(full)
366
-
367
- if (typeof script === 'function') {
368
- script(this)
369
- this.parseHelp(path.join(filepath, filename))
370
- } else {
371
- this.logger.warning(`Expected ${full} to assign a function to module.exports, got ${typeof script}`)
372
- }
388
+ await this[`load${ext}`](full)
389
+ this.parseHelp(full)
373
390
  } catch (error) {
374
391
  this.logger.error(`Unable to load ${full}: ${error.stack}`)
375
392
  process.exit(1)
@@ -381,11 +398,12 @@ class Robot {
381
398
  // path - A String path on the filesystem.
382
399
  //
383
400
  // Returns nothing.
384
- load (path) {
401
+ async load (path) {
385
402
  this.logger.debug(`Loading scripts from ${path}`)
386
403
 
387
404
  if (fs.existsSync(path)) {
388
- fs.readdirSync(path).sort().map(file => this.loadFile(path, file))
405
+ const tasks = fs.readdirSync(path).sort().map(file => this.loadFile(path, file))
406
+ await Promise.all(tasks)
389
407
  }
390
408
  }
391
409