1 | # Athloi
|
2 |
|
3 | [![CircleCI](https://circleci.com/gh/Financial-Times/athloi/tree/master.svg?style=svg)](https://circleci.com/gh/Financial-Times/athloi/tree/master)
|
4 |
|
5 | Athloi is a tool to assist with the management of multi-package repositories (a.k.a. [monorepos]) with git and npm. It provides an interface to execute commands and scripts within the scope of each package.
|
6 |
|
7 | [monorepos]: https://github.com/babel/babel/blob/master/doc/design/monorepo.md
|
8 |
|
9 | ## Features
|
10 |
|
11 | - Provides a number of helpers to improve your monorepo workflow such as: installing all dependencies, running npm or custom scripts, publishing public packages, updating version numbers, etc.
|
12 | - Capable of running tasks serially or in parallel whilst preserving topological sort order between cross-dependent packages.
|
13 | - Options to filter the packages to target either by name or `package.json` field
|
14 | - Works well with Yarn workspaces.
|
15 |
|
16 | ## Getting Started
|
17 |
|
18 | Start by installing Athloi within your project using [npm].
|
19 |
|
20 | ```sh
|
21 | npm install --save-dev @financial-times/athloi
|
22 | ```
|
23 |
|
24 | [npm]: https://www.npmjs.com/
|
25 |
|
26 | Next you must configure where Athloi should look for the directories containing your packages. To do this you must add an extra `"workspaces"` property to your root `package.json` file if you do not have one already.
|
27 |
|
28 | This property is an array of [globs] matching your package directories. This designed to be compatible with [Yarn].
|
29 |
|
30 | ```json
|
31 | {
|
32 | "workspaces": ["components/*", "tools/*"]
|
33 | }
|
34 | ```
|
35 |
|
36 | [globs]: https://en.wikipedia.org/wiki/Glob_(programming)
|
37 | [lerna]: https://lernajs.io/
|
38 | [yarn]: https://yarnpkg.com/en/
|
39 |
|
40 | ## Commands
|
41 |
|
42 | _Please note:_ Before executing a command Athloi will sort the packages [topologically] based on their cross-dependencies and run tasks in this order.
|
43 |
|
44 | ### exec
|
45 |
|
46 | Runs an arbitrary command within the scope of each package.
|
47 |
|
48 | ```sh
|
49 | athloi exec npm install
|
50 | ```
|
51 |
|
52 | A double-dash (`--`) is necessary to pass any dashed arguments to the command being executed.
|
53 |
|
54 | ```sh
|
55 | athloi exec -- npm i -D lodash
|
56 | ```
|
57 |
|
58 | ### run
|
59 |
|
60 | Runs an [npm script] in each package that defines that script.
|
61 |
|
62 | ```sh
|
63 | athloi run build
|
64 | ```
|
65 |
|
66 | [npm script]: https://docs.npmjs.com/misc/scripts
|
67 |
|
68 | ### script
|
69 |
|
70 | Runs the given Node script in the scope of each package.
|
71 |
|
72 | ```sh
|
73 | athloi script path/to/task.js
|
74 | ```
|
75 |
|
76 | ### version
|
77 |
|
78 | Updates the release number for public packages and their cross-dependencies and writes the data back to `package.json`. The given tag must parseable as a valid semver number.
|
79 |
|
80 | ```sh
|
81 | athloi version v1.0.0
|
82 | ```
|
83 |
|
84 | Please note that when using the `version` command with the [filter option](#filter) any cross-dependent packages which have been excluded will fall back to their latest published version on npm.
|
85 |
|
86 | ### publish
|
87 |
|
88 | Runs [`npm publish`][npm-publish] in the scope of each public package.
|
89 |
|
90 | ```sh
|
91 | athloi publish
|
92 | ```
|
93 |
|
94 | Dashed arguments may be passed using a double dash (`--`)
|
95 |
|
96 | ```sh
|
97 | athloi publish -- --access=public
|
98 | ```
|
99 |
|
100 | [npm-publish]: https://docs.npmjs.com/cli/publish
|
101 |
|
102 | ## Options
|
103 |
|
104 | ### concurrency
|
105 |
|
106 | A global option which will execute up to the given number of tasks concurrently. By default one task will be run at a time.
|
107 |
|
108 | ```sh
|
109 | # run a lint script in up to 3 packages at a time
|
110 | athloi run lint --concurrency 3
|
111 | ```
|
112 |
|
113 | ### preserve-order
|
114 |
|
115 | A global flag which will ensure tasks maintain topological sort order. When used with a concurrency value higher than 1 this option will force queued tasks to wait for any still running tasks in cross-dependent packages to finish first.
|
116 |
|
117 | ```sh
|
118 | # run a concurrent build script but ensure dependencies are built first
|
119 | athloi run build --concurrency 5 --preserve-order
|
120 | ```
|
121 |
|
122 | ### filter
|
123 |
|
124 | A global option which can be used for all tasks. It filters packages based on the value of a field within their package manifest or the package name.
|
125 |
|
126 | ```sh
|
127 | # Run a build script in only the packages marked as private
|
128 | athloi run build --filter private:true
|
129 | ```
|
130 |
|
131 | The value of the field will be coerced using `JSON.parse()` so boolean and number values can be used and string values must use double-quotes.
|
132 |
|
133 | Property values inside arrays and objects can also be matched:
|
134 |
|
135 | ```sh
|
136 | # Run the script for packages with a keyword of "demo"
|
137 | athloi run build --filter 'keywords:"demo"'
|
138 |
|
139 | # Run the script for packages with a dependency on the "lodash" package
|
140 | athloi run build --filter 'dependencies:"lodash"'
|
141 | ```
|
142 |
|
143 | The field name preceeding the colon (`:`) is optional and if omitted Athloi will default to checking package names, ignoring the npm organisation name.
|
144 |
|
145 | ```sh
|
146 | # Run a build script for only the package named "@financial-times/x-interaction"
|
147 | athloi run build --filter x-interaction
|
148 | ```
|
149 |
|
150 | When filtering by package name you can also use a [glob pattern] to match them using wildcard characters:
|
151 |
|
152 | ```sh
|
153 | # Run a build script for all packages with names beginning "@financial-times/x-"
|
154 | athloi run build --filter 'x-*'
|
155 | ```
|
156 |
|
157 | [glob pattern]: https://en.wikipedia.org/wiki/Glob_(programming)
|
158 |
|
159 | ## What's with the name?
|
160 |
|
161 | One of the twelve labours of Hercules (hoi hērakleous athloi) was to slay the Lernean Hydra.
|
162 |
|
163 | ## licence
|
164 |
|
165 | isc
|