separate client and server

This commit is contained in:
monoid 2021-01-17 03:24:55 +09:00
parent e63e82fde9
commit 1dfb3c3c49
12 changed files with 173 additions and 80 deletions

View File

@ -4,10 +4,6 @@
"description": "",
"main": "build/app.js",
"scripts": {
"build:dev": "webpack --mode development",
"build:prod": "webpack --mode production",
"build:watch": "webpack --mode development -w",
"start": "ts-node src/server.ts",
"compile": "tsc",
"compile:watch": "tsc -w",
"app": "electron build/app.js",
@ -18,8 +14,7 @@
"files": [
"build/**/*",
"node_modules/**/*",
"package.json",
"!node_modules/@material-ui/**/*"
"package.json"
],
"appId": "com.prelude.ionian.app",
"productName": "Ionian",
@ -33,20 +28,9 @@
"app": "."
}
},
"browserslist": {
"production": [
"> 10%"
],
"development": [
"last 1 chrome version",
"last 1 firefox version"
]
},
"author": "",
"license": "ISC",
"dependencies": {
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2",
"jsonwebtoken": "^8.5.1",
"knex": "^0.21.14",
"koa": "^2.13.0",
@ -54,40 +38,19 @@
"koa-router": "^10.0.0",
"natural-orderby": "^2.0.3",
"node-stream-zip": "^1.12.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"sqlite3": "^5.0.0"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/preset-env": "^7.12.11",
"@babel/preset-react": "^7.12.10",
"@babel/preset-typescript": "^7.12.7",
"@types/jsonwebtoken": "^8.5.0",
"@types/knex": "^0.16.1",
"@types/koa": "^2.11.6",
"@types/koa-bodyparser": "^4.3.0",
"@types/koa-router": "^7.4.1",
"@types/node": "^14.14.16",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-router-dom": "^5.1.7",
"babel-core": "^6.26.3",
"babel-loader": "^8.2.2",
"css-loader": "^5.0.1",
"electron": "^11.1.1",
"electron-builder": "^22.9.1",
"eslint-plugin-node": "^11.1.0",
"mini-css-extract-plugin": "^1.3.3",
"style-loader": "^2.0.0",
"ts-json-schema-generator": "^0.82.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"webpack": "^5.11.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
"typescript": "^4.1.3"
}
}

View File

