Skip to content

Commit 2d595cb

Browse files
Pothercajwerle
authored andcommitted
Adds guidelines from the bpkg/bpkg repository. (#34)
1 parent 70acfad commit 2d595cb

File tree

1 file changed

+117
-1
lines changed

1 file changed

+117
-1
lines changed

guidelines/index.md

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,121 @@ header : Post Archive
55
group : navigation
66
---
77

8-
Oh yeah.
8+
## Package details
99

10+
Here we lay down some info on the structure of a package.
11+
12+
## package.json
13+
14+
Every package must have a file called `package.json`; it specifies package metadata on the [JSON format][json].
15+
16+
Here's an example of a well-formed `package.json`:
17+
18+
```json
19+
{
20+
"name": "term",
21+
"version": "0.0.1",
22+
"description": "Terminal utility functions",
23+
"scripts": [ "term.sh" ],
24+
"install": "make install"
25+
}
26+
```
27+
28+
All fields are mandatory except when noted.
29+
Here's a detailed explanation on all fields:
30+
31+
### name
32+
33+
The `name` attribute is required as it is used to tell `bpkg` where to put it in the `deps/` directory in you project.
34+
35+
```json
36+
"name": "my-script"
37+
```
38+
39+
### version (optional)
40+
41+
The `version` attribute is not required but can be useful. It should correspond to the version that is associated with the installed package.
42+
43+
```json
44+
"version": "0.0.1"
45+
```
46+
47+
### description
48+
49+
A human readable description of what the package offers for functionality.
50+
51+
```json
52+
"description": "This script makes monkeys jump out of your keyboard"
53+
```
54+
55+
### global
56+
57+
Indicates that the package is only intended to be install as a script. This allows the omission of the `-g` or `--global` flag during installation.
58+
59+
```json
60+
"global": "true"
61+
```
62+
63+
### install
64+
65+
Shell script used to invoke in the install script. This is required if the `global` attribute is set to `true` or if the `-g` or `--global` flags are provided.
66+
67+
```json
68+
"install": "make install"
69+
```
70+
71+
### scripts
72+
73+
This is an array of scripts that will be installed into a project.
74+
75+
```json
76+
"scripts": ["script.sh"]
77+
```
78+
79+
### files
80+
81+
This is an array of files that will be installed into a project.
82+
83+
```json
84+
"files": ["bar.txt", "foo.txt"]
85+
```
86+
87+
### dependencies (optional)
88+
89+
This is a hash of dependencies. The keys are the package names, and the values are the version specifiers. If you want the latest code use `'master'` in the version specifier. Otherwise, use a tagged release identifier. This works the same as `bpkg install`'s package/version specifiers.
90+
91+
```json
92+
"dependencies": {
93+
"term": "0.0.1"
94+
}
95+
```
96+
97+
98+
## Packaging best practices
99+
100+
These are guidelines that we strongly encourage developers to follow.
101+
102+
### Package exports
103+
104+
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:
105+
106+
```sh
107+
if [[ ${BASH_SOURCE[0]} != $0 ]]; then
108+
export -f my_script
109+
else
110+
my_script "${@}"
111+
exit $?
112+
fi
113+
```
114+
115+
This allows a user to `source` your script or invoke as a script.
116+
117+
```sh
118+
# Running as a script
119+
$ ./my_script.sh some args --blah
120+
# Sourcing the script
121+
$ source my_script.sh
122+
$ my_script some more args --blah
123+
```
124+
125+
[json]: http://json.org/example

0 commit comments

Comments
 (0)