Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondra committed Feb 17, 2025
1 parent 3139a2b commit bda747c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
48 changes: 40 additions & 8 deletions setup.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,52 @@ async function copyFile(source: string, destination: string): Promise<void> {
}
}

const prepareDir = async (dir: string) => {
try {
await fs.rm(dir, { recursive: true, force: true });
await fs.mkdir(dir , { recursive: true });
} catch (error) {
console.error(`Error preparing directory: ${dir} ${error}`);
}
}

const downloadFile = async (url: string, destinationFile: string) => {
const content = await (await fetch(url)).text();
await fs.writeFile(destinationFile, content);
}

const downloadEspHomeSchemas = async () => {
const fileList: any[] = await (await fetch("https://api.github.com/repos/esphome/dashboard/contents/schema")).json();

await fs.rm("./public/schema", { recursive: true, force: true });
await fs.mkdir("./public/schema", { recursive: true });
await prepareDir("./public/schema");

const promises = fileList.map((file) => downloadFile(file.download_url, `./public/schema/${file.name}`));

await Promise.all(promises)
console.log(`Downloaded ${promises.length} EspHome schema files`);
}

const downloadEspHomeMonacoFiles = async () => {
const downloadSrcEditor = async (fileName: string) =>
downloadFile(`https://raw.githubusercontent.com/esphome/dashboard/main/src/editor/${fileName}`, `./src/3rd-party/esphome-dashboard/src/editor/${fileName}`);

await prepareDir("./src/3rd-party/esphome-dashboard/src/editor");
await prepareDir("./src/3rd-party/esphome-dashboard/src/editor/utils");

const promises = fileList.map(async (file) => {
const content = await (await fetch(file.download_url)).text();
await fs.writeFile(`./public/schema/${file.name}`, content);
});
const promises = [
"completions-handler.ts",
"editor-shims.ts",
"esphome-document.ts",
"esphome-schema.ts",
"hover-handler.ts",
"utils/objects.ts",
"utils/text-buffer.ts",
]
.map((file) => downloadSrcEditor(file));

await Promise.all(promises)
console.log(`Downloaded ${fileList.length} EspHome schema files`);
console.log(`Downloaded ${promises.length} EspHome Monaco-Editor files`);
}

await downloadEspHomeSchemas();
//await downloadEspHomeSchemas();
await downloadEspHomeMonacoFiles();
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ export class ESPHomeDocuments {
private documents: { [uri: string]: ESPHomeDocument } = {};

update(uri: string, buffer: TextBuffer) {
console.log("update", uri);
const doc = this.documents[uri];
if (doc === undefined) {
this.documents[uri] = new ESPHomeDocument(buffer);
Expand All @@ -245,7 +244,6 @@ export class ESPHomeDocuments {
}

public getDocument(uri: string): ESPHomeDocument {
console.log("getDocument", uri);
return this.documents[uri];
}
}

0 comments on commit bda747c

Please sign in to comment.