@ -6,36 +6,11 @@ import {Link as RouterLink} from 'react-router-dom';
import { LoadingCircle, ContentInfo, NavList, NavItem } from './mod';
import {toQueryString} from '../accessor/util';
const useStyles = makeStyles((theme:Theme)=>({
root:{
display:"grid",
gridGap: theme.spacing(4),
},
anchor_thumbnail:{
background: '#272733',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
[theme.breakpoints.up("sm")]:{
width: theme.spacing(25),
height: theme.spacing(25),
flexShrink: 0,
}
},
contentPaper:{
overflowY:'hidden',
display:'flex',
flexDirection: 'column',
[theme.breakpoints.up("sm")]:{
height:200,
flexDirection: 'row',
},
},
content_thumnail: {
maxWidth: '100%',
maxHeight: '100%',
},
}));
export type GalleryProp = {
@ -49,6 +24,7 @@ export const GalleryInfo = (props: GalleryProp)=>{
const [state,setState]= useState<GalleryState>({documents:undefined});
useEffect(()=>{
const load = (async ()=>{
console.log("mounted");
const c = await ContentAccessor.findList(props.option);
//todo : if c is undefined, retry to fetch 3 times. and show error message.
setState({documents:c});

51
src/client/package.json Normal file
View File

@ -0,0 +1,51 @@
{
"name": "ionian-client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build:dev": "webpack --mode development",
"build:prod": "webpack --mode production",
"build:watch": "webpack --mode development -w",
"type-check": "tsc --noEmit"
},
"author": "",
"license": "ISC",
"browserslist": {
"production": [
"> 10%"
],
"development": [
"last 1 chrome version",
"last 1 firefox version"
]
},
"dependencies": {
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/preset-env": "^7.12.11",
"@babel/preset-react": "^7.12.10",
"@babel/preset-typescript": "^7.12.7",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-router-dom": "^5.1.7",
"babel-core": "^6.26.3",
"babel-loader": "^8.2.2",
"css-loader": "^5.0.1",
"eslint-plugin-node": "^11.1.0",
"mini-css-extract-plugin": "^1.3.3",
"style-loader": "^2.0.0",
"ts-json-schema-generator": "^0.82.0",
"typescript": "^4.1.3",
"webpack": "^5.15.0",
"webpack-cli": "^4.3.1"
}
}

View File

@ -27,7 +27,7 @@ export function ProfilePage(){
const permission_list =userctx.permission.map(p=>(
<Chip key={p} label={p}></Chip>
));
const isElectronContent = window['electron'] !== undefined;
const isElectronContent = (((window['electron'] as any) !== undefined) as boolean);
const handle_open = ()=>set_pw_open(true);
const handle_close = ()=>{
set_pw_open(false);
@ -36,7 +36,7 @@ export function ProfilePage(){
};
const handle_ok= ()=>{
if(isElectronContent){
const elec = window['electron'];
const elec = window['electron'] as any;
if(newpw == newpwch){
const success = elec.passwordReset(userctx.username,newpw);
if(!success){

View File

@ -50,8 +50,10 @@ export const doLogout = async ()=>{
method: 'POST',
});
await res.json();
localObj.refreshExpired = 0;
localObj.username = "";
localObj.permission = [];
localObj = {
refreshExpired: 0,
username:"",
permission:[]
}
window.localStorage.setItem("UserLoginContext", JSON.stringify(localObj));
}

70
src/client/tsconfig.json Normal file
View File

@ -0,0 +1,70 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
// "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": "./build", /* 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 */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
"isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

View File

@ -2,9 +2,9 @@ const path = require("path");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = ()=>{return {
entry: './src/client/app.tsx',
entry: './app.tsx',
output: {
path: path.resolve(__dirname, 'dist/js'),
path: path.resolve(__dirname, '../../dist/js'),
filename: 'bundle.js'
},
module: {
@ -14,6 +14,18 @@ module.exports = ()=>{return {
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
babelrc: true,//why babelrc not working? why is webpack not reading '.babelrc'?
presets: [
'@babel/preset-env',
'@babel/preset-typescript',
'@babel/preset-react'
],
plugins: [
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread'
]
}
}
},
{
@ -29,9 +41,5 @@ module.exports = ()=>{return {
devtool: 'source-map',
resolve: {
extensions: ['.js','.css','.ts','.tsx']
},
devServer: {
historyApiFallback: true,
port: 3001
}
};}

View File

@ -1,5 +1,6 @@
import {TagAccessor} from './tag';
import {check_type} from '../util/type_check'
import {JSONMap} from '../types/json';
export interface DocumentBody{
title : string,

5
src/types/json.d.ts vendored
View File

@ -1,5 +0,0 @@
type JSONPrimitive = null|boolean|number|string;
interface JSONMap extends Record<string, JSONType>{}
interface JSONArray extends Array<JSONType>{};
type JSONType = JSONMap|JSONPrimitive|JSONArray;

5
src/types/json.ts Normal file
View File

@ -0,0 +1,5 @@
export type JSONPrimitive = null|boolean|number|string;
export interface JSONMap extends Record<string, JSONType>{}
export interface JSONArray extends Array<JSONType>{};
export type JSONType = JSONMap|JSONPrimitive|JSONArray;

22
src/util/type_check.js Normal file
View File

@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.check_type = void 0;
function check_type(obj, check_proto) {
for (const it in check_proto) {
let defined = check_proto[it];
if (defined === undefined)
return false;
defined = defined.trim();
if (defined.endsWith("[]")) {
if (!(obj[it] instanceof Array)) {
return false;
}
}
else if (defined !== typeof obj[it]) {
return false;
}
}
return true;
}
exports.check_type = check_type;
;