Add basic file watching
This commit is contained in:
parent
c9f6998e89
commit
c4926a7444
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
20
lib/index.ts
20
lib/index.ts
|
@ -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" }));
|
||||||
|
@ -60,6 +76,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);
|
||||||
|
|
||||||
const apRouter = Router();
|
const apRouter = Router();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue