Skip to content

Commit 8c8b25d

Browse files
author
Florian Pichler
committed
v1.1.0
- Made indexPath accessible via options for more complex configuration - Cleaned up README - Added error messages for required params
1 parent 87cef43 commit 8c8b25d

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.1.0
4+
5+
- Made indexPath accessible via options for more complex configuration
6+
- Cleaned up README
7+
- Added error messages for required params
8+
39
## 1.0.0
410

511
- Initial release

README.md

+1-14
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,7 @@ app.on('ready', () => {
3535

3636
## API
3737

38-
### protocolServe(cwd, options)
39-
40-
```js
41-
/**
42-
* @param {String} cwd the path to the dist folder of your Ember app
43-
* @param {Object} options.app electron.app
44-
* @param {Object} options.protocol electron.protocol
45-
* @param {String} options.name name of your protocol, defaults to `serve`
46-
* @param {String} options.endpoint endpoint of your protocol, defaults to `dist`
47-
* @param {String} options.directoryIndexFile directory index. usally the default, `index.html`
48-
* @return {String} name of your protocol
49-
*/
50-
```
51-
38+
See `index.js`.
5239

5340

5441
## Credits

index.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
11
const { join } = require('path');
22
const fs = require('fs');
33

4+
function requiredParam(param, errorMessage) {
5+
if (!param) {
6+
throw new Error(`electron-protocol-serve: ${errorMessage}`);
7+
}
8+
}
9+
410
/**
511
* Registers a file protocol with a single endpoint which handles
612
* the proper discovery of local files inside of Electron
713
* without modifiying the Ember app.
814
*
9-
* @param {String} cwd the path to the dist folder of your Ember app
15+
* @param {String} options.cwd the path to the dist folder of your Ember app
1016
* @param {Object} options.app electron.app
1117
* @param {Object} options.protocol electron.protocol
1218
* @param {String} options.name name of your protocol, defaults to `serve`
1319
* @param {String} options.endpoint endpoint of your protocol, defaults to `dist`
1420
* @param {String} options.directoryIndexFile directory index. usally the default, `index.html`
21+
* @param {String} options.indexPath defaults to cwd + directoryIndexFile
22+
*
1523
* @return {String} name of your protocol
1624
*/
17-
module.exports = (cwd, {
25+
module.exports = function protocolServe({
26+
cwd = undefined,
1827
app,
1928
protocol,
2029
name = 'serve',
2130
endpoint = 'dist',
2231
directoryIndexFile = 'index.html',
23-
}) => {
24-
const indexPath = join(cwd, directoryIndexFile);
32+
indexPath = undefined,
33+
}) {
34+
requiredParam(cwd, 'cwd must be specified, should be a valid path');
35+
requiredParam(protocol, 'protocol must be specified, should be electron.protocol');
36+
requiredParam(app, 'app must be specified, should be electron.app');
37+
38+
indexPath = indexPath || join(cwd, directoryIndexFile);
39+
2540
const cache = {};
2641
const prefixLength = name.length + 3 + endpoint.length;
2742

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "electron-protocol-serve",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "A file protocol that serves any existing file in a directory and redirects everything not found to index.html.",
55
"main": "index.js",
66
"repository": "git@github.com:pichfl/electron-protocol-ember.git",

0 commit comments

Comments
 (0)