-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFC: User Config file integration (#53)
* fix: adding config file read and integrate with context/webpack, adding additional tests * fix: updating webpack.develop.js * fix: remove dev output * docs: updating readme Signed-off-by: HutchGrant <[email protected]> * fix: removing additional output * fix: indentation 2 spaces * fix: .json to .js config files * docs: chaning .json to .js readme * test: moving greenwood config into mock-app * fix: webpack config merge * fix: config source paths in context * docs: root directory to workspace directory * docs: add current working directory note * fix: adding config validation, changing source to workspace * docs: updating readme for config workspace var * test: update test for workspace instead of source * fix: adding additional check for if workspace exists * docs: updating readme to note http:// default * fix: refactor config validation, some leftover merge cleanup * fix: tiny config refactor * fix: check the devServer exists before checking keys
- Loading branch information
1 parent
afcd21e
commit d39adf5
Showing
16 changed files
with
221 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const url = require('url'); | ||
|
||
let config = { | ||
workspace: path.join(process.cwd(), 'src'), | ||
devServer: { | ||
port: 1984, | ||
host: 'http://localhost' | ||
}, | ||
publicPath: '/', | ||
// TODO add global meta data see issue #5 | ||
// https://github.com/ProjectEvergreen/greenwood/issues/5 | ||
meta: { | ||
title: '', | ||
description: '', | ||
author: '', | ||
domain: '' | ||
} | ||
}; | ||
|
||
module.exports = readAndMergeConfig = async() => { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
if (fs.existsSync(path.join(process.cwd(), 'greenwood.config.js'))) { | ||
const userCfgFile = require(path.join(process.cwd(), 'greenwood.config.js')); | ||
|
||
// prepend userCfgFile devServer.host with http by default | ||
userCfgFile.devServer.host = 'http://' + userCfgFile.devServer.host; | ||
|
||
const { workspace, devServer, publicPath } = userCfgFile; | ||
|
||
if (workspace) { | ||
if (typeof workspace !== 'string') { | ||
reject('Error: greenwood.config.js workspace path must be a string'); | ||
} | ||
|
||
if (!path.isAbsolute(workspace)) { | ||
// prepend relative path with current directory | ||
userCfgFile.workspace = path.join(process.cwd(), workspace); | ||
} | ||
|
||
if (!fs.existsSync(workspace)) { | ||
reject('Error: greenwood.config.js workspace doesn\'t exist! \n' + | ||
'common issues to check might be: \n' + | ||
'- typo in your workspace directory name, or in greenwood.config.js \n' + | ||
'- if using relative paths, make sure your workspace is in the same cwd as _greenwood.config.js_ \n' + | ||
'- consider using an absolute path, e.g. path.join(__dirname, \'my\', \'custom\', \'path\') // <__dirname>/my/custom/path/ '); | ||
} | ||
} | ||
|
||
if (publicPath && typeof publicPath !== 'string') { | ||
reject('Error: greenwood.config.js publicPath must be a string'); | ||
} | ||
|
||
if (devServer && Object.keys(devServer).length > 0) { | ||
|
||
if (url.parse(devServer.host).hostname === null) { | ||
reject('Error: greenwood.config.js devServer host type must be a valid url'); | ||
} | ||
|
||
if (!Number.isInteger(devServer.port)) { | ||
reject('Error: greenwood.config.js devServer port must be an integer'); | ||
} | ||
} | ||
|
||
config = { ...config, ...userCfgFile }; | ||
} | ||
resolve(config); | ||
|
||
} catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
--- | ||
label: 'hello' | ||
template: 'page' | ||
--- | ||
### Hello World | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
--- | ||
label: 'index' | ||
template: 'page' | ||
--- | ||
### Greenwood | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.