|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2021 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# Find Namespace READMEs |
| 22 | + |
| 23 | +> Find stdlib namespace package READMEs. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var findREADMEs = require( '@stdlib/_tools/pkgs/namespace-readmes' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### findREADMEs( \[options,] clbk ) |
| 34 | + |
| 35 | +Asynchronously search for namespace package READMEs. |
| 36 | + |
| 37 | +<!-- run-disable --> |
| 38 | + |
| 39 | +```javascript |
| 40 | +findREADMEs( onFiles ); |
| 41 | + |
| 42 | +function onFiles( error, files ) { |
| 43 | + if ( error ) { |
| 44 | + throw error; |
| 45 | + } |
| 46 | + console.log( files.join( '\n' ) ); |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +The function accepts the following `options`: |
| 51 | + |
| 52 | +- **dir**: root directory from which to search for namespace package READMEs. May be either an absolute path or a path relative to the `stdlib/lib/node_modules/` directory. Default: `/path/to/stdlib/lib/node_modules/`. |
| 53 | +- **pattern**: glob pattern used to find namespace packages. Default: `'**/package.json'` (note: pattern **must** end with `package.json`). |
| 54 | +- **ignore**: list of glob patterns used to exclude matches. |
| 55 | + |
| 56 | +To search from a descendant directory, set the `dir` option. |
| 57 | + |
| 58 | +```javascript |
| 59 | +var opts = { |
| 60 | + 'dir': './@stdlib/math/base' |
| 61 | +}; |
| 62 | + |
| 63 | +findREADMEs( opts, onFiles ); |
| 64 | + |
| 65 | +function onFiles( error, files ) { |
| 66 | + if ( error ) { |
| 67 | + throw error; |
| 68 | + } |
| 69 | + console.log( files.join( '\n' ) ); |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +To provide an alternative include filter, set the `pattern` option. |
| 74 | + |
| 75 | +```javascript |
| 76 | +var opts = { |
| 77 | + 'pattern': '**/foo/**/package.json' |
| 78 | +}; |
| 79 | + |
| 80 | +findREADMEs( opts, onFiles ); |
| 81 | + |
| 82 | +function onFiles( error, files ) { |
| 83 | + if ( error ) { |
| 84 | + throw error; |
| 85 | + } |
| 86 | + console.log( files.join( '\n' ) ); |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +To exclude matches, set the `ignore` option. |
| 91 | + |
| 92 | +<!-- run-disable --> |
| 93 | + |
| 94 | +```javascript |
| 95 | +var opts = { |
| 96 | + 'ignore': [ |
| 97 | + 'node_modules/**', |
| 98 | + 'build/**', |
| 99 | + 'reports/**' |
| 100 | + ] |
| 101 | +}; |
| 102 | + |
| 103 | +findREADMEs( opts, onFiles ); |
| 104 | + |
| 105 | +function onFiles( error, files ) { |
| 106 | + if ( error ) { |
| 107 | + throw error; |
| 108 | + } |
| 109 | + console.log( files.join( '\n' ) ); |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +#### findREADMEs.sync( \[options] ) |
| 114 | + |
| 115 | +Synchronously searches for namespace package READMEs. |
| 116 | + |
| 117 | +<!-- run-disable --> |
| 118 | + |
| 119 | +```javascript |
| 120 | +var files = findREADMEs.sync(); |
| 121 | +// returns [...] |
| 122 | +``` |
| 123 | + |
| 124 | +The function accepts the same `options` as `findREADMEs()` above. |
| 125 | + |
| 126 | +</section> |
| 127 | + |
| 128 | +<!-- /.usage --> |
| 129 | + |
| 130 | +<section class="notes"> |
| 131 | + |
| 132 | +## Notes |
| 133 | + |
| 134 | +- The implementation resolves namespace package READMEs by checking for a `README.md` file in the directory containing a namespace package's `package.json` file. |
| 135 | +- Both functions **only** return package READMEs under the `@stdlib` scope. |
| 136 | +- Both functions **always** ignore `examples/fixtures`, `test/fixtures`, and `benchmark/fixtures` directories, irrespective of whether an `ignore` option is provided. |
| 137 | +- Be **careful** when using the `pattern` option. Both functions first resolve a list of packages matching the search criteria and then prune the list to resolve "namespaces" relative to the resolved list. For example, if the `pattern` option results in resolving only a single package, both functions will always fail to resolve a namespace, regardless as to whether the package actually is a namespace. Only when both functions resolve leaf packages will the functions resolve namespaces. |
| 138 | + |
| 139 | +</section> |
| 140 | + |
| 141 | +<!-- /.notes --> |
| 142 | + |
| 143 | +<section class="examples"> |
| 144 | + |
| 145 | +## Examples |
| 146 | + |
| 147 | +<!-- run-disable --> |
| 148 | + |
| 149 | +<!-- eslint no-undef: "error" --> |
| 150 | + |
| 151 | +```javascript |
| 152 | +var findREADMEs = require( '@stdlib/_tools/pkgs/namespace-readmes' ); |
| 153 | + |
| 154 | +findREADMEs( onFiles ); |
| 155 | + |
| 156 | +function onFiles( error, files ) { |
| 157 | + if ( error ) { |
| 158 | + throw error; |
| 159 | + } |
| 160 | + console.log( files.join( '\n' ) ); |
| 161 | +} |
| 162 | +``` |
| 163 | + |
| 164 | +</section> |
| 165 | + |
| 166 | +<!-- /.examples --> |
| 167 | + |
| 168 | +* * * |
| 169 | + |
| 170 | +<section class="cli"> |
| 171 | + |
| 172 | +## CLI |
| 173 | + |
| 174 | +<section class="usage"> |
| 175 | + |
| 176 | +### Usage |
| 177 | + |
| 178 | +```text |
| 179 | +Usage: stdlib-namespace-readmes [options] [<dir>] |
| 180 | +
|
| 181 | +Options: |
| 182 | +
|
| 183 | + -h, --help Print this message. |
| 184 | + -V, --version Print the package version. |
| 185 | + --pattern pattern Inclusion glob pattern. |
| 186 | + --ignore pattern Exclusion glob pattern. |
| 187 | +``` |
| 188 | + |
| 189 | +</section> |
| 190 | + |
| 191 | +<!-- /.usage --> |
| 192 | + |
| 193 | +<section class="notes"> |
| 194 | + |
| 195 | +### Notes |
| 196 | + |
| 197 | +- If not provided a `dir` argument, the search directory is the top-level `stdlib` package directory. |
| 198 | + |
| 199 | +- To provide multiple exclusion glob patterns, set multiple `--ignore` option arguments. |
| 200 | + |
| 201 | + <!-- run-disable --> |
| 202 | + |
| 203 | + ```bash |
| 204 | + $ stdlib-namespace-readmes --ignore=node_modules/** --ignore=build/** --ignore=reports/** |
| 205 | + ``` |
| 206 | + |
| 207 | +</section> |
| 208 | + |
| 209 | +<!-- /.notes --> |
| 210 | + |
| 211 | +<section class="examples"> |
| 212 | + |
| 213 | +### Examples |
| 214 | + |
| 215 | +<!-- run-disable --> |
| 216 | + |
| 217 | +```bash |
| 218 | +$ stdlib-namespace-readmes |
| 219 | +<filepath> |
| 220 | +<filepath> |
| 221 | +... |
| 222 | +``` |
| 223 | + |
| 224 | +</section> |
| 225 | + |
| 226 | +<!-- /.examples --> |
| 227 | + |
| 228 | +</section> |
| 229 | + |
| 230 | +<!-- /.cli --> |
| 231 | + |
| 232 | +<section class="links"> |
| 233 | + |
| 234 | +</section> |
| 235 | + |
| 236 | +<!-- /.links --> |
0 commit comments