hubot 9.0.2 → 9.1.0
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/README.md +10 -0
- package/bin/hubot.js +5 -7
- package/package.json +2 -2
- package/src/GenHubot.js +88 -0
package/README.md
CHANGED
|
@@ -15,6 +15,16 @@ for details on getting up and running with your very own robot friend.
|
|
|
15
15
|
In most cases, you'll probably never have to hack on this repo directly if you
|
|
16
16
|
are building your own bot. But if you do, check out [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
17
17
|
|
|
18
|
+
# Create your own Hubot instance
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
mkdir myhubot
|
|
22
|
+
cd myhubot
|
|
23
|
+
npx hubot --create myhubot --adapter @hubot-friends/hubot-slack
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Review `scripts/example.mjs`. Create more scripts in the `scripts` folder.
|
|
27
|
+
|
|
18
28
|
## License
|
|
19
29
|
|
|
20
30
|
See the [LICENSE](LICENSE.md) file for license rights and limitations (MIT).
|
package/bin/hubot.js
CHANGED
|
@@ -6,6 +6,7 @@ const pathResolve = require('path').resolve
|
|
|
6
6
|
const OptParse = require('optparse')
|
|
7
7
|
|
|
8
8
|
const Hubot = require('..')
|
|
9
|
+
const create = require('../src/GenHubot.js')
|
|
9
10
|
|
|
10
11
|
const switches = [
|
|
11
12
|
['-a', '--adapter HUBOT_ADAPTER', 'The Adapter to use, e.g. "shell" (to load the default hubot shell adapter)'],
|
|
@@ -86,14 +87,11 @@ Parser.on((opt, value) => {
|
|
|
86
87
|
Parser.parse(process.argv)
|
|
87
88
|
|
|
88
89
|
if (options.create) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
console.error(` cd ${options.path}`)
|
|
93
|
-
console.error(' yo hubot')
|
|
94
|
-
console.error('See https://github.com/github/hubot/blob/main/docs/index.md for more details on getting started.')
|
|
95
|
-
process.exit(1)
|
|
90
|
+
options.hubotInstallationPath = process.env.HUBOT_INSTALLATION_PATH ?? 'hubot'
|
|
91
|
+
create(options.path, options)
|
|
92
|
+
process.exit(0)
|
|
96
93
|
}
|
|
94
|
+
|
|
97
95
|
if (options.file) {
|
|
98
96
|
options.adapter = options.file.split('/').pop().split('.')[0]
|
|
99
97
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hubot",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"author": "hubot",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"pino": "^8.11.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"semantic-release": "^21.0.1",
|
|
28
27
|
"standard": "^17.1.0"
|
|
29
28
|
},
|
|
30
29
|
"engines": {
|
|
@@ -37,6 +36,7 @@
|
|
|
37
36
|
},
|
|
38
37
|
"scripts": {
|
|
39
38
|
"start": "bin/hubot",
|
|
39
|
+
"gen": "bin/hubot --create myhubot",
|
|
40
40
|
"pretest": "standard",
|
|
41
41
|
"test": "node --test",
|
|
42
42
|
"test:smoke": "node src/**/*.js",
|
package/src/GenHubot.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const { spawnSync } = require('child_process')
|
|
2
|
+
const File = require('fs')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
|
|
5
|
+
function runCommands (hubotDirectory, options) {
|
|
6
|
+
options.hubotInstallationPath = options?.hubotInstallationPath ?? 'hubot'
|
|
7
|
+
console.log('creating hubot directory', hubotDirectory)
|
|
8
|
+
try {
|
|
9
|
+
spawnSync('mkdir', [hubotDirectory])
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.log(`${hubotDirectory} exists, continuing to the next operation.`)
|
|
12
|
+
}
|
|
13
|
+
const envFilePath = path.resolve(process.cwd(), '.env')
|
|
14
|
+
process.chdir(hubotDirectory)
|
|
15
|
+
|
|
16
|
+
spawnSync('npm', ['init', '-y'])
|
|
17
|
+
spawnSync('npm', ['i', options.hubotInstallationPath].concat(options.adapter, 'hubot-help', 'hubot-rules', 'hubot-diagnostics'))
|
|
18
|
+
spawnSync('mkdir', ['scripts'])
|
|
19
|
+
spawnSync('touch', ['external-scripts.json'])
|
|
20
|
+
|
|
21
|
+
const externalScriptsPath = path.resolve('./', 'external-scripts.json')
|
|
22
|
+
let escripts = File.readFileSync(externalScriptsPath, 'utf8')
|
|
23
|
+
if (escripts.length === 0) escripts = '[]'
|
|
24
|
+
const externalScripts = JSON.parse(escripts)
|
|
25
|
+
externalScripts.push('hubot-help')
|
|
26
|
+
externalScripts.push('hubot-rules')
|
|
27
|
+
externalScripts.push('hubot-diagnostics')
|
|
28
|
+
|
|
29
|
+
File.writeFileSync(externalScriptsPath, JSON.stringify(externalScripts, null, 2))
|
|
30
|
+
|
|
31
|
+
File.writeFileSync('./scripts/example.mjs', `// Description:
|
|
32
|
+
// Test script
|
|
33
|
+
//
|
|
34
|
+
// Commands:
|
|
35
|
+
// hubot helo - Responds with Hello World!.
|
|
36
|
+
//
|
|
37
|
+
// Notes:
|
|
38
|
+
// This is a test script.
|
|
39
|
+
//
|
|
40
|
+
|
|
41
|
+
export default (robot) => {
|
|
42
|
+
robot.respond(/helo/, async res => {
|
|
43
|
+
await res.send('Hello World!')
|
|
44
|
+
})
|
|
45
|
+
}`)
|
|
46
|
+
|
|
47
|
+
const packageJsonPath = path.resolve(process.cwd(), 'package.json')
|
|
48
|
+
const packageJson = JSON.parse(File.readFileSync(packageJsonPath, 'utf8'))
|
|
49
|
+
|
|
50
|
+
packageJson.scripts = {
|
|
51
|
+
start: 'hubot'
|
|
52
|
+
}
|
|
53
|
+
if (options.adapter) {
|
|
54
|
+
packageJson.scripts.start += ` --adapter ${options.adapter}`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
File.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
58
|
+
console.log('package.json updated successfully.')
|
|
59
|
+
const hubotEnvFilePath = path.resolve('.env')
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
File.accessSync(envFilePath)
|
|
63
|
+
File.copyFileSync(envFilePath, hubotEnvFilePath)
|
|
64
|
+
console.log('.env file copied successfully.')
|
|
65
|
+
|
|
66
|
+
const envContent = File.readFileSync(hubotEnvFilePath, 'utf8')
|
|
67
|
+
const envLines = envContent.split('\n')
|
|
68
|
+
|
|
69
|
+
for (const line of envLines) {
|
|
70
|
+
const trimmedLine = line.trim()
|
|
71
|
+
|
|
72
|
+
if (trimmedLine && !trimmedLine.startsWith('#')) {
|
|
73
|
+
const [key, ...values] = trimmedLine.split('=')
|
|
74
|
+
const value = values.join('=')
|
|
75
|
+
process.env[key] = value
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.log('.env file not found, continuing to the next operation.')
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
module.exports = (hubotDirectory, options) => {
|
|
83
|
+
try {
|
|
84
|
+
runCommands(hubotDirectory, options)
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error('An error occurred:', error)
|
|
87
|
+
}
|
|
88
|
+
}
|