Skip to content

Commit 7315cb2

Browse files
committed
Add RC option
1 parent b14ee39 commit 7315cb2

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed

docs/cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The Nollup CLI is the preferred method of using Nollup. You're probably already
1313
The following flags can be passed into Nollup CLI. You can find a full description of each of these options [here](./options.md).
1414

1515
* ```-c | --config [file]```
16+
* ```--rc [file]```
1617
* ```--content-base [folder]```
1718
* ```--history-api-fallback [fallback]?```
1819
* ```--hot```

docs/dev-server.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The following options can be passed into Nollup Dev Server. You can find a full
2525
* ```Function before```
2626
* ```Function after```
2727
* ```Object|String config```
28+
* ```String rc```
2829
* ```Boolean hot```
2930
* ```Number port```
3031
* ```Boolean verbose```

docs/nolluprc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Configuration file that can be used to pass configuration instead of as flags th
99
}
1010
```
1111

12-
A JavaScript file called ```.nolluprc.js``` can be used instead.
12+
A JavaScript file called ```.nolluprc.js``` or specified file can be used instead.
1313

1414
```
1515
module.exports = {

docs/options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This list provides a description of all of the options for the [CLI](./cli.md),
55
| Type | Name | Description |
66
|------|------|-------------|
77
| ```String\|Object``` | ```config``` | Pass a Rollup configuration file. By default it will look for ```rollup.config.js``` but can be specified otherwise. If object is supported, can receive Rollup config object. |
8+
| ```String``` | ```rc``` | Pass a Nollup configuration file. By default it will look for one of ```.nolluprc```, ```.nolluprc.js```. |
89
| ```String``` | ```contentBase``` | Folder to serve static content from. Typically the content would contain additional resources like images. By default it will be looking in ```./```. |
910
| ```Boolean``` | ```hot``` | Enable Hot Module Replacement. Default is ```false```. |
1011
| ```Number``` | ```port``` | Port number to run server on. Default is ```8080```. |

lib/cli.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ let options = {
3737
hmrHost: undefined,
3838
https: false,
3939
host: 'localhost',
40-
liveBindings: false
40+
liveBindings: false,
41+
rc: undefined
4142
};
4243

4344
function getValue (index) {
@@ -61,6 +62,15 @@ for (let i = 0; i < process.argv.length; i++) {
6162
}
6263
break;
6364

65+
case '--rc':
66+
value = getValue(i);
67+
if (value) {
68+
options.rc = value;
69+
} else {
70+
throw new Error('Missing value for rc.');
71+
}
72+
break;
73+
6474
case '--environment':
6575
value = getValue(i);
6676
if (value) {

lib/dev-server.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,29 @@ let NollupDevMiddleware = require('./dev-middleware');
99
let ConfigLoader = require('./impl/ConfigLoader');
1010
let app = express();
1111

12+
async function loadRc (options, file) {
13+
let nollupRc;
14+
15+
if (file.endsWith('.js')) {
16+
nollupRc = await ConfigLoader.load(path.resolve(process.cwd(), file));
17+
} else {
18+
nollupRc = JSON.parse(fs.readFileSync(file, 'utf8'));
19+
}
20+
21+
return Object.assign({}, options, nollupRc);
22+
}
23+
1224
async function devServer(options) {
13-
if (fs.existsSync('.nolluprc')) {
14-
options = Object.assign({}, options, JSON.parse(fs.readFileSync('.nolluprc')));
25+
if (options.rc) {
26+
if (fs.existsSync(options.rc)) {
27+
options = await loadRc(options, options.rc);
28+
} else {
29+
throw new Error('File does not exist: ' + options.rc);
30+
}
31+
} else if (fs.existsSync('.nolluprc')) {
32+
options = await loadRc(options, '.nolluprc');
1533
} else if (fs.existsSync('.nolluprc.js')) {
16-
let nollupRc = await ConfigLoader.load(path.resolve(process.cwd(), '.nolluprc.js'));
17-
options = Object.assign({}, options, nollupRc);
34+
options = await loadRc(options, '.nolluprc.js');
1835
}
1936

2037
if (options.before) {

0 commit comments

Comments
 (0)