Skip to content

Commit

Permalink
ipc: stream handlers converted from async gens (#120)
Browse files Browse the repository at this point in the history
* ipc: stream handlers converted from async gens

* fixes, stage warmup still to fix

* run fix

* ERR_INPUT not a constructor

* ERR_INPUT -> ERR_INVALID_INPUT

* tweaks/fixes

* tweaks
  • Loading branch information
davidmarkclements committed May 13, 2024
1 parent 6df7712 commit cfadb2c
Show file tree
Hide file tree
Showing 7 changed files with 461 additions and 439 deletions.
10 changes: 5 additions & 5 deletions cmd/dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const os = require('bare-os')
const { isAbsolute, resolve } = require('bare-path')
const { outputter } = require('./iface')
const { ERR_INPUT } = require('../lib/errors')
const { ERR_INVALID_INPUT } = require('../lib/errors')
const output = outputter('stage', {
dumping: ({ key, dir }) => `\n🍐 Dumping ${key} into ${dir}`,
complete: '\nDumping complete!\n',
Expand All @@ -11,8 +11,8 @@ const output = outputter('stage', {

module.exports = (ipc) => async function dump (cmd) {
const { checkout, json } = cmd.flags
const { key, dir = os.cwd() } = cmd.args
if (!dir) throw new ERR_INPUT('Output dir must be specified.')
if (!key) throw new ERR_INPUT('The pear link must be specified.')
await output(json, ipc.dump({ id: Bare.pid, key, dir: isAbsolute(dir) ? dir : resolve(os.cwd(), dir), checkout }))
const { link, dir = os.cwd() } = cmd.args
if (!dir) throw ERR_INVALID_INPUT('Output dir must be specified.')
if (!link) throw ERR_INVALID_INPUT('The pear link must be specified.')
await output(json, ipc.dump({ id: Bare.pid, link, dir: isAbsolute(dir) ? dir : resolve(os.cwd(), dir), checkout }))
}
13 changes: 6 additions & 7 deletions cmd/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ const keys = ({ content, discovery, project }) => `
content ${content}
`

const info = ({ channel, release, name, live }) => `
const info = ({ channel, release, name }) => `
info value
----------- -----------------
live ${live}
name ${name}
channel ${channel}
release ${release}
Expand All @@ -29,7 +28,7 @@ const changelog = ({ changelog, full }) => `
`

const output = outputter('info', {
retrieving: ({ z32 }) => `🔑 :-\n pear://${z32}\n...`,
retrieving: ({ z32 }) => `---:\n pear://${z32}\n...`,
keys,
info,
changelog,
Expand All @@ -38,15 +37,15 @@ const output = outputter('info', {

module.exports = (ipc) => async function info (cmd) {
const { json, changelog, fullChangelog: full, metadata, key: showKey, keys } = cmd.flags
const isKey = parseLink(cmd.args.link).key !== null
const isKey = cmd.args.link && parseLink(cmd.args.link).key !== null
const channel = isKey ? null : cmd.args.link
const key = isKey ? cmd.args.link : null
if (key && isKey === false) throw new ERR_INVALID_INPUT('Key "' + key + '" is not valid')
const link = isKey ? cmd.args.link : null
if (link && isKey === false) throw ERR_INVALID_INPUT('Link "' + link + '" is not a valid key')
let dir = cmd.args.dir || os.cwd()
if (isAbsolute(dir) === false) dir = dir ? resolve(os.cwd(), dir) : os.cwd()

await output(json, ipc.info({
key,
link,
channel,
dir,
showKey,
Expand Down
12 changes: 6 additions & 6 deletions cmd/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ const { ERR_INVALID_INPUT } = require('../lib/errors')
const parseLink = require('../run/parse-link')

const output = outputter('release', {
releasing: ({ name, channel }) => `\n${ansi.pear} Releasing ${name} [ ${channel} ]\n`,
releasing: ({ name, channel, link }) => `\n${ansi.pear} Releasing ${name} [ ${channel || link} ]\n`,
'updating-to': ({ releaseLength, currentLength }) => `Current length is ${currentLength}\nSetting release to ${releaseLength}\n`,
released: ({ name, channel, length }) => `The ${name} app (${channel} channel) was successfully released.\nLatest length: ${length}\n`,
released: ({ name, channel, link, length }) => `The ${name} app (${channel || link} channel) was successfully released.\nLatest length: ${length}\n`,
final: { output: 'print', message: 'Release complete\n', success: true }
})

module.exports = (ipc) => async function release (cmd) {
const { checkout, name, json } = cmd.flags
const isKey = parseLink(cmd.args.channel).key !== null
const channel = isKey ? null : cmd.args.channel
const key = isKey ? cmd.args.channel : null
if (!channel && !key) throw new ERR_INVALID_INPUT('A key or the channel name must be specified.')
const link = isKey ? cmd.args.channel : null
if (!channel && !link) throw ERR_INVALID_INPUT('A valid pear link or the channel name must be specified.')
let dir = cmd.args.dir || os.cwd()
if (isAbsolute(dir) === false) dir = resolve(os.cwd(), dir)
if (checkout !== undefined && Number.isInteger(+checkout) === false) {
throw new ERR_INVALID_INPUT('--checkout flag must supply an integer if set')
throw ERR_INVALID_INPUT('--checkout flag must supply an integer if set')
}
const id = Bare.pid
await output(json, ipc.release({ id, name, channel, key, checkout, dir }))
await output(json, ipc.release({ id, name, channel, link, checkout, dir }))
}
8 changes: 4 additions & 4 deletions cmd/shift.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ module.exports = (ipc) => async function shift (cmd) {
const src = cmd.args.source
const dst = cmd.args.destination

if (!src || parseLink(src).key === null) {
throw new ERR_INVALID_INPUT('A source application key must be specified.')
if (parseLink(src).key === null) {
throw ERR_INVALID_INPUT('A valid source application link must be specified.')
}

if (!dst || parseLink(dst).key === null) {
throw new ERR_INVALID_INPUT('A destination application key must be specified.')
if (parseLink(dst).key === null) {
throw ERR_INVALID_INPUT('A valid destination application link must be specified.')
}

await output(json, ipc.shift({ src, dst, force }))
Expand Down
4 changes: 2 additions & 2 deletions cmd/stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const os = require('bare-os')
const { isAbsolute, resolve } = require('bare-path')
const { outputter, ansi } = require('./iface')
const parseLink = require('../run/parse-link')
const { ERR_INPUT } = require('../lib/errors')
const { ERR_INVALID_INPUT } = require('../lib/errors')

let blocks = 0
let total = 0
Expand All @@ -29,7 +29,7 @@ module.exports = (ipc) => async function stage (cmd) {
const isKey = cmd.args.channel && parseLink(cmd.args.channel).key !== null
const channel = isKey ? null : cmd.args.channel
const key = isKey ? cmd.args.channel : null
if (!channel && !key) throw new ERR_INPUT('A key or the channel name must be specified.')
if (!channel && !key) throw ERR_INVALID_INPUT('A key or the channel name must be specified.')
let { dir = os.cwd() } = cmd.args
if (isAbsolute(dir) === false) dir = dir ? resolve(os.cwd(), dir) : os.cwd()
const id = Bare.pid
Expand Down
Loading

0 comments on commit cfadb2c

Please sign in to comment.