@hubspot/local-dev-lib 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/archive.d.ts +3 -1
- package/lib/archive.js +11 -10
- package/package.json +1 -1
package/lib/archive.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { LogCallbacksArg } from '../types/LogCallbacks';
|
|
3
|
+
declare const archiveCallbackKeys: string[];
|
|
2
4
|
type CopySourceToDestOptions = {
|
|
3
5
|
sourceDir?: string;
|
|
4
6
|
includesRootDir?: boolean;
|
|
5
7
|
};
|
|
6
|
-
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions): Promise<boolean>;
|
|
8
|
+
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions, logCallbacks?: LogCallbacksArg<typeof archiveCallbackKeys>): Promise<boolean>;
|
|
7
9
|
export {};
|
package/lib/archive.js
CHANGED
|
@@ -7,17 +7,17 @@ exports.extractZipArchive = void 0;
|
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const os_1 = require("os");
|
|
10
|
-
const util_1 = require("util");
|
|
11
10
|
const extract_zip_1 = __importDefault(require("extract-zip"));
|
|
12
11
|
const fileSystemErrors_1 = require("../errors/fileSystemErrors");
|
|
13
12
|
const standardErrors_1 = require("../errors/standardErrors");
|
|
14
13
|
const logger_1 = require("../utils/logger");
|
|
15
|
-
const extract = (0, util_1.promisify)(extract_zip_1.default);
|
|
16
14
|
const i18nKey = 'lib.archive';
|
|
17
|
-
|
|
15
|
+
const archiveCallbackKeys = ['init', 'copy'];
|
|
16
|
+
async function extractZip(name, zip, logCallbacks) {
|
|
17
|
+
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
18
18
|
const result = { extractDir: '', tmpDir: '' };
|
|
19
19
|
const TMP_FOLDER_PREFIX = `hubspot-temp-${name}-`;
|
|
20
|
-
(
|
|
20
|
+
logger('init', `${i18nKey}.extractZip.init`);
|
|
21
21
|
// Write zip to disk
|
|
22
22
|
let tmpZipPath = '';
|
|
23
23
|
try {
|
|
@@ -43,7 +43,7 @@ async function extractZip(name, zip) {
|
|
|
43
43
|
// Extract zip
|
|
44
44
|
try {
|
|
45
45
|
const tmpExtractPath = (0, path_1.join)(result.tmpDir, 'extracted');
|
|
46
|
-
await
|
|
46
|
+
await (0, extract_zip_1.default)(tmpZipPath, { dir: tmpExtractPath });
|
|
47
47
|
result.extractDir = tmpExtractPath;
|
|
48
48
|
}
|
|
49
49
|
catch (err) {
|
|
@@ -52,9 +52,10 @@ async function extractZip(name, zip) {
|
|
|
52
52
|
(0, logger_1.debug)(`${i18nKey}.extractZip.success`);
|
|
53
53
|
return result;
|
|
54
54
|
}
|
|
55
|
-
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true } = {}) {
|
|
55
|
+
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true } = {}, logCallbacks) {
|
|
56
56
|
try {
|
|
57
|
-
(0, logger_1.
|
|
57
|
+
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
58
|
+
logger('copy', `${i18nKey}.copySourceToDest.init`);
|
|
58
59
|
const srcDirPath = [src];
|
|
59
60
|
if (includesRootDir) {
|
|
60
61
|
const files = await fs_extra_1.default.readdir(src);
|
|
@@ -95,15 +96,15 @@ function cleanupTempDir(tmpDir) {
|
|
|
95
96
|
(0, logger_1.debug)(`${i18nKey}.cleanupTempDir.error`, { tmpDir });
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}) {
|
|
99
|
+
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}, logCallbacks) {
|
|
99
100
|
let success = false;
|
|
100
101
|
if (zip) {
|
|
101
|
-
const { extractDir, tmpDir } = await extractZip(name, zip);
|
|
102
|
+
const { extractDir, tmpDir } = await extractZip(name, zip, logCallbacks);
|
|
102
103
|
if (extractDir !== null) {
|
|
103
104
|
success = await copySourceToDest(extractDir, dest, {
|
|
104
105
|
sourceDir,
|
|
105
106
|
includesRootDir,
|
|
106
|
-
});
|
|
107
|
+
}, logCallbacks);
|
|
107
108
|
}
|
|
108
109
|
cleanupTempDir(tmpDir);
|
|
109
110
|
}
|
package/package.json
CHANGED