Skip to content

Commit

Permalink
use a dataDir for the fake cert
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Mar 24, 2020
1 parent cde1a38 commit 99345cc
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 11 deletions.
3 changes: 3 additions & 0 deletions bin/servez
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ try {
process.exit(1); // eslint-disable-line
}

const dataDir = require('../src/appdata')('servez-cli');

const colorSupport = require('color-support') || {};
const c = require('ansi-colors');
c.enabled = colorSupport.hasBasic;
const Servez = require('servez-lib');
const server = new Servez(Object.assign({
root,
dataDir,
logger: {
log: console.log.bind(console),
error: (...args) => {
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ansi-colors": "^4.1.1",
"color-support": "^1.1.3",
"optionator": "^0.8.2",
"servez-lib": "^1.7.0"
"servez-lib": "^2.0.0"
},
"bin": {
"servez": "./bin/servez"
Expand Down
69 changes: 69 additions & 0 deletions src/appdata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2018, Greggman.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Greggman. nor the names of their
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

const fs = require('fs');
const path = require('path');

function mkdir(dirPath) {
if (!fileExists(dirPath)) {
fs.mkdirSync(dirPath);
}
}

function getDataDirPath(dirName) {
if (process.platform.toLowerCase() === 'darwin') {
return path.join(process.env.HOME, 'Library', 'Application Support', dirName);
} else if (process.platform.substring(0, 3).toLowerCase() === 'win') {
return path.join(process.env.LOCALAPPDATA || process.env.APPDATA, dirName);
} else {
const configDir = path.join(process.env.HOME, '.config');
return path.join(process.env.HOME, dirName);
}
}

function fileExists(filename) {
try {
const stat = fs.statSync(filename);
return !!stat;
} catch (e) {
return false;
}
}

function getDataDir(dirName) {
const dataDir = getDataDirPath(dirName);
mkdir(dataDir);
return dataDir;
}

module.exports = getDataDir;

0 comments on commit 99345cc

Please sign in to comment.