Skip to content

Commit e89b2f4

Browse files
committed
fix(website): commonjs imports
1 parent 20d6171 commit e89b2f4

File tree

18 files changed

+840
-522
lines changed

18 files changed

+840
-522
lines changed

docs/content/api/compile.md

Lines changed: 82 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
title: API method `compile`
33
navtitle: shell.compile
44
description: How to use the `compile` method to convert an object to an arguments array.
5-
keywords: ["shell", "node.js", "cli", "api", "compile", "arguments", "argv", "array"]
5+
keywords:
6+
["shell", "node.js", "cli", "api", "compile", "arguments", "argv", "array"]
67
maturity: review
78
---
89

910
# Method `shell.compile(command, [options])`
1011

1112
Convert data to an arguments array.
1213

13-
* `data` (object, optional)
14+
- `data` (object, optional)
1415
The data to be converted into an array of arguments.
15-
* `options` (object)
16+
- `options` (object)
1617
Options used to alter the behavior of the `compile` method.
17-
* `extended` (boolean, optional, `false`)
18-
The value `true` indicates that the parameters are provided in extended format, default to the configuration `extended` value which is `false` by default.
19-
* `script` (string, optional, `false`)
20-
The JavaScript file being executed by the Node.js engine. When provided, the Node.js engine and the script names will prepend the returned arguments.
21-
* Returns: (array)
18+
- `extended` (boolean, optional, `false`)
19+
The value `true` indicates that the parameters are provided in extended format, default to the configuration `extended` value which is `false` by default.
20+
- `script` (string, optional, `false`)
21+
The JavaScript file being executed by the Node.js engine. When provided, the Node.js engine and the script names will prepend the returned arguments.
22+
- Returns: (array)
2223
The command line arguments.
2324

2425
## Description
@@ -32,69 +33,97 @@ It supports both the default flatten mode and the extended mode. The `extended`
3233
Considering a "server" application containing a "start" command and initialised with the following configuration:
3334

3435
```js
35-
require("should")
36-
const shell = require("shell")
37-
const app = shell(
38-
{ name: "server",
36+
require("should");
37+
const { shell } = require("shell");
38+
const app = shell({
39+
name: "server",
3940
description: "Manage a web server",
40-
options:
41-
{ "config":
42-
{ shortcut: "c" } },
43-
commands:
44-
{ "start":
45-
{ description: "Start a web server",
46-
options:
47-
{ "host":
48-
{ shortcut: "h",
49-
description: "Web server listen host"},
50-
"port":
51-
{ shortcut: "p", type: "integer",
52-
description: "Web server listen port" } } } } })
41+
options: { config: { shortcut: "c" } },
42+
commands: {
43+
start: {
44+
description: "Start a web server",
45+
options: {
46+
host: { shortcut: "h", description: "Web server listen host" },
47+
port: {
48+
shortcut: "p",
49+
type: "integer",
50+
description: "Web server listen port",
51+
},
52+
},
53+
},
54+
},
55+
});
5356
```
5457

5558
Called with only the `config` option, the `compile` method convert an object literal into a shell command:
5659

