Add Composer and npm to project

This commit is contained in:
Florine W. Dekker 2022-08-09 19:20:02 +02:00
parent a58548300a
commit 7799b522fd
Signed by: FWDekker
GPG Key ID: D3DCFAA8A4560BE0
15 changed files with 456 additions and 28 deletions

11
.editorconfig Normal file
View File

@ -0,0 +1,11 @@
root = true
[*]
charset = utf-8
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
composer.lock binary
package-lock.json binary

133
.gitignore vendored
View File

@ -1,3 +1,132 @@
## Node
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# 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
# 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 variables file
.env
.env.test
# 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
# 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
.pnp.*
## Composer
composer.phar
/vendor/
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
## Custom
dist/
src/main/.death-notifier.db
src/main/config.ini
src/main/mailer
src/main/config.ini.php

132
Gruntfile.js Normal file
View File

@ -0,0 +1,132 @@
const path = require("path");
module.exports = grunt => {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
clean: {
default: ["dist/"],
},
copy: {
composer: {
files: [{expand: true, cwd: "./", src: "vendor/**", dest: "dist/", flatten: false}]
},
css: {
files: [{expand: true, cwd: "src/main/", src: "**/*.css", dest: "dist/", flatten: true}]
},
html: {
files: [{expand: true, cwd: "src/main/", src: "**/*.html", dest: "dist/", flatten: true}]
},
php: {
files: [{expand: true, cwd: "src/main/", src: "**/*.php", dest: "dist/", flatten: true}]
},
},
focus: {
dev: {
include: ["css", "html", "php", "ts"],
},
},
replace: {
dev: {
src: ["./dist/**/*.html", "./dist/**/*.js", "./dist/**/*.php"],
replacements: [
{
from: "%%VERSION_NUMBER%%",
to: "<%= pkg.version %>+" + new Date().toISOString().slice(0, 19).replace(/[-:T]/g, "")
}
],
overwrite: true
},
deploy: {
src: ["./dist/**/*.html", "./dist/**/*.js", "./dist/**/*.php"],
replacements: [
{
from: "%%VERSION_NUMBER%%",
to: "<%= pkg.version %>"
}
],
overwrite: true
},
},
watch: {
css: {
files: ["src/main/**/*.css"],
tasks: ["copy:css"],
},
html: {
files: ["src/main/**/*.html"],
tasks: ["copy:html"],
},
php: {
files: ["src/main/**/*.php"],
tasks: ["copy:php"],
},
ts: {
files: ["src/main/**/*.ts"],
tasks: ["webpack:dev", "replace:dev"],
},
},
webpack: {
options: {
entry: "./src/main/js/Main.ts",
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".ts"],
},
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist/"),
},
},
dev: {
mode: "development",
devtool: "inline-source-map",
},
deploy: {
mode: "production",
},
},
});
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-focus");
grunt.loadNpmTasks("grunt-text-replace");
grunt.loadNpmTasks("grunt-webpack");
grunt.registerTask("dev", [
// Pre
"clean",
// Copy files
"copy:composer",
"copy:css",
"copy:html",
"copy:php",
// Compile JS
"webpack:dev",
"replace:dev",
]);
grunt.registerTask("dev:server", ["dev", "focus:dev"]);
grunt.registerTask("deploy", [
// Pre
"clean",
// Copy files
"copy:composer",
"copy:css",
"copy:html",
"copy:php",
// Compile JS
"webpack:deploy",
"replace:deploy",
]);
grunt.registerTask("default", ["dev"]);
};

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Florine W. Dekker
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

23
composer.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "fwdekker/death-notifier",
"description": "Get notified when a famous person dies.",
"version": "0.0.1",
"type": "project",
"license": "MIT",
"homepage": "https://git.fwdekker.com/tools/death-notifier",
"support": {
"issues": "https://git.fwdekker.com/tools/death-notifier/issues",
"source": "https://git.fwdekker.com/tools/death-notifier"
},
"authors": [
{
"name": "Florine W. Dekker",
"email": "florine@fwdekker.com"
}
],
"require": {
"ext-sqlite3": "*",
"phpmailer/phpmailer": "^6.5"
},
"minimum-stability": "stable"
}

BIN
composer.lock generated Normal file

Binary file not shown.

BIN
package-lock.json generated Normal file

Binary file not shown.

32
package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "death-notifier",
"version": "0.0.1",
"description": "Get notified when a famous person dies.",
"author": "Florine W. Dekker",
"browser": "dist/bundle.js",
"repository": {
"type": "git",
"url": "git@git.fwdekker.com:tools/death-notifier.git"
},
"private": true,
"scripts": {
"clean": "grunt clean",
"dev": "grunt dev",
"dev:server": "grunt dev:server",
"deploy": "grunt deploy"
},
"devDependencies": {
"grunt": "^1.5.3",
"grunt-cli": "^1.4.3",
"grunt-contrib-clean": "^2.0.1",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-focus": "^1.0.0",
"grunt-text-replace": "^0.4.0",
"grunt-webpack": "^5.0.0",
"ts-loader": "^9.3.1",
"typescript": "^4.7.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
}
}

View File

