electron-protocol-serve
Advanced tools
Comparing version 1.0.0 to 1.1.0
# Changelog | ||
## 1.1.0 | ||
- Made indexPath accessible via options for more complex configuration | ||
- Cleaned up README | ||
- Added error messages for required params | ||
## 1.0.0 | ||
- Initial release |
23
index.js
const { join } = require('path'); | ||
const fs = require('fs'); | ||
function requiredParam(param, errorMessage) { | ||
if (!param) { | ||
throw new Error(`electron-protocol-serve: ${errorMessage}`); | ||
} | ||
} | ||
/** | ||
@@ -9,3 +15,3 @@ * Registers a file protocol with a single endpoint which handles | ||
* | ||
* @param {String} cwd the path to the dist folder of your Ember app | ||
* @param {String} options.cwd the path to the dist folder of your Ember app | ||
* @param {Object} options.app electron.app | ||
@@ -16,5 +22,8 @@ * @param {Object} options.protocol electron.protocol | ||
* @param {String} options.directoryIndexFile directory index. usally the default, `index.html` | ||
* @param {String} options.indexPath defaults to cwd + directoryIndexFile | ||
* | ||
* @return {String} name of your protocol | ||
*/ | ||
module.exports = (cwd, { | ||
module.exports = function protocolServe({ | ||
cwd = undefined, | ||
app, | ||
@@ -25,4 +34,10 @@ protocol, | ||
directoryIndexFile = 'index.html', | ||
}) => { | ||
const indexPath = join(cwd, directoryIndexFile); | ||
indexPath = undefined, | ||
}) { | ||
requiredParam(cwd, 'cwd must be specified, should be a valid path'); | ||
requiredParam(protocol, 'protocol must be specified, should be electron.protocol'); | ||
requiredParam(app, 'app must be specified, should be electron.app'); | ||
indexPath = indexPath || join(cwd, directoryIndexFile); | ||
const cache = {}; | ||
@@ -29,0 +44,0 @@ const prefixLength = name.length + 3 + endpoint.length; |
{ | ||
"name": "electron-protocol-serve", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A file protocol that serves any existing file in a directory and redirects everything not found to index.html.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -38,18 +38,5 @@ # electron-protocol-serve | ||
### protocolServe(cwd, options) | ||
See `index.js`. | ||
```js | ||
/** | ||
* @param {String} cwd the path to the dist folder of your Ember app | ||
* @param {Object} options.app electron.app | ||
* @param {Object} options.protocol electron.protocol | ||
* @param {String} options.name name of your protocol, defaults to `serve` | ||
* @param {String} options.endpoint endpoint of your protocol, defaults to `dist` | ||
* @param {String} options.directoryIndexFile directory index. usally the default, `index.html` | ||
* @return {String} name of your protocol | ||
*/ | ||
``` | ||
## Credits | ||
@@ -56,0 +43,0 @@ |
8332
173
45