fixed compiling error, re-organized ts source code
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"port": 3001,
|
"port": 3001,
|
||||||
"database": ".testdb",
|
"database": ".testdb",
|
||||||
"rcFile": "./dev/test/.codexdocsrc",
|
"rcFile": "./src/test/.codexdocsrc",
|
||||||
"uploads": "public/uploads_test",
|
"uploads": "public/uploads_test",
|
||||||
"secret": "iamasecretstring"
|
"secret": "iamasecretstring"
|
||||||
}
|
}
|
||||||
|
|
14
package.json
|
@ -10,15 +10,15 @@
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "cross-env NODE_ENV=production nodemon --config nodemon.json ./dist/bin/server.js",
|
"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:ts": "cross-env NODE_ENV=production nodemon --config nodemon.json ./src/bin/server.ts",
|
||||||
"start:dev": "cross-env NODE_ENV=development nodemon --config nodemon.json ./dev/bin/server.ts",
|
"start:dev": "cross-env NODE_ENV=development nodemon --config nodemon.json ./src/bin/server.ts",
|
||||||
"test": "cross-env NODE_ENV=testing mocha --recursive ./dist/test --exit",
|
"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",
|
"test:ts": "cross-env NODE_ENV=testing ts-mocha ./src/test/*.ts ./src/test/**/*.ts --exit",
|
||||||
"lint": "eslint --fix --cache --ext .ts ./dev/src",
|
"lint": "eslint --fix --cache --ext .ts ./src/backend",
|
||||||
"build": "webpack ./frontend/js/app.js --o='./public/dist/[name].bundle.js' --output-library=Docs --output-public-path=/dist/ -p --mode=production",
|
"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 ./frontend/js/app.js --o='./public/dist/[name].bundle.js' --output-library=Docs --output-public-path=/dist/ -p --mode=development --watch",
|
"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",
|
||||||
"precommit": "yarn lint && yarn test:ts",
|
"precommit": "yarn lint && yarn test:ts",
|
||||||
"generatePassword:ts": "ts-node ./dev/generatePassword.ts",
|
"generatePassword:ts": "ts-node ./src/generatePassword.ts",
|
||||||
"generatePassword": "node ./dist/generatePassword.js",
|
"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",
|
"editor-upgrade": "yarn add -D @editorjs/{editorjs,header,code,delimiter,list,link,image,table,inline-code,marker,warning,checklist,raw}@latest",
|
||||||
"compile": "npx tsc"
|
"compile": "npx tsc"
|
||||||
|
|
|
@ -12,7 +12,7 @@ const config = rcParser.getConfiguration();
|
||||||
app.locals.config = config;
|
app.locals.config = config;
|
||||||
|
|
||||||
// view engine setup
|
// view engine setup
|
||||||
app.set('views', path.join(__dirname, '../../', 'views'));
|
app.set('views', path.join(__dirname, '../../src/backend/', 'views'));
|
||||||
app.set('view engine', 'twig');
|
app.set('view engine', 'twig');
|
||||||
require('./utils/twig');
|
require('./utils/twig');
|
||||||
|
|
|
@ -87,7 +87,7 @@ class File {
|
||||||
* @param {object} query - input query
|
* @param {object} query - input query
|
||||||
* @returns {Promise<File[]>}
|
* @returns {Promise<File[]>}
|
||||||
*/
|
*/
|
||||||
public static async getAll(query: FileData = {}): Promise<File[]> {
|
public static async getAll(query: Record<string, unknown> = {}): Promise<File[]> {
|
||||||
const docs = await filesDb.find(query);
|
const docs = await filesDb.find(query);
|
||||||
|
|
||||||
return Promise.all(docs.map(doc => new File(doc)));
|
return Promise.all(docs.map(doc => new File(doc)));
|
|
@ -83,7 +83,7 @@ class Page {
|
||||||
* @param {object} query - input query
|
* @param {object} query - input query
|
||||||
* @returns {Promise<Page[]>}
|
* @returns {Promise<Page[]>}
|
||||||
*/
|
*/
|
||||||
public static async getAll(query: PageData = {}): Promise<Page[]> {
|
public static async getAll(query: Record<string, unknown> = {}): Promise<Page[]> {
|
||||||
const docs = await pagesDb.find(query);
|
const docs = await pagesDb.find(query);
|
||||||
|
|
||||||
return Promise.all(docs.map(doc => new Page(doc)));
|
return Promise.all(docs.map(doc => new Page(doc)));
|
|
@ -71,7 +71,7 @@ export class Database<DocType> {
|
||||||
* @param {Object} projection - projection object
|
* @param {Object} projection - projection object
|
||||||
* @returns {Promise<Array<Object>|Error>} - found docs or Error object
|
* @returns {Promise<Array<Object>|Error>} - found docs or Error object
|
||||||
*/
|
*/
|
||||||
public async find(query: DocType, projection?: DocType): Promise<Array<DocType>> {
|
public async find(query: Record<string, unknown>, projection?: DocType): Promise<Array<DocType>> {
|
||||||
const cbk = (resolve: ResolveFunction, reject: RejectFunction) => (err: Error | null, docs: DocType[]) => {
|
const cbk = (resolve: ResolveFunction, reject: RejectFunction) => (err: Error | null, docs: DocType[]) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
|
@ -98,7 +98,7 @@ export class Database<DocType> {
|
||||||
* @param {Object} projection - projection object
|
* @param {Object} projection - projection object
|
||||||
* @returns {Promise<Object|Error>} - found doc or Error object
|
* @returns {Promise<Object|Error>} - found doc or Error object
|
||||||
*/
|
*/
|
||||||
public async findOne(query: DocType, projection?: DocType): Promise<DocType> {
|
public async findOne(query: Record<string, unknown>, projection?: DocType): Promise<DocType> {
|
||||||
const cbk = (resolve: ResolveFunction, reject: RejectFunction) => (err: Error | null, doc: DocType) => {
|
const cbk = (resolve: ResolveFunction, reject: RejectFunction) => (err: Error | null, doc: DocType) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
|
@ -126,7 +126,7 @@ export class Database<DocType> {
|
||||||
* @param {Options} options - optional params
|
* @param {Options} options - optional params
|
||||||
* @returns {Promise<number|Object|Object[]|Error>} - number of updated rows or affected docs or Error object
|
* @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|Array<DocType>> {
|
public async update(query: Record<string, unknown>, update: DocType, options: Options = {}): Promise<number|boolean|Array<DocType>> {
|
||||||
return new Promise((resolve, reject) => this.db.update(query, update, options, (err, result, affectedDocs) => {
|
return new Promise((resolve, reject) => this.db.update(query, update, options, (err, result, affectedDocs) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
|
@ -157,7 +157,7 @@ export class Database<DocType> {
|
||||||
* @param {Options} options - optional params
|
* @param {Options} options - optional params
|
||||||
* @returns {Promise<number|Error>} - number of removed rows or Error object
|
* @returns {Promise<number|Error>} - number of removed rows or Error object
|
||||||
*/
|
*/
|
||||||
public async remove(query: DocType, options: Options = {}): Promise<number> {
|
public async remove(query: Record<string, unknown>, options: Options = {}): Promise<number> {
|
||||||
return new Promise((resolve, reject) => this.db.remove(query, options, (err, result) => {
|
return new Promise((resolve, reject) => this.db.remove(query, options, (err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
|
@ -16,7 +16,7 @@ export default (function () {
|
||||||
* @returns {string} - svg code
|
* @returns {string} - svg code
|
||||||
*/
|
*/
|
||||||
twig.extendFunction('svg', function (filename: string) {
|
twig.extendFunction('svg', function (filename: string) {
|
||||||
return fs.readFileSync(`./frontend/svg/${filename}.svg`, 'utf-8');
|
return fs.readFileSync(`./src/frontend/svg/${filename}.svg`, 'utf-8');
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
import app from '../src/app';
|
import app from '../backend/app';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import Debug from 'debug';
|
import Debug from 'debug';
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 164 B After Width: | Height: | Size: 164 B |
Before Width: | Height: | Size: 219 B After Width: | Height: | Size: 219 B |
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import database from './src/utils/database';
|
import database from './backend/utils/database';
|
||||||
import commander from 'commander';
|
import commander from 'commander';
|
||||||
import bcrypt from 'bcrypt';
|
import bcrypt from 'bcrypt';
|
||||||
|
|
|
@ -3,7 +3,7 @@ import config from 'config';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import Datastore from 'nedb';
|
import Datastore from 'nedb';
|
||||||
|
|
||||||
import { Database } from '../src/utils/database';
|
import { Database } from '../backend/utils/database';
|
||||||
|
|
||||||
interface Document {
|
interface Document {
|
||||||
data?: any;
|
data?: any;
|
|
@ -2,9 +2,9 @@ import { expect } from 'chai';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import Alias from '../../src/models/alias';
|
import Alias from '../../backend/models/alias';
|
||||||
import { binaryMD5 } from '../../src/utils/crypto';
|
import { binaryMD5 } from '../../backend/utils/crypto';
|
||||||
import database from '../../src/utils/database';
|
import database from '../../backend/utils/database';
|
||||||
|
|
||||||
const aliases = database['aliases'];
|
const aliases = database['aliases'];
|
||||||
|
|
|
@ -2,8 +2,8 @@ import { expect } from 'chai';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import File from '../../src/models/file';
|
import File from '../../backend/models/file';
|
||||||
import database from '../../src/utils/database';
|
import database from '../../backend/utils/database';
|
||||||
|
|
||||||
const files = database['files'];
|
const files = database['files'];
|
||||||
|
|
|
@ -2,9 +2,9 @@ import { expect } from 'chai';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import Page from '../../src/models/page';
|
import Page from '../../backend/models/page';
|
||||||
import translateString from '../../src/utils/translation';
|
import translateString from '../../backend/utils/translation';
|
||||||
import database from '../../src/utils/database';
|
import database from '../../backend/utils/database';
|
||||||
|
|
||||||
const pages = database['pages'];
|
const pages = database['pages'];
|
||||||
|
|
|
@ -2,8 +2,8 @@ import { expect } from 'chai';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import PageOrder from '../../src/models/pageOrder';
|
import PageOrder from '../../backend/models/pageOrder';
|
||||||
import database from '../../src/utils/database';
|
import database from '../../backend/utils/database';
|
||||||
|
|
||||||
const pagesOrder = database['pagesOrder'];
|
const pagesOrder = database['pagesOrder'];
|
||||||
|
|
|
@ -4,7 +4,7 @@ import path from 'path';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import sinon = require('sinon');
|
import sinon = require('sinon');
|
||||||
|
|
||||||
import rcParser from '../src/utils/rcparser';
|
import rcParser from '../backend/utils/rcparser';
|
||||||
|
|
||||||
const rcPath = path.resolve(process.cwd(), config.get('rcFile'));
|
const rcPath = path.resolve(process.cwd(), config.get('rcFile'));
|
||||||
|
|
|
@ -4,10 +4,10 @@ import config from 'config';
|
||||||
import chai from 'chai';
|
import chai from 'chai';
|
||||||
import chaiHTTP from 'chai-http';
|
import chaiHTTP from 'chai-http';
|
||||||
import server from '../../bin/server';
|
import server from '../../bin/server';
|
||||||
import model from '../../src/models/page';
|
import model from '../../backend/models/page';
|
||||||
import Page from '../../src/models/page';
|
import Page from '../../backend/models/page';
|
||||||
import PageOrder from '../../src/models/pageOrder';
|
import PageOrder from '../../backend/models/pageOrder';
|
||||||
import translateString from '../../src/utils/translation';
|
import translateString from '../../backend/utils/translation';
|
||||||
|
|
||||||
const {expect} = chai;
|
const {expect} = chai;
|
||||||
const app = server.app;
|
const app = server.app;
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
@ -6,7 +6,7 @@ import chaiHTTP from 'chai-http';
|
||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import server from '../../bin/server';
|
import server from '../../bin/server';
|
||||||
import model from '../../src/models/file';
|
import model from '../../backend/models/file';
|
||||||
|
|
||||||
const {expect} = chai;
|
const {expect} = chai;
|
||||||
const app = server.app;
|
const app = server.app;
|
||||||
|
@ -38,7 +38,7 @@ describe('Transport routes: ', () => {
|
||||||
|
|
||||||
it('Uploading an image', async () => {
|
it('Uploading an image', async () => {
|
||||||
const name = 'test_image.png';
|
const name = 'test_image.png';
|
||||||
const image = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
|
const image = fs.readFileSync(path.resolve(`./src/test/rest/${name}`));
|
||||||
const res = await agent
|
const res = await agent
|
||||||
.post('/api/transport/image')
|
.post('/api/transport/image')
|
||||||
.attach('image', image, name);
|
.attach('image', image, name);
|
||||||
|
@ -75,7 +75,7 @@ describe('Transport routes: ', () => {
|
||||||
|
|
||||||
it('Uploading an image with map option', async () => {
|
it('Uploading an image with map option', async () => {
|
||||||
const name = 'test_image.png';
|
const name = 'test_image.png';
|
||||||
const image = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
|
const image = fs.readFileSync(path.resolve(`./src/test/rest/${name}`));
|
||||||
const res = await agent
|
const res = await agent
|
||||||
.post('/api/transport/image')
|
.post('/api/transport/image')
|
||||||
.attach('image', image, name)
|
.attach('image', image, name)
|
||||||
|
@ -96,7 +96,7 @@ describe('Transport routes: ', () => {
|
||||||
|
|
||||||
it('Uploading a file', async () => {
|
it('Uploading a file', async () => {
|
||||||
const name = 'test_file.json';
|
const name = 'test_file.json';
|
||||||
const json = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
|
const json = fs.readFileSync(path.resolve(`./src/test/rest/${name}`));
|
||||||
const res = await agent
|
const res = await agent
|
||||||
.post('/api/transport/file')
|
.post('/api/transport/file')
|
||||||
.attach('file', json, name);
|
.attach('file', json, name);
|
||||||
|
@ -127,7 +127,7 @@ describe('Transport routes: ', () => {
|
||||||
|
|
||||||
it('Uploading a file with map option', async () => {
|
it('Uploading a file with map option', async () => {
|
||||||
const name = 'test_file.json';
|
const name = 'test_file.json';
|
||||||
const json = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
|
const json = fs.readFileSync(path.resolve(`./src/test/rest/${name}`));
|
||||||
const res = await agent
|
const res = await agent
|
||||||
.post('/api/transport/file')
|
.post('/api/transport/file')
|
||||||
.attach('file', json, name)
|
.attach('file', json, name)
|
||||||
|
@ -207,7 +207,7 @@ describe('Transport routes: ', () => {
|
||||||
expect(body.success).to.equal(0);
|
expect(body.success).to.equal(0);
|
||||||
|
|
||||||
const name = 'test_file.json';
|
const name = 'test_file.json';
|
||||||
const json = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
|
const json = fs.readFileSync(path.resolve(`./src/test/rest/${name}`));
|
||||||
res = await agent
|
res = await agent
|
||||||
.post('/api/transport/file')
|
.post('/api/transport/file')
|
||||||
.attach('file', json, name)
|
.attach('file', json, name)
|
||||||
|
@ -230,7 +230,7 @@ describe('Transport routes: ', () => {
|
||||||
expect(body.success).to.equal(0);
|
expect(body.success).to.equal(0);
|
||||||
|
|
||||||
let name = 'test_file.json';
|
let name = 'test_file.json';
|
||||||
const json = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
|
const json = fs.readFileSync(path.resolve(`./src/test/rest/${name}`));
|
||||||
res = await agent
|
res = await agent
|
||||||
.post('/api/transport/image')
|
.post('/api/transport/image')
|
||||||
.attach('image', json, name);
|
.attach('image', json, name);
|
||||||
|
@ -238,7 +238,7 @@ describe('Transport routes: ', () => {
|
||||||
expect(res).to.have.status(400);
|
expect(res).to.have.status(400);
|
||||||
|
|
||||||
name = 'test_image.png';
|
name = 'test_image.png';
|
||||||
const image = fs.readFileSync(path.resolve(`./dev/test/rest/${name}`));
|
const image = fs.readFileSync(path.resolve(`./src/test/rest/${name}`));
|
||||||
res = await agent
|
res = await agent
|
||||||
.post('/api/transport/image')
|
.post('/api/transport/image')
|
||||||
.attach('image', image, name)
|
.attach('image', image, name)
|