Skip to content

Install definitions #42

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

Merged
merged 1 commit into from
Mar 21, 2025
Merged
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
31 changes: 29 additions & 2 deletions src/install.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as log from "../deps/@std/log/mod.ts";
import * as path from "../deps/@std/path/mod.ts";

import { getTemplateInfo, ProcessOptions, processTemplate } from "./process.ts";
import { makeRelativeUrl } from "./utils.ts";
import { getInstallDirectories, makeRelativeUrl, mkdirAll } from "./utils.ts";
import * as cache from "./cache.ts";
import { TemplateMap } from "./config.ts";

Expand Down Expand Up @@ -67,13 +68,39 @@ export async function installTemplate(
});

if (structure) {
log.info(`Installing ${module.info.name}...`);
registry[module.info.name] = {
...module.info,
url: url.toString(),
};

const dirs = await getInstallDirectories();
const definitions = structure.definitions || {};
for (const name of Object.keys(definitions)) {
log.info(`Installing definition ${name}...`);
let definitonPath = definitions[name];

if (!definitonPath.startsWith("./")) {
definitonPath = "./" + definitonPath;
}

const download = new URL(definitonPath, url);
try {
const content = await cache.load(download.toString());

const definitionDir = path.join(dirs.definitions, name);
await mkdirAll(definitionDir, 0o700);
const specDir = path.join(definitionDir, "index.axdl");

Deno.writeFileSync(specDir, content);
} catch (e) {
log.warn(`Could not load ${download.toString()}: ${e}`);
}
}

const files = structure.files || [];
if (files.length > 0) {
log.info(`Installing template ${module.info.name}...`);
}
for (let path of files) {
if (path.indexOf("..") != -1) {
throw new Error(`invalid path ${path}`);
Expand Down