-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated config to uploaders. Also slight uploaders tests refactoring. Resolves #6
- Loading branch information
Showing
22 changed files
with
977 additions
and
462 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const applyScheme = require('./scheme'); | ||
const defineGetters = require('../metadata/utils').defineGetters; | ||
|
||
const DEFAULT_CONFIG_NAME = 'docpub.conf'; | ||
|
||
module.exports = class Config { | ||
constructor(configPath, docPath) { | ||
if (!docPath && !configPath) { | ||
throw new Error('No config path and no doc path provided'); | ||
} | ||
|
||
this._configPath = path.resolve(configPath || path.join(docPath, DEFAULT_CONFIG_NAME)); | ||
|
||
this._load(); | ||
} | ||
|
||
_load() { | ||
const raw = this._read(); | ||
const parsed = this._parse(raw); | ||
|
||
defineGetters(this, parsed); | ||
} | ||
|
||
_read() { | ||
try { | ||
return fs.readFileSync(this._configPath, 'utf-8'); | ||
} catch (e) { | ||
if (e.code === 'ENOENT') { | ||
throw new Error(`Config file does not exist: ${this._configPath}`); | ||
} | ||
throw e; | ||
} | ||
} | ||
|
||
_parse(raw) { | ||
const json = JSON.parse(raw); | ||
const env = process.env; | ||
const argv = process.argv; | ||
|
||
return applyScheme({ | ||
options: json, | ||
env, | ||
argv | ||
}); | ||
} | ||
}; |
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,24 @@ | ||
const configParser = require('gemini-configparser'); | ||
|
||
const root = configParser.root; | ||
const section = configParser.section; | ||
const option = configParser.option; | ||
|
||
const shouldBeString = require('../metadata/validation-utils').shouldBeString; | ||
|
||
const ENV_PREFIX = `${require('../../package').name}_`; | ||
|
||
module.exports = root( | ||
section({ | ||
username: option({ | ||
validate: shouldBeString | ||
}), | ||
|
||
apiToken: option({ | ||
validate: shouldBeString | ||
}), | ||
|
||
url: option({ | ||
validate: shouldBeString | ||
}) | ||
}), {envPrefix: ENV_PREFIX}); |
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
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
Oops, something went wrong.