57-
```javascript
58-
app.compile({
59-
config: "app.yaml"
60-
})
61-
.should.eql( [ "--config", "app.yaml" ] )
60+
```js
61+
app
62+
.compile({
63+
config: "app.yaml",
64+
})
65+
.should.eql(["--config", "app.yaml"]);
6266
```
6367

6468
In extended mode, the data input will be an array instead of an object:
6569

6670
```js
67-
app.compile([{
68-
config: "app.yaml"
69-
}], {
70-
extended: true
71-
})
72-
.should.eql( [ "--config", "app.yaml" ] )
71+
app
72+
.compile(
73+
[
74+
{
75+
config: "app.yaml",
76+
},
77+
],
78+
{
79+
extended: true,
80+
},
81+
)
82+
.should.eql(["--config", "app.yaml"]);
7383
```
7484

7585
Working with commands is quite similar:
7686

7787
```js
78-
app.compile({
79-
config: "app.yml",
80-
command: ["start"],
81-
host: "127.0.0.1",
82-
port: 80
83-
}).should.eql(
84-
["--config", "app.yml", "start", "--host", "127.0.0.1", "--port", "80"]
85-
);
88+
app
89+
.compile({
90+
config: "app.yml",
91+
command: ["start"],
92+
host: "127.0.0.1",
93+
port: 80,
94+
})
95+
.should.eql([
96+
"--config",
97+
"app.yml",
98+
"start",
99+
"--host",
100+
"127.0.0.1",
101+
"--port",
102+
"80",
103+
]);
86104
```
87105

88106
In extended mode, the data input will be an array with 2 elements instead of an object:
89107

90108
```js
91-
app.compile([{
92-
config: "app.yml"
93-
},{
94-
command: "start",
95-
host: "127.0.0.1",
96-
port: 80
97-
}]).should.eql(
98-
["--config", "app.yml", "start", "--host", "127.0.0.1", "--port", "80"]
99-
);
109+
app
110+
.compile([
111+
{
112+
config: "app.yml",
113+
},
114+
{
115+
command: "start",
116+
host: "127.0.0.1",
117+
port: 80,
118+
},
119+
])
120+
.should.eql([
121+
"--config",
122+
"app.yml",
123+
"start",
124+
"--host",
125+
"127.0.0.1",
126+
"--port",
127+
"80",
128+
]);
100129
```

docs/content/api/help.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
title: API method `help`
33
navtitle: shell.help
44
description: How to use the `help` method to print help to the user console.
5-
keywords: ['shell', 'node.js', 'cli', 'api', 'help', 'print']
5+
keywords: ["shell", "node.js", "cli", "api", "help", "print"]
66
maturity: review
77
---
88

99
# Method `shell.help(commands, options)`
1010

1111
Format the configuration into a readable documentation string.
1212

13-
* `commands` ([string] | string)
13+
- `commands` ([string] | string)
1414
The string or array containing the command name if any, optional.
15-
* `options.extended` (boolean)
15+
- `options.extended` (boolean)
1616
Print the child command descriptions, default is `false`.
17-
* `options.indent` (string)
17+
- `options.indent` (string)
1818
Indentation used with output help, default to 2 spaces.
1919

2020
All options are optional.
@@ -36,15 +36,15 @@ Considering a "server" application containing a "start" command and initialized
3636
To print the help of the overall application does not require any arguments. It behaves the same as calling the `help` method with an empty array.
3737

3838
```js
39-
process.stdout.write( app.help() )
40-
process.stdout.write( app.help( [] ) )
39+
process.stdout.write(app.help());
40+
process.stdout.write(app.help([]));
4141
```
4242

4343
Pass the name of the command as an array to print the help of any nested command. It behaves the same as defining the command as a string.
4444

4545
```js
46-
process.stdout.write( app.help( ['start'] ) );
47-
process.stdout.write( app.help( 'start' ) );
46+
process.stdout.write(app.help(["start"]));
47+
process.stdout.write(app.help("start"));
4848
```
4949

5050
## Implementation

docs/content/api/helping.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
title: API method `helping`
33
navtitle: shell.helping
44
description: How to use the `helping` method to determine if help was requested.
5-
keywords: ['shell', 'node.js', 'cli', 'api', 'helping', 'help', 'print']
5+
keywords: ["shell", "node.js", "cli", "api", "helping", "help", "print"]
66
maturity: review
77
---
88

99
# Method `shell.helping(params)`
1010

1111
Determine if help was requested by returning zero to n commands if help is requested or null otherwise.
1212

13-
* `params` ([object] | object)
13+
- `params` ([object] | object)
1414
The parameter object parsed from arguments, an object in flatten mode or an array in extended mode, optional.
1515

1616
## Description
@@ -22,25 +22,30 @@ This method is commonly used conjointly with the `help` method. It provides an i
2222
The workflow is to `parse` the arguments to get the extracted data, to create a condition to get the command associated with help and to print the help by passing the returned command:
2323

2424
```js
25-
const shell = require('shell')
25+
const { shell } = require("shell");
2626
const app = shell({
27-
name: 'server',
28-
description: 'Manage a web server',
27+
name: "server",
28+
description: "Manage a web server",
2929
commands: {
30-
'start': {
31-
description: 'Start a web server',
30+
start: {
31+
description: "Start a web server",
3232
options: {
33-
'host': {shortcut: 'h', description: 'Web server listen host'},
34-
'port': {shortcut: 'p', type: 'integer', description: 'Web server listen port'}
35-
}
36-
}
37-
}
33+
host: { shortcut: "h", description: "Web server listen host" },
34+
port: {
35+
shortcut: "p",
36+
type: "integer",
37+
description: "Web server listen port",
38+
},
39+
},
40+
},
41+
},
3842
});
39-
const params = app.parse()
40-
if(let command = app.helping(params)){
41-
const help = app.help(command)
42-
process.stdout.write(help)
43-
process.exit()
43+
const params = app.parse();
44+
const command = app.helping(params);
45+
if (command) {
46+
const help = app.help(command);
47+
process.stdout.write(help);
48+
process.exit();
4449
}
4550
```
4651

docs/content/api/index.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
---
22
title: API
33
description: API methods supported.
4-
keywords: ['shell', 'node.js', 'cli', 'api', 'help', 'parse', 'load', 'route', 'compile']
4+
keywords:
5+
[
6+
"shell",
7+
"node.js",
8+
"cli",
9+
"api",
10+
"help",
11+
"parse",
12+
"load",
13+
"route",
14+
"compile",
15+
]
516
maturity: review
617
sort: 3
718
---
819

9-
# API
20+
# API
1021

1122
Shell.js is written as an ESM package. It is also available as a CommonJS package. To import the package, uses:
1223

1324
```js
1425
// ESM package
15-
import { shell } from 'shell';
26+
import { shell } from "shell";
1627
// CommonJS package
17-
const shell = require('shell');
28+
const { shell } = require("shell");
1829
```
1930

2031
A Shell.js application is initilized with a [configuration](/config/) object:
@@ -26,17 +37,17 @@ const app = shell(config);
2637

2738
It exposes the following functions:
2839

29-
* [`shell.compile`](./compile/) (command, [options])
40+
- [`shell.compile`](./compile/) (command, [options])
3041
Convert data to an arguments array.
31-
* [`shell.help`](./help/) (command)
42+
- [`shell.help`](./help/) (command)
3243
Format the configuration into a readable documentation string.
33-
* [`shell.helping`](./helping/) (command)
44+
- [`shell.helping`](./helping/) (command)
3445
Determine if help was requested by returning zero to n commands if help is requested or null otherwise.
35-
* [`shell.load`](./load/) (module[string])
46+
- [`shell.load`](./load/) (module[string])
3647
Internal function used to load modules, see the [`load`](/config/load/) option to pass a function or a module referencing the function.
37-
* [`shell.parse`](./parse/) ([arguments])
48+
- [`shell.parse`](./parse/) ([arguments])
3849
Convert an arguments list to a data object.
39-
* [`shell.route`](./route/) (argv[array|process], args[mixed]...)
50+
- [`shell.route`](./route/) (argv[array|process], args[mixed]...)
4051
Similar to parse but it will also call the function defined by the "route"
4152
option. The first argument is the arguments array to parse, other arguments
4253
are simply transmitted to the `route` method or module as additional arguments.

docs/content/api/load.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: API method `load`
33
navtitle: shell.load
44
description: How to use the `load` method to load modules.
5-
keywords: ['shell', 'node.js', 'cli', 'api', 'load', module]
5+
keywords: ["shell", "node.js", "cli", "api", "load", module]
66
maturity: initial
77
---
88

0 commit comments

Comments
 (0)