|
1 | 1 | import * as log from "../deps/@std/log/mod.ts"; |
| 2 | +import * as path from "../deps/@std/path/mod.ts"; |
2 | 3 |
|
3 | 4 | import { getTemplateInfo, ProcessOptions, processTemplate } from "./process.ts"; |
4 | | -import { makeRelativeUrl } from "./utils.ts"; |
| 5 | +import { getInstallDirectories, makeRelativeUrl, mkdirAll } from "./utils.ts"; |
5 | 6 | import * as cache from "./cache.ts"; |
6 | 7 | import { TemplateMap } from "./config.ts"; |
7 | 8 |
|
@@ -67,13 +68,39 @@ export async function installTemplate( |
67 | 68 | }); |
68 | 69 |
|
69 | 70 | if (structure) { |
70 | | - log.info(`Installing ${module.info.name}...`); |
71 | 71 | registry[module.info.name] = { |
72 | 72 | ...module.info, |
73 | 73 | url: url.toString(), |
74 | 74 | }; |
75 | 75 |
|
| 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 | + |
76 | 100 | const files = structure.files || []; |
| 101 | + if (files.length > 0) { |
| 102 | + log.info(`Installing template ${module.info.name}...`); |
| 103 | + } |
77 | 104 | for (let path of files) { |
78 | 105 | if (path.indexOf("..") != -1) { |
79 | 106 | throw new Error(`invalid path ${path}`); |
|
0 commit comments