@toa.io/cli 0.1.0-dev.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/LICENSE +22 -0
- package/bin/toa +4 -0
- package/package.json +35 -0
- package/src/commands/compose.js +31 -0
- package/src/commands/deploy/export.js +18 -0
- package/src/commands/deploy.js +19 -0
- package/src/commands/invoke.js +26 -0
- package/src/commands/manifest.js +18 -0
- package/src/handlers/compose.js +14 -0
- package/src/handlers/deploy/export.js +16 -0
- package/src/handlers/deploy.js +14 -0
- package/src/handlers/invoke.js +26 -0
- package/src/handlers/manifest.js +14 -0
- package/src/program.js +41 -0
- package/src/util/args.js +21 -0
- package/src/util/find.js +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2020-present Artem Gurtovoi
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/bin/toa
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@toa.io/cli",
|
|
3
|
+
"version": "0.1.0-dev.0",
|
|
4
|
+
"description": "Toa CLI",
|
|
5
|
+
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
|
+
"homepage": "https://github.com/toa-io/toa#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/toa-io/toa.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/toa-io/toa/issues"
|
|
13
|
+
},
|
|
14
|
+
"main": "package.json",
|
|
15
|
+
"bin": {
|
|
16
|
+
"toa": "bin/toa"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@toa.io/boot": "^0.0.0",
|
|
26
|
+
"@toa.io/core": "^0.0.0",
|
|
27
|
+
"@toa.io/gears": "^0.0.0",
|
|
28
|
+
"@toa.io/package": "^0.0.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"find-up": "5.0.0",
|
|
32
|
+
"yargs": "17.2.1"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "632df6cead03909ad2cfb8852e178914ac4ab5d2"
|
|
35
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { compose } = require('../handlers/compose')
|
|
4
|
+
|
|
5
|
+
const builder = (yargs) => {
|
|
6
|
+
yargs
|
|
7
|
+
.positional('paths', {
|
|
8
|
+
type: 'string',
|
|
9
|
+
desc: 'Path to package',
|
|
10
|
+
default: '.'
|
|
11
|
+
})
|
|
12
|
+
.array('paths')
|
|
13
|
+
.option('bindings', {
|
|
14
|
+
group: 'Command options:',
|
|
15
|
+
type: 'string',
|
|
16
|
+
desc: 'Bindings'
|
|
17
|
+
})
|
|
18
|
+
.array('bindings')
|
|
19
|
+
.example([
|
|
20
|
+
['$0 compose ./component', 'Path to component package'],
|
|
21
|
+
['$0 compose ./first ./second', 'Paths enumeration'],
|
|
22
|
+
['$0 compose ./components/**/', 'Glob pattern'],
|
|
23
|
+
['$0 compose ./a/**/ ./b/**/', 'Glob patterns enumeration']
|
|
24
|
+
])
|
|
25
|
+
.strictCommands()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.command = 'compose [paths...]'
|
|
29
|
+
exports.desc = 'Start composition'
|
|
30
|
+
exports.builder = builder
|
|
31
|
+
exports.handler = compose
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { dump } = require('../../handlers/deploy/export')
|
|
4
|
+
|
|
5
|
+
const builder = (yargs) => {
|
|
6
|
+
yargs
|
|
7
|
+
.positional('path', {
|
|
8
|
+
type: 'string',
|
|
9
|
+
desc: 'Path to context',
|
|
10
|
+
default: '.'
|
|
11
|
+
})
|
|
12
|
+
.usage('Usage: toa deploy export /path/to/context')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.command = 'export [path]'
|
|
16
|
+
exports.desc = 'Export context deployment'
|
|
17
|
+
exports.builder = builder
|
|
18
|
+
exports.handler = dump
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { deploy } = require('../handlers/deploy')
|
|
4
|
+
|
|
5
|
+
const builder = (yargs) => {
|
|
6
|
+
yargs
|
|
7
|
+
.positional('path', {
|
|
8
|
+
type: 'string',
|
|
9
|
+
desc: 'Path to context',
|
|
10
|
+
default: '.'
|
|
11
|
+
})
|
|
12
|
+
.usage('Usage: toa deploy /path/to/context')
|
|
13
|
+
.commandDir('./deploy')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.command = 'deploy [path]'
|
|
17
|
+
exports.desc = 'Deploy context'
|
|
18
|
+
exports.builder = builder
|
|
19
|
+
exports.handler = deploy
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { invoke } = require('../handlers/invoke')
|
|
4
|
+
|
|
5
|
+
const builder = (yargs) => {
|
|
6
|
+
yargs
|
|
7
|
+
.positional('operation', {
|
|
8
|
+
type: 'string',
|
|
9
|
+
desc: 'Operation name'
|
|
10
|
+
})
|
|
11
|
+
.positional('request', {
|
|
12
|
+
type: 'string',
|
|
13
|
+
desc: 'Request YAML'
|
|
14
|
+
})
|
|
15
|
+
.option('path', {
|
|
16
|
+
group: 'Command options:',
|
|
17
|
+
type: 'string',
|
|
18
|
+
describe: 'Path to component',
|
|
19
|
+
default: '.'
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.command = 'invoke <operation> [request]'
|
|
24
|
+
exports.desc = 'Invoke operation'
|
|
25
|
+
exports.builder = builder
|
|
26
|
+
exports.handler = invoke
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { manifest } = require('../handlers/manifest')
|
|
4
|
+
|
|
5
|
+
const builder = (yargs) => {
|
|
6
|
+
yargs
|
|
7
|
+
.positional('path', {
|
|
8
|
+
type: 'string',
|
|
9
|
+
desc: 'Path to component',
|
|
10
|
+
default: '.'
|
|
11
|
+
})
|
|
12
|
+
.usage('Usage: toa manifest /path/to/component')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.command = 'manifest [path]'
|
|
16
|
+
exports.desc = 'Print manifest'
|
|
17
|
+
exports.builder = builder
|
|
18
|
+
exports.handler = manifest
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const boot = require('@toa.io/boot')
|
|
4
|
+
|
|
5
|
+
const { manifest: find } = require('../util/find')
|
|
6
|
+
|
|
7
|
+
async function compose (argv) {
|
|
8
|
+
const paths = [...new Set(argv.paths.map(find))]
|
|
9
|
+
const composition = await boot.composition(paths, argv)
|
|
10
|
+
|
|
11
|
+
await composition.connect()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.compose = compose
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const boot = require('@toa.io/boot')
|
|
4
|
+
const { console } = require('@toa.io/gears')
|
|
5
|
+
|
|
6
|
+
const { context: find } = require('../../util/find')
|
|
7
|
+
|
|
8
|
+
const dump = async (argv) => {
|
|
9
|
+
const context = find(argv.path)
|
|
10
|
+
const deployment = await boot.deployment(context)
|
|
11
|
+
const path = await deployment.export()
|
|
12
|
+
|
|
13
|
+
console.log(path)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.dump = dump
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const boot = require('@toa.io/boot')
|
|
4
|
+
|
|
5
|
+
const { context: find } = require('../util/find')
|
|
6
|
+
|
|
7
|
+
const deploy = async (argv) => {
|
|
8
|
+
const context = find(argv.path)
|
|
9
|
+
const deployment = await boot.deployment(context)
|
|
10
|
+
|
|
11
|
+
await deployment.install()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.deploy = deploy
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const boot = require('@toa.io/boot')
|
|
4
|
+
const { yaml } = require('@toa.io/gears')
|
|
5
|
+
const { manifest: find } = require('../util/find')
|
|
6
|
+
|
|
7
|
+
async function invoke (argv) {
|
|
8
|
+
const path = find(argv.path)
|
|
9
|
+
const request = yaml.parse(argv.request)
|
|
10
|
+
|
|
11
|
+
const composition = await boot.composition([path], { bindings: null })
|
|
12
|
+
await composition.connect()
|
|
13
|
+
|
|
14
|
+
const manifest = await boot.manifest(path)
|
|
15
|
+
const remote = await boot.remote(manifest.locator, manifest)
|
|
16
|
+
await remote.connect()
|
|
17
|
+
|
|
18
|
+
const reply = await remote.invoke(argv.operation, request)
|
|
19
|
+
|
|
20
|
+
await remote.disconnect()
|
|
21
|
+
await composition.disconnect()
|
|
22
|
+
|
|
23
|
+
console.dir(reply)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.invoke = invoke
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { manifest: load } = require('@toa.io/package')
|
|
4
|
+
const { console, yaml } = require('@toa.io/gears')
|
|
5
|
+
|
|
6
|
+
const { manifest: find } = require('../util/find')
|
|
7
|
+
|
|
8
|
+
const print = async (argv) => {
|
|
9
|
+
const manifest = await load(find(argv.path))
|
|
10
|
+
|
|
11
|
+
console.log(yaml.dump(manifest))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.manifest = print
|
package/src/program.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const yargs = require('yargs/yargs')
|
|
4
|
+
|
|
5
|
+
const { console } = require('@toa.io/gears')
|
|
6
|
+
const { version } = require('../package.json')
|
|
7
|
+
|
|
8
|
+
yargs(process.argv.slice(2))
|
|
9
|
+
.middleware((argv) => {
|
|
10
|
+
if (argv.log === undefined) {
|
|
11
|
+
if (process.env.TOA_ENV === 'dev') argv.log = 'info'
|
|
12
|
+
else argv.log = 'warn'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
console.level(argv.log)
|
|
16
|
+
})
|
|
17
|
+
.fail((msg, err) => {
|
|
18
|
+
const actual = err || new Error(msg)
|
|
19
|
+
|
|
20
|
+
if (process.env.TOA_ENV === 'dev') console.log(actual)
|
|
21
|
+
else console.error(actual.message)
|
|
22
|
+
|
|
23
|
+
process.exit(actual.exitCode > 0 ? actual.exitCode : 1)
|
|
24
|
+
})
|
|
25
|
+
.option('log', {
|
|
26
|
+
type: 'string',
|
|
27
|
+
describe: 'Log level'
|
|
28
|
+
})
|
|
29
|
+
.commandDir('./commands')
|
|
30
|
+
.demandCommand(1, 'A command is required. Pass --help to see all available commands and options.')
|
|
31
|
+
.strict()
|
|
32
|
+
.help()
|
|
33
|
+
.version(version)
|
|
34
|
+
.alias('h', 'help')
|
|
35
|
+
.alias('v', 'version')
|
|
36
|
+
.parse()
|
|
37
|
+
|
|
38
|
+
process.on('unhandledRejection', (e) => {
|
|
39
|
+
console.error(e)
|
|
40
|
+
process.exit(1)
|
|
41
|
+
})
|
package/src/util/args.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const bindings = (argv) => {
|
|
4
|
+
if (argv.bindings === 'null') return null
|
|
5
|
+
|
|
6
|
+
let bindings
|
|
7
|
+
|
|
8
|
+
if (argv.bindings !== undefined) {
|
|
9
|
+
bindings = argv.bindings.map((binding) => {
|
|
10
|
+
if (binding[0] === '@' && binding.indexOf('/') === -1) {
|
|
11
|
+
binding = '@toa.io/bindings.' + binding.substr(1)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return binding
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return bindings
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.bindings = bindings
|
package/src/util/find.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { dirname, resolve } = require('node:path')
|
|
4
|
+
const findUp = require('find-up')
|
|
5
|
+
|
|
6
|
+
const find = (from = '.', filename) => {
|
|
7
|
+
const path = findUp.sync(filename, { cwd: resolve(process.cwd(), from) })
|
|
8
|
+
|
|
9
|
+
if (path === undefined) throw new Error(`File ${filename} not found in ${from}`)
|
|
10
|
+
|
|
11
|
+
return dirname(path)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const manifest = (from = '.') => find(from, MANIFEST)
|
|
15
|
+
const context = (from = '.') => find(from, CONTEXT)
|
|
16
|
+
|
|
17
|
+
const MANIFEST = 'manifest.toa.yaml'
|
|
18
|
+
const CONTEXT = 'context.toa.yaml'
|
|
19
|
+
|
|
20
|
+
exports.manifest = manifest
|
|
21
|
+
exports.context = context
|