Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 41 additions & 40 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
{
"parserOptions": {
"ecmaVersion": 9
},
"extends": "google",
"rules": {
{
"parserOptions": {
"ecmaVersion": 9
},
"extends": "google",
"rules": {
"no-unused-vars": 0,
"no-tabs": 0,
"one-var": 0,
"linebreak-style": 0,
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
"max-len": 0,
"no-multiple-empty-lines": ["error", { "max": 1, "maxBOF": 1 }],
"padded-blocks": 0,
"curly": 0,
"object-curly-spacing": ["error", "always"],
"block-spacing": ["error", "always"],
"array-bracket-spacing": ["error", "always"],
"prefer-template": 2,
"new-cap": 0,
"guard-for-in": 0,
"indent": [
"error", "tab", {
"CallExpression": {
"arguments": 1
},
"FunctionDeclaration": {
"body": 1,
"parameters": 2
},
"FunctionExpression": {
"body": 1,
"parameters": 2
},
"MemberExpression": 2,
"ObjectExpression": 1,
"SwitchCase": 1,
"ignoredNodes": [
"ConditionalExpression",
"VariableDeclarator"
]
}
]
}
}
"max-len": 0,
"no-multiple-empty-lines": ["error", { "max": 1, "maxBOF": 1 }],
"padded-blocks": 0,
"curly": 0,
"object-curly-spacing": ["error", "always"],
"block-spacing": ["error", "always"],
"array-bracket-spacing": ["error", "always"],
"prefer-template": 2,
"new-cap": 0,
"guard-for-in": 0,
"indent": [
"error", "tab", {
"CallExpression": {
"arguments": 1
},
"FunctionDeclaration": {
"body": 1,
"parameters": 2
},
"FunctionExpression": {
"body": 1,
"parameters": 2
},
"MemberExpression": 2,
"ObjectExpression": 1,
"SwitchCase": 1,
"ignoredNodes": [
"ConditionalExpression",
"VariableDeclarator"
]
}
]
}
}
166 changes: 85 additions & 81 deletions local-server.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,94 @@
const htmlFiles = [
'header',
'main',
'dashboard/dashboard',
'my-addresses/my-addresses',
'new-address/new-address',
'send/send',
'transactions/transactions',
'footer',
'welcome/welcome',
'restore/restore',
'create-wallet/create-wallet',
'set-password/set-password',
'login/login',
];

const htmlFiles = [
'header',
'main',
'dashboard/dashboard',
'my-addresses/my-addresses',
'new-address/new-address',
'send/send',
'transactions/transactions',
'footer',
'welcome/welcome',
'restore/restore',
'create-wallet/create-wallet',
'set-password/set-password',
'login/login',
];
let workDir = '/src/';
if (process.env.DIST_FOLDER) workDir = `/${process.env.DIST_FOLDER}/`;

const express = require('express');
const app = express();
const fs = require('fs');
const packageConfig = require('./package.json').config || {};

process.env.IP = process.env.IP || packageConfig.IP;
process.env.PORT = process.env.PORT || packageConfig.PORT;

if ( ! process.env.IP || ! process.env.PORT) {
console.error('Need to specify IP and PORT environments (example: IP=192.168.23.42 PORT=80 node local-server.js) !');
process.exit();
}

let server;
if (process.env.PORT !== '443') server = require('http').createServer(app);
else server = require('https').createServer({
pfx: fs.readFileSync(`${__dirname}/localhost.pfx`),
passphrase: '12345',
}, app);

server.listen(process.env.PORT, process.env.IP, () => {
const address = server.address().address;
console.log(`Server running at http${process.env.PORT === '443' ? 's' : ''}://${address === '127.0.0.1' ? 'localhost' : address}:${server.address().port} from ${workDir}`);
});

app.use(express.static(__dirname + workDir));

