Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement building app distributables using pear build #98

Open
wants to merge 70 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
fea7c43
Add subsystem for pear build
jkcdarunday Mar 21, 2024
fc8c874
Add initial pear build implementation that uses bare-dev to build the…
jkcdarunday Mar 21, 2024
5c23dc8
Add workarounds for the which dependency in bare-dev
jkcdarunday Mar 21, 2024
c8ad54e
Revert splitting of source and build directory
jkcdarunday Mar 21, 2024
0bf1dfd
Add loading of configuration from package.json
jkcdarunday Mar 22, 2024
39ef519
Use parse library for args and add verbose flag support
jkcdarunday Mar 22, 2024
52bd204
Remove excess newline
jkcdarunday Mar 22, 2024
5941a2b
Add usage documentation for pear build
jkcdarunday Mar 22, 2024
bc7cc7b
Move subsystem function calls to the build function
jkcdarunday Mar 22, 2024
e110c27
Fix tmp dir subdirectory name
jkcdarunday Mar 22, 2024
c466c74
Use parse to correctly resolve and pear links and keys
jkcdarunday Mar 22, 2024
e0c54a0
Add error handling for requirement and input errors
jkcdarunday Mar 22, 2024
f45fb77
Fix platform keys in required fields
jkcdarunday Mar 22, 2024
c3cc164
Add support for build-specific name fields
jkcdarunday Mar 22, 2024
124303c
Remove channel from supported pear build arguments
jkcdarunday Mar 22, 2024
50921d9
Use InputError for the invalid key error
jkcdarunday Mar 22, 2024
7fc3fef
Remove unnecessary Bare.exit
jkcdarunday Mar 22, 2024
83fba4a
Change build directory to required instead of optional
jkcdarunday Mar 25, 2024
1848e67
Add call to ipc.close() before exit
jkcdarunday Mar 28, 2024
e60a7e2
Remove workarounds and update bare-dev to latest
jkcdarunday Apr 4, 2024
e71efc5
App storage move (#111)
davidmarkclements Apr 4, 2024
bc8f10a
Also remove unused bare-process dependency
jkcdarunday Apr 4, 2024
cf60ddb
Move build subsystem exports to lib
jkcdarunday Apr 4, 2024
4be582a
Trust dialog poc (#110)
rafapaezbas Apr 4, 2024
6dcc1aa
Add bare-dev to dependencies
jkcdarunday Mar 21, 2024
b33a340
Move build functions to the build submodule and call it using pear-ipc
jkcdarunday Apr 5, 2024
f10992d
Add build function in sidecar and add call to dump without finalization
jkcdarunday Apr 5, 2024
b1a3908
Remove overrides to package fields under pear.build
jkcdarunday Apr 5, 2024
48f3468
Make final yield success=false when there is an error
jkcdarunday Apr 5, 2024
3892d23
Update pear-ipc version to 1.0.11
jkcdarunday Apr 5, 2024
18a3ad8
Update usage description of build subcommand
jkcdarunday Apr 5, 2024
e82b2ff
Cleanup removed verbose flag
jkcdarunday Apr 8, 2024
9bf2dd3
Convert build function to use stream instead of generator
jkcdarunday Apr 9, 2024
816a586
Move session out if the inner async function
jkcdarunday Apr 10, 2024
ff0efbd
Pass stdio to bare-dev functions and forward stdout to client
jkcdarunday Apr 10, 2024
af2f6e9
Remove leftover verbose option and set verbose to false to workaround…
jkcdarunday Apr 10, 2024
1aaf4a7
Update message when generating CMakeLists.txt
jkcdarunday Apr 10, 2024
393747f
Always close created session
jkcdarunday Apr 10, 2024
7ea8c7b
Remove unused session instance
jkcdarunday Apr 10, 2024
8950723
Add space between imports and outputter declaration
jkcdarunday Apr 10, 2024
8f31ddc
Remove trailing comma
jkcdarunday Apr 11, 2024
71af0a5
Update bare-dev version
jkcdarunday Apr 11, 2024
7d950cf
Switch build handler to use async generators
jkcdarunday Apr 11, 2024
234cfe8
Remove try catch as it is already handled outside the function
jkcdarunday Apr 11, 2024
db5fabc
usage refine
davidmarkclements Apr 11, 2024
a9c9781
refine usage
davidmarkclements Apr 11, 2024
36e225b
usage typo
davidmarkclements Apr 11, 2024
ee5b835
Update usage docs to exclude verbose and include the json flag
jkcdarunday Apr 11, 2024
2d78f6e
build after dump, build in long form usage
davidmarkclements Apr 11, 2024
8bf6a37
Replace RequirementError with simple errors with code
jkcdarunday Apr 11, 2024
79a7392
Add checking of package.json before doing the dump
jkcdarunday Apr 11, 2024
24d6637
Add pulling of app bundle before checking package.json
jkcdarunday Apr 11, 2024
b4112a8
Update invalid package.json message and use option chaining in toString
jkcdarunday Apr 11, 2024
a2e5f3c
Add slash before package.json path
jkcdarunday Apr 11, 2024
3c740d4
App storage move (#111)
davidmarkclements Apr 4, 2024
9b87344
Trust dialog poc (#110)
rafapaezbas Apr 4, 2024
ec869ed
copy/paste text only using right-click (#123)
yassernasc Apr 11, 2024
a69e56a
Pear info <channelName> (#108)
ruy-dan Apr 11, 2024
0a56500
Merge branch 'next' into feature/pear-build
jkcdarunday Apr 12, 2024
fcf55bf
Fix linting error
jkcdarunday Apr 12, 2024
8224252
Fix wrong exit code value in error message
jkcdarunday Apr 12, 2024
b4d47ac
Add installation of bare-dev CMake files to the app build directory
jkcdarunday Apr 15, 2024
2dbe35b
Install full bare-dev instead of just the cmake files
jkcdarunday Apr 15, 2024
3d9be26
Fix wrong variable used in symlink
jkcdarunday Apr 15, 2024
c89704f
Switch to using npm to install bare-dev
jkcdarunday Apr 15, 2024
b1dfe8e
Skip install when bare-dev is available globally
jkcdarunday Apr 15, 2024
4ff2537
Add nothrow to global bare-dev check
jkcdarunday Apr 15, 2024
105aec9
Add symlinking when not globally-installed
jkcdarunday Apr 15, 2024
d3676a1
Add symlinking to cmake folder of global npm if found
jkcdarunday Apr 15, 2024
f59d07a
Remove usage of npm and use hardcoded defined interpreter in bare-dev…
jkcdarunday Apr 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions cmd/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict'
const path = require('bare-path')
const { outputter, print, InputError } = require('./iface')
const parse = require('../lib/parse')

const output = outputter('build', {
starting: ({ platform, arch, key, dir }) => `Starting build for pear://${key} on ${platform}-${arch} in ${dir}`,
dumping: ({ key, dir }) => `Dumping ${key} into ${dir}`,
initializing: () => 'Initializing...',
cmakeListsCreated: () => ' Generated CMakeLists.txt from package.json',
cmakeListsExists: () => ' Using existing CMakeLists.txt',
installingBareDev: () => 'Installing bare-dev to build directory...',
bareDevExistsInApp: () => ' bare-dev is already installed in build directory',
bareDevExistsInPath: () => ' bare-dev is already installed globally',
bareDevInstalled: () => ' bare-dev installed to build directory',
configuring: () => 'Configuring...',
building: () => 'Building...',
done: ({ key, dir }) => `Build complete for pear://${key} in ${dir}`,
error: ({ code, stack }) => `Build Error (code: ${code || 'none'}) ${stack}`,
stdout: (data) => ` ${data?.trimEnd()?.split('\n')?.join('\n ')}`,
stderr: (data) => ` ${data?.trimEnd()?.split('\n')?.join('\n ')}`
})

module.exports = (ipc) => async function build (args) {
try {
const { _: [passedKey, buildDirArg], json } = parse.args(args, { boolean: ['json'] })

const key = parse.runkey(passedKey)?.key?.z32
if (!key) throw new InputError(passedKey ? `Key "${passedKey}" is not valid` : 'Key must be specified')
if (!buildDirArg) throw new InputError('Build directory must be specified')

const dir = path.resolve(buildDirArg)

await output(json, ipc.build({ key, dir }))
} catch (err) {
if (err instanceof InputError) {
ipc.userData.usage.output('build')
print(err.message, false)
} else {
console.error(err)
}
} finally {
await ipc.close()
}
}
15 changes: 9 additions & 6 deletions cmd/iface.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ function indicator (value, type = 'success') {
}

const outputter = (cmd, taggers = {}) => async (json, stream, state = {}) => {
let error = null
try {
for await (const { tag, data = {} } of stream) {
if (json) {
print(JSON.stringify({ cmd, tag, data }))
continue
}
if (tag === 'error') {
const err = new Error(data.message)
err.sidecarCode = data.code
err.sidecarStack = data.stack
throw err
let result = null
try {
result = typeof taggers[tag] === 'function' ? taggers[tag](data, state) : (taggers[tag] || false)
} catch (err) {
error = err
break
}
let result = typeof taggers[tag] === 'function' ? taggers[tag](data, state) : (taggers[tag] || false)
if (result === undefined) continue
if (typeof result === 'string') result = { output: 'print', message: result }
if (result === false) {
Expand All @@ -87,6 +88,8 @@ const outputter = (cmd, taggers = {}) => async (json, stream, state = {}) => {
} catch (err) {
if (err.sidecarCode === 'ERR_BARE_CORE') print(err.message, -1)
else if (err.code === 'E_MUX_REMOTE') throw (err.remote || err)
} finally {
if (error) throw error // eslint-disable-line no-unsafe-finally
}
}

Expand Down
7 changes: 4 additions & 3 deletions cmd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const seed = require('./seed')
const release = require('./release')
const info = require('./info')
const dump = require('./dump')
const shift = require('./shift')
const sidecar = require('./sidecar')
const run = require('./run')
const build = require('./build')
const parse = require('../lib/parse')
const { CHECKOUT } = require('../lib/constants')

Expand Down Expand Up @@ -70,7 +72,8 @@ module.exports = async (ipc) => {
cmd.add('launch', launch) // launch is legacy alias for run
cmd.add('info', info(ipc))
cmd.add('dump', dump(ipc))
cmd.add('build', build)
cmd.add('build', build(ipc))
cmd.add('shift', shift(ipc))
cmd.add('sidecar', (args) => sidecar(ipc)(args))

await cmd.run(argv)
Expand All @@ -79,7 +82,5 @@ module.exports = async (ipc) => {
return run(ipc)(args)
}

function build () { throw new Error('Not Implemented: build') }

return ipc
}
28 changes: 22 additions & 6 deletions cmd/info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'
const parse = require('../lib/parse')
const { outputter, print } = require('./iface')
const os = require('bare-os')
const { isAbsolute, resolve } = require('bare-path')

const keys = ({ content, discovery, project }) => `
keys hex
Expand Down Expand Up @@ -36,14 +38,28 @@ const output = outputter('info', {
module.exports = (ipc) => async function info (args) {
try {
const flags = parse.args(args, {
boolean: ['json']
boolean: ['json', 'changelog', 'full-changelog', 'metadata', 'key']
})
const { _, json } = flags
const [key] = _
const isKey = key ? parse.runkey(key).key !== null : false
const { _, json, changelog, 'full-changelog': full, metadata, key: showKey, keys } = flags
const [from] = _
let [, dir = ''] = _
const isKey = from ? parse.runkey(from).key !== null : false
const channel = isKey ? null : from
const key = isKey ? from : null
if (key && isKey === false) throw new Error('Key "' + key + '" is not valid')
const id = Bare.pid
await output(json, ipc.info({ id, key }))

if (isAbsolute(dir) === false) dir = dir ? resolve(os.cwd(), dir) : os.cwd()

await output(json, ipc.info({
key,
channel,
dir,
showKey,
keys,
metadata,
changelog,
full
}))
} catch (err) {
ipc.userData.usage.output('info', false)
print(err.message, false)
Expand Down
42 changes: 42 additions & 0 deletions cmd/shift.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict'
const { outputter, print, InputError } = require('./iface')
const parse = require('../lib/parse')

const output = outputter('shift', {
moving: ({ src, dst, force }) => `Moving user application storage\n\nFrom: ${src}\nTo: ${dst}\n${force ? '\nForce flag used, overwriting existing application storage.' : ''}`,
complete: ({ from, to }) => `Moved\n\nFrom: ${from}\nTo: ${to}\n\nShift Complete`,
error: ({ code, stack, message }) => {
if (code === 'ERR_EXISTS' || code === 'ERR_NOENT') throw Object.assign(new Error(message), { code })
return `Shift Error (code: ${code || 'none'}) ${stack}`
}
})

module.exports = (ipc) => async function shift (args) {
try {
const { _, force, json } = parse.args(args, {
boolean: ['force', 'json']
})
const [src, dst] = _

if (!src || parse.runkey(src.toString()).key === null) {
throw new InputError('A source application key must be specified.')
}

if (!dst || parse.runkey(dst.toString()).key === null) {
throw new InputError('A destination application key must be specified.')
}

await output(json, ipc.shift({ src, dst, force }))
} catch (err) {
if (err instanceof InputError || err.code === 'ERR_INVALID_FLAG' || err.code === 'ERR_EXISTS' || err.code === 'ERR_NOENT') {
print(err.message, false)
ipc.userData.usage.output('shift')
} else {
print('An error occured', false)
console.error(err)
}
Bare.exit(1)
} finally {
await ipc.close()
}
}
41 changes: 37 additions & 4 deletions cmd/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,21 @@ module.exports = ({ fork, length, key }) => {
`

const info = ansi.bold(cmd + ' info')
const infoArgs = ansi.bold('[key]')
const infoArgs = ansi.bold('[channel|key]')
const infoBrief = 'Read project information.'
const infoExplain = `${info} ${infoArgs}

${infoBrief}

Supply a key to view application info
Supply a key or channel to view application information.

Without a key pear info shows Pear info
Supply no argument to view platform information.

--json Newline delimited JSON output
--changelog View changelog only
--full-changelog Full record of changes
--metadata View metadata only
--key View key only
--json Newline delimited JSON output
`

const dump = ansi.bold(cmd + ' dump')
Expand Down Expand Up @@ -140,6 +144,29 @@ module.exports = ({ fork, length, key }) => {
--verbose|-v Additional output
`

const shift = ansi.bold(cmd + ' shift')
const shiftArgs = ansi.bold('<src-key> <dst-key> [--force]')
const shiftBrief = 'Advanced. Move storage between apps.'
const shiftExplain = `${shift} ${shiftArgs}

${shiftBrief}

--force Overwrite existing application storage if present
--json Newline delimited JSON output
`

const build = ansi.bold(cmd + ' build')
const buildArgs = ansi.bold('<key> <dir>')
const buildBrief = 'Build project distributable.'
const buildExplain = `${build} ${buildArgs}

${buildBrief}

Creates a distributable per host OS at given dir from application key.

--json Newline delimited JSON output
`

const sidecar = ansi.bold(cmd + ' sidecar')
const sidecarBrief = 'Advanced. Run sidecar in terminal.'
const sidecarExplain = `${sidecar}
Expand Down Expand Up @@ -203,6 +230,8 @@ module.exports = ({ fork, length, key }) => {
dump: dumpExplain,
run: runExplain,
seed: seedExplain,
shift: shiftExplain,
build: buildExplain,
sidecar: sidecarExplain,
help: helpExplain,
output,
Expand All @@ -216,6 +245,8 @@ module.exports = ({ fork, length, key }) => {
${release} ${ansi.sep} ${dedot(releaseBrief)}
${info} ${ansi.sep} ${dedot(infoBrief)}
${dump} ${ansi.sep} ${dedot(dumpBrief)}
${build} ${ansi.sep} ${dedot(buildBrief)}
${shift} ${ansi.sep} ${dedot(shiftBrief)}
${sidecar} ${ansi.sep} ${dedot(sidecarBrief)}
${versions} ${ansi.sep} ${dedot(versionsBrief)}

Expand All @@ -229,6 +260,8 @@ ${footer}`,
${releaseExplain}
${infoExplain}
${dumpExplain}
${buildExplain}
${shiftExplain}
${sidecarExplain}
${versionsExplain}
${helpExplain}
Expand Down
Loading