Skip to content

Commit

Permalink
Add RC option
Browse files Browse the repository at this point in the history
  • Loading branch information
PepsRyuu committed Mar 30, 2021
1 parent b14ee39 commit 7315cb2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The Nollup CLI is the preferred method of using Nollup. You're probably already
The following flags can be passed into Nollup CLI. You can find a full description of each of these options [here](./options.md).

* ```-c | --config [file]```
* ```--rc [file]```
* ```--content-base [folder]```
* ```--history-api-fallback [fallback]?```
* ```--hot```
Expand Down
1 change: 1 addition & 0 deletions docs/dev-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The following options can be passed into Nollup Dev Server. You can find a full
* ```Function before```
* ```Function after```
* ```Object|String config```
* ```String rc```
* ```Boolean hot```
* ```Number port```
* ```Boolean verbose```
Expand Down
2 changes: 1 addition & 1 deletion docs/nolluprc.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Configuration file that can be used to pass configuration instead of as flags th
}
```

A JavaScript file called ```.nolluprc.js``` can be used instead.
A JavaScript file called ```.nolluprc.js``` or specified file can be used instead.

```
module.exports = {
Expand Down
1 change: 1 addition & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This list provides a description of all of the options for the [CLI](./cli.md),
| Type | Name | Description |
|------|------|-------------|
| ```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. |
| ```String``` | ```rc``` | Pass a Nollup configuration file. By default it will look for one of ```.nolluprc```, ```.nolluprc.js```. |
| ```String``` | ```contentBase``` | Folder to serve static content from. Typically the content would contain additional resources like images. By default it will be looking in ```./```. |
| ```Boolean``` | ```hot``` | Enable Hot Module Replacement. Default is ```false```. |
| ```Number``` | ```port``` | Port number to run server on. Default is ```8080```. |
Expand Down
12 changes: 11 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ let options = {
hmrHost: undefined,
https: false,
host: 'localhost',
liveBindings: false
liveBindings: false,
rc: undefined
};

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

case '--rc':
value = getValue(i);
if (value) {
options.rc = value;
} else {
throw new Error('Missing value for rc.');
}
break;

case '--environment':
value = getValue(i);
if (value) {
Expand Down
25 changes: 21 additions & 4 deletions lib/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,29 @@ let NollupDevMiddleware = require('./dev-middleware');
let ConfigLoader = require('./impl/ConfigLoader');
let app = express();

async function loadRc (options, file) {
let nollupRc;

if (file.endsWith('.js')) {
nollupRc = await ConfigLoader.load(path.resolve(process.cwd(), file));
} else {
nollupRc = JSON.parse(fs.readFileSync(file, 'utf8'));
}

return Object.assign({}, options, nollupRc);
}

async function devServer(options) {
if (fs.existsSync('.nolluprc')) {
options = Object.assign({}, options, JSON.parse(fs.readFileSync('.nolluprc')));
if (options.rc) {
if (fs.existsSync(options.rc)) {
options = await loadRc(options, options.rc);
} else {
throw new Error('File does not exist: ' + options.rc);
}
} else if (fs.existsSync('.nolluprc')) {
options = await loadRc(options, '.nolluprc');
} else if (fs.existsSync('.nolluprc.js')) {
let nollupRc = await ConfigLoader.load(path.resolve(process.cwd(), '.nolluprc.js'));
options = Object.assign({}, options, nollupRc);
options = await loadRc(options, '.nolluprc.js');
}

if (options.before) {
Expand Down

0 comments on commit 7315cb2

Please sign in to comment.