@hubspot/local-dev-lib 1.2.0 → 1.4.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/api/projects.d.ts +3 -0
- package/api/projects.js +19 -1
- package/lib/archive.d.ts +2 -1
- package/lib/archive.js +11 -6
- package/lib/cms/watch.d.ts +1 -1
- package/lib/cms/watch.js +16 -15
- package/package.json +1 -1
- package/types/Migration.d.ts +24 -0
- package/types/Migration.js +10 -0
package/api/projects.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Build, FetchProjectBuildsResponse } from '../types/Build';
|
|
|
5
5
|
import { ComponentMetadataResponse, ComponentStructureResponse } from '../types/ComponentStructure';
|
|
6
6
|
import { Deploy, ProjectDeployResponse } from '../types/Deploy';
|
|
7
7
|
import { ProjectLog } from '../types/ProjectLog';
|
|
8
|
+
import { MigrateAppResponse, PollAppResponse } from '../types/Migration';
|
|
8
9
|
export declare function fetchProjects(accountId: number): Promise<FetchProjectResponse>;
|
|
9
10
|
export declare function createProject(accountId: number, name: string): Promise<Project>;
|
|
10
11
|
export declare function uploadProject(accountId: number, projectName: string, projectFile: string, uploadMessage: string, platformVersion?: string): Promise<UploadProjectResponse>;
|
|
@@ -35,4 +36,6 @@ export declare function fetchBuildWarnLogs(accountId: number, projectName: strin
|
|
|
35
36
|
export declare function fetchDeployWarnLogs(accountId: number, projectName: string, deployId: number): Promise<{
|
|
36
37
|
logs: Array<ProjectLog>;
|
|
37
38
|
}>;
|
|
39
|
+
export declare function migrateApp(accountId: number, appId: number, projectName: string): Promise<MigrateAppResponse>;
|
|
40
|
+
export declare function checkMigrationStatus(accountId: number, id: number): Promise<PollAppResponse>;
|
|
38
41
|
export {};
|
package/api/projects.js
CHANGED
|
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchDeployWarnLogs = exports.fetchBuildWarnLogs = exports.cancelStagedBuild = exports.deleteFileFromBuild = exports.uploadFileToBuild = exports.queueBuild = exports.provisionBuild = exports.fetchDeployComponentsMetadata = exports.fetchProjectSettings = exports.getDeployStructure = exports.getDeployStatus = exports.deployProject = exports.getBuildStructure = exports.getBuildStatus = exports.fetchProjectBuilds = exports.fetchPlatformVersions = exports.deleteProject = exports.downloadProject = exports.fetchProject = exports.uploadProject = exports.createProject = exports.fetchProjects = void 0;
|
|
6
|
+
exports.checkMigrationStatus = exports.migrateApp = exports.fetchDeployWarnLogs = exports.fetchBuildWarnLogs = exports.cancelStagedBuild = exports.deleteFileFromBuild = exports.uploadFileToBuild = exports.queueBuild = exports.provisionBuild = exports.fetchDeployComponentsMetadata = exports.fetchProjectSettings = exports.getDeployStructure = exports.getDeployStatus = exports.deployProject = exports.getBuildStructure = exports.getBuildStatus = exports.fetchProjectBuilds = exports.fetchPlatformVersions = exports.deleteProject = exports.downloadProject = exports.fetchProject = exports.uploadProject = exports.createProject = exports.fetchProjects = void 0;
|
|
7
7
|
const http_1 = __importDefault(require("../http"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const PROJECTS_API_PATH = 'dfs/v1/projects';
|
|
10
10
|
const PROJECTS_DEPLOY_API_PATH = 'dfs/deploy/v1';
|
|
11
11
|
const PROJECTS_LOGS_API_PATH = 'dfs/logging/v1';
|
|
12
12
|
const DEVELOPER_PROJECTS_API_PATH = 'developer/projects/v1';
|
|
13
|
+
const MIGRATIONS_API_PATH = 'dfs/migrations/v1';
|
|
13
14
|
async function fetchProjects(accountId) {
|
|
14
15
|
return http_1.default.get(accountId, {
|
|
15
16
|
url: PROJECTS_API_PATH,
|
|
@@ -172,3 +173,20 @@ async function fetchDeployWarnLogs(accountId, projectName, deployId) {
|
|
|
172
173
|
});
|
|
173
174
|
}
|
|
174
175
|
exports.fetchDeployWarnLogs = fetchDeployWarnLogs;
|
|
176
|
+
async function migrateApp(accountId, appId, projectName) {
|
|
177
|
+
return http_1.default.post(accountId, {
|
|
178
|
+
url: `${MIGRATIONS_API_PATH}/migrations`,
|
|
179
|
+
data: {
|
|
180
|
+
componentId: appId,
|
|
181
|
+
componentType: 'PUBLIC_APP_ID',
|
|
182
|
+
projectName,
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
exports.migrateApp = migrateApp;
|
|
187
|
+
async function checkMigrationStatus(accountId, id) {
|
|
188
|
+
return http_1.default.get(accountId, {
|
|
189
|
+
url: `${MIGRATIONS_API_PATH}/migrations/${id}`,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
exports.checkMigrationStatus = checkMigrationStatus;
|
package/lib/archive.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
type CopySourceToDestOptions = {
|
|
3
3
|
sourceDir?: string;
|
|
4
4
|
includesRootDir?: boolean;
|
|
5
|
+
hideLogs?: boolean;
|
|
5
6
|
};
|
|
6
|
-
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions): Promise<boolean>;
|
|
7
|
+
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir, hideLogs }?: CopySourceToDestOptions): Promise<boolean>;
|
|
7
8
|
export {};
|
package/lib/archive.js
CHANGED
|
@@ -13,10 +13,12 @@ const standardErrors_1 = require("../errors/standardErrors");
|
|
|
13
13
|
const logger_1 = require("./logger");
|
|
14
14
|
const lang_1 = require("../utils/lang");
|
|
15
15
|
const i18nKey = 'lib.archive';
|
|
16
|
-
async function extractZip(name, zip) {
|
|
16
|
+
async function extractZip(name, zip, hideLogs = false) {
|
|
17
17
|
const result = { extractDir: '', tmpDir: '' };
|
|
18
18
|
const TMP_FOLDER_PREFIX = `hubspot-temp-${name}-`;
|
|
19
|
-
|
|
19
|
+
if (!hideLogs) {
|
|
20
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.extractZip.init`));
|
|
21
|
+
}
|
|
20
22
|
// Write zip to disk
|
|
21
23
|
let tmpZipPath = '';
|
|
22
24
|
try {
|
|
@@ -51,9 +53,11 @@ async function extractZip(name, zip) {
|
|
|
51
53
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.extractZip.success`));
|
|
52
54
|
return result;
|
|
53
55
|
}
|
|
54
|
-
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true } = {}) {
|
|
56
|
+
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true, hideLogs = false, } = {}) {
|
|
55
57
|
try {
|
|
56
|
-
|
|
58
|
+
if (!hideLogs) {
|
|
59
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.init`));
|
|
60
|
+
}
|
|
57
61
|
const srcDirPath = [src];
|
|
58
62
|
if (includesRootDir) {
|
|
59
63
|
const files = await fs_extra_1.default.readdir(src);
|
|
@@ -94,14 +98,15 @@ function cleanupTempDir(tmpDir) {
|
|
|
94
98
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.cleanupTempDir.error`, { tmpDir }));
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
|
-
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}) {
|
|
101
|
+
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir, hideLogs } = {}) {
|
|
98
102
|
let success = false;
|
|
99
103
|
if (zip) {
|
|
100
|
-
const { extractDir, tmpDir } = await extractZip(name, zip);
|
|
104
|
+
const { extractDir, tmpDir } = await extractZip(name, zip, hideLogs);
|
|
101
105
|
if (extractDir !== null) {
|
|
102
106
|
success = await copySourceToDest(extractDir, dest, {
|
|
103
107
|
sourceDir,
|
|
104
108
|
includesRootDir,
|
|
109
|
+
hideLogs,
|
|
105
110
|
});
|
|
106
111
|
}
|
|
107
112
|
cleanupTempDir(tmpDir);
|
package/lib/cms/watch.d.ts
CHANGED
|
@@ -13,5 +13,5 @@ type WatchOptions = {
|
|
|
13
13
|
filePaths?: Array<string>;
|
|
14
14
|
};
|
|
15
15
|
type ErrorHandler = (error: AxiosError) => void;
|
|
16
|
-
export declare function watch(accountId: number, src: string, dest: string, { mode, remove, disableInitial, notify, commandOptions, filePaths, }: WatchOptions, postInitialUploadCallback?: ((result: Array<UploadFolderResults>) => void) | null, onUploadFolderError?: ErrorHandler, onQueueAddError?: ErrorHandler): chokidar.FSWatcher;
|
|
16
|
+
export declare function watch(accountId: number, src: string, dest: string, { mode, remove, disableInitial, notify, commandOptions, filePaths, }: WatchOptions, postInitialUploadCallback?: ((result: Array<UploadFolderResults>) => void) | null, onUploadFolderError?: ErrorHandler, onQueueAddError?: ErrorHandler, onUploadFileError?: (file: string, dest: string, accountId: number) => ErrorHandler): chokidar.FSWatcher;
|
|
17
17
|
export {};
|
package/lib/cms/watch.js
CHANGED
|
@@ -35,7 +35,18 @@ function _notifyOfThemePreview(filePath, accountId) {
|
|
|
35
35
|
}));
|
|
36
36
|
}
|
|
37
37
|
const notifyOfThemePreview = (0, debounce_1.default)(_notifyOfThemePreview, 1000);
|
|
38
|
-
|
|
38
|
+
const defaultOnUploadFileError = (file, dest, accountId) => (error) => {
|
|
39
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFailed`, {
|
|
40
|
+
file,
|
|
41
|
+
dest,
|
|
42
|
+
}));
|
|
43
|
+
(0, apiErrors_1.throwApiUploadError)(error, {
|
|
44
|
+
accountId,
|
|
45
|
+
request: dest,
|
|
46
|
+
payload: file,
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
async function uploadFile(accountId, file, dest, options, mode = null, onUploadFileError = defaultOnUploadFileError) {
|
|
39
50
|
const src = options.src;
|
|
40
51
|
const absoluteSrcPath = path_1.default.resolve((0, path_2.getCwd)(), file);
|
|
41
52
|
const themeJsonPath = (0, themes_1.getThemeJSONPath)(absoluteSrcPath);
|
|
@@ -71,17 +82,7 @@ async function uploadFile(accountId, file, dest, options, mode = null) {
|
|
|
71
82
|
.catch(() => {
|
|
72
83
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFailed`, { file, dest }));
|
|
73
84
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadRetry`, { file, dest }));
|
|
74
|
-
return (0, fileMapper_2.upload)(accountId, file, dest, apiOptions).catch((
|
|
75
|
-
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFailed`, {
|
|
76
|
-
file,
|
|
77
|
-
dest,
|
|
78
|
-
}));
|
|
79
|
-
(0, apiErrors_1.throwApiUploadError)(error, {
|
|
80
|
-
accountId,
|
|
81
|
-
request: dest,
|
|
82
|
-
payload: file,
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
+
return (0, fileMapper_2.upload)(accountId, file, dest, apiOptions).catch(onUploadFileError(file, dest, accountId));
|
|
85
86
|
});
|
|
86
87
|
});
|
|
87
88
|
}
|
|
@@ -108,7 +109,7 @@ async function deleteRemoteFile(accountId, filePath, remoteFilePath) {
|
|
|
108
109
|
});
|
|
109
110
|
});
|
|
110
111
|
}
|
|
111
|
-
function watch(accountId, src, dest, { mode, remove, disableInitial, notify, commandOptions, filePaths, }, postInitialUploadCallback = null, onUploadFolderError, onQueueAddError) {
|
|
112
|
+
function watch(accountId, src, dest, { mode, remove, disableInitial, notify, commandOptions, filePaths, }, postInitialUploadCallback = null, onUploadFolderError, onQueueAddError, onUploadFileError) {
|
|
112
113
|
const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(src)}`);
|
|
113
114
|
if (notify) {
|
|
114
115
|
(0, ignoreRules_1.ignoreFile)(notify);
|
|
@@ -145,7 +146,7 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
|
|
|
145
146
|
const uploadPromise = uploadFile(accountId, filePath, destPath, {
|
|
146
147
|
src,
|
|
147
148
|
commandOptions,
|
|
148
|
-
}, mode);
|
|
149
|
+
}, mode, onUploadFileError);
|
|
149
150
|
(0, notify_1.triggerNotify)(notify, 'Added', filePath, uploadPromise);
|
|
150
151
|
});
|
|
151
152
|
if (remove) {
|
|
@@ -185,7 +186,7 @@ function watch(accountId, src, dest, { mode, remove, disableInitial, notify, com
|
|
|
185
186
|
const uploadPromise = uploadFile(accountId, filePath, destPath, {
|
|
186
187
|
src,
|
|
187
188
|
commandOptions,
|
|
188
|
-
}, mode);
|
|
189
|
+
}, mode, onUploadFileError);
|
|
189
190
|
(0, notify_1.triggerNotify)(notify, 'Changed', filePath, uploadPromise);
|
|
190
191
|
});
|
|
191
192
|
return watcher;
|
package/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ValueOf } from './Utils';
|
|
2
|
+
import { OptionalError } from './Error';
|
|
3
|
+
export declare const MIGRATION_STATUS: {
|
|
4
|
+
readonly BUILDING: "BUILDING";
|
|
5
|
+
readonly FAILURE: "FAILURE";
|
|
6
|
+
readonly PREPARING: "PREPARING";
|
|
7
|
+
readonly PENDING: "PENDING";
|
|
8
|
+
readonly SUCCESS: "SUCCESS";
|
|
9
|
+
};
|
|
10
|
+
export type MigrateAppResponse = {
|
|
11
|
+
id: number;
|
|
12
|
+
status: ValueOf<typeof MIGRATION_STATUS>;
|
|
13
|
+
};
|
|
14
|
+
export type PollAppResponse = {
|
|
15
|
+
id: number;
|
|
16
|
+
project?: {
|
|
17
|
+
id: number;
|
|
18
|
+
name: string;
|
|
19
|
+
buildId: number;
|
|
20
|
+
deployId: number;
|
|
21
|
+
};
|
|
22
|
+
error: OptionalError;
|
|
23
|
+
status: ValueOf<typeof MIGRATION_STATUS>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MIGRATION_STATUS = void 0;
|
|
4
|
+
exports.MIGRATION_STATUS = {
|
|
5
|
+
BUILDING: 'BUILDING',
|
|
6
|
+
FAILURE: 'FAILURE',
|
|
7
|
+
PREPARING: 'PREPARING',
|
|
8
|
+
PENDING: 'PENDING',
|
|
9
|
+
SUCCESS: 'SUCCESS',
|
|
10
|
+
};
|