if (workDir === '/src/') {
const path = require('path');

const templateJs = (file) => { return `<script defer src="${file}"></script>`; };
const templateCss = (file) => { return `<link rel="stylesheet" href="${file}">`; };

let pathJsFiles = ``;
let pathCssFiles = ``;

const generatePathFiles = async (filePath = '') => {
const fullFilePath = workDir + filePath;
let files;
try {
files = fs.readdirSync(path.join(__dirname, fullFilePath));
}
catch (err) {
return console.error(`unable read files ${fullFilePath}:`, err);
}
for await (const file of files) {
const fileExt = path.extname(file).substr(1);
if (fileExt === 'js') pathJsFiles += templateJs(file);
else if (fileExt === 'css') pathCssFiles += templateCss(file);
else if ( ! fileExt) {
app.use(express.static(__dirname + fullFilePath + file));
generatePathFiles(filePath + file);
}
}
};

(async () => {
await generatePathFiles('../lib/');
await generatePathFiles();
})();

app.use(express.static(`${__dirname}/public/`));
app.use(express.static(`${__dirname}/lib/`));

app.get('/', (req, res) => {
let outputStr = '';
outputStr += pathCssFiles;
htmlFiles.forEach((htmlFile) => {
outputStr += fs.readFileSync(`${__dirname + workDir + htmlFile}.html`);
});
outputStr += pathJsFiles;
res.setHeader('Content-Type', 'text/html');
res.send(outputStr);
});
}
process.exit();
}
let server;
if (process.env.PORT !== '443') server = require('http').createServer(app);
else server = require('https').createServer({
pfx: fs.readFileSync(`${__dirname}/localhost.pfx`),
passphrase: '12345',
}, app);
server.listen(process.env.PORT, process.env.IP, () => {
const address = server.address().address;
console.log(`Server running at http${process.env.PORT === '443' ? 's' : ''}://${address === '127.0.0.1' ? 'localhost' : address}:${server.address().port} from ${workDir}`);
});
app.use(express.static(__dirname + workDir));
if (workDir === '/src/') {
const path = require('path');
const templateJs = (file) => { return `<script defer src="${file}"></script>`; };
const templateCss = (file) => { return `<link rel="stylesheet" href="${file}">`; };
let pathJsFiles = ``;
let pathCssFiles = ``;
const generatePathFiles = async (filePath = '') => {
const fullFilePath = workDir + filePath;
let files;
try {
files = fs.readdirSync(path.join(__dirname, fullFilePath));
}
catch (err) {
return console.error(`unable read files ${fullFilePath}:`, err);
}
for await (const file of files) {
const fileExt = path.extname(file).substr(1);
if (fileExt === 'js') pathJsFiles += templateJs(file);
else if (fileExt === 'css') pathCssFiles += templateCss(file);
else if ( ! fileExt) {
app.use(express.static(__dirname + fullFilePath + file));
generatePathFiles(filePath + file);
}
}
};
(async () => {
await generatePathFiles('../lib/');
await generatePathFiles();
})();
app.use(express.static(`${__dirname}/public/`));
app.use(express.static(`${__dirname}/lib/`));
app.get('/', (req, res) => {
let outputStr = '';
outputStr += pathCssFiles;
htmlFiles.forEach((htmlFile) => {
outputStr += fs.readFileSync(`${__dirname + workDir + htmlFile}.html`);
});
outputStr += pathJsFiles;
res.setHeader('Content-Type', 'text/html');
res.send(outputStr);
});
}
74 changes: 37 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
{
"name": "bitgesell-wallet",
"version": "0.9.5",
"description": "Bitgesell Wallet JS",
"homepage": "https://app.bglwallet.io",
"bugs": "https://github.com/epexa/bitgesell-wallet/issues",
"license": "Proprietary",
"author": "epexa",
"main": "local-server.js",
"repository": "epexa/bitgesell-wallet",
"config": {
"IP": "127.0.0.1",
"PORT": "80",
"DIST_FOLDER": "../bitgesell-wallet-dist"
},
{
"name": "bitgesell-wallet",
"version": "0.9.5",
"description": "Bitgesell Wallet JS",
"homepage": "https://app.bglwallet.io",
"bugs": "https://github.com/epexa/bitgesell-wallet/issues",
"license": "Proprietary",
"author": "epexa",
"main": "local-server.js",
"repository": "epexa/bitgesell-wallet",
"config": {
"IP": "127.0.0.1",
"PORT": "80",
"DIST_FOLDER": "../bitgesell-wallet-dist"
},
"scripts": {
"test": "eslint 'src/*.js'",
"local-server": "IP=$npm_package_config_IP PORT=$npm_package_config_PORT node local-server.js",
"test": "eslint src/*.js",
"local-server": "node local-server.js",
"start": "npm test && npm run local-server",
"build": "./build.sh $npm_package_config_DIST_FOLDER",
"dist-start": "npm run build && DIST_FOLDER=$npm_package_config_DIST_FOLDER npm run local-server"
},
"husky": {
"hooks": {
"pre-commit": "npm test"
}
"build": "npm test && node scripts/build.js",
"dist-start": "npm run build && node scripts/dist-server.js"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"clean-css-cli": "^4.2.1",
"eslint": "^5.15.3",
"eslint-config-google": "^0.12.0",
"express": "^4.16.4",
"html-minifier": "^3.5.21",
"husky": "^2.3.0",
"uglify-js": "^3.5.2"
}
}
"husky": {
"hooks": {
"pre-commit": "npm test"
}
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"clean-css-cli": "^4.2.1",
"eslint": "^5.15.3",
"eslint-config-google": "^0.12.0",
"express": "^4.16.4",
"html-minifier": "^3.5.21",
"husky": "^2.3.0",
"uglify-js": "^3.5.2"
}
}
Loading