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

V1 #140

Merged
merged 33 commits into from
Mar 23, 2022
Merged

V1 #140

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c85ab3b
Add support for bpkg.json, next to package.json.
Potherca Jan 3, 2021
62c9c31
Fix all Shellcheck SC1090 violations.
Potherca Jan 9, 2021
a623d00
Fix all Shellcheck SC2004 violations.
Potherca Jan 9, 2021
a1c9758
Fix all Shellcheck SC2053 violations.
Potherca Jan 9, 2021
4c6eb87
Fix all Shellcheck SC2059 violations.
Potherca Jan 9, 2021
9b7cb21
Fix all Shellcheck SC2086 violations.
Potherca Jan 9, 2021
fb50ebe
Fix all Shellcheck SC2236 violations.
Potherca Jan 9, 2021
bc0fa54
Fix all Shellcheck SC2219 violations.
Potherca Jan 9, 2021
2a30a04
Fix all Shellcheck SC2230 violations.
Potherca Jan 10, 2021
1305200
Fix all Shellcheck SC2155 violations.
Potherca Jan 10, 2021
f94e3a0
Fix all Shellcheck SC2034 violations.
Potherca Jan 10, 2021
3013e91
Remove unused variable.
Potherca Jan 10, 2021
a9936a2
Fix all Shellcheck SC2206 violations.
Potherca Jan 10, 2021
d7b0262
Fix various Shellcheck violations.
Potherca Jan 10, 2021
aaa2989
Fix more Shellcheck SC2155 violations.
Potherca Jan 10, 2021
ccde826
Fix more Shellcheck SC2034 violations.
Potherca Jan 10, 2021
4f7bbc3
Fix more Shellcheck violations.
Potherca Jan 10, 2021
579eb2f
Add GitHub Action for Shellcheck.
Potherca Jan 10, 2021
17b7573
Update pipeline-components/shellcheck in workflow.
Potherca Mar 12, 2021
067384e
Change pipeline-components/shellcheck to latest version.
Potherca Mar 13, 2021
1034144
refactor(): support 'bpkg.json'
jwerle Mar 18, 2022
eb2fe6d
refactor(): support custom 'deps/' dir
jwerle Mar 18, 2022
094d47b
feat(): introduce 'bpkg-run'
jwerle Mar 18, 2022
acbcac9
feat(): introduce 'bpkg source <name>'
jwerle Mar 18, 2022
860a1f0
fix(install.sh,run.sh): fix output
jwerle Mar 18, 2022
f165044
doc(README.md): update sponsors
jwerle Mar 21, 2022
2a84d17
chore(.github/workflows/shellcheck-per-file.yml): fix shellcheck version
jwerle Mar 21, 2022
8d1bc60
refactor(lib): cleanup, remove useless code, fix lint
jwerle Mar 21, 2022
7567e47
fix(install.sh): fix broken url
jwerle Mar 21, 2022
f1971d4
fix(bpkg.json): use 'v1' as version for now
jwerle Mar 22, 2022
c27c5cd
refactor(): support 'commands' for 'bpkg run' and 'BPKG_SCRIPT_SOURCE…
jwerle Mar 23, 2022
0c902c5
fix(lib/run/run.sh): fix typo
jwerle Mar 23, 2022
0eab4e9
chore(bpkg.json): set version to '1.0.0'
jwerle Mar 23, 2022
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
54 changes: 54 additions & 0 deletions .github/workflows/shellcheck-per-file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
# The idea here is to run Shellcheck for each file, so violations can be fixed
# incrementally. As soon as a file has been fixed to pass shellcheck, it should
# no longer be allowed to fail.
#
# Once all files have been fixed, the jobs can all be replaced by one single run
# that checks all files at once.
#
# For discussion and further details see: https://github.com/bpkg/bpkg/issues/78

on:
- push
- pull_request

