Quick and dirty typescript setup to get going.

This commit is contained in:
baldo 2020-04-08 01:55:48 +02:00
parent e5ccfeadce
commit 94d01310b9
17 changed files with 99 additions and 14 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ node_modules
*.swp
config.json
README.html
/server-build/

View file

@ -115,7 +115,7 @@ module.exports = function (grunt) {
'<%= yeoman.app %>/scripts/{,**/}*.js',
'shared/{,**/}*.js',
'server/{,**/}*.js',
'!server/templates/{,**/}*.js'
'!server/templates/{,**/}*.template'
]
},
@ -356,10 +356,11 @@ module.exports = function (grunt) {
},
{
expand: true,
cwd: 'server',
cwd: 'server-build',
dest: '<%= yeoman.dist %>/server',
src: [
'{,**/}*.html',
'{,**/}*.template',
'{,**/}*.js',
'{,**/}*.sql',
'{,**/}*.txt'

View file

@ -333,7 +333,7 @@ fastd-Key und die MAC-Adresse angeben.
### Build
`grunt clean build`
`npm run clean && npm run build`
Der Output landet dann unter `dist/`.
@ -341,14 +341,14 @@ Der Output landet dann unter `dist/`.
### Server starten
1. Zunächst eine `config.json` anlegen wie oben unter "Installation / Konfiguration" beschrieben.
2. `node server/main.js -c config.json`
2. `npm run server:run -- -c config.json`
Der Server ist dann erreichbar unter [http://localhost:8080](http://localhost:8080).
### Life-Reload vom Client
`grunt serve`
`npm client:serve`
Der Client ist dann erreichbar via [http://localhost:9000](http://localhost:9000), erwartet aber, dass der Server für
die REST-API auch läuft (s. o.) und auf Port `8080` erreichbar ist.

View file

@ -3,6 +3,7 @@
## Short term
* Integrate typescript in the build and start migrating the server code.
* Find a nice way to integrate typescript with grunt.
## Mid term

6
package-lock.json generated
View file

@ -9070,6 +9070,12 @@
"mime-types": "~2.1.24"
}
},
"typescript": {
"version": "3.8.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz",
"integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==",
"dev": true
},
"typical": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz",

View file

@ -18,6 +18,13 @@
"bin": {
"ffffng": "server/main.js"
},
"scripts": {
"build": "npm run server:build && grunt build",
"clean": "rm -rf server-build/ && grunt clean",
"client:serve": "grunt serve",
"server:build": "tsc -b server && ln -sfv ../server/db/patches ./server-build/db/ && ln -sfv ../server/templates ./server-build/",
"server:run": "npm run server:build && node server-build/main.js"
},
"dependencies": {
"async": "^3.1.0",
"body-parser": "^1.19.0",
@ -73,7 +80,8 @@
"imagemin-gifsicle": "^6.0.1",
"jshint-stylish": "^2.2.1",
"load-grunt-tasks": "^5.1.0",
"time-grunt": "^2.0.0"
"time-grunt": "^2.0.0",
"typescript": "^3.8.3"
},
"engines": {
"node": ">=10.0.0"

View file

@ -41,7 +41,8 @@ fi
echo
if confirm "Continue publishing?"; then
./node_modules/.bin/grunt clean build
npm run clean
npm run build
cd dist
npm publish

View file

@ -43,7 +43,7 @@ module.exports = (() => {
router.use(compress());
function serveTemplate (mimeType, req, res, next) {
return fs.readFile(templateDir + '/' + req.path, 'utf8', function (err, body) {
return fs.readFile(templateDir + '/' + req.path + '.template', 'utf8', function (err, body) {
if (err) {
return next(err);
}

View file

@ -1,6 +1,6 @@
'use strict';
const Constraints = require('../../shared/validation/constraints')
const Constraints = require('../validation/constraints')
const ErrorTypes = require('../utils/errorTypes')
const Logger = require('../logger')
const MailService = require('../services/mailService')

View file

@ -2,7 +2,7 @@
const _ = require('lodash')
const Constraints = require('../../shared/validation/constraints')
const Constraints = require('../validation/constraints')
const ErrorTypes = require('../utils/errorTypes')
const Logger = require('../logger')
const MonitoringService = require('../services/monitoringService')

View file

@ -3,7 +3,7 @@
const _ = require('lodash')
const deepExtend = require('deep-extend')
const Constraints = require('../../shared/validation/constraints')
const Constraints = require('../validation/constraints')
const ErrorTypes = require('../utils/errorTypes')
const Logger = require('../logger')
const MonitoringService = require('../services/monitoringService')

View file

@ -2,7 +2,7 @@
const _ = require('lodash')
const Constraints = require('../../shared/validation/constraints')
const Constraints = require('../validation/constraints')
const ErrorTypes = require('../utils/errorTypes')
const Resources = require('../utils/resources')
const Scheduler = require('../jobs/scheduler')

View file

@ -6,7 +6,7 @@ const moment = require('moment')
const request = require('request')
const config = require('../config').config
const Constraints = require('../../shared/validation/constraints')
const Constraints = require('../validation/constraints')
const Database = require('../db/database').db
const DatabaseUtil = require('../utils/databaseUtil')
const ErrorTypes = require('../utils/errorTypes')

66
server/tsconfig.json Normal file
View file

@ -0,0 +1,66 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es2018", /* 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": ["es2018"], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
"checkJs": false, /* Report errors in .js files. */
// "jsx": "preserve", /* 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": "../server-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. */
/* 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 */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

View file

@ -2,7 +2,7 @@
const _ = require('lodash')
const Constraints = require('../../shared/validation/constraints')
const Constraints = require('../validation/constraints')
const ErrorTypes = require('../utils/errorTypes')
const Logger = require('../logger')
const Validator = require('../validation/validator')

View file

@ -0,0 +1 @@
../../shared/validation/constraints.js