Replace javascript config with typescript

This commit is contained in:
Jannis Mattheis 2018-04-18 20:02:03 +02:00 committed by Jannis Mattheis
parent 3cfcbb1251
commit 75e3f88c9b
8 changed files with 3036 additions and 3850 deletions

View File

@ -1,18 +0,0 @@
module.exports = {
'extends': ['google', 'plugin:react/recommended'],
'parser': 'babel-eslint',
'env': {
'browser': true,
},
'globals': {
'React': true,
},
'plugins': ['react', 'babel'],
'rules': {
'linebreak-style': 0,
'max-len': ['error', 140],
'require-jsdoc': 0,
'babel/no-invalid-this': 1,
'no-invalid-this': 0,
},
};

21
ui/.gitignore vendored Normal file
View File

@ -0,0 +1,21 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
/node_modules
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

6686
ui/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "gotify-ui",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
@ -10,29 +10,34 @@
"material-ui-icons": "^1.0.0-beta.36",
"notifyjs": "^3.0.0",
"prop-types": "^15.6.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-global-configuration": "^1.2.1",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-list": "^0.8.8",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-scripts": "1.1.1",
"react-scripts-ts": "2.15.1",
"react-timeago": "^3.4.3",
"typeface-roboto": "0.0.54",
"typeface-roboto-mono": "0.0.54"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"lint": "eslint src",
"eject": "react-scripts eject"
"start": "react-scripts-ts start",
"build": "react-scripts-ts build",
"test": "react-scripts-ts test --env=jsdom",
"eject": "react-scripts-ts eject",
"lint": "tslint --project .",
"lintfix": "tslint --fix --project ."
},
"devDependencies": {
"babel-eslint": "^8.2.2",
"eslint": "^4.18.2",
"eslint-config-google": "^0.9.1",
"eslint-plugin-babel": "^4.1.2",
"eslint-plugin-react": "^7.7.0"
"@types/notifyjs": "^1.2.30",
"@types/detect-browser": "^2.0.1",
"@types/flux": "^3.1.7",
"@types/jest": "^22.2.3",
"@types/node": "^9.6.5",
"@types/react": "^16.3.11",
"@types/react-dom": "^16.0.5",
"@types/react-list": "^0.8.3",
"@types/react-router-dom": "^4.2.6",
"typescript": "^2.8.1"
}
}

View File

@ -1,8 +1,9 @@
// tslint:disable:no-console
// In production, we register a service worker to serve assets from local cache.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on the "N+1" visit to a page, since previously
// will only see deployed updates on the 'N+1' visit to a page, since previously
// cached resources are updated in the background.
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
@ -21,9 +22,10 @@ const isLocalhost = Boolean(
export default function register() {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
const publicUrl = new URL(
process.env.PUBLIC_URL!,
window.location.toString()
);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
@ -32,7 +34,7 @@ export default function register() {
}
window.addEventListener('load', () => {
const swUrl = `./service-worker.js`;
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Lets check if a service worker still exists or not.
@ -54,49 +56,51 @@ export default function register() {
}
}
function registerValidSW(swUrl) {
function registerValidSW(swUrl: string) {
if (!window.location.href.match('^([^/]*\\/)(.*\\.js|.*.html|static\\/.*|)$')) {
return;
}
navigator.serviceWorker
.register(swUrl)
.then((registration) => {
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker) {
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the old content will have been purged and
// the fresh content will have been added to the cache.
// It's the perfect time to display a "New content is
// available; please refresh." message in your web app.
// It's the perfect time to display a 'New content is
// available; please refresh.' message in your web app.
console.log('New content is available; please refresh.');
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
// 'Content is cached for offline use.' message.
console.log('Content is cached for offline use.');
}
}
};
}
};
})
.catch((error) => {
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl) {
function checkValidServiceWorker(swUrl: string) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then((response) => {
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
if (
response.status === 404 ||
response.headers.get('content-type').indexOf('javascript') === -1
response.headers.get('content-type')!.indexOf('javascript') === -1
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then((registration) => {
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
@ -115,7 +119,7 @@ function checkValidServiceWorker(swUrl) {
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then((registration) => {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
}

31
ui/tsconfig.json Normal file
View File

@ -0,0 +1,31 @@
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "build/dist",
"module": "esnext",
"target": "es5",
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules",
"build",
"scripts",
"acceptance-tests",
"webpack",
"jest",
"src/setupTests.ts"
]
}

6
ui/tsconfig.test.json Normal file
View File

@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs"
}
}

19
ui/tslint.json Normal file
View File

@ -0,0 +1,19 @@
{
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
"jsRules": {
"object-literal-sort-keys": false,
"no-console": false
},
"rules": {
"object-literal-sort-keys": false,
"jsx-boolean-value": false,
"no-console": false,
"jsx-no-lambda": false
},
"linterOptions": {
"exclude": [
"config/**/*.js",
"node_modules/**/*.ts"
]
}
}