jobs:
allowed_to_fail:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
file:
- bpkg.sh
- setup.sh
- lib/init/init.sh
- lib/install/install.sh
- lib/json/JSON.sh
- lib/suggest/suggest.sh
steps:
- uses: actions/checkout@v2
- uses: pipeline-components/shellcheck@v0.6.1
continue-on-error: true
with:
directory: ${{ matrix.file }}
options: -f gcc -x lib/utils/utils.sh

must_pass:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
file:
- lib/getdeps/getdeps.sh
- lib/list/list.sh
- lib/package/package.sh
- lib/show/show.sh
- lib/term/term.sh
- lib/update/update.sh
- lib/utils/utils.sh
steps:
- uses: actions/checkout@v2
- uses: pipeline-components/shellcheck@v0.6.1
with:
directory: ${{ matrix.file }}
options: -f gcc -x lib/utils/utils.sh
16 changes: 16 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# shellcheck disable=SC2034

## Allow: To read lines rather than words, pipe/redirect to a 'while read' loop
disable=SC2013

## Allow: Declare and assign separately to avoid masking return values
disable=SC2155

## Allow: Prefer mapfile or read -a to split command output (or quote to avoid splitting)
disable=SC2207

## Allow: Instead of 'let expr', prefer (( expr ))
disable=SC2219
jwerle marked this conversation as resolved.
Show resolved Hide resolved

## Allow: Not following source
disable=SC1091
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ _JavaScript has npm, Ruby has Gems, Python has pip and now Shell has bpkg!_

`bpkg` is a lightweight bash package manager. It takes care of fetching the shell scripts, installing them appropriately, setting the execution permission and more.

You can install shell scripts globally (on `/usr/local/bin`) or use them on a _per-project basis_ (on `./deps/`), as a lazy-man "copy and paste".
You can install shell scripts globally (on `${PREFIX:-/usr/local/bin}`) or use them on a _per-project basis_ (on `${BPKG_DEPS:-./deps/}`), as a lazy-man "copy and paste".

