Skip to content

Commit b7919f1

Browse files
authored
Install definitions (#42)
1 parent 5b50cb9 commit b7919f1

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/install.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as log from "../deps/@std/log/mod.ts";
2+
import * as path from "../deps/@std/path/mod.ts";
23

34
import { getTemplateInfo, ProcessOptions, processTemplate } from "./process.ts";
4-
import { makeRelativeUrl } from "./utils.ts";
5+
import { getInstallDirectories, makeRelativeUrl, mkdirAll } from "./utils.ts";
56
import * as cache from "./cache.ts";
67
import { TemplateMap } from "./config.ts";
78

@@ -67,13 +68,39 @@ export async function installTemplate(
6768
});
6869

6970
if (structure) {
70-
log.info(`Installing ${module.info.name}...`);
7171
registry[module.info.name] = {
7272
...module.info,
7373
url: url.toString(),
7474
};
7575

76+
const dirs = await getInstallDirectories();
77+
const definitions = structure.definitions || {};
78+
for (const name of Object.keys(definitions)) {
79+
log.info(`Installing definition ${name}...`);
80+
let definitonPath = definitions[name];
81+
82+
if (!definitonPath.startsWith("./")) {
83+
definitonPath = "./" + definitonPath;
84+
}
85+
86+
const download = new URL(definitonPath, url);
87+
try {
88+
const content = await cache.load(download.toString());
89+
90+
const definitionDir = path.join(dirs.definitions, name);
91+
await mkdirAll(definitionDir, 0o700);
92+
const specDir = path.join(definitionDir, "index.axdl");
93+
94+
Deno.writeFileSync(specDir, content);
95+
} catch (e) {
96+
log.warn(`Could not load ${download.toString()}: ${e}`);
97+
}
98+
}
99+
76100
const files = structure.files || [];
101+
if (files.length > 0) {
102+
log.info(`Installing template ${module.info.name}...`);
103+
}
77104
for (let path of files) {
78105
if (path.indexOf("..") != -1) {
79106
throw new Error(`invalid path ${path}`);

0 commit comments

Comments
 (0)