@microtica/code-repository
Advanced tools
Comparing version 2.1.5 to 2.1.6
@@ -15,3 +15,5 @@ /// <reference types="node" /> | ||
listVersions(repoName: string): Promise<RepoVersion[]>; | ||
downloadVersion(repoName: string, version: string, hooks?: _.Dictionary<NodeJS.WritableStream>, subPath?: string): NodeJS.ReadableStream; | ||
downloadVersion(repoName: string, version: string, hooks?: _.Dictionary<NodeJS.WritableStream & { | ||
processed?: boolean; | ||
}>, subPath?: string): NodeJS.ReadableStream; | ||
} |
@@ -101,11 +101,8 @@ "use strict"; | ||
const packageArchive = archiver('zip', { zlib: { level: 9 } }); | ||
let bitbucketPathPrefix; | ||
// Pack code package in ZIP format | ||
// Pack code package | ||
codeReponse.pipe(unzip.Parse()) | ||
.on('entry', (entry) => { | ||
if (!bitbucketPathPrefix) { | ||
bitbucketPathPrefix = entry.path.split('/')[0]; | ||
} | ||
const rootFolder = entry.path.split('/')[0]; | ||
// if it does not start with the prefix | ||
if (!entry.path.startsWith(`${bitbucketPathPrefix}/${subPath}`)) { | ||
if (!entry.path.startsWith(`${rootFolder}/${subPath}`)) { | ||
return; | ||
@@ -118,4 +115,8 @@ } | ||
// at this point we have what we need. | ||
const normalizedPath = path.normalize(`${bitbucketPathPrefix}/${subPath}/`); | ||
const name = entry.path.split(normalizedPath)[1]; | ||
const normalizedPath = path.normalize(`${rootFolder}/${subPath}/`); | ||
let name = entry.path.split(normalizedPath)[1]; | ||
// if provided subPath does not exist | ||
if (!name) { | ||
name = entry.path.split(`${rootFolder}/`)[1]; | ||
} | ||
console.log('[INFO] Zip:', name); | ||
@@ -128,3 +129,4 @@ packageArchive.append(entry, { name }); | ||
.on('entry', (entry) => { | ||
const normalizedPath = path.normalize(`${bitbucketPathPrefix}/${subPath}/`); | ||
const rootFolder = entry.path.split('/')[0]; | ||
const normalizedPath = path.normalize(`${rootFolder}/${subPath}/`); | ||
const name = entry.path.split(normalizedPath)[1]; | ||
@@ -134,3 +136,8 @@ if (hooks[name]) { | ||
entry.pipe(hooks[name]); | ||
hooks[name].processed = true; | ||
} | ||
}) | ||
.on('finish', () => { | ||
const missingHooks = _.filter(hooks, h => !h.processed); | ||
_.forEach(missingHooks, stream => stream.end()); | ||
}); | ||
@@ -137,0 +144,0 @@ return packageArchive; |
{ | ||
"name": "@microtica/code-repository", | ||
"version": "2.1.5", | ||
"version": "2.1.6", | ||
"description": "Integration module with git repository providers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
16067
227