Skip to content

Commit 40f16d9

Browse files
committed
Add utility to list all standalone package names
1 parent aaf306e commit 40f16d9

File tree

18 files changed

+1707
-0
lines changed

18 files changed

+1707
-0
lines changed
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
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+
# Standalone Package Names
22+
23+
> List stdlib standalone package names.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var ls = require( '@stdlib/_tools/pkgs/standalones' );
31+
```
32+
33+
#### ls( \[options,] clbk )
34+
35+
Asynchronously returns a list of stdlib standalone package names.
36+
37+
```javascript
38+
ls( onList );
39+
40+
function onList( error, names ) {
41+
if ( error ) {
42+
throw error;
43+
}
44+
console.log( names.join( '\n' ) );
45+
}
46+
```
47+
48+
The function accepts the following `options`:
49+
50+
- **dir**: directory from which to search for packages. May be either an absolute path or a path relative to the `stdlib/lib/node_modules/` directory (e.g., `./@stdlib/math`). Default: `/path/to/stdlib/lib/node_modules/`.
51+
- **pattern**: glob pattern used to find packages. Default: `'**/package.json'` (note: pattern **must** end with `package.json`).
52+
- **ignore**: list of glob patterns used to exclude matches.
53+
54+
To search from a descendant directory, set the `dir` option.
55+
56+
```javascript
57+
var opts = {
58+
'dir': './@stdlib/math/base'
59+
};
60+
61+
ls( opts, onList );
62+
63+
function onList( error, names ) {
64+
if ( error ) {
65+
throw error;
66+
}
67+
console.log( names.join( '\n' ) );
68+
}
69+
```
70+
71+
To provide an alternative include filter, set the `pattern` option.
72+
73+
```javascript
74+
var opts = {
75+
'pattern': '**/foo/**/package.json'
76+
};
77+
78+
ls( opts, onList );
79+
80+
function onList( error, names ) {
81+
if ( error ) {
82+
throw error;
83+
}
84+
console.log( names.join( '\n' ) );
85+
}
86+
```
87+
88+
To exclude matches, set the `ignore` option.
89+
90+
```javascript
91+
var opts = {
92+
'ignore': [
93+
'node_modules/**',
94+
'build/**',
95+
'reports/**',
96+
'foo/**'
97+
]
98+
};
99+
100+
ls( opts, onList );
101+
102+
function onList( error, names ) {
103+
if ( error ) {
104+
throw error;
105+
}
106+
console.log( names.join( '\n' ) );
107+
}
108+
```
109+
110+
#### ls.sync( \[options] )
111+
112+
Synchronously returns a list of stdlib standalone package names.
113+
114+
```javascript
115+
var names = ls.sync();
116+
// returns [...]
117+
```
118+
119+
The function accepts the same `options` as `ls()` above.
120+
121+
</section>
122+
123+
<!-- /.usage -->
124+
125+
<section class="notes">
126+
127+
## Notes
128+
129+
- Both functions **only** return standalone package names for packages under the `@stdlib` scope.
130+
- Both functions **always** ignore `examples/fixtures`, `test/fixtures`, and `benchmark/fixtures` directories, irrespective of whether an `ignore` option is provided.
131+
132+
</section>
133+
134+
<!-- /.notes -->
135+
136+
<section class="examples">
137+
138+
## Examples
139+
140+
<!-- eslint no-undef: "error" -->
141+
142+
```javascript
143+
var ls = require( '@stdlib/_tools/pkgs/standalones' );
144+
145+
ls( onList );
146+
147+
function onList( error, names ) {
148+
if ( error ) {
149+
throw error;
150+
}
151+
console.log( names.join( '\n' ) );
152+
}
153+
```
154+
155+
</section>
156+
157+
<!-- /.examples -->
158+
159+
* * *
160+
161+
<section class="cli">
162+
163+
## CLI
164+
165+
<section class="usage">
166+
167+
### Usage
168+
169+
```text
170+
Usage: stdlib-standalone-pkg-names [options] [<dir>]
171+
172+
Options:
173+
174+
-h, --help Print this message.
175+
-V, --version Print the package version.
176+
--pattern pattern Inclusion glob pattern.
177+
--ignore pattern Exclusion glob pattern.
178+
```
179+
180+
</section>
181+
182+
<!-- /.usage -->
183+
184+
<section class="notes">
185+
186+
### Notes
187+
188+
- If not provided a `dir` argument, the search directory is the current working directory.
189+
190+
- To provide multiple exclusion glob patterns, set multiple `--ignore` option arguments.
191+
192+
```bash
193+
$ stdlib-standalone-pkg-names --ignore=node_modules/** --ignore=build/** --ignore=reports/**
194+
```
195+
196+
</section>
197+
198+
<!-- /.notes -->
199+
200+
<section class="examples">
201+
202+
### Examples
203+
204+
```bash
205+
$ stdlib-standalone-pkg-names
206+
<package_name>
207+
<package_name>
208+
...
209+
```
210+
211+
</section>
212+
213+
<!-- /.examples -->
214+
215+
</section>
216+
217+
<!-- /.cli -->
218+
219+
<section class="links">
220+
221+
</section>
222+
223+
<!-- /.links -->
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* @license Apache-2.0
5+
*
6+
* Copyright (c) 2021 The Stdlib Authors.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var resolve = require( 'path' ).resolve;
26+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
27+
var CLI = require( '@stdlib/cli/ctor' );
28+
var ls = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
/**
34+
* Main execution sequence.
35+
*
36+
* @private
37+
*/
38+
function main() {
39+
var flags;
40+
var args;
41+
var opts;
42+
var cli;
43+
44+
// Create a command-line interface:
45+
cli = new CLI({
46+
'pkg': require( './../package.json' ),
47+
'options': require( './../etc/cli_opts.json' ),
48+
'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
49+
'encoding': 'utf8'
50+
})
51+
});
52+
53+
// Get any provided command-line options:
54+
flags = cli.flags();
55+
if ( flags.help || flags.version ) {
56+
return;
57+
}
58+
59+
// Get any provided command-line arguments:
60+
args = cli.args();
61+
62+
// Extract options...
63+
opts = {};
64+
if ( flags.pattern ) {
65+
opts.pattern = flags.pattern;
66+
}
67+
if ( flags.ignore ) {
68+
if ( typeof flags.ignore === 'string' ) {
69+
opts.ignore = [ flags.ignore ];
70+
} else {
71+
opts.ignore = flags.ignore;
72+
}
73+
}
74+
if ( args[ 0 ] ) {
75+
opts.dir = args[ 0 ];
76+
}
77+
// Find package names:
78+
ls( opts, onList );
79+
80+
/**
81+
* Callback invoked after retrieving a list of standalone package names.
82+
*
83+
* @private
84+
* @param {(Error|null)} error - error object
85+
* @param {(StringArray|EmptyArray)} names - list of standalone package names
86+
* @returns {void}
87+
*/
88+
function onList( error, names ) {
89+
if ( error ) {
90+
return cli.error( error );
91+
}
92+
if ( names.length ) {
93+
console.log( names.join( '\n' ) ); // eslint-disable-line no-console
94+
}
95+
}
96+
}
97+
98+
main();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Usage: stdlib-standalone-pkg-names [options] [<dir>]
3+
4+
Options:
5+
6+
-h, --help Print this message.
7+
-V, --version Print the package version.
8+
--pattern pattern Inclusion glob pattern.
9+
--ignore pattern Exclusion glob pattern.
10+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"string": [
3+
"pattern",
4+
"ignore"
5+
],
6+
"boolean": [
7+
"help",
8+
"version"
9+
],
10+
"alias": {
11+
"help": [
12+
"h"
13+
],
14+
"version": [
15+
"V"
16+
]
17+
}
18+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var ls = require( './../lib' );
22+
23+
ls( onList );
24+
25+
function onList( error, names ) {
26+
if ( error ) {
27+
throw error;
28+
}
29+
console.log( names.join( '\n' ) );
30+
}

0 commit comments

Comments
 (0)