<!-- BEGIN-MARKDOWN-TOC -->
* [Install](#install)
Expand All @@ -17,7 +17,7 @@ You can install shell scripts globally (on `/usr/local/bin`) or use them on a _p
* [Packages With Dependencies](#packages-with-dependencies)
* [Retrieving package info](#retrieving-package-info)
* [Package details](#package-details)
* [package.json](#packagejson)
* [bpkg.json](#bpkgjson)
* [name](#name)
* [version (optional)](#version-optional)
* [description](#description)
Expand Down Expand Up @@ -78,8 +78,8 @@ You use `bpkg` by simply sending commands, pretty much like `npm` or `pip`.

### Installing packages

Packages can either be global (on `/usr/local/bin` if installed as root or
`$HOME/.local/bin` otherwize) or local (under `./deps`).
Packages can either be global (on `${PREFIX:-/usr/local/bin}` if installed as root or
`${PREFIX:-$HOME/.local/bin}` otherwize) or local (under `${BPKG_DEPS:-./deps}`).

For example, here's a **global install for the current user** of the [term package][term]:

Expand Down Expand Up @@ -109,17 +109,16 @@ bpkg install jwerle/suggest.sh@0.0.1 -g

**Note:** to do that the packages **must be tagged releases** on the repository.

You can also *install packages without a `package.json`*.
You can also *install packages without a `bpkg.json` (or `package.json`)*.
As long as there is a `Makefile` in the repository it will try to invoke `make install` as long as the `-g` or `--global` flags are set when invoking `bpkg install`.

For example you could install [git-standup](https://github.com/stephenmathieson/git-standup) with an omitted `package.json` because of the `Makefile` and the `install` target found in it.
For example you could install [git-standup](https://github.com/stephenmathieson/git-standup) with an omitted `bpkg.json` (or `package.json`) because of the `Makefile` and the `install` target found in it.

```sh
bpkg install stephenmathieson/git-standup -g

info: Using latest (master)
warn: Package doesn't exist
warn: Missing build script
warn: bpkg.json doesn`t exist
warn: package.json doesn`t exist
warn: Trying `make install'...
info: install: `make install'
cp -f git-standup /usr/local/bin
Expand All @@ -131,6 +130,10 @@ You can install a packages dependencies with the `bpkg getdeps` command. These w

_Note: There is no protection against circular dependencies, so be careful!_

### Running packages with `bpkg`

You can run a package script with `bpkg run` which will install your
package globally and execute it as a command

### Retrieving package info

Expand All @@ -157,11 +160,12 @@ bpkg package

Here we lay down some info on the structure of a package.

## package.json
## bpkg.json

Every package must have a file called `package.json`; it specifies package metadata on the [JSON format][json].
Every package must have a file called `bpkg.json` (for backward-compatibility
`package.json` can also be used); it specifies package metadata on the [JSON format][json].

Here's an example of a well-formed `package.json`:
Here's an example of a well-formed `bpkg.json`:

```json
{
Expand Down Expand Up @@ -242,7 +246,6 @@ This is a hash of dependencies. The keys are the package names, and the values a
}
```


## Packaging best practices

These are guidelines that we strongly encourage developers to follow.
Expand All @@ -252,7 +255,7 @@ These are guidelines that we strongly encourage developers to follow.
It's nice to have a bash package that can be used in the terminal and also be invoked as a command line function. To achieve this the exporting of your functionality *should* follow this pattern:

```sh
if [[ ${BASH_SOURCE[0]} != $0 ]]; then
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
export -f my_script
else
my_script "${@}"
Expand All @@ -274,6 +277,8 @@ my_script some more args --blah

**bpkg** wouldn't be where it is today without the help of its authors, contributors, and sponsors:

* [@socketsupply](https://github.com/socketsupply) ([socketsupply.co](https://socketsupply.co))
* [@little-core-labs](https://github.com/little-core-labs)
* [@littlstar](https://github.com/littlstar) ([littlstar.com](https://littlstar.com))
* [@spotify](https://github.com/spotify) ([spotify.com](https://spotify.com))

Expand All @@ -295,15 +300,12 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
<a href="graphs/contributors"><img src="https://opencollective.com/bpkg/contributors.svg?width=890&button=false" /></a>


### Backers

Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/bpkg#backer)]

<a href="https://opencollective.com/bpkg#backers" target="_blank"><img src="https://opencollective.com/bpkg/backers.svg?width=890"></a>



## License

`bpkg` is released under the **MIT license**.
Expand Down
1 change: 1 addition & 0 deletions bpkg-run
1 change: 1 addition & 0 deletions bpkg-source
11 changes: 11 additions & 0 deletions bpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "bpkg",
"version": "1.0.0",
"description": "Lightweight bash package manager",
"global": true,
"repo": "bpkg/bpkg",
"install": "bash setup.sh",
"commands": {
"lint": "shellcheck $BPKG_SCRIPT_SOURCES"
}
}
18 changes: 11 additions & 7 deletions bpkg.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

## prevent sourcing
if [[ ${BASH_SOURCE[0]} != $0 ]]; then
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
echo >&2 "error: \`bpkg' cannot be sourced"
return 1
fi
Expand All @@ -24,7 +24,9 @@ usage () {
## commands
commands () {
{
declare -a local cmds=( $(
local cmds

declare -a cmds=( $(
bpkg-suggest 'bpkg-' |
tail -n+2 |
sed 's/.*\/bpkg-//g' |
Expand All @@ -38,11 +40,12 @@ commands () {

## feature tests
features () {
declare -a local features=(bpkg-json bpkg-suggest)
local features
declare -a features=(bpkg-json bpkg-suggest)
for ((i = 0; i < ${#features[@]}; ++i)); do
local f="${features[$i]}"
if ! type "${f}" > /dev/null 2>&1; then
error "Missing "${f}" dependency"
error "Missing \"${f}\" dependency"
return 1
fi
done
Expand Down Expand Up @@ -70,7 +73,7 @@ bpkg () {
echo "Here are some commands available in your path:"
echo
local cmds=($(commands))
for cmd in ${cmds[@]}; do
for cmd in "${cmds[@]}"; do
echo " ${cmd}"
done
return 0
Expand All @@ -88,9 +91,10 @@ bpkg () {
else
echo >&2 "error: \`${arg}' is not a bpkg command."
{
declare -a local res=($(commands))
local res
declare -a res=($(commands))

if [ ! -z "${res}" ]; then
if [ -n "${res[*]}" ]; then
echo
echo >&2 "Did you mean one of these?"
found=0
Expand Down
17 changes: 11 additions & 6 deletions lib/getdeps/getdeps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ usage () {
## Read a package property
bpkg_getdeps () {
local cwd="$(pwd)"
local pkg="${cwd}/package.json"
local pkg="${cwd}/bpkg.json"

## parse flags
case "$1" in
Expand All @@ -22,24 +22,29 @@ bpkg_getdeps () {

## ensure there is a package to read
if ! test -f "${pkg}"; then
echo 2>&1 "error: Unable to find \`package.json' in $(pwd)"
return 1
pkg="${cwd}/package.json"
if ! test -f "${pkg}"; then
echo 2>&1 "error: Unable to find \`bpkg.json' or \`package.json' in $cwd"
return 1
fi
fi

# shellcheck disable=SC2002
dependencies=$(cat "${pkg}" | bpkg-json -b | grep '\[\"dependencies' | sed "s/\[\"dependencies\",//" | sed "s/\"\]$(printf '\t')\"/@/" | tr -d '"')
dependencies=($(echo ${dependencies[@]}))
# shellcheck disable=SC2206
dependencies=(${dependencies[@]})

## run bpkg install for each dependency
for (( i = 0; i < ${#dependencies[@]} ; ++i )); do
(
local package=${dependencies[$i]}
bpkg install ${package}
bpkg install "${package}"
)
done
return 0
}

if [[ ${BASH_SOURCE[0]} != $0 ]]; then
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
export -f bpkg_getdeps
else
bpkg_getdeps "${@}"
Expand Down
16 changes: 8 additions & 8 deletions lib/init/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bpkg-init
=========

Interactively generate a `package.json` for your [bpkg][bp]. Code, format,
Interactively generate a `bpkg.json` for your [bpkg][bp]. Code, format,
and instructions based heavily on [jwerle's][jw] [clib-init][cb].

[bp]: https://github.com/bpkg/bpkg/
Expand Down Expand Up @@ -29,30 +29,30 @@ usage
-----

Simply invoke `bpkg init` and you wil be prompted with a series
of questions about the generation of your `package.json`. Most options
of questions about the generation of your `bpkg.json`. Most options
have sane defaults.

This will walk you through initializing the bpkg `package.json` file.
This will walk you through initializing the bpkg `bpkg.json` file.
It will prompt you for the bare minimum that is needed and provide
defaults.

See github.com/bpkg/bpkg for more information on defining the bpkg
`package.json` file.
`bpkg.json` file.

You can press `^C` anytime to quit this prompt. The `package.json` file
You can press `^C` anytime to quit this prompt. The `bpkg.json` file
will only be written upon completion.

```sh
$ bpkg init

This will walk you through initializing the bpkg `package.json` file.
This will walk you through initializing the bpkg `bpkg.json` file.
It will prompt you for the bare minimum that is needed and provide
defaults.

See github.com/bpkg/bpkg for more information on defining the bpkg
`package.json` file.
`bpkg.json` file.

You can press ^C anytime to quit this prompt. The `package.json` file
You can press ^C anytime to quit this prompt. The `bpkg.json` file
will only be written upon completion.

name: (bpkg-init)
Expand Down
4 changes: 2 additions & 2 deletions lib/init/package.json → lib/init/bpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bpkg-init",
"version": "0.0.1",
"description": "Initialize a bpkg package.json",
"version": "0.1.0",
"description": "Initialize a bpkg.json",
"global": "true",
"install": "make install",
"scripts": [
Expand Down
Loading