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

fixed compiling error, re-organized ts source code

This commit is contained in:
nvc8996 2021-10-06 16:35:31 +03:00
parent 4899f44e4c
commit 4c0540ff6e
90 changed files with 42 additions and 42 deletions

View file

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

View file

@ -10,15 +10,15 @@
],
"scripts": {
"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",
"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 ./src/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",
"test:ts": "cross-env NODE_ENV=testing ts-mocha ./src/test/*.ts ./src/test/**/*.ts --exit",
"lint": "eslint --fix --cache --ext .ts ./src/backend",
"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",
"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",
"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

@ -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, '../../src/backend/', 'views'));
app.set('view engine', 'twig');
require('./utils/twig');

View file

@ -87,7 +87,7 @@ class File {
* @param {object} query - input query
* @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);
return Promise.all(docs.map(doc => new File(doc)));

View file

@ -83,7 +83,7 @@ class Page {
* @param {object} query - input query
* @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);
return Promise.all(docs.map(doc => new Page(doc)));

View file

@ -71,7 +71,7 @@ export class Database<DocType> {
* @param {Object} projection - projection 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[]) => {
if (err) {
reject(err);
@ -98,7 +98,7 @@ export class Database<DocType> {
* @param {Object} projection - projection 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) => {
if (err) {
reject(err);
@ -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|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) => {
if (err) {
reject(err);
@ -157,7 +157,7 @@ export class Database<DocType> {
* @param {Options} options - optional params
* @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) => {
if (err) {
reject(err);

View file

@ -16,7 +16,7 @@ export default (function () {
* @returns {string} - svg code
*/
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');
});
/**

View file

@ -1,7 +1,7 @@
/**
* Module dependencies.
*/
import app from '../src/app';
import app from '../backend/app';
import http from 'http';
import config from 'config';
import Debug from 'debug';

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

@ -1,6 +1,6 @@
#!/usr/bin/env node
import database from './src/utils/database';
import database from './backend/utils/database';
import commander from 'commander';
import bcrypt from 'bcrypt';

View file

@ -3,7 +3,7 @@ import config from 'config';
import { expect } from 'chai';
import Datastore from 'nedb';
import { Database } from '../src/utils/database';
import { Database } from '../backend/utils/database';
interface Document {
data?: any;

View file

@ -2,9 +2,9 @@ import { expect } from 'chai';
import fs from 'fs';
import path from 'path';
import config from 'config';
import Alias from '../../src/models/alias';
import { binaryMD5 } from '../../src/utils/crypto';
import database from '../../src/utils/database';
import Alias from '../../backend/models/alias';
import { binaryMD5 } from '../../backend/utils/crypto';
import database from '../../backend/utils/database';
const aliases = database['aliases'];

View file

@ -2,8 +2,8 @@ import { expect } from 'chai';
import fs from 'fs';
import path from 'path';
import config from 'config';
import File from '../../src/models/file';
import database from '../../src/utils/database';
import File from '../../backend/models/file';
import database from '../../backend/utils/database';
const files = database['files'];

View file

@ -2,9 +2,9 @@ import { expect } from 'chai';
import fs from 'fs';
import path from 'path';
import config from 'config';
import Page from '../../src/models/page';
import translateString from '../../src/utils/translation';
import database from '../../src/utils/database';
import Page from '../../backend/models/page';
import translateString from '../../backend/utils/translation';
import database from '../../backend/utils/database';
const pages = database['pages'];

View file

@ -2,8 +2,8 @@ import { expect } from 'chai';
import fs from 'fs';
import path from 'path';
import config from 'config';
import PageOrder from '../../src/models/pageOrder';
import database from '../../src/utils/database';
import PageOrder from '../../backend/models/pageOrder';
import database from '../../backend/utils/database';
const pagesOrder = database['pagesOrder'];

View file

@ -4,7 +4,7 @@ import path from 'path';
import config from 'config';
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'));

View file

@ -4,10 +4,10 @@ import config from 'config';
import chai from 'chai';
import chaiHTTP from 'chai-http';
import server from '../../bin/server';
import model from '../../src/models/page';
import Page from '../../src/models/page';
import PageOrder from '../../src/models/pageOrder';
import translateString from '../../src/utils/translation';
import model from '../../backend/models/page';
import Page from '../../backend/models/page';
import PageOrder from '../../backend/models/pageOrder';
import translateString from '../../backend/utils/translation';
const {expect} = chai;
const app = server.app;

View file

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Before After
Before After

View file

@ -6,7 +6,7 @@ import chaiHTTP from 'chai-http';
import rimraf from 'rimraf';
import config from 'config';
import server from '../../bin/server';
import model from '../../src/models/file';
import model from '../../backend/models/file';
const {expect} = chai;
const app = server.app;
@ -38,7 +38,7 @@ describe('Transport routes: ', () => {
it('Uploading an image', async () => {
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
.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(`./dev/test/rest/${name}`));
const image = fs.readFileSync(path.resolve(`./src/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(`./dev/test/rest/${name}`));
const json = fs.readFileSync(path.resolve(`./src/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(`./dev/test/rest/${name}`));
const json = fs.readFileSync(path.resolve(`./src/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(`./dev/test/rest/${name}`));
const json = fs.readFileSync(path.resolve(`./src/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(`./dev/test/rest/${name}`));
const json = fs.readFileSync(path.resolve(`./src/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(`./dev/test/rest/${name}`));
const image = fs.readFileSync(path.resolve(`./src/test/rest/${name}`));
res = await agent
.post('/api/transport/image')
.attach('image', image, name)