@ -1,6 +1,8 @@
<?php
http_response_code(404);
exit();
namespace main;
use SQLite3;
class Database
@ -21,7 +23,9 @@ class Database
function install(): void
{
$this->db->exec("CREATE TABLE users(uuid text primary key not null, email text not null, password text not null);");
// TODO: Do email verification stuff: `current_email` and `email_is_verified` and stuff
$this->db->exec("CREATE TABLE trackings(user_uuid text not null, person_name text not null, is_deceased int not null)");
}
function add_user($uuid, $email, $password): bool

View File

@ -1,40 +1,35 @@
<?php
namespace main;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use SQLite3;
require "mailer/Exception.php";
require "mailer/PHPMailer.php";
require "mailer/SMTP.php";
/** @noinspection PhpIncludeInspection Exists after `npm run deploy` */
require_once __DIR__ . "/vendor/autoload.php";
require_once __DIR__ . "/Database.php";
header("Content-type:application/json;charset=utf-8");
//header("Content-type:application/json;charset=utf-8");
$config = parse_ini_file("config.default.ini", process_sections: true, scanner_mode: INI_SCANNER_TYPED);
if (file_exists("config.ini")) {
$config_custom = parse_ini_file("config.ini", process_sections: true, scanner_mode: INI_SCANNER_TYPED);
$config = parse_ini_file("config.default.ini.php", process_sections: true, scanner_mode: INI_SCANNER_TYPED);
if (file_exists("config.ini.php")) {
$config_custom = parse_ini_file("config.ini.php", process_sections: true, scanner_mode: INI_SCANNER_TYPED);
$config = array_merge($config, $config_custom);
}
// TODO: CSRF token check!
// TODO: GET should never modify state!!!
if (isset($_GET["action"]) && $_GET["action"] == "install") {
if (file_exists($config["database"]["filename"])) {
unlink($config["database"]["filename"]);
}
$db = new SQLite3($config["database"]["filename"]);
$db->exec("CREATE TABLE users(uuid text primary key not null, email text not null, password text not null);");
// TODO: Do email verification stuff: `current_email` and `email_is_verified` and stuff
$db->exec("CREATE TABLE trackings(user_uuid text not null, person_name text not null, is_deceased int not null)");
$db->close();
}
if (!file_exists($config["database"]["filename"])) {
exit();
(new SQLite3($config["database"]["filename"]))->close();
$db = new Database($config["database"]["filename"], SQLITE3_OPEN_READWRITE);
$db->install();
$db->close();
}
session_start();

View File

@ -1,3 +1,5 @@
;<?php exit(); ?>
[database]
filename = .death-notifier.db

View File

@ -1,9 +1,58 @@
<!---->
<!--Start the session and generate a random token.-->
<!--session_start();-->
<!--$_SESSION["token"] = bin2hex(random_bytes(32));-->
<!--Embed the CSRF token into the HTML form.-->
<!--<input type="hidden" name="token" value="--><?//=$_SESSION["token"]?><!--"/>-->
<!--<input type="hidden" name="token" value="$_SESSION["token"]" />-->
<!--When the form is submitted, cross-check the submitted token against the session.-->
<!--if (!isset($_POST["token"]) || !isset($_SESSION["token"])) { exit(); }-->
<!--if ($_POST["token"] == $_SESSION["token"]) { DO PROCESSING } -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="Florine W. Dekker" />
<meta name="application-name" content="Death Notifier" />
<meta name="description" content="Get notified when a famous person dies." />
<meta name="theme-color" content="#0033cc" />
<title>Death Notifier | FWDekker</title>
<link rel="stylesheet" href="https://static.fwdekker.com/fonts/roboto/roboto.css" />
<link rel="stylesheet" href="https://static.fwdekker.com/lib/template/2.x.x/template.css" />
<!--suppress HtmlUnknownTarget -->
<link rel="stylesheet" href="main.css?v=%%VERSION_NUMBER%%" />
<script async src="https://stats.fwdekker.com/count.js"
data-goatcounter="https://stats.fwdekker.com/count"></script>
</head>
<body>
<noscript>
<img src="https://stats.fwdekker.com/count?p=/tools/death-notifier/" alt="Counting pixel" />
<p>
This website does not function if JavaScript is disabled.
Please check the
<a href="https://www.enable-javascript.com/">instructions on how to enable JavaScript in your web browser</a>.
</p>
</noscript>
<main class="hidden">
<div id="nav"></div>
<div id="contents">
<div id="header"></div>
<!-- Input -->
<section class="container">
CONTENTS
</section>
</div>
<div id="footer"></div>
</main>
<script src="https://static.fwdekker.com/lib/template/2.x.x/template.js"></script>
<!--suppress HtmlUnknownTarget -->
<script src="bundle.js?v=%%VERSION_NUMBER%%"></script>
</body>
</html>

17
src/main/js/Main.ts Normal file
View File

@ -0,0 +1,17 @@
// @ts-ignore
const {$, doAfterLoad, footer, header, nav} = window.fwdekker;
doAfterLoad(() => {
// Initialize template
$("#nav").appendChild(nav("/Tools/Death-Notifier/"));
$("#header").appendChild(header({
title: "Death Notifier",
description: "Get notified when a famous person dies"
}));
$("#footer").appendChild(footer({
vcsURL: "https://git.fwdekker.com/tools/death-notifier/",
version: "v%%VERSION_NUMBER%%"
}));
$("main").classList.remove("hidden");
});

11
tsconfig.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es6",
"strict": true,
"rootDir": "./src/main/js/",
"outDir": "./dist/js/"
},
"include": [
"src/main/js/**/*.ts"
]
}