Add support for intellisense imports for the vscode extension
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Fabian Stamm 2021-01-15 02:32:51 +01:00
parent 6bc090e51b
commit 9dfb8d65d3
7 changed files with 134 additions and 13 deletions

View File

@ -9,8 +9,6 @@ declare namespace JSX {
} }
} }
export { Fragment };
export type Element = { export type Element = {
component: Component | string | typeof Fragment; component: Component | string | typeof Fragment;
props: any; props: any;
@ -34,6 +32,10 @@ export function h(
}; };
} }
const createElement = h;
export { Fragment, createElement };
export async function renderSSR(element: Element | string): Promise<string> { export async function renderSSR(element: Element | string): Promise<string> {
if (typeof element === "string") return element; if (typeof element === "string") return element;
else if (typeof element.component === "string") else if (typeof element.component === "string")

View File

@ -45,6 +45,9 @@ for (const key in env) {
case "S3_REGION": case "S3_REGION":
config.s3 = { ...(config.s3 || {}), region: env[key] }; config.s3 = { ...(config.s3 || {}), region: env[key] };
break; break;
case "WEB_URL":
config.web.url = env[key];
break;
case "WEB_TRACKING": case "WEB_TRACKING":
config.web.tracking = env[key]; config.web.tracking = env[key];
break; break;
@ -59,6 +62,10 @@ if (config.general.dev) {
console.warn("Dev mode active!!!"); console.warn("Dev mode active!!!");
} }
if (!config.web.url) {
console.error("The web.url configuration has to be set!");
}
console.log("Known users:", Object.keys(config.user)); console.log("Known users:", Object.keys(config.user));
export default config; export default config;

View File

@ -38,9 +38,11 @@ api(app.group("/api"));
import raw from "./http/raw.ts"; import raw from "./http/raw.ts";
raw(app.group("/raw")); raw(app.group("/raw"));
import intellisense from "./http/intellisense.ts";
intellisense(app.group("/.well-known"));
import view from "./http/views.ts"; import view from "./http/views.ts";
view(app); view(app);
// function logNode(router: Node, indent = 0) { // function logNode(router: Node, indent = 0) {
// trees.map((tree) => { // trees.map((tree) => {
// console.log("Path:", tree.path); // console.log("Path:", tree.path);

View File

@ -1,7 +1,13 @@
import { ABC, Path, Compress, FS, Colors, S3Error } from "../deps.ts"; import { ABC, Path, Compress, FS, Colors, S3Error } from "../deps.ts";
import bucket from "../s3.ts"; import bucket from "../s3.ts";
import { isValidPackageName, basicauth, isValidFullVersion } from "../utils.ts"; import {
isValidPackageName,
basicauth,
isValidFullVersion,
getAbsolutePackageVersion,
getBucketFilePath,
} from "../utils.ts";
import db, { IPackage } from "../db.ts"; import db, { IPackage } from "../db.ts";
@ -21,8 +27,60 @@ export default function api(g: ABC.Group) {
cacheControl cacheControl
); );
g.get("/module", async (ctx) => {
return db.package.find({}).then((res) => res.map((e) => e.name));
});
g.get("/module/:module", async (ctx) => {
const module = await db.package.findOne({ name: ctx.params.module });
if (!module) {
ctx.response.status = 404;
return "// Not found";
} else {
return module.versions;
}
});
g.get("/module/:module/v/:version", async (ctx) => {
const module = await db.package.findOne({ name: ctx.params.module });
if (!module) {
ctx.response.status = 404;
return "// Not found";
} else {
let version = getAbsolutePackageVersion(
module,
ctx.params.version
) as string;
if (!version) {
ctx.response.status = 404;
return "// Not found";
}
const bucketPath = await getBucketFilePath(module.name, version, "/");
const filesItr = bucket.listAllObjects({
batchSize: 100,
prefix: bucketPath,
});
const allowedExts = new Set(
(ctx.queryParams.ext || "js|ts").split("|").map((e) => "." + e)
);
let files: string[] = [];
for await (let file of filesItr) {
const relPath = Path.posix.relative(bucketPath, file.key || "");
const ext = Path.extname(relPath);
if (allowedExts.has(ext)) files.push(relPath);
}
return files;
}
});
// g.post("/getapikey", getApiKey, basicauth("api")); // g.post("/getapikey", getApiKey, basicauth("api"));
g.post("/package/:name", uploadPackage, cacheControl, basicauth("api")); g.post("/package/:name", uploadPackage, cacheControl, basicauth("api"));
g.post("/module/:name", uploadPackage, cacheControl, basicauth("api")); //Switch no module instead of package
} }
// async function getApiKey(ctx: ABC.Context) { // async function getApiKey(ctx: ABC.Context) {

View File

@ -0,0 +1,43 @@
import { ABC } from "../deps.ts";
import config from "../config.ts";
export default function raw(g: ABC.Group) {
g.get("/deno-import-intellisense.json", (ctx) => {
return {
version: 1,
registries: [
{
schema: "/raw/:module([@]*[a-z0-9\\-\\_]*)@:version?/:path*",
variables: [
{
key: "module",
url: `${config.web.url}/api/module`,
},
{
key: "version",
url: `${config.web.url}/api/module/\${module}`,
},
{
key: "path",
url: `${config.web.url}/api/module/\${module}/v/\${{version}}`,
},
],
},
{
schema: "/raw/:module([@]*[a-z0-9\\-\\_]*)/:path*",
variables: [
{
key: "module",
url: `${config.web.url}/api/module`,
},
{
key: "path",
url: `${config.web.url}/api/module/\${module}/v/latest`,
},
],
},
],
};
});
}

View File

@ -46,14 +46,23 @@ async function loadComponent(name: string) {
return mod; return mod;
} }
import index from "./views/index.tsx"; Promise.resolve().then(async () => {
componentCache.set("index", index as Component); console.log("[PRECACHE] Start loading pages");
import pkg from "./views/package.tsx"; await loadComponent("index");
componentCache.set("package", pkg as Component); await loadComponent("package");
import browse_folder from "./views/browse_folder.tsx"; await loadComponent("browse_folder");
componentCache.set("browse_folder", browse_folder as Component); await loadComponent("browse_file");
import browse_file from "./views/browse_file.tsx"; console.log("[PRECACHE] Finished loading pages");
componentCache.set("browse_file", browse_file as Component); });
// import index from "./views/index.tsx";
// componentCache.set("index", index as Component);
// import pkg from "./views/package.tsx";
// componentCache.set("package", pkg as Component);
// import browse_folder from "./views/browse_folder.tsx";
// componentCache.set("browse_folder", browse_folder as Component);
// import browse_file from "./views/browse_file.tsx";
// componentCache.set("browse_file", browse_file as Component);
export default async function render( export default async function render(
name: string, name: string,

View File

@ -99,7 +99,7 @@ export function getAbsolutePackageVersion(
const versions = pkg.versions.sort(sortVersions).reverse(); const versions = pkg.versions.sort(sortVersions).reverse();
if (!version) { if (!version || version === "latest") {
version = versions[0]; version = versions[0];
} else { } else {
const v = versions.filter((e) => e.startsWith(version as string)); const v = versions.filter((e) => e.startsWith(version as string));