eslint integration
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
module.exports = {
|
||||||
|
'plugins': ['jest'],
|
||||||
|
'env': {
|
||||||
|
'commonjs': true,
|
||||||
|
'es2021': true,
|
||||||
|
'node': true,
|
||||||
|
'jest/globals': true
|
||||||
|
},
|
||||||
|
'extends': ['eslint:recommended'],
|
||||||
|
'parserOptions': {
|
||||||
|
'ecmaVersion': 12
|
||||||
|
},
|
||||||
|
'rules': {
|
||||||
|
'indent': [
|
||||||
|
'error',
|
||||||
|
4
|
||||||
|
],
|
||||||
|
'linebreak-style': [
|
||||||
|
'error',
|
||||||
|
'unix'
|
||||||
|
],
|
||||||
|
'quotes': [
|
||||||
|
'error',
|
||||||
|
'single'
|
||||||
|
],
|
||||||
|
'semi': [
|
||||||
|
'error',
|
||||||
|
'always'
|
||||||
|
],
|
||||||
|
'curly': [
|
||||||
|
'error',
|
||||||
|
'all'
|
||||||
|
],
|
||||||
|
'brace-style': [
|
||||||
|
'error',
|
||||||
|
'1tbs'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"esversion": 6,
|
|
||||||
"maxerr": 999,
|
|
||||||
"indent": true,
|
|
||||||
"camelcase": true,
|
|
||||||
"eqeqeq": true,
|
|
||||||
"forin": true,
|
|
||||||
"immed": true,
|
|
||||||
"latedef": true,
|
|
||||||
"noarg": true,
|
|
||||||
"noempty": true,
|
|
||||||
"nonew": true,
|
|
||||||
"undef": true,
|
|
||||||
"unused": true,
|
|
||||||
"varstmt": true,
|
|
||||||
"sub": true,
|
|
||||||
"quotmark": "single",
|
|
||||||
"node": true,
|
|
||||||
"globals": {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Generated
+2616
-28
File diff suppressed because it is too large
Load Diff
+4
-1
@@ -19,6 +19,8 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"coveralls": "^3.0.4",
|
"coveralls": "^3.0.4",
|
||||||
|
"eslint": "^7.23.0",
|
||||||
|
"eslint-plugin-jest": "^24.3.2",
|
||||||
"jest": "^24.8.0",
|
"jest": "^24.8.0",
|
||||||
"superagent": "^5.1.0",
|
"superagent": "^5.1.0",
|
||||||
"supertest": "^4.0.2"
|
"supertest": "^4.0.2"
|
||||||
@@ -26,7 +28,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node src/server.js",
|
"start": "node src/server.js",
|
||||||
"test": "jest --silent -i",
|
"test": "jest --silent -i",
|
||||||
"install": "node src/postinstall.js"
|
"install": "node src/postinstall.js",
|
||||||
|
"lint": "eslint --fix ."
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
+22
-14
@@ -71,18 +71,20 @@ module.exports = (config) => {
|
|||||||
Object.keys(dict).forEach((key) => articles[key] = dict[key]);
|
Object.keys(dict).forEach((key) => articles[key] = dict[key]);
|
||||||
const nb = Object.keys(articles).length;
|
const nb = Object.keys(articles).length;
|
||||||
const dnb = Object.values(articles).filter(a => a.draft).length;
|
const dnb = Object.values(articles).filter(a => a.draft).length;
|
||||||
if (nb > 0)
|
if (nb > 0) {
|
||||||
console.log(cons.ok, `loaded ${nb} article${nb > 1 ? 's' : ''} (${dnb} drafted)`);
|
console.log(cons.ok, `loaded ${nb} article${nb > 1 ? 's' : ''} (${dnb} drafted)`);
|
||||||
else
|
} else {
|
||||||
console.log(cons.warn, `no articles loaded, check your configuration`);
|
console.log(cons.warn, 'no articles loaded, check your configuration');
|
||||||
|
}
|
||||||
|
|
||||||
lastRSS = '';
|
lastRSS = '';
|
||||||
|
|
||||||
success();
|
success();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
if (config['test'])
|
if (config['test']) {
|
||||||
app.reload = reload;
|
app.reload = reload;
|
||||||
|
}
|
||||||
|
|
||||||
render = (req, res, vPath, data, code = 200) => {
|
render = (req, res, vPath, data, code = 200) => {
|
||||||
data.info = {
|
data.info = {
|
||||||
@@ -100,18 +102,20 @@ module.exports = (config) => {
|
|||||||
} else if (err) {
|
} else if (err) {
|
||||||
res.sendStatus(500);
|
res.sendStatus(500);
|
||||||
console.log(cons.error, `failed to render error page : ${err}`);
|
console.log(cons.error, `failed to render error page : ${err}`);
|
||||||
} else
|
} else {
|
||||||
res.status(code).send(html);
|
res.status(code).send(html);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
showError = (req, res, code) => {
|
showError = (req, res, code) => {
|
||||||
const errorPath = path.join(config['data_dir'], config['home']['error']);
|
const errorPath = path.join(config['data_dir'], config['home']['error']);
|
||||||
fs.access(errorPath, fs.constants.R_OK, (err) => {
|
fs.access(errorPath, fs.constants.R_OK, (err) => {
|
||||||
if (err)
|
if (err) {
|
||||||
res.sendStatus(code);
|
res.sendStatus(code);
|
||||||
else
|
} else {
|
||||||
render(req, res, errorPath, {error: code}, code);
|
render(req, res, errorPath, {error: code}, code);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -150,14 +154,15 @@ module.exports = (config) => {
|
|||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
const homePath = path.join(config['data_dir'], config['home']['index']);
|
const homePath = path.join(config['data_dir'], config['home']['index']);
|
||||||
fs.access(homePath, fs.constants.R_OK, (err) => {
|
fs.access(homePath, fs.constants.R_OK, (err) => {
|
||||||
if (err)
|
if (err) {
|
||||||
showError(req, res, 404);
|
showError(req, res, 404);
|
||||||
else
|
} else {
|
||||||
render(req, res, homePath,
|
render(req, res, homePath,
|
||||||
{
|
{
|
||||||
articles: Object.values(articles)
|
articles: Object.values(articles)
|
||||||
.filter(d => !d.draft).sort((a, b) => ('' + b.path).localeCompare(a.path))
|
.filter(d => !d.draft).sort((a, b) => ('' + b.path).localeCompare(a.path))
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -216,8 +221,9 @@ module.exports = (config) => {
|
|||||||
|
|
||||||
//rewrite urls to hide articles titles : /2019/05/05/sometitle/img.png => /2019/05/05/img.png
|
//rewrite urls to hide articles titles : /2019/05/05/sometitle/img.png => /2019/05/05/img.png
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
if (/^\/\d{4}\/\d{2}\/\d{2}\//.test(req.url))
|
if (/^\/\d{4}\/\d{2}\/\d{2}\//.test(req.url)) {
|
||||||
req.url = req.url.slice(0, 11) + req.url.slice(req.url.lastIndexOf('/'));
|
req.url = req.url.slice(0, 11) + req.url.slice(req.url.lastIndexOf('/'));
|
||||||
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -226,9 +232,9 @@ module.exports = (config) => {
|
|||||||
if (/^\/\d{4}\/\d{2}\/\d{2}\/$/.test(req.path)) {
|
if (/^\/\d{4}\/\d{2}\/\d{2}\/$/.test(req.path)) {
|
||||||
const articlePath = req.path.substr(1, 10);
|
const articlePath = req.path.substr(1, 10);
|
||||||
const article = articles[articlePath];
|
const article = articles[articlePath];
|
||||||
if (!article)
|
if (!article) {
|
||||||
showError(req, res, 404);
|
showError(req, res, 404);
|
||||||
else {
|
} else {
|
||||||
renderer.render(article.realPath, (err, html) => {
|
renderer.render(article.realPath, (err, html) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(cons.error, `failed to render article ${req.path} : ${err}`);
|
console.log(cons.error, `failed to render article ${req.path} : ${err}`);
|
||||||
@@ -240,8 +246,9 @@ module.exports = (config) => {
|
|||||||
if (err) {
|
if (err) {
|
||||||
console.log(cons.error, `no template found at ${templatePath}`);
|
console.log(cons.error, `no template found at ${templatePath}`);
|
||||||
showError(req, res, 500);
|
showError(req, res, 500);
|
||||||
} else
|
} else {
|
||||||
render(req, res, templatePath, {article: article});
|
render(req, res, templatePath, {article: article});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -272,8 +279,9 @@ module.exports = (config) => {
|
|||||||
//log all server errors
|
//log all server errors
|
||||||
app.use((err, req, res, next) => {
|
app.use((err, req, res, next) => {
|
||||||
console.log(cons.error, `error when handling ${req.method} ${req.path} request : ${err}`);
|
console.log(cons.error, `error when handling ${req.method} ${req.path} request : ${err}`);
|
||||||
if (!config['error_log'])
|
if (!config['error_log']) {
|
||||||
next(err);
|
next(err);
|
||||||
|
}
|
||||||
fs.appendFile(config['error_log'],
|
fs.appendFile(config['error_log'],
|
||||||
`500 ${req.method} ${req.url} ${new Date().toUTCString()} ${req.ips.join(' ') || req.ip}\n${err.stack}\n`,
|
`500 ${req.method} ${req.url} ${new Date().toUTCString()} ${req.ips.join(' ') || req.ip}\n${err.stack}\n`,
|
||||||
{encoding: 'UTF-8'}, () => {
|
{encoding: 'UTF-8'}, () => {
|
||||||
|
|||||||
+20
-10
@@ -12,25 +12,29 @@ const getFileTree = (dir, cb) => {
|
|||||||
let list = [];
|
let list = [];
|
||||||
let remaining = 0;
|
let remaining = 0;
|
||||||
fs.readdir(dir, {withFileTypes: true}, (err, items) => {
|
fs.readdir(dir, {withFileTypes: true}, (err, items) => {
|
||||||
if (err)
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
}
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
if (item.isDirectory()) {
|
if (item.isDirectory()) {
|
||||||
remaining++;
|
remaining++;
|
||||||
getFileTree(path.join(dir, item.name), (err, out) => {
|
getFileTree(path.join(dir, item.name), (err, out) => {
|
||||||
if (err)
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
}
|
||||||
list.push(...out);
|
list.push(...out);
|
||||||
remaining--;
|
remaining--;
|
||||||
if (remaining === 0)
|
if (remaining === 0) {
|
||||||
cb(null, list);
|
cb(null, list);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
list.push(path.join(dir, item.name));
|
list.push(path.join(dir, item.name));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (remaining === 0)
|
if (remaining === 0) {
|
||||||
cb(null, list);
|
cb(null, list);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,8 +46,9 @@ const getFileTree = (dir, cb) => {
|
|||||||
*/
|
*/
|
||||||
const readIndexFile = (path, thumbnailTag, cb) => {
|
const readIndexFile = (path, thumbnailTag, cb) => {
|
||||||
fs.readFile(path, {encoding: 'UTF-8'}, (err, data) => {
|
fs.readFile(path, {encoding: 'UTF-8'}, (err, data) => {
|
||||||
if (err)
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
}
|
||||||
|
|
||||||
let info = {};
|
let info = {};
|
||||||
|
|
||||||
@@ -68,14 +73,16 @@ module.exports = (config) => {
|
|||||||
*/
|
*/
|
||||||
fetchArticles: (cb) => {
|
fetchArticles: (cb) => {
|
||||||
getFileTree(config['data_dir'], (err, fileList) => {
|
getFileTree(config['data_dir'], (err, fileList) => {
|
||||||
if (err)
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
}
|
||||||
const paths = fileList
|
const paths = fileList
|
||||||
.map((p) => p.substr(config['data_dir'].length + 1).split(path.sep))
|
.map((p) => p.substr(config['data_dir'].length + 1).split(path.sep))
|
||||||
.filter((p) => p.length === 4 && (p[3] === config['article']['index'] || p[3] === config['article']['draft']) &&
|
.filter((p) => p.length === 4 && (p[3] === config['article']['index'] || p[3] === config['article']['draft']) &&
|
||||||
/^\d{4}$/.test(p[0]) && /^\d{2}$/.test(p[1]) && /^\d{2}$/.test(p[2]));
|
/^\d{4}$/.test(p[0]) && /^\d{2}$/.test(p[1]) && /^\d{2}$/.test(p[2]));
|
||||||
if (paths.length === 0)
|
if (paths.length === 0) {
|
||||||
cb(null, {});
|
cb(null, {});
|
||||||
|
}
|
||||||
const articles = {};
|
const articles = {};
|
||||||
let remaining = 0;
|
let remaining = 0;
|
||||||
paths.forEach((p) => {
|
paths.forEach((p) => {
|
||||||
@@ -91,17 +98,20 @@ module.exports = (config) => {
|
|||||||
article.date.setUTCHours(0);
|
article.date.setUTCHours(0);
|
||||||
remaining++;
|
remaining++;
|
||||||
readIndexFile(article.realPath, config['article']['thumbnail_tag'], (err, info) => {
|
readIndexFile(article.realPath, config['article']['thumbnail_tag'], (err, info) => {
|
||||||
if (err)
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
}
|
||||||
article.title = info.title || config['article']['default_title'];
|
article.title = info.title || config['article']['default_title'];
|
||||||
article.thumbnail = info.thumbnail ? joinUrl(article.path, info.thumbnail) : config['article']['default_thumbnail'];
|
article.thumbnail = info.thumbnail ? joinUrl(article.path, info.thumbnail) : config['article']['default_thumbnail'];
|
||||||
article.escapedTitle = article.title.toLowerCase().replace(/[^\w]/gm, ' ').trim().replace(/ /gm, '_');
|
article.escapedTitle = article.title.toLowerCase().replace(/[^\w]/gm, ' ').trim().replace(/ /gm, '_');
|
||||||
article.url = '/' + joinUrl(article.path, article.escapedTitle) + '/';
|
article.url = '/' + joinUrl(article.path, article.escapedTitle) + '/';
|
||||||
if (!articles[article.path] || !article.draft)
|
if (!articles[article.path] || !article.draft) {
|
||||||
articles[article.path] = article;
|
articles[article.path] = article;
|
||||||
|
}
|
||||||
remaining--;
|
remaining--;
|
||||||
if (remaining === 0)
|
if (remaining === 0) {
|
||||||
cb(null, articles);
|
cb(null, articles);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -4,10 +4,11 @@ const ncp = require('ncp').ncp;
|
|||||||
|
|
||||||
const copy = (src, dest) => {
|
const copy = (src, dest) => {
|
||||||
ncp(src, dest, function (err) {
|
ncp(src, dest, function (err) {
|
||||||
if (err)
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
else
|
} else {
|
||||||
console.log(`copied ${src} to ${dest}`);
|
console.log(`copied ${src} to ${dest}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -23,8 +24,9 @@ if (!fs.existsSync('data')) {
|
|||||||
const datetime = new Date();
|
const datetime = new Date();
|
||||||
const dir = path.join('data', datetime.getFullYear().toString(), pad0(datetime.getMonth() + 1), pad0(datetime.getDate()));
|
const dir = path.join('data', datetime.getFullYear().toString(), pad0(datetime.getMonth() + 1), pad0(datetime.getDate()));
|
||||||
|
|
||||||
if (!fs.existsSync(dir))
|
if (!fs.existsSync(dir)) {
|
||||||
fs.mkdirSync(dir, {recursive: true});
|
fs.mkdirSync(dir, {recursive: true});
|
||||||
|
}
|
||||||
|
|
||||||
copy(path.join('sample_data', 'article'), dir);
|
copy(path.join('sample_data', 'article'), dir);
|
||||||
}
|
}
|
||||||
+22
-12
@@ -21,11 +21,12 @@ module.exports = (config) => {
|
|||||||
});
|
});
|
||||||
i += match.index + match[0].length;
|
i += match.index + match[0].length;
|
||||||
}
|
}
|
||||||
if (i < data.length)
|
if (i < data.length) {
|
||||||
parts.push({
|
parts.push({
|
||||||
index: i,
|
index: i,
|
||||||
text: data.slice(i, data.length),
|
text: data.slice(i, data.length),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
parts = parts.filter((p, i) => i % 2 === 0); //filter out code parts
|
parts = parts.filter((p, i) => i % 2 === 0); //filter out code parts
|
||||||
|
|
||||||
@@ -40,11 +41,12 @@ module.exports = (config) => {
|
|||||||
});
|
});
|
||||||
i += match.index + match[0].length;
|
i += match.index + match[0].length;
|
||||||
}
|
}
|
||||||
if (i < p.text.length)
|
if (i < p.text.length) {
|
||||||
subParts.push({
|
subParts.push({
|
||||||
index: p.index + i,
|
index: p.index + i,
|
||||||
text: p.text.slice(i, p.text.length),
|
text: p.text.slice(i, p.text.length),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
parts.splice(pi, 1, ...subParts);
|
parts.splice(pi, 1, ...subParts);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -59,12 +61,14 @@ module.exports = (config) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let Prism;
|
let Prism;
|
||||||
if (config['modules']['prism'])
|
if (config['modules']['prism']) {
|
||||||
Prism = require('node-prismjs');
|
Prism = require('node-prismjs');
|
||||||
|
}
|
||||||
|
|
||||||
const renderPrism = (data, cb) => {
|
const renderPrism = (data, cb) => {
|
||||||
if (!config['modules']['prism'])
|
if (!config['modules']['prism']) {
|
||||||
return cb(data);
|
return cb(data);
|
||||||
|
}
|
||||||
const codeRegex = /```([\w-]+)\r?\n((?:(?!```)[\s\S])*)\r?\n```/m;
|
const codeRegex = /```([\w-]+)\r?\n((?:(?!```)[\s\S])*)\r?\n```/m;
|
||||||
let match;
|
let match;
|
||||||
while ((match = codeRegex.exec(data))) {
|
while ((match = codeRegex.exec(data))) {
|
||||||
@@ -81,17 +85,19 @@ module.exports = (config) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const renderPlantUML = (data, cb) => {
|
const renderPlantUML = (data, cb) => {
|
||||||
if (!config['modules']['plantuml'])
|
/* global encode64 */
|
||||||
|
if (!config['modules']['plantuml']) {
|
||||||
return cb(data);
|
return cb(data);
|
||||||
|
}
|
||||||
const parts = getParts(data);
|
const parts = getParts(data);
|
||||||
const umlRegex = /@startuml\r?\n((?:(?!@enduml)[\s\S])*)\r?\n@enduml/m;
|
const umlRegex = /@startuml\r?\n((?:(?!@enduml)[\s\S])*)\r?\n@enduml/m;
|
||||||
let match;
|
let match;
|
||||||
parts.forEach(part => {
|
parts.forEach(part => {
|
||||||
while ((match = umlRegex.exec(part.text))) {
|
while ((match = umlRegex.exec(part.text))) {
|
||||||
const code = match[1].trim();
|
const code = match[1].trim();
|
||||||
const s = unescape(encodeURIComponent(code)); // jshint ignore:line
|
const s = unescape(encodeURIComponent(code));
|
||||||
const compressed = global['zip_deflate'](s);
|
const compressed = global['zip_deflate'](s);
|
||||||
const url = `http://www.plantuml.com/plantuml/${config['plantuml']['output_format']}/${encode64(compressed)}`;// jshint ignore:line
|
const url = `http://www.plantuml.com/plantuml/${config['plantuml']['output_format']}/${encode64(compressed)}`;
|
||||||
part.text = part.text.slice(0, match.index) + `<img alt="generated PlantUML diagram" src="${url}">` + part.text.slice(match.index + match[0].length);
|
part.text = part.text.slice(0, match.index) + `<img alt="generated PlantUML diagram" src="${url}">` + part.text.slice(match.index + match[0].length);
|
||||||
}
|
}
|
||||||
data = data.slice(0, part.index) + part.text + data.slice(part.end);
|
data = data.slice(0, part.index) + part.text + data.slice(part.end);
|
||||||
@@ -113,8 +119,9 @@ module.exports = (config) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const renderMathJax = (data, cb) => {
|
const renderMathJax = (data, cb) => {
|
||||||
if (!config['modules']['mathjax'])
|
if (!config['modules']['mathjax']) {
|
||||||
return cb(data);
|
return cb(data);
|
||||||
|
}
|
||||||
|
|
||||||
const parts = getParts(data);
|
const parts = getParts(data);
|
||||||
|
|
||||||
@@ -157,8 +164,9 @@ module.exports = (config) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const renderFaDiagrams = (data, cb) => {
|
const renderFaDiagrams = (data, cb) => {
|
||||||
if (!config['modules']['fa-diagrams'])
|
if (!config['modules']['fa-diagrams']) {
|
||||||
return cb(data);
|
return cb(data);
|
||||||
|
}
|
||||||
const parts = getParts(data);
|
const parts = getParts(data);
|
||||||
const diagramsRegex = /@startfad\r?\n((?:(?!@endfad)[\s\S])*)\r?\n@endfad/m;
|
const diagramsRegex = /@startfad\r?\n((?:(?!@endfad)[\s\S])*)\r?\n@endfad/m;
|
||||||
let match;
|
let match;
|
||||||
@@ -170,10 +178,11 @@ module.exports = (config) => {
|
|||||||
const diagData = toml.parse(code);
|
const diagData = toml.parse(code);
|
||||||
const findLineBreaks = (data) => {
|
const findLineBreaks = (data) => {
|
||||||
Object.keys(data).forEach(key => {
|
Object.keys(data).forEach(key => {
|
||||||
if (typeof data[key] === 'object')
|
if (typeof data[key] === 'object') {
|
||||||
findLineBreaks(data[key]);
|
findLineBreaks(data[key]);
|
||||||
else if (typeof data[key] === 'string')
|
} else if (typeof data[key] === 'string') {
|
||||||
data[key] = data[key].replace(/\\n/gm, '\n');
|
data[key] = data[key].replace(/\\n/gm, '\n');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
findLineBreaks(diagData);
|
findLineBreaks(diagData);
|
||||||
@@ -197,8 +206,9 @@ module.exports = (config) => {
|
|||||||
renderFaDiagrams: config['test'] ? renderFaDiagrams : undefined,
|
renderFaDiagrams: config['test'] ? renderFaDiagrams : undefined,
|
||||||
render: (file, cb) => {
|
render: (file, cb) => {
|
||||||
fs.readFile(file, {encoding: 'UTF-8'}, (err, data) => {
|
fs.readFile(file, {encoding: 'UTF-8'}, (err, data) => {
|
||||||
if (err)
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
}
|
||||||
|
|
||||||
renderPlantUML(data, (data) => {
|
renderPlantUML(data, (data) => {
|
||||||
renderFaDiagrams(data, (data) => {
|
renderFaDiagrams(data, (data) => {
|
||||||
|
|||||||
+6
-7
@@ -1,4 +1,3 @@
|
|||||||
/* jshint -W117 */
|
|
||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@@ -49,13 +48,13 @@ describe('Test reload', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Test request logging', () => {
|
describe('Test request logging', () => {
|
||||||
test('test no log', (done) => {
|
test('no log', (done) => {
|
||||||
request(app).get('/rsstest').then(() => {
|
request(app).get('/rsstest').then(() => {
|
||||||
expect(fs.existsSync(path.join(dataDir, 'access.log'))).toBe(false);
|
expect(fs.existsSync(path.join(dataDir, 'access.log'))).toBe(false);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('test get 200', (done) => {
|
test('get 200', (done) => {
|
||||||
config['access_log'] = path.join(dataDir, 'access.log');
|
config['access_log'] = path.join(dataDir, 'access.log');
|
||||||
request(app).get('/rsstest').then(() => {
|
request(app).get('/rsstest').then(() => {
|
||||||
fs.readFile(path.join(dataDir, 'access.log'), {encoding: 'UTF-8'}, (err, data) => {
|
fs.readFile(path.join(dataDir, 'access.log'), {encoding: 'UTF-8'}, (err, data) => {
|
||||||
@@ -65,7 +64,7 @@ describe('Test request logging', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('test post 400', (done) => {
|
test('post 400', (done) => {
|
||||||
config['access_log'] = path.join(dataDir, 'access.log');
|
config['access_log'] = path.join(dataDir, 'access.log');
|
||||||
request(app).post('/rsstest').then(() => {
|
request(app).post('/rsstest').then(() => {
|
||||||
fs.readFile(path.join(dataDir, 'access.log'), {encoding: 'UTF-8'}, (err, data) => {
|
fs.readFile(path.join(dataDir, 'access.log'), {encoding: 'UTF-8'}, (err, data) => {
|
||||||
@@ -75,7 +74,7 @@ describe('Test request logging', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('test 2 requests', (done) => {
|
test('2 requests', (done) => {
|
||||||
config['access_log'] = path.join(dataDir, 'access.log');
|
config['access_log'] = path.join(dataDir, 'access.log');
|
||||||
request(app).get('/rss').then(() => {
|
request(app).get('/rss').then(() => {
|
||||||
request(app).post('/rsstest').then(() => {
|
request(app).post('/rsstest').then(() => {
|
||||||
@@ -91,14 +90,14 @@ describe('Test request logging', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Test error logging', () => {
|
describe('Test error logging', () => {
|
||||||
test('test no log', (done) => {
|
test('no log', (done) => {
|
||||||
config['home']['index'] = null;
|
config['home']['index'] = null;
|
||||||
request(app).get('/').then(() => {
|
request(app).get('/').then(() => {
|
||||||
expect(fs.existsSync(path.join(dataDir, 'error.log'))).toBe(false);
|
expect(fs.existsSync(path.join(dataDir, 'error.log'))).toBe(false);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('test null error ', (done) => {
|
test('null error', (done) => {
|
||||||
config['home']['index'] = null;
|
config['home']['index'] = null;
|
||||||
config['error_log'] = path.join(dataDir, 'error.log');
|
config['error_log'] = path.join(dataDir, 'error.log');
|
||||||
request(app).get('/').then(() => {
|
request(app).get('/').then(() => {
|
||||||
|
|||||||
+4
-3
@@ -1,4 +1,3 @@
|
|||||||
/* jshint -W117 */
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
@@ -21,8 +20,9 @@ afterAll(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('no config', () => {
|
test('no config', () => {
|
||||||
if (fs.existsSync(configFile))
|
if (fs.existsSync(configFile)) {
|
||||||
fs.unlinkSync(configFile);
|
fs.unlinkSync(configFile);
|
||||||
|
}
|
||||||
expect(fs.existsSync(configFile)).toBeFalsy();
|
expect(fs.existsSync(configFile)).toBeFalsy();
|
||||||
const config = require('../src/config')();
|
const config = require('../src/config')();
|
||||||
expect(config).toBeDefined();
|
expect(config).toBeDefined();
|
||||||
@@ -31,8 +31,9 @@ test('no config', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('example config', () => {
|
test('example config', () => {
|
||||||
if (fs.existsSync(configFile))
|
if (fs.existsSync(configFile)) {
|
||||||
fs.unlinkSync(configFile);
|
fs.unlinkSync(configFile);
|
||||||
|
}
|
||||||
fs.copyFileSync(path.join('src', 'config.default.json'), configFile);
|
fs.copyFileSync(path.join('src', 'config.default.json'), configFile);
|
||||||
const data = fs.readFileSync(configFile, {encoding: 'UTF-8'});
|
const data = fs.readFileSync(configFile, {encoding: 'UTF-8'});
|
||||||
fs.writeFileSync(configFile, data.replace('3000', '3333'), {encoding: 'UTF-8'});
|
fs.writeFileSync(configFile, data.replace('3000', '3333'), {encoding: 'UTF-8'});
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* jshint -W117 */
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const utils = require('./test_utils');
|
const utils = require('./test_utils');
|
||||||
|
|||||||
+16
-17
@@ -1,4 +1,3 @@
|
|||||||
/* jshint -W117 */
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const utils = require('./test_utils');
|
const utils = require('./test_utils');
|
||||||
@@ -181,9 +180,9 @@ describe('Test MathJax', () => {
|
|||||||
});
|
});
|
||||||
test('full eq', (done) => {
|
test('full eq', (done) => {
|
||||||
renderer.renderMathJax('$$\n\nA\n\n$$', (data) => {
|
renderer.renderMathJax('$$\n\nA\n\n$$', (data) => {
|
||||||
expect(data).toBe('<span class=\"mjx-chtml MJXc-display\" style=\"text-align: center;\">' +
|
expect(data).toBe('<span class="mjx-chtml MJXc-display" style="text-align: center;">' +
|
||||||
'<span class=\"mjx-math\"><span class=\"mjx-mrow\"><span class=\"mjx-mi\">' +
|
'<span class="mjx-math"><span class="mjx-mrow"><span class="mjx-mi">' +
|
||||||
'<span class=\"mjx-char MJXc-TeX-math-I\" style=\"padding-top: 0.519em; padding-bottom: 0.298em;\">' +
|
'<span class="mjx-char MJXc-TeX-math-I" style="padding-top: 0.519em; padding-bottom: 0.298em;">' +
|
||||||
'A' +
|
'A' +
|
||||||
'</span></span></span></span></span>');
|
'</span></span></span></span></span>');
|
||||||
done();
|
done();
|
||||||
@@ -192,9 +191,9 @@ describe('Test MathJax', () => {
|
|||||||
test('inline eq', (done) => {
|
test('inline eq', (done) => {
|
||||||
renderer.renderMathJax('start $a$ end', (data) => {
|
renderer.renderMathJax('start $a$ end', (data) => {
|
||||||
expect(data).toBe('start ' +
|
expect(data).toBe('start ' +
|
||||||
'<span class=\"mjx-chtml\">' +
|
'<span class="mjx-chtml">' +
|
||||||
'<span class=\"mjx-math\"><span class=\"mjx-mrow\"><span class=\"mjx-mi\">' +
|
'<span class="mjx-math"><span class="mjx-mrow"><span class="mjx-mi">' +
|
||||||
'<span class=\"mjx-char MJXc-TeX-math-I\" style=\"padding-top: 0.225em; padding-bottom: 0.298em;\">' +
|
'<span class="mjx-char MJXc-TeX-math-I" style="padding-top: 0.225em; padding-bottom: 0.298em;">' +
|
||||||
'a' +
|
'a' +
|
||||||
'</span></span></span></span></span>' +
|
'</span></span></span></span></span>' +
|
||||||
' end');
|
' end');
|
||||||
@@ -216,21 +215,21 @@ describe('Test MathJax', () => {
|
|||||||
test('multiple eq', (done) => {
|
test('multiple eq', (done) => {
|
||||||
renderer.renderMathJax('$$\n\nA\n\n$$\nstart $a$ end\n$$\n\nA\n\n$$', (data) => {
|
renderer.renderMathJax('$$\n\nA\n\n$$\nstart $a$ end\n$$\n\nA\n\n$$', (data) => {
|
||||||
expect(data).toBe('' +
|
expect(data).toBe('' +
|
||||||
'<span class=\"mjx-chtml MJXc-display\" style=\"text-align: center;\">' +
|
'<span class="mjx-chtml MJXc-display" style="text-align: center;">' +
|
||||||
'<span class=\"mjx-math\"><span class=\"mjx-mrow\"><span class=\"mjx-mi\">' +
|
'<span class="mjx-math"><span class="mjx-mrow"><span class="mjx-mi">' +
|
||||||
'<span class=\"mjx-char MJXc-TeX-math-I\" style=\"padding-top: 0.519em; padding-bottom: 0.298em;\">' +
|
'<span class="mjx-char MJXc-TeX-math-I" style="padding-top: 0.519em; padding-bottom: 0.298em;">' +
|
||||||
'A' +
|
'A' +
|
||||||
'</span></span></span></span></span>\n' +
|
'</span></span></span></span></span>\n' +
|
||||||
'start ' +
|
'start ' +
|
||||||
'<span class=\"mjx-chtml\">' +
|
'<span class="mjx-chtml">' +
|
||||||
'<span class=\"mjx-math\"><span class=\"mjx-mrow\"><span class=\"mjx-mi\">' +
|
'<span class="mjx-math"><span class="mjx-mrow"><span class="mjx-mi">' +
|
||||||
'<span class=\"mjx-char MJXc-TeX-math-I\" style=\"padding-top: 0.225em; padding-bottom: 0.298em;\">' +
|
'<span class="mjx-char MJXc-TeX-math-I" style="padding-top: 0.225em; padding-bottom: 0.298em;">' +
|
||||||
'a' +
|
'a' +
|
||||||
'</span></span></span></span></span>' +
|
'</span></span></span></span></span>' +
|
||||||
' end\n' +
|
' end\n' +
|
||||||
'<span class=\"mjx-chtml MJXc-display\" style=\"text-align: center;\">' +
|
'<span class="mjx-chtml MJXc-display" style="text-align: center;">' +
|
||||||
'<span class=\"mjx-math\"><span class=\"mjx-mrow\"><span class=\"mjx-mi\">' +
|
'<span class="mjx-math"><span class="mjx-mrow"><span class="mjx-mi">' +
|
||||||
'<span class=\"mjx-char MJXc-TeX-math-I\" style=\"padding-top: 0.519em; padding-bottom: 0.298em;\">' +
|
'<span class="mjx-char MJXc-TeX-math-I" style="padding-top: 0.519em; padding-bottom: 0.298em;">' +
|
||||||
'A' +
|
'A' +
|
||||||
'</span></span></span></span></span>');
|
'</span></span></span></span></span>');
|
||||||
done();
|
done();
|
||||||
@@ -279,7 +278,7 @@ describe('Test render', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('normal file', (done) => {
|
test('normal file', (done) => {
|
||||||
fs.writeFileSync(file, `# Hello`);
|
fs.writeFileSync(file, '# Hello');
|
||||||
renderer.render(file, (err, html) => {
|
renderer.render(file, (err, html) => {
|
||||||
expect(err).toBeNull();
|
expect(err).toBeNull();
|
||||||
expect(html).toBe('<h1 id="hello">Hello</h1>');
|
expect(html).toBe('<h1 id="hello">Hello</h1>');
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* jshint -W117 */
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const utils = require('./test_utils');
|
const utils = require('./test_utils');
|
||||||
|
|||||||
+5
-3
@@ -2,14 +2,16 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const deleteFolderSync = (dir) => {
|
const deleteFolderSync = (dir) => {
|
||||||
if (!fs.existsSync(dir))
|
if (!fs.existsSync(dir)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
let items;
|
let items;
|
||||||
const deleteItem = (item) => {
|
const deleteItem = (item) => {
|
||||||
if (item.isDirectory())
|
if (item.isDirectory()) {
|
||||||
deleteFolderSync(path.join(dir, item.name));
|
deleteFolderSync(path.join(dir, item.name));
|
||||||
else
|
} else {
|
||||||
fs.unlinkSync(path.join(dir, item.name));
|
fs.unlinkSync(path.join(dir, item.name));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
do {
|
do {
|
||||||
items = fs.readdirSync(dir, {withFileTypes: true});
|
items = fs.readdirSync(dir, {withFileTypes: true});
|
||||||
|
|||||||
Reference in New Issue
Block a user