Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit 142cf1b

Browse files
authored
V4 (#55)
- The composition json is now _just_ the AST with no implicit lowering. - `composer.lower(composition, [combinators])` is now exposed and gives control over the lowering (if desired). - The `compose` command has two new options: `--lower` and `--version`. - The combinators are now automatically derived from spec, e.g, `if: { args: [{ _: 'test' }, { _: 'consequent' }, { _: 'alternate', optional: true }], since: '0.4.0' }`. - The spec for the combinators is now exposed as well (`composer.combinators`). - The core language has shrunk thanks to `composer.mask` and a more aggressive use of lowering. - The fsm has fewer states. - The code is now split into three components: 1 compiler component available client-side and server-side, 2 client-side composer, and 3 server-side conductor.
1 parent 600e006 commit 142cf1b

12 files changed

+820
-613
lines changed

bin/compose

+16-9
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ const minimist = require('minimist')
88
const composer = require('../composer')
99

1010
const argv = minimist(process.argv.slice(2), {
11-
string: ['apihost', 'auth', 'deploy'],
12-
boolean: ['insecure', 'encode', 'json'],
13-
alias: { auth: 'u', insecure: 'i' }
11+
string: ['apihost', 'auth', 'deploy', 'lower'],
12+
boolean: ['insecure', 'encode', 'json', 'version'],
13+
alias: { auth: 'u', insecure: 'i', version: 'v' }
1414
})
1515

16+
if (argv.version) {
17+
console.log(composer.version)
18+
return
19+
}
20+
1621
let count = 0
1722
if (argv.json) count++
1823
if (argv.encode) count++
@@ -26,27 +31,29 @@ if (argv._.length !== 1 || count > 1 || argv.deploy === '') {
2631
console.error(' --deploy NAME deploy the composition with name NAME')
2732
console.error(' --encode output the conductor action code for the composition')
2833
console.error('Flags:')
34+
console.error(' --lower [VERSION] lower to primitive combinators or specific composer version')
2935
console.error(' --apihost HOST API HOST')
3036
console.error(' -u, --auth KEY authorization KEY')
3137
console.error(' -i, --insecure bypass certificate checking')
38+
console.error(' -v, --version output the composer version')
3239
return
3340
}
3441

3542
const filename = argv._[0]
3643
const source = fs.readFileSync(filename, { encoding: 'utf8' })
37-
const composition = filename.slice(filename.lastIndexOf('.')) === '.js' ? vm.runInNewContext(source, { composer, require, console, process }) : composer.deserialize(JSON.parse(source))
44+
let composition = filename.slice(filename.lastIndexOf('.')) === '.js' ? vm.runInNewContext(source, { composer, require, console, process }) : composer.deserialize(JSON.parse(source))
45+
const lower = typeof argv.lower === 'string' ? argv.lower : false
3846
if (argv.deploy) {
3947
const options = { ignore_certs: argv.insecure }
4048
if (argv.apihost) options.apihost = argv.apihost
4149
if (argv.auth) options.api_key = argv.auth
42-
const obj = composition.named(argv.deploy)
43-
composer.openwhisk(options).compositions.deploy(obj)
44-
.then(() => {
50+
composer.openwhisk(options).compositions.deploy(composer.composition(argv.deploy, composition), lower)
51+
.then(obj => {
4552
const names = obj.actions.map(action => action.name)
4653
console.log(`ok: created action${names.length > 1 ? 's' : ''} ${names}`)
4754
}, console.error)
4855
} else if (argv.encode) {
49-
console.log(composition.encode('anonymous').actions.slice(-1)[0].action.exec.code)
56+
console.log(composer.encode(composer.composition('anonymous', composition), lower).actions.slice(-1)[0].action.exec.code)
5057
} else {
51-
console.log(JSON.stringify(composition, null, 4))
58+
console.log(JSON.stringify(composer.lower(composition, lower), null, 4))
5259
}

0 commit comments

Comments
 (0)