Skip to content
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

feature/grouping-static-routes #177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
43 changes: 34 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,40 @@
);

// Add yaml entries for all files outside _app directory, such as favicons
const additionalClientAssets = clientFiles
.filter((file) => !file.startsWith("_app/"))
.map((file) => ({
url: `/${file}`,
// eslint-disable-next-line camelcase
static_files: join("storage", file).replaceAll("\\", "/"),
upload: join("storage", file).replaceAll("\\", "/"),
secure: "always",
}));
const groupedFiles = {};
const additionalClientAssets = [];
// Group files by the first directory in their path
clientFiles.filter((file) => !file.startsWith("_app/")).forEach(path => {

Check failure on line 134 in index.js

View workflow job for this annotation

GitHub Actions / lint

Replace `.filter((file)·=>·!file.startsWith("_app/")).forEach(path` with `⏎········.filter((file)·=>·!file.startsWith("_app/"))⏎········.forEach((path)`
if (path.includes('/')) {

Check failure on line 135 in index.js

View workflow job for this annotation

GitHub Actions / lint

Replace `········if·(path.includes('/'` with `··········if·(path.includes("/"`
const parts = path.split('/');

Check failure on line 136 in index.js

View workflow job for this annotation

GitHub Actions / lint

Replace `··········const·parts·=·path.split('/'` with `············const·parts·=·path.split("/"`
const firstDir = parts[0]; // The first directory in the path

Check failure on line 137 in index.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`

if (!groupedFiles[firstDir]) {

Check failure on line 139 in index.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
groupedFiles[firstDir] = [];
}

Check failure on line 141 in index.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
groupedFiles[firstDir].push(path);

Check failure on line 142 in index.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
} else {

Check failure on line 143 in index.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
const config = {

Check failure on line 144 in index.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
url: `/${path}`,

Check failure on line 145 in index.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
static_files: join("storage", path).replaceAll("\\", "/"),
upload: join("storage", path).replaceAll("\\", "/"),
secure: "always",
}
additionalClientAssets.push(config);
}
});

// Generate configuration objects
Object.keys(groupedFiles).forEach(dir => {
const regexBase = dir + '/(.+/)?([^/]+)'; // Create regex for capturing everything under the directory
const config = {
url: `/${regexBase}`,
static_files: `storage/${dir}/\\1\\2`,
upload: `storage/${regexBase}`,
secure: 'always',
};
additionalClientAssets.push(config);
});

// Load existing app.yaml if it exists
let yaml = {};
Expand Down
Loading