Skip to content

Adding a routes.json manifest file #1824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 23 additions & 1 deletion packages/kit/src/core/create_app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function create_app({ manifest_data, output, cwd = process.cwd() }) {
const base = path.relative(cwd, dir);

write_if_changed(`${dir}/manifest.js`, generate_client_manifest(manifest_data, base));

write_if_changed(`${dir}/routes.json`, generate_route_manifest(manifest_data));
write_if_changed(`${dir}/root.svelte`, generate_app(manifest_data, base));
}

Expand Down Expand Up @@ -107,6 +107,28 @@ function generate_client_manifest(manifest_data, base) {
`);
}

/**
* Information about all page routes, in a language-agnostic JSON file.
*
* @param {ManifestData} manifest_data
* @returns {string}
*/
function generate_route_manifest(manifest_data) {
const page_routes = manifest_data.routes
.map((route) => {
if (route.type === 'page') {
const pattern = route.pattern.toString();
return {
pattern: pattern.slice(1, pattern.length - 1), // strip delimiters
params: route.params,
componentPath: route.a[route.a.length - 1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there won't be any .svelte files in the build directory, so is this really useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True but it's an easy transformation to get from that to the HTML file. Basically replacing .svelte with .html and possibly adding an /index.

};
}
})
.filter((route) => !!route);
return JSON.stringify(page_routes, undefined, 2);
}

/**
* @param {ManifestData} manifest_data
* @param {string} base
Expand Down