specify installation repository, fix tmpdir creation
This commit is contained in:
parent
53fc842210
commit
a4fb2ef5de
@ -17,18 +17,9 @@ export class RepositoryManager {
|
||||
|
||||
constructor(private env: IEnvironment, private plugins: PluginManager) {}
|
||||
|
||||
public repoProvidesPlugin(repo: IRepository, name: string | IPlugin | IPluginManifest): IRepoPluginDef | null {
|
||||
let realName: string;
|
||||
if (typeof name === 'string') {
|
||||
realName = name;
|
||||
} else if ('manifest' in name) {
|
||||
realName = name.manifest.name;
|
||||
} else {
|
||||
realName = name.name;
|
||||
}
|
||||
|
||||
public repoProvidesPlugin(repo: IRepository, mf: IPluginManifest): IRepoPluginDef | null {
|
||||
for (const plugin of repo.plugins) {
|
||||
if (plugin.name === realName) {
|
||||
if (plugin.name === mf.name && mf.repository === repo.name) {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
@ -60,17 +51,25 @@ export class RepositoryManager {
|
||||
}
|
||||
|
||||
public async installPlugin(name: string): Promise<IPluginManifest> {
|
||||
const repo = this.findRepoForPlugin(name);
|
||||
let repo;
|
||||
if (name.indexOf('/') !== -1) {
|
||||
const naming = name.split('/');
|
||||
repo = this.getRepoByName(naming[0]);
|
||||
name = naming[1];
|
||||
} else {
|
||||
repo = this.findRepoForPlugin(name);
|
||||
}
|
||||
|
||||
if (!repo) {
|
||||
throw new Error('Could not find a repository for a plugin named ' + name);
|
||||
}
|
||||
|
||||
const srcFile = name + '.plugin.tgz';
|
||||
const pluginPath = repo.url + '/' + srcFile;
|
||||
const tempdir = path.join(this.env.path, await fs.mkdtemp('.sbdl'));
|
||||
const tempdir = await fs.mkdtemp(path.join(this.env.path, '.sbdl'));
|
||||
const tempfile = path.join(tempdir, srcFile);
|
||||
let manifest;
|
||||
|
||||
let manifest: IPluginManifest;
|
||||
try {
|
||||
const save = await httpGET(pluginPath, {}, false, tempfile);
|
||||
const extract = await tar.x({
|
||||
@ -93,8 +92,12 @@ export class RepositoryManager {
|
||||
throw new Error('Not a valid plugin manifest file.');
|
||||
}
|
||||
manifest = loadManifest;
|
||||
const fp = path.join(this.env.pluginsPath, manifest.name);
|
||||
manifest.fullPath = fp;
|
||||
manifest.repository = repo.name;
|
||||
|
||||
await fs.copy(findByName, path.join(this.env.pluginsPath, manifest.name));
|
||||
await fs.writeJSON(manifestFile, manifest);
|
||||
await fs.copy(findByName, fp);
|
||||
} catch (e) {
|
||||
await fs.remove(tempdir);
|
||||
throw e;
|
||||
|
Loading…
Reference in New Issue
Block a user