Add basic file watching

This commit is contained in:
Shadowfacts 2021-09-09 10:31:03 -04:00
parent c9f6998e89
commit c4926a7444
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 4273 additions and 37 deletions

View File

@ -1,7 +1,6 @@
import { promises as fs } from "fs"; import { promises as fs } from "fs";
import * as util from "../util"; import * as util from "../util";
import sass, { Result as SassResult } from "sass"; import sass, { Result as SassResult } from "sass";
import ejs from "ejs";
function renderSass(data: string): Promise<SassResult> { function renderSass(data: string): Promise<SassResult> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -33,8 +32,4 @@ export default async function css() {
generate("light"); generate("light");
generate("dark"); generate("dark");
generate("auto"); generate("auto");
if (process.env.NODE_ENV === "development") {
require("fs").watch("site/css/", css);
}
} }

View File

@ -10,6 +10,7 @@ import validateHttpSig from "./activitypub/middleware/http-signature";
import "reflect-metadata"; import "reflect-metadata";
import { createConnection} from "typeorm"; import { createConnection} from "typeorm";
import * as path from "path"; import * as path from "path";
import chokidar from "chokidar";
async function generate(): Promise<Page[]> { async function generate(): Promise<Page[]> {
generators.copy(); generators.copy();
@ -28,7 +29,22 @@ async function generate(): Promise<Page[]> {
return posts; return posts;
} }
function watch() {
const watcher = chokidar.watch("site/", {
ignoreInitial: true,
});
watcher.on("all", (event, path) => {
console.log(`Regenerating due to ${event} ${path}`);
// todo: this could be smarter about not regenerating everything
generate();
});
}
(async () => { (async () => {
if (process.env.NODE_ENV === undefined) {
process.env.NODE_ENV = "development";
}
const app = express(); const app = express();
app.use(morgan("dev")); app.use(morgan("dev"));
app.use(bodyParser.json({ type: "application/activity+json" })); app.use(bodyParser.json({ type: "application/activity+json" }));
@ -59,6 +75,10 @@ async function generate(): Promise<Page[]> {
}); });
const posts = await generate(); const posts = await generate();
if (process.env.NODE_ENV === "development") {
watch();
}
await activitypub.articles.setup(posts); await activitypub.articles.setup(posts);

4284
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,7 @@
"@types/sqlite3": "^3.1.4", "@types/sqlite3": "^3.1.4",
"@types/uuid": "^3.4.4", "@types/uuid": "^3.4.4",
"body-parser": "^1.18.3", "body-parser": "^1.18.3",
"chokidar": "^3.5.2",
"date-fns": "^1.30.1", "date-fns": "^1.30.1",
"ejs": "^2.6.1", "ejs": "^2.6.1",
"express": "^4.16.4", "express": "^4.16.4",