Busily prototyping multiple entrypoints for the main app and serviceworker
This commit is contained in:
parent
f178b69bf8
commit
2fe06ba4ba
17
Makefile
17
Makefile
|
@ -1,20 +1,29 @@
|
|||
#
|
||||
#
|
||||
# Root Makefile to make the building and testing of this project easier
|
||||
# regardless of *nix based platform
|
||||
|
||||
PATH:=./node_modules/.bin:./tools:$(PATH)
|
||||
|
||||
all: build check
|
||||
|
||||
build:
|
||||
depends: package.json package-lock.json
|
||||
if [ ! -d node_modules ]; then \
|
||||
npm install; \
|
||||
fi;
|
||||
|
||||
build: depends
|
||||
webpack-cli
|
||||
|
||||
check: build
|
||||
check: depends
|
||||
jest
|
||||
|
||||
run: depends
|
||||
webpack-dev-server --mode=development
|
||||
|
||||
clean:
|
||||
rm -rf dist
|
||||
rm -f src/*.js
|
||||
|
||||
.PHONY: all clean check
|
||||
.PHONY: all depends build clean check
|
||||
|
||||
# vim: set et
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="dist/main.js"></script>
|
||||
<title>How You Can Help Us</title>
|
||||
</head>
|
||||
<body>
|
||||
<center>
|
||||
Hello World
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,56 @@
|
|||
{
|
||||
"name": "howyoucanhelp.us",
|
||||
"version": "1.0.0",
|
||||
"description": "How can you help us?",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^9.0.0",
|
||||
"npm": ">= 3.0.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/rtyler/howyoucanhelpus.git"
|
||||
},
|
||||
"author": "R Tyler Croy",
|
||||
"license": "AGPL-3.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/rtyler/howyoucanhelp.us/issues"
|
||||
},
|
||||
"homepage": "https://github.com/rtyler/howyoucanhelp.us#readme",
|
||||
"devDependencies": {
|
||||
"@types/service_worker_api": "0.0.9",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
"jest": "^23.4.1",
|
||||
"ts-loader": "^4.4.2",
|
||||
"typescript": "^2.9.2",
|
||||
"webpack": "^4.16.0",
|
||||
"webpack-cli": "^3.0.8",
|
||||
"webpack-dev-server": "^3.1.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@feathersjs/feathers": "^3.1.7",
|
||||
"@types/feathersjs__feathers": "^3.0.4",
|
||||
"feathers-localstorage": "^2.0.2",
|
||||
"winston": "^3.0.0"
|
||||
},
|
||||
"jest": {
|
||||
"collectCoverage": true,
|
||||
"coveragePathIgnorePatterns": [],
|
||||
"coverageReporters": [
|
||||
"json",
|
||||
"lcov",
|
||||
"text-summary"
|
||||
],
|
||||
"coverageThreshold": {
|
||||
"global": {
|
||||
"statements": 87,
|
||||
"branches": 63,
|
||||
"functions": 70,
|
||||
"lines": 87
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
66
src/index.ts
66
src/index.ts
|
@ -1,3 +1,69 @@
|
|||
import feathers from '@feathersjs/feathers';
|
||||
|
||||
const app = feathers();
|
||||
console.debug('Initialized feathers');
|
||||
|
||||
// XXX Hack
|
||||
declare var Notification: any;
|
||||
|
||||
if ('PushManager' in window) {
|
||||
// Push is available!
|
||||
console.debug('Push is enabled for this browser');
|
||||
}
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
// Service Workers are available
|
||||
console.debug('Service Workers are enabled for this browser');
|
||||
}
|
||||
|
||||
function askPermission() {
|
||||
return new Promise(function(resolve: Function, reject: Function) {
|
||||
const permissionResult = Notification.requestPermission(function(result: string) {
|
||||
resolve(result);
|
||||
});
|
||||
|
||||
if (permissionResult) {
|
||||
permissionResult.then(resolve, reject);
|
||||
}
|
||||
})
|
||||
.then(function(permissionResult: string) {
|
||||
if (permissionResult !== 'granted') {
|
||||
throw new Error('We weren\'t granted permission.');
|
||||
}
|
||||
else {
|
||||
const n = new Notification('Thanks for granting notification permissions!', {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
console.debug('Window loaded');
|
||||
askPermission();
|
||||
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
|
||||
serviceWorkerRegistration.pushManager.subscribe({userVisibleOnly: true})
|
||||
.then(function(subscription) {
|
||||
// The subscription was successful
|
||||
console.log('subscription successful');
|
||||
|
||||
// TODO: Send the subscription subscription.endpoint
|
||||
// to your server and save it to send a push message
|
||||
// at a later date
|
||||
// return sendSubscriptionToServer(subscription);
|
||||
})
|
||||
.catch(function(e) {
|
||||
if (Notification.permission === 'denied') {
|
||||
// The user denied the notification permission which
|
||||
// means we failed to subscribe and the user will need
|
||||
// to manually change the notification permission to
|
||||
// subscribe to push messages
|
||||
console.debug('Permission for Notifications was denied');
|
||||
} else {
|
||||
// A problem occurred with the subscription, this can
|
||||
// often be down to an issue or lack of the gcm_sender_id
|
||||
// and / or gcm_user_visible_only
|
||||
console.debug('Unable to subscribe to push.', e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
import feathers from '@feathersjs/feathers';
|
||||
|
||||
const app = feathers();
|
||||
console.debug('Service Worker initialized');
|
||||
|
|
@ -15,7 +15,7 @@ if [[ "${1}" =~ "--" ]]; then
|
|||
COMMAND="node $@";
|
||||
fi;
|
||||
|
||||
exec docker run --rm ${TTY_ARGS} \
|
||||
exec docker run --rm ${TTY_ARGS} --net host \
|
||||
-u $(id -u):$(id -g) \
|
||||
-w ${PWD} \
|
||||
--mount type=tmpfs,destination=/.npm \
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"outDir": "./dist/",
|
||||
"noImplicitAny": true,
|
||||
"module": "es6",
|
||||
"target": "es5",
|
||||
"target": "es2015",
|
||||
"allowJs": true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
entry: './src/index.ts',
|
||||
entry: {
|
||||
main: './src/index.ts',
|
||||
worker: './src/service-worker.ts',
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
|
@ -11,12 +15,17 @@ module.exports = {
|
|||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
template: "./index.html"
|
||||
}),
|
||||
],
|
||||
resolve: {
|
||||
extensions: [ '.tsx', '.ts', '.js' ]
|
||||
},
|
||||
output: {
|
||||
filename: 'main.js',
|
||||
path: path.resolve(__dirname, 'dist')
|
||||
filename: '[name].js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue