1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-08 06:55:26 +02:00

compiled JS files -> dist, fixed compiling errors

This commit is contained in:
nvc8996 2021-10-06 01:15:19 +03:00
parent 49a19edc0a
commit 4899f44e4c
93 changed files with 266 additions and 248 deletions

3
.gitignore vendored
View file

@ -76,3 +76,6 @@ typings/
# Uploads
/public/uploads
/public/uploads_test
# Compiled files
/dist/*

View file

@ -1,94 +0,0 @@
/**
* Module dependencies.
*/
import app from "../src/app";
import http from "http";
import config from "config";
import Debug from "debug";
const debug = Debug.debug("codex.editor.docs:server");
/**
* Get port from environment and store in Express.
*/
const port = normalizePort(config.get("port") || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val: string): number | string | false {
const value = parseInt(val, 10);
if (isNaN(value)) {
// named pipe
return val;
}
if (value >= 0) {
// port number
return value;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error: NodeJS.ErrnoException) {
if (error.syscall !== 'listen') {
throw error;
}
const bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
const addr = server.address();
if (addr === null) {
debug('Address not found');
process.exit(1);
}
const bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
export default {server, app};

View file

@ -1,7 +1,7 @@
{
"port": 3001,
"database": ".testdb",
"rcFile": "./test/.codexdocsrc",
"rcFile": "./dev/test/.codexdocsrc",
"uploads": "public/uploads_test",
"secret": "iamasecretstring"
}

99
dev/bin/server.ts Normal file
View file

@ -0,0 +1,99 @@
/**
* Module dependencies.
*/
import app from '../src/app';
import http from 'http';
import config from 'config';
import Debug from 'debug';
const debug = Debug.debug('codex.editor.docs:server');
/**
* Get port from environment and store in Express.
*/
const port = normalizePort(config.get('port') || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
* @param val
*/
function normalizePort(val: string): number | string | false {
const value = parseInt(val, 10);
if (isNaN(value)) {
// named pipe
return val;
}
if (value >= 0) {
// port number
return value;
}
return false;
}
/**
* Event listener for HTTP server 'error' event.
* @param error
*/
function onError(error: NodeJS.ErrnoException): void {
if (error.syscall !== 'listen') {
throw error;
}
const bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server 'listening' event.
*/
function onListening(): void {
const addr = server.address();
if (addr === null) {
debug('Address not found');
process.exit(1);
}
const bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
export default {
server,
app,
};

View file

@ -12,7 +12,7 @@ const config = rcParser.getConfiguration();
app.locals.config = config;
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('views', path.join(__dirname, '../../', 'views'));
app.set('view engine', 'twig');
require('./utils/twig');
@ -20,7 +20,7 @@ app.use(morgan('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, '../public')));
app.use(express.static(path.join(__dirname, '../../public')));
app.use('/', routes);

View file

@ -103,7 +103,7 @@ class PageOrder {
*
* @param {string} pageId - page's id
*/
public push(pageId: string): void {
public push(pageId: string | number): void {
if (typeof pageId === 'string') {
if (this.order === undefined) {
this.order = [];

View file

@ -42,7 +42,7 @@ router.get('*', verifyToken, async (req: Request, res: Response) => {
} catch (err) {
res.status(400).json({
success: false,
error: err.message,
error: err,
});
}
});

View file

@ -23,7 +23,7 @@ router.get('/page/:id', async (req: Request, res: Response) => {
} catch (err) {
res.status(400).json({
success: false,
error: err.message,
error: (err as Error).message,
});
}
});
@ -44,7 +44,7 @@ router.get('/pages', async (req: Request, res: Response) => {
} catch (err) {
res.status(400).json({
success: false,
error: err.message,
error: (err as Error).message,
});
}
});
@ -77,7 +77,7 @@ router.put('/page', multer.none(), async (req: Request, res: Response) => {
} catch (err) {
res.status(400).json({
success: false,
error: err.message,
error: (err as Error).message,
});
}
});
@ -134,7 +134,7 @@ router.post('/page/:id', multer.none(), async (req: Request, res: Response) => {
} catch (err) {
res.status(400).json({
success: false,
error: err.message,
error: (err as Error).message,
});
}
});
@ -213,7 +213,7 @@ router.delete('/page/:id', async (req: Request, res: Response) => {
} catch (err) {
res.status(400).json({
success: false,
error: err.message,
error: (err as Error).message,
});
}
});

View file

@ -126,7 +126,7 @@ export class Database<DocType> {
* @param {Options} options - optional params
* @returns {Promise<number|Object|Object[]|Error>} - number of updated rows or affected docs or Error object
*/
public async update(query: DocType, update: DocType, options: Options = {}): Promise<number|boolean> {
public async update(query: DocType, update: DocType, options: Options = {}): Promise<number|boolean|Array<DocType>> {
return new Promise((resolve, reject) => this.db.update(query, update, options, (err, result, affectedDocs) => {
if (err) {
reject(err);

View file

@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import config from 'config';
const rcPath = path.resolve(__dirname, '../../', config.get('rcFile') || './.codexdocsrc');
const rcPath = path.resolve(__dirname, '../../../', config.get('rcFile') || './.codexdocsrc');
/**
* @typedef {object} menu

View file

@ -16,7 +16,7 @@ export default (function () {
* @returns {string} - svg code
*/
twig.extendFunction('svg', function (filename: string) {
return fs.readFileSync(`${__dirname}/../frontend/svg/${filename}.svg`, 'utf-8');
return fs.readFileSync(`./frontend/svg/${filename}.svg`, 'utf-8');
});
/**

View file

@ -15,7 +15,7 @@ interface Document {
describe('Database', () => {
const pathToDB = `./${config.get('database')}/test.db`;
let nedbInstance;
let db: Database;
let db: Database<any>;
before(() => {
if (fs.existsSync(pathToDB)) {
@ -77,7 +77,10 @@ describe('Database', () => {
});
it('Updating documents with options', async () => {
const data = {update: true, data: 'Text data'};
const data = {
update: true,
data: 'Text data',
};
await db.insert(data);
await db.insert(data);
@ -86,7 +89,14 @@ describe('Database', () => {
expect(numberOfUpdatedDocs).to.equal(2);
const affectedDocs = await db.update({update: true}, {$set: {data: 'Second update'}}, {multi: true, returnUpdatedDocs: true}) as Array<any>;
const affectedDocs = await db.update(
{ update: true },
{ $set: { data: 'Second update' } },
{
multi: true,
returnUpdatedDocs: true,
}
) as Array<Document>;
expect(affectedDocs).to.be.a('array');
affectedDocs.forEach((doc: Document) => {
@ -150,31 +160,31 @@ describe('Database', () => {
try {
await db.insert({});
} catch (err) {
expect(err.message).to.equal('Cannot read property \'_id\' of undefined');
expect((err as Error).message).to.equal('Cannot read property \'_id\' of undefined');
}
try {
await db.find({ size: { $invalidComparator: 1 } });
} catch (err) {
expect(err.message).to.equal('Unknown comparison function $invalidComparator');
expect((err as Error).message).to.equal('Unknown comparison function $invalidComparator');
}
try {
await db.findOne({ field: { $invalidComparator: 1 } });
} catch (err) {
expect(err.message).to.equal('Unknown comparison function $invalidComparator');
expect((err as Error).message).to.equal('Unknown comparison function $invalidComparator');
}
try {
await db.update({field: {$undefinedComparator: 1}});
await db.update({ field: { $undefinedComparator: 1 } }, {});
} catch (err) {
expect(err.message).to.equal('Unknown comparison function $undefinedComparator');
expect((err as Error).message).to.equal('Unknown comparison function $undefinedComparator');
}
try {
await db.remove({ field: { $undefinedComparator: 1 } });
} catch (err) {
expect(err.message).to.equal('Unknown comparison function $undefinedComparator');
expect((err as Error).message).to.equal('Unknown comparison function $undefinedComparator');
}
});

View file

@ -10,7 +10,7 @@ const aliases = database['aliases'];
describe('Alias model', () => {
after(() => {
const pathToDB = path.resolve(__dirname, '../../', config.get('database'), './aliases.db');
const pathToDB = path.resolve(__dirname, '../../../', config.get('database'), './aliases.db');
if (fs.existsSync(pathToDB)) {
fs.unlinkSync(pathToDB);

View file

@ -10,7 +10,7 @@ const files = database['files'];
describe('File model', () => {
after(() => {
const pathToDB = path.resolve(__dirname, '../../', config.get('database'), './files.db');
const pathToDB = path.resolve(__dirname, '../../../', config.get('database'), './files.db');
if (fs.existsSync(pathToDB)) {
fs.unlinkSync(pathToDB);

View file

@ -21,7 +21,7 @@ describe('Page model', () => {
};
after(() => {
const pathToDB = path.resolve(__dirname, '../../', config.get('database'), './pages.db');
const pathToDB = path.resolve(__dirname, '../../../', config.get('database'), './pages.db');
if (fs.existsSync(pathToDB)) {
fs.unlinkSync(pathToDB);

View file

@ -9,7 +9,7 @@ const pagesOrder = database['pagesOrder'];
describe('PageOrder model', () => {
after(() => {
const pathToDB = path.resolve(__dirname, '../../', config.get('database'), './pagesOrder.db');
const pathToDB = path.resolve(__dirname, '../../../', config.get('database'), './pagesOrder.db');
if (fs.existsSync(pathToDB)) {
fs.unlinkSync(pathToDB);

View file

@ -42,8 +42,8 @@ describe('RC file parser test', () => {
menu: [
{ title: 'Option 1', uri: '/option1' },
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
]
{ title: 'Option 3', uri: '/option3' },
],
};
fs.writeFileSync(rcPath, JSON.stringify(normalConfig), 'utf8');
@ -58,8 +58,8 @@ describe('RC file parser test', () => {
menu: [
{ title: 'Option 1', uri: '/option1' },
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
]
{ title: 'Option 3', uri: '/option3' },
],
};
fs.writeFileSync(rcPath, JSON.stringify(normalConfig), 'utf8');
@ -72,7 +72,7 @@ describe('RC file parser test', () => {
it('Missed menu', () => {
const normalConfig = {
title: 'Documentation'
title: 'Documentation',
};
fs.writeFileSync(rcPath, JSON.stringify(normalConfig), 'utf8');
@ -89,8 +89,8 @@ describe('RC file parser test', () => {
menu: {
0: { title: 'Option 1', uri: '/option1' },
1: { title: 'Option 2', uri: '/option2' },
2: {title: 'Option 3', uri: '/option3'}
}
2: { title: 'Option 3', uri: '/option3' },
},
};
fs.writeFileSync(rcPath, JSON.stringify(normalConfig), 'utf8');
@ -112,14 +112,14 @@ describe('RC file parser test', () => {
menu: [
'Option 1',
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
]
{ title: 'Option 3', uri: '/option3' },
],
};
const expectedMenu = [
{ title: 'Option 1', uri: '/option-1' },
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
{ title: 'Option 3', uri: '/option3' },
];
fs.writeFileSync(rcPath, JSON.stringify(normalConfig), 'utf8');
@ -136,13 +136,13 @@ describe('RC file parser test', () => {
menu: [
[ { title: 'Option 1', uri: '/option1' } ],
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
]
{ title: 'Option 3', uri: '/option3' },
],
};
const expectedMenu = [
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
{ title: 'Option 3', uri: '/option3' },
];
const spy = sinon.spy(console, 'log');
@ -164,13 +164,13 @@ describe('RC file parser test', () => {
menu: [
{ uri: '/option1' },
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
]
{ title: 'Option 3', uri: '/option3' },
],
};
const expectedMenu = [
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
{ title: 'Option 3', uri: '/option3' },
];
const spy = sinon.spy(console, 'log');
@ -192,13 +192,13 @@ describe('RC file parser test', () => {
menu: [
{ title: [], uri: '/option1' },
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
]
{ title: 'Option 3', uri: '/option3' },
],
};
const expectedMenu = [
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
{ title: 'Option 3', uri: '/option3' },
];
const spy = sinon.spy(console, 'log');
@ -220,13 +220,13 @@ describe('RC file parser test', () => {
menu: [
{ title: 'Option 1' },
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
]
{ title: 'Option 3', uri: '/option3' },
],
};
const expectedMenu = [
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
{ title: 'Option 3', uri: '/option3' },
];
const spy = sinon.spy(console, 'log');
@ -248,13 +248,13 @@ describe('RC file parser test', () => {
menu: [
{ title: 'Option 1', uri: [] },
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
]
{ title: 'Option 3', uri: '/option3' },
],
};
const expectedMenu = [
{ title: 'Option 2', uri: '/option2' },
{title: 'Option 3', uri: '/option3'}
{ title: 'Option 3', uri: '/option3' },
];
const spy = sinon.spy(console, 'log');

View file

@ -32,9 +32,9 @@ describe('Pages REST: ', () => {
});
after(async () => {
const pathToPagesDB = path.resolve(__dirname, '../../', config.get('database'), './pages.db');
const pathToPagesOrderDB = path.resolve(__dirname, '../../', config.get('database'), './pagesOrder.db');
const pathToAliasesDB = path.resolve(__dirname, '../../', config.get('database'), './aliases.db');
const pathToPagesDB = path.resolve(__dirname, '../../../', config.get('database'), './pages.db');
const pathToPagesOrderDB = path.resolve(__dirname, '../../../', config.get('database'), './pagesOrder.db');
const pathToAliasesDB = path.resolve(__dirname, '../../../', config.get('database'), './aliases.db');
if (fs.existsSync(pathToPagesDB)) {
fs.unlinkSync(pathToPagesDB);
@ -102,7 +102,6 @@ describe('Pages REST: ', () => {
const { success, error } = res.body;
expect(success).to.be.false;
// expect(error).to.equal('Error: Some of required fields is missed');
expect(error).to.equal('validationError');
});

View file

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Before After
Before After

View file

@ -25,7 +25,7 @@ describe('Transport routes: ', () => {
});
after(async () => {
const pathToDB = path.resolve(__dirname, '../../', config.get('database'), './files.db');
const pathToDB = path.resolve(__dirname, '../../../', config.get('database'), './files.db');
if (fs.existsSync(pathToDB)) {
fs.unlinkSync(pathToDB);
@ -38,7 +38,7 @@ describe('Transport routes: ', () => {
it('Uploading an image', async () => {
const name = 'test_image.png';
const image = fs.readFileSync(path.resolve(`./test/rest/${name}`));
const image = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
const res = await agent
.post('/api/transport/image')
.attach('image', image, name);
@ -75,7 +75,7 @@ describe('Transport routes: ', () => {
it('Uploading an image with map option', async () => {
const name = 'test_image.png';
const image = fs.readFileSync(path.resolve(`./test/rest/${name}`));
const image = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
const res = await agent
.post('/api/transport/image')
.attach('image', image, name)
@ -96,7 +96,7 @@ describe('Transport routes: ', () => {
it('Uploading a file', async () => {
const name = 'test_file.json';
const json = fs.readFileSync(path.resolve(`./test/rest/${name}`));
const json = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
const res = await agent
.post('/api/transport/file')
.attach('file', json, name);
@ -127,7 +127,7 @@ describe('Transport routes: ', () => {
it('Uploading a file with map option', async () => {
const name = 'test_file.json';
const json = fs.readFileSync(path.resolve(`./test/rest/${name}`));
const json = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
const res = await agent
.post('/api/transport/file')
.attach('file', json, name)
@ -207,7 +207,7 @@ describe('Transport routes: ', () => {
expect(body.success).to.equal(0);
const name = 'test_file.json';
const json = fs.readFileSync(path.resolve(`./test/rest/${name}`));
const json = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
res = await agent
.post('/api/transport/file')
.attach('file', json, name)
@ -230,7 +230,7 @@ describe('Transport routes: ', () => {
expect(body.success).to.equal(0);
let name = 'test_file.json';
const json = fs.readFileSync(path.resolve(`./test/rest/${name}`));
const json = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
res = await agent
.post('/api/transport/image')
.attach('image', json, name);
@ -238,7 +238,7 @@ describe('Transport routes: ', () => {
expect(res).to.have.status(400);
name = 'test_image.png';
const image = fs.readFileSync(path.resolve(`./test/rest/${name}`));
const image = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
res = await agent
.post('/api/transport/image')
.attach('image', image, name)

View file

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 164 B

After

Width:  |  Height:  |  Size: 164 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 219 B

After

Width:  |  Height:  |  Size: 219 B

Before After
Before After

View file

@ -9,16 +9,17 @@
"> 1%"
],
"scripts": {
"start": "cross-env NODE_ENV=production nodemon --config nodemon.json ./bin/server.js",
"start:ts": "cross-env NODE_ENV=production nodemon --config nodemon.json ./bin/server.ts",
"start:dev": "cross-env NODE_ENV=development nodemon --config nodemon.json ./bin/server.ts",
"test": "cross-env NODE_ENV=testing mocha --recursive ./test --exit",
"test:ts": "cross-env NODE_ENV=testing ts-mocha ./test/*.ts ./test/**/*.ts --exit",
"lint": "eslint --fix --cache --ext .ts ./src",
"build": "webpack ./src/frontend/js/app.js --o='./public/dist/[name].bundle.js' --output-library=Docs --output-public-path=/dist/ -p --mode=production",
"build:dev": "webpack ./src/frontend/js/app.js --o='./public/dist/[name].bundle.js' --output-library=Docs --output-public-path=/dist/ -p --mode=development --watch",
"start": "cross-env NODE_ENV=production nodemon --config nodemon.json ./dist/bin/server.js",
"start:ts": "cross-env NODE_ENV=production nodemon --config nodemon.json ./dev/bin/server.ts",
"start:dev": "cross-env NODE_ENV=development nodemon --config nodemon.json ./dev/bin/server.ts",
"test": "cross-env NODE_ENV=testing mocha --recursive ./dist/test --exit",
"test:ts": "cross-env NODE_ENV=testing ts-mocha ./dev/test/*.ts ./dev/test/**/*.ts --exit",
"lint": "eslint --fix --cache --ext .ts ./dev/src",
"build": "webpack ./frontend/js/app.js --o='./public/dist/[name].bundle.js' --output-library=Docs --output-public-path=/dist/ -p --mode=production",
"build:dev": "webpack ./frontend/js/app.js --o='./public/dist/[name].bundle.js' --output-library=Docs --output-public-path=/dist/ -p --mode=development --watch",
"precommit": "yarn lint && yarn test:ts",
"generatePassword": "ts-node ./generatePassword.ts",
"generatePassword:ts": "ts-node ./dev/generatePassword.ts",
"generatePassword": "node ./dist/generatePassword.js",
"editor-upgrade": "yarn add -D @editorjs/{editorjs,header,code,delimiter,list,link,image,table,inline-code,marker,warning,checklist,raw}@latest",
"compile": "npx tsc"
},

View file

@ -14,7 +14,7 @@
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
"outDir": "./dist/", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */