From a6d2df419385a0896eff28c10c98e04e337a0aac Mon Sep 17 00:00:00 2001
From: Omar Rizwan
Date: Mon, 16 Aug 2021 16:43:34 -0700
Subject: [PATCH] extension: Add source code view to routes.html. Del unused
stuff --
background.js and background.js.html -- for now.
---
extension/background.js | 120 ++++++++--------------------------------
1 file changed, 23 insertions(+), 97 deletions(-)
diff --git a/extension/background.js b/extension/background.js
index f140ee9..aa7a4de 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -659,35 +659,22 @@ Routes["/runtime/reload"] = {
});
})();
-// added at first to make development on Safari less painful: Safari
-// normally requires you to recompile the whole Xcode project to
-// deploy any update to background.js.
-Routes["/runtime/background.js"] = {
- usage: '',
- ...makeRouteWithContents(
- async () => {
- // `window.backgroundJS` is (a Promise of) the source code of
- // the file you're reading right now!
- return window.backgroundJS;
- },
- async ({}, buf) => { window.backgroundJS = buf; }
- ),
- async release({fh}) {
- // Note that we eval on release, not on write.
- eval(await window.backgroundJS);
- // TODO: would be better if we could call 'super'.release() so
- // we wouldn't need to involve how Cache works here.
- makeRouteWithContents.Cache.removeObjectForHandle(fh);
- return {};
- }
-};
-
Routes["/runtime/routes.html"] = makeRouteWithContents(async () => {
// WIP
const jsLines = (await window.backgroundJS).split('\n');
- function findRouteLineNumber(path) {
+ function findRouteLineRange(path) {
+ console.log('frlr', path);
for (let i = 0; i < jsLines.length; i++) {
- if (jsLines[i].includes(path)) { return i + 1; }
+ if (jsLines[i].includes(`Routes["${path}"] = `)) { return [
+ i + 1, // + 1 because GitHub line numbers are 1-indexed
+ (function() {
+ // TODO:
+ // find the first bracket on that line after the =
+ // walk forward until we find the corresponding match for it
+ // that's the last line?
+ return i + 2;
+ })()
+ ]; }
}
}
return `
@@ -697,19 +684,24 @@ Routes["/runtime/routes.html"] = makeRouteWithContents(async () => {
` + Object.entries(Routes).map(([path, {usage, description, __isInfill}]) => {
if (__isInfill) { return ''; }
- path = path.substring(1); // drop leading /
let usages = usage ? (Array.isArray(usage) ? usage : [usage]) : [];
- usages = usages.map(u => u.replace('\$0', path));
- const href = `https://github.com/osnr/TabFS/blob/master/extension/background.js#L${findRouteLineNumber(path)}`;
+ usages = usages.map(u => u.replace('\$0', path.substring(1) /* drop leading / */));
+ const lineRange = findRouteLineRange(path);
return `
- - ${path} (source)
+ - ${path.substring(1)}
${description ? `- Description: ${description}
` :
- '- No description!
'}
+ '- No description found!
'}
${usages.length > 0 ? `- Usage:
${usages.map(u => `- ${u}
`).join('\n')}
- ` : '- No usage!
'}`;
+ ` : '- No usage found!
'}
+ ${lineRange ?
+ `
+ Source code (on GitHub)
+ ${jsLines[lineRange[0] - 1]}
+
` : '- No source code found!
'}
+ `;
}).join('\n') + `
- (very work in progress)
-
- ${classedJs}
-
-
-
@@ -717,72 +709,6 @@ Routes["/runtime/routes.html"] = makeRouteWithContents(async () => {
`;
});
-Routes["/runtime/background.js.html"] = makeRouteWithContents(async () => {
- // WIP
- const classes = [
- [/Routes\["[^\]]+"\] = /, 'route'],
- [/usage:/, 'usage'],
- [/description:/, 'description']
- ];
-
- const js = await window.backgroundJS;
- const classedJs =
- js.split('\n')
- .map((line, i) => {
- const class_ = classes.find(([re, class_]) => re.test(line));
- line = line
- .replace(/&/g, "&")
- .replace(//g, ">")
- .replace(/"/g, """)
- .replace(/'/g, "'");
- if (!class_) { return `
${line}
`; }
- return `
${line}
`;
- })
- .join('');
-
- return `
-
-
-
-
-
-