@hubspot/local-dev-lib 3.7.0 → 3.7.1-beta.0
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 +1 -1
- package/lib/archive.js +60 -6
- package/lib/github.js +2 -1
- package/package.json +1 -1
- package/types/Archive.d.ts +7 -1
- package/types/Github.d.ts +3 -1
package/lib/archive.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { CopySourceToDestOptions } from '../types/Archive';
|
|
4
|
-
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir, hideLogs }?: CopySourceToDestOptions): Promise<boolean>;
|
|
4
|
+
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir, hideLogs, handleCollision, }?: CopySourceToDestOptions): Promise<boolean>;
|
package/lib/archive.js
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
29
|
exports.extractZipArchive = void 0;
|
|
7
30
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const path_1 = require("path");
|
|
31
|
+
const path_1 = __importStar(require("path"));
|
|
9
32
|
const os_1 = require("os");
|
|
10
33
|
const extract_zip_1 = __importDefault(require("extract-zip"));
|
|
11
34
|
const logger_1 = require("./logger");
|
|
12
35
|
const lang_1 = require("../utils/lang");
|
|
13
36
|
const FileSystemError_1 = require("../models/FileSystemError");
|
|
37
|
+
const fs_1 = require("./fs");
|
|
14
38
|
const i18nKey = 'lib.archive';
|
|
15
39
|
async function extractZip(name, zip, hideLogs = false) {
|
|
16
40
|
const result = { extractDir: '', tmpDir: '' };
|
|
@@ -55,7 +79,7 @@ async function extractZip(name, zip, hideLogs = false) {
|
|
|
55
79
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.extractZip.success`));
|
|
56
80
|
return result;
|
|
57
81
|
}
|
|
58
|
-
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true, hideLogs = false, } = {}) {
|
|
82
|
+
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true, hideLogs = false, handleCollision, } = {}) {
|
|
59
83
|
try {
|
|
60
84
|
if (!hideLogs) {
|
|
61
85
|
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.init`));
|
|
@@ -73,11 +97,40 @@ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true,
|
|
|
73
97
|
}
|
|
74
98
|
srcDirPath.push(rootDir);
|
|
75
99
|
}
|
|
100
|
+
const sourceDirs = [];
|
|
76
101
|
if (sourceDir) {
|
|
77
|
-
|
|
102
|
+
sourceDirs.push(...(Array.isArray(sourceDir) ? new Set(sourceDir) : [sourceDir]));
|
|
103
|
+
}
|
|
104
|
+
if (sourceDirs.length === 0) {
|
|
105
|
+
const projectSrcDir = (0, path_1.join)(...srcDirPath);
|
|
106
|
+
await fs_extra_1.default.copy(projectSrcDir, dest);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
for (let i = 0; i < sourceDirs.length; i++) {
|
|
110
|
+
const projectSrcDir = (0, path_1.join)(...srcDirPath, sourceDirs[i]);
|
|
111
|
+
let collisions = [];
|
|
112
|
+
if (fs_extra_1.default.existsSync(dest) &&
|
|
113
|
+
handleCollision &&
|
|
114
|
+
typeof handleCollision === 'function') {
|
|
115
|
+
const existingFiles = (await (0, fs_1.walk)(dest, ['node_modules'])).map(file => path_1.default.normalize(path_1.default.relative(dest, file)));
|
|
116
|
+
const newFiles = (await (0, fs_1.walk)(projectSrcDir, ['node_modules'])).map(file => path_1.default.relative(projectSrcDir, file));
|
|
117
|
+
// Find files that exist in the same positions in both directories
|
|
118
|
+
collisions = existingFiles.filter(currentFile => newFiles.includes(currentFile));
|
|
119
|
+
}
|
|
120
|
+
if (collisions.length &&
|
|
121
|
+
handleCollision &&
|
|
122
|
+
typeof handleCollision === 'function') {
|
|
123
|
+
await handleCollision({
|
|
124
|
+
dest,
|
|
125
|
+
src: projectSrcDir,
|
|
126
|
+
collisions,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
await fs_extra_1.default.copy(projectSrcDir, dest);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
78
133
|
}
|
|
79
|
-
const projectSrcDir = (0, path_1.join)(...srcDirPath);
|
|
80
|
-
await fs_extra_1.default.copy(projectSrcDir, dest);
|
|
81
134
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.success`));
|
|
82
135
|
return true;
|
|
83
136
|
}
|
|
@@ -99,7 +152,7 @@ async function cleanupTempDir(tmpDir) {
|
|
|
99
152
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.cleanupTempDir.error`, { tmpDir }));
|
|
100
153
|
}
|
|
101
154
|
}
|
|
102
|
-
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir, hideLogs } = {}) {
|
|
155
|
+
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir, hideLogs, handleCollision, } = {}) {
|
|
103
156
|
let success = false;
|
|
104
157
|
if (zip) {
|
|
105
158
|
const { extractDir, tmpDir } = await extractZip(name, zip, hideLogs);
|
|
@@ -108,6 +161,7 @@ async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir,
|
|
|
108
161
|
sourceDir,
|
|
109
162
|
includesRootDir,
|
|
110
163
|
hideLogs,
|
|
164
|
+
handleCollision,
|
|
111
165
|
});
|
|
112
166
|
}
|
|
113
167
|
await cleanupTempDir(tmpDir);
|
package/lib/github.js
CHANGED
|
@@ -78,7 +78,7 @@ async function downloadGithubRepoZip(repoPath, isRelease = false, options = {})
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
async function cloneGithubRepo(repoPath, dest, options = {}) {
|
|
81
|
-
const { tag, isRelease, branch, sourceDir, type, hideLogs } = options;
|
|
81
|
+
const { tag, isRelease, branch, sourceDir, type, hideLogs, handleCollision } = options;
|
|
82
82
|
const zip = await downloadGithubRepoZip(repoPath, isRelease, {
|
|
83
83
|
tag,
|
|
84
84
|
branch,
|
|
@@ -87,6 +87,7 @@ async function cloneGithubRepo(repoPath, dest, options = {}) {
|
|
|
87
87
|
const success = await (0, archive_1.extractZipArchive)(zip, repoName, dest, {
|
|
88
88
|
sourceDir,
|
|
89
89
|
hideLogs,
|
|
90
|
+
handleCollision,
|
|
90
91
|
});
|
|
91
92
|
if (success && !hideLogs) {
|
|
92
93
|
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.cloneGithubRepo.success`, {
|
package/package.json
CHANGED
package/types/Archive.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
export interface Collision {
|
|
2
|
+
dest: string;
|
|
3
|
+
src: string;
|
|
4
|
+
collisions: string[];
|
|
5
|
+
}
|
|
1
6
|
export type ZipData = {
|
|
2
7
|
extractDir: string;
|
|
3
8
|
tmpDir: string;
|
|
4
9
|
};
|
|
5
10
|
export type CopySourceToDestOptions = {
|
|
6
|
-
sourceDir?: string;
|
|
11
|
+
sourceDir?: string | string[];
|
|
7
12
|
includesRootDir?: boolean;
|
|
8
13
|
hideLogs?: boolean;
|
|
14
|
+
handleCollision?: (collision: Collision) => void | Promise<void>;
|
|
9
15
|
};
|
package/types/Github.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Collision } from './Archive';
|
|
1
2
|
type GithubAuthor = {
|
|
2
3
|
login: string;
|
|
3
4
|
id: number;
|
|
@@ -71,7 +72,8 @@ export type CloneGithubRepoOptions = {
|
|
|
71
72
|
type?: string;
|
|
72
73
|
branch?: string;
|
|
73
74
|
tag?: string;
|
|
74
|
-
sourceDir?: string;
|
|
75
|
+
sourceDir?: string | string[];
|
|
75
76
|
hideLogs?: boolean;
|
|
77
|
+
handleCollision?: (collision: Collision) => void;
|
|
76
78
|
};
|
|
77
79
|
export {};
|