Initial commit

This commit is contained in:
William Moore 2023-06-05 00:06:36 -05:00
commit c113b2f1fa
11 changed files with 2364 additions and 0 deletions

136
.gitignore vendored Normal file
View File

@ -0,0 +1,136 @@
# ---> Node
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
certs/
build/
public/js/
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

1975
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

30
package.json Normal file
View File

@ -0,0 +1,30 @@
{
"name": "lavender",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "npx tsc && npx rollup -c",
"clean": "rm -rf build",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"date-fns": "^2.30.0",
"lit": "^2.7.5",
"typescript": "^5.1.3"
},
"devDependencies": {
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-terser": "^0.4.3",
"@web/rollup-plugin-copy": "^0.4.0",
"@web/rollup-plugin-html": "^2.0.0",
"@web/rollup-plugin-polyfills-loader": "^2.0.0",
"rollup": "^2.79.1",
"rollup-plugin-minify-html-literals": "^1.2.6",
"rollup-plugin-summary": "^2.0.0"
}
}

9
public/biblevotd.html Normal file
View File

@ -0,0 +1,9 @@
<html>
<head>
<meta http-equiv="refresh" content="3600">
<script type="module" src="./js/BibleGatewayCEB.js"></script>
</head>
<body>
<bible-gateway-ceb></bible-gateway-ceb>
</body>
</html>

8
public/rainfall.html Normal file
View File

@ -0,0 +1,8 @@
<html>
<head>
<script type="module" src="./js/Rainfall.js"></script>
</head>
<body>
<lavendar-rainfall></lavendar-rainfall>
</body>
</html>

8
public/teasense.html Normal file
View File

@ -0,0 +1,8 @@
<html>
<head>
<script type="module" src="./js/TeaSense.js"></script>
</head>
<body>
<tea-sense></tea-sense>
</body>
</html>

30
rollup.config.mjs Normal file
View File

@ -0,0 +1,30 @@
// Import rollup plugins
import { rollupPluginHTML as html } from "@web/rollup-plugin-html";
import {copy} from '@web/rollup-plugin-copy';
import resolve from '@rollup/plugin-node-resolve';
import * as terser from '@rollup/plugin-terser';
import * as minifyHTML from 'rollup-plugin-minify-html-literals';
import summary from 'rollup-plugin-summary';
export default {
plugins: [
// Entry point for application build; can specify a glob to build multiple
// HTML files for non-SPA app
html({
input: 'public/**.html',
}),
// Resolve bare module specifiers to relative paths
resolve(),
// Print bundle summary
summary(),
// Optional: copy any static assets to build directory
copy({
patterns: ['images/**/*', 'css/**/*.css'],
}),
],
output: {
dir: 'build',
},
experimentalCodeSplitting: true,
preserveEntrySignatures: 'strict',
};

15
src/BibleGatewayCEB.ts Normal file
View File

@ -0,0 +1,15 @@
import { LitElement, html } from 'lit';
import { customElement } from 'lit/decorators.js';
@customElement('bible-gateway-ceb')
export class BibleGatewayCEB extends LitElement {
override render() {
return html`<iframe framespacing="0" width="100%" height="100%" frameborder="no" src="https://www.biblegateway.com/votd/get/?format=html&version=CEB">View Verse of the Day</iframe>`;
}
}
declare global {
interface HTMLElementTagNameMap {
'bible-gateway-ceb': BibleGatewayCEB;
}
}

59
src/Rainfall.ts Normal file
View File

@ -0,0 +1,59 @@
import { LitElement, html, css } from 'lit';
import { customElement } from 'lit/decorators.js';
@customElement('lavendar-rainfall')
export class Rainfall extends LitElement {
value = 0.0;
constructor() {
super();
this.pullValueFromBackend();
}
async pullValueFromBackend() {
const response = await fetch('https://sensors.mooreforge.com/api/rainfall');
const data = await response.json();
const result = data
.map((datum: any) => datum.value)
.reduce((accum: number, datum: number) => accum + datum, 0);
this.setValue(result);
setTimeout(() => this.pullValueFromBackend(), 60000);
}
setValue(newValue: number) {
this.value = newValue;
this.requestUpdate();
}
static override styles = [
css`
.gauge-body {
display: flex;
flex-direction: column;
justify-content: space-between;
align-content: space-between;
text-align: center;
}
.gauge-label {
font-weight: bold;
}
`
]
override render() {
return html`
<div class="gauge-body">
<div class="gauge-label">Rainfall (mm water)</div>
<div>${this.value}</div>
</div>
`;
}
}
declare global {
interface HTMLElementTagNameMap {
'lavendar-rainfall': Rainfall;
}
}

60
src/TeaSense.ts Normal file
View File

@ -0,0 +1,60 @@
import { LitElement, html, css } from 'lit';
import { customElement } from 'lit/decorators.js';
import { isBefore } from 'date-fns';
@customElement('tea-sense')
export class TeaSense extends LitElement {
temp = 0.0;
constructor() {
super();
this.pullTempFromBackend();
}
async pullTempFromBackend() {
const response = await fetch('https://sensors.mooreforge.com/api/teasense');
const data = await response.json();
const result = data
.reduce((accum: any, datum: any) => (((accum && isBefore(new Date(accum?.timestamp), new Date(datum?.timestamp))) || !accum) ? datum : accum));
this.setTemp(result.value);
setTimeout(() => this.pullTempFromBackend(), 5000);
}
setTemp(newTemp: number) {
this.temp = newTemp;
this.requestUpdate();
}
static override styles = [
css`
.gauge-body {
display: flex;
flex-direction: column;
justify-content: space-between;
align-content: space-between;
text-align: center;
}
.gauge-label {
font-weight: bold;
}
`
]
override render() {
return html`
<div class="gauge-body">
<div class="gauge-label">TeaSense</div>
<div class="gauge-label">Temperature (in C)</div>
<div>${this.temp}</div>
</div>
`;
}
}
declare global {
interface HTMLElementTagNameMap {
'tea-sense': TeaSense;
}
}

34
tsconfig.json Normal file
View File

@ -0,0 +1,34 @@
{
"compilerOptions": {
"target": "ES2019",
"module": "ES2020",
"lib": ["ES2019", "DOM", "DOM.Iterable"],
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"inlineSources": true,
"outDir": "./public/js",
"rootDir": "./src",
"strict": true,
"isolatedModules": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitThis": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"noImplicitOverride": true,
"useDefineForClassFields": false,
"plugins": [
{
"name": "ts-lit-plugin",
"strict": true
}
]
},
"compileOnSave": true
}