mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 19:45:26 +00:00
26 lines
958 B
TypeScript
26 lines
958 B
TypeScript
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import glob from 'glob';
|
|
import create_routes from './create_routes';
|
|
import { fudge_mtime, posixify, write } from './utils';
|
|
import { Route } from '../interfaces';
|
|
|
|
export default function create_serviceworker({ routes, client_files }: {
|
|
routes: Route[];
|
|
client_files: string[];
|
|
}) {
|
|
const assets = glob.sync('**', { cwd: 'assets', nodir: true });
|
|
|
|
let code = `
|
|
// This file is generated by Sapper — do not edit it!
|
|
export const timestamp = ${Date.now()};
|
|
|
|
export const assets = [\n\t${assets.map((x: string) => `"${x}"`).join(',\n\t')}\n];
|
|
|
|
export const shell = [\n\t${client_files.map((x: string) => `"${x}"`).join(',\n\t')}\n];
|
|
|
|
export const routes = [\n\t${routes.filter((r: Route) => r.type === 'page' && !/^_[45]xx$/.test(r.id)).map((r: Route) => `{ pattern: ${r.pattern} }`).join(',\n\t')}\n];
|
|
`.replace(/^\t\t/gm, '').trim();
|
|
|
|
write('app/manifest/service-worker.js', code);
|
|
} |