Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

various improvements to manifest generation - fixes #148 #152

Merged
merged 1 commit into from
Mar 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/cli/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,23 @@ export default async function dev() {
// TODO watch the configs themselves?
const compilers = create_compilers();

function watch_files(pattern: string, callback: () => void) {
function watch_files(pattern: string, events: string[], callback: () => void) {
const watcher = chokidar.watch(pattern, {
persistent: false
persistent: true,
ignoreInitial: true
});

watcher.on('add', callback);
watcher.on('change', callback);
watcher.on('unlink', callback);
events.forEach(event => {
watcher.on(event, callback);
});
}

watch_files('routes/**/*.+(html|js|mjs)', () => {
watch_files('routes/**/*', ['add', 'unlink'], () => {
const routes = create_routes();
create_app({ routes, dev_port });
});

watch_files('app/template.html', () => {
watch_files('app/template.html', ['change'], () => {
const template = create_template();
// TODO reload current page?
});
Expand Down
18 changes: 16 additions & 2 deletions src/core/create_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@ import { fudge_mtime, posixify, write } from './utils';
import { dev } from '../config';
import { Route } from '../interfaces';

// in dev mode, we avoid touching the fs unnecessarily
let last_client_manifest: string = null;
let last_server_manifest: string = null;

export default function create_app({ routes, dev_port }: {
routes: Route[];
dev_port: number;
}) {
mkdirp.sync('app/manifest');

write('app/manifest/client.js', generate_client(routes, dev_port));
write('app/manifest/server.js', generate_server(routes));
const client_manifest = generate_client(routes, dev_port);
const server_manifest = generate_server(routes);

if (client_manifest !== last_client_manifest) {
write(`app/manifest/client.js`, client_manifest);
last_client_manifest = client_manifest;
}

if (server_manifest !== last_server_manifest) {
write(`app/manifest/server.js`, server_manifest);
last_server_manifest = server_manifest;
}
}

function generate_client(routes: Route[], dev_port?: number) {
Expand Down