@hubspot/ui-extensions-dev-server 0.8.2 → 0.8.4
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/README.md +2 -24
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -2
- package/dist/lib/DevModeInterface.d.ts +13 -8
- package/dist/lib/DevModeInterface.js +45 -35
- package/dist/lib/DevServerState.d.ts +28 -0
- package/dist/lib/DevServerState.js +67 -0
- package/dist/lib/build.d.ts +0 -3
- package/dist/lib/build.js +1 -17
- package/dist/lib/config.d.ts +3 -0
- package/dist/lib/config.js +40 -0
- package/dist/lib/constants.d.ts +4 -0
- package/dist/lib/constants.js +5 -1
- package/dist/lib/dev.d.ts +2 -12
- package/dist/lib/dev.js +10 -30
- package/dist/lib/extensionsService.d.ts +3 -3
- package/dist/lib/extensionsService.js +12 -9
- package/dist/lib/plugins/codeCheckingPlugin.js +2 -1
- package/dist/lib/plugins/devBuildPlugin.d.ts +2 -4
- package/dist/lib/plugins/devBuildPlugin.js +53 -34
- package/dist/lib/plugins/friendlyLoggingPlugin.js +2 -0
- package/dist/lib/plugins/manifestPlugin.js +2 -0
- package/dist/lib/server.d.ts +3 -8
- package/dist/lib/server.js +15 -8
- package/dist/lib/types.d.ts +6 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.js +11 -1
- package/package.json +3 -6
- package/dist/cli/config.d.ts +0 -8
- package/dist/cli/config.js +0 -80
- package/dist/cli/run.d.ts +0 -2
- package/dist/cli/run.js +0 -89
- package/dist/cli/utils.d.ts +0 -3
- package/dist/cli/utils.js +0 -79
package/README.md
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
1
|
# UI Extensions – Dev Server
|
|
2
2
|
|
|
3
|
-
Development server to run
|
|
3
|
+
Development server library to run your HubSpot UI Extensions.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
|
-
This package contains the
|
|
6
|
+
This package contains the library functions for running HubSpot UI extensions locally, as well as running a production build for debugging purposes.
|
|
7
7
|
|
|
8
|
-
### Help
|
|
9
|
-
If for any reason you need help with the `ui-extensions-dev-server` you can access the help menu in a few ways:
|
|
10
|
-
|
|
11
|
-
- `hs-ui-extensions-dev-server`
|
|
12
|
-
- `hs-ui-extensions-dev-server -h`
|
|
13
|
-
- `hs-ui-extensions-dev-server --help`
|
|
14
|
-
|
|
15
|
-
### Local Development
|
|
16
|
-
Prompts you which of your extensions you would like to run in local dev mode. Once you have made your selection, it sets up a watcher on the entry point file for that project as well as any child files. Any changes to those files will trigger a local build which will bundle your code and output the bundle in a `dist/` directory inside of your current working directory. To initiate local dev mode in the browser, you just need to navigate to the CRM where your the deployed version of your card lives. The browser will detect that you have the dev server running, and make the connection on your behalf.
|
|
17
|
-
|
|
18
|
-
| Action | Command |
|
|
19
|
-
| - | - |
|
|
20
|
-
| Standard Local Dev | `hs-ui-extensions-dev-server dev` |
|
|
21
|
-
| Bypass Prompt | `hs-ui-extensions-dev-server dev --extension MyEntryPointFile.jsx` <br /> `hs-ui-extensions-dev-server dev -e MyEntryPointFile.jsx`|
|
|
22
|
-
|
|
23
|
-
### Production Build
|
|
24
|
-
This should not be required in the standard development workflow. It is there to aid debugging the output of an extension. This command will run a build similar to what we will run when these extensions are uploaded. The output will be written into a `dist/` directory in the current working directory.
|
|
25
|
-
|
|
26
|
-
| Action | Command |
|
|
27
|
-
| - | - |
|
|
28
|
-
| Build All Extensions | `hs-ui-extensions-dev-server build` |
|
|
29
|
-
| Build a single extension | `hs-ui-extensions-dev-server build --extension MyEntryPointFile.jsx` <br /> `hs-ui-extensions-dev-server build -e MyEntryPointFile.jsx`|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { remoteBuild,
|
|
1
|
+
import { remoteBuild, buildSingleExtension } from './lib/build';
|
|
2
2
|
import DevModeInterface from './lib/DevModeInterface';
|
|
3
|
-
export { remoteBuild,
|
|
3
|
+
export { remoteBuild, buildSingleExtension, DevModeInterface };
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,9 @@ 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.DevModeInterface = exports.buildSingleExtension = exports.
|
|
6
|
+
exports.DevModeInterface = exports.buildSingleExtension = exports.remoteBuild = void 0;
|
|
7
7
|
const build_1 = require("./lib/build");
|
|
8
8
|
Object.defineProperty(exports, "remoteBuild", { enumerable: true, get: function () { return build_1.remoteBuild; } });
|
|
9
|
-
Object.defineProperty(exports, "buildAllExtensions", { enumerable: true, get: function () { return build_1.buildAllExtensions; } });
|
|
10
9
|
Object.defineProperty(exports, "buildSingleExtension", { enumerable: true, get: function () { return build_1.buildSingleExtension; } });
|
|
11
10
|
const DevModeInterface_1 = __importDefault(require("./lib/DevModeInterface"));
|
|
12
11
|
exports.DevModeInterface = DevModeInterface_1.default;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ExtensionConfig, ProjectComponentMap } from './types';
|
|
2
|
-
import { ServiceConfiguration } from '@hubspot/app-functions-dev-server/dist/types';
|
|
1
|
+
import type { ExtensionConfig, PlatformVersion, ProjectComponentMap } from './types';
|
|
2
|
+
import type { ServiceConfiguration } from '@hubspot/app-functions-dev-server/dist/types';
|
|
3
3
|
import { PromptModule } from 'inquirer';
|
|
4
|
+
import { DevServerState } from './DevServerState';
|
|
4
5
|
interface SetupArguments {
|
|
5
6
|
components: ProjectComponentMap;
|
|
6
7
|
debug?: boolean;
|
|
@@ -8,27 +9,31 @@ interface SetupArguments {
|
|
|
8
9
|
onUploadRequired?: VoidFunction;
|
|
9
10
|
promptUser: PromptModule;
|
|
10
11
|
}
|
|
12
|
+
interface ProjectConfig {
|
|
13
|
+
name: string;
|
|
14
|
+
srcDir: string;
|
|
15
|
+
platformVersion?: PlatformVersion;
|
|
16
|
+
}
|
|
11
17
|
interface StartArguments {
|
|
12
18
|
accountId?: number;
|
|
13
19
|
debug?: boolean;
|
|
14
20
|
httpClient?: ServiceConfiguration['httpClient'];
|
|
21
|
+
projectConfig?: ProjectConfig;
|
|
15
22
|
}
|
|
16
23
|
interface AppExtensionMapping {
|
|
17
24
|
name: string;
|
|
18
25
|
value: ExtensionConfig;
|
|
19
26
|
}
|
|
20
27
|
declare class DevModeInterface {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
title?: string;
|
|
24
|
-
extensionConfigPath?: string;
|
|
28
|
+
configs?: ExtensionConfig[];
|
|
29
|
+
devServerState?: DevServerState;
|
|
25
30
|
onUploadRequired?: VoidFunction;
|
|
26
31
|
shutdown?: () => Promise<void>;
|
|
27
|
-
_setDataFromExtensionConfig(extensionConfig: ExtensionConfig): void;
|
|
28
32
|
_generateAppExtensionMappings(components: ProjectComponentMap): AppExtensionMapping[];
|
|
33
|
+
_getPlatformVersion(projectConfig?: ProjectConfig): PlatformVersion;
|
|
29
34
|
setup({ components, debug, extensionConfig, onUploadRequired, promptUser, }: SetupArguments): Promise<void>;
|
|
30
35
|
fileChange(filePath: string, __event: unknown): Promise<void>;
|
|
31
|
-
start({ accountId, debug, httpClient }: StartArguments): Promise<void>;
|
|
36
|
+
start({ accountId, debug, httpClient, projectConfig }: StartArguments): Promise<void>;
|
|
32
37
|
cleanup(): Promise<void>;
|
|
33
38
|
}
|
|
34
39
|
declare const _default: DevModeInterface;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* hs-eslint ignored failing-rules */
|
|
3
|
+
/* eslint-disable hubspot-dev/no-unsupported-ts-syntax */
|
|
2
4
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
5
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
6
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,23 +10,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
10
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
11
|
});
|
|
10
12
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
14
|
const dev_1 = require("./dev");
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
17
15
|
const constants_1 = require("./constants");
|
|
18
|
-
const config_1 = require("
|
|
16
|
+
const config_1 = require("./config");
|
|
19
17
|
// @ts-expect-error no type defs
|
|
20
18
|
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
19
|
+
const DevServerState_1 = require("./DevServerState");
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
21
|
class DevModeInterface {
|
|
22
|
-
_setDataFromExtensionConfig(extensionConfig) {
|
|
23
|
-
this.config = extensionConfig;
|
|
24
|
-
this.extensionConfigPath = extensionConfig.extensionConfigPath;
|
|
25
|
-
this.appName = extensionConfig.data.appName;
|
|
26
|
-
this.title = extensionConfig.data.title;
|
|
27
|
-
}
|
|
28
22
|
_generateAppExtensionMappings(components) {
|
|
29
23
|
// Loop over all of the app configs that are passed in
|
|
30
24
|
const allComponentNames = Object.keys(components);
|
|
@@ -48,12 +42,26 @@ class DevModeInterface {
|
|
|
48
42
|
return appExtensionMappings;
|
|
49
43
|
}, []);
|
|
50
44
|
}
|
|
45
|
+
_getPlatformVersion(projectConfig) {
|
|
46
|
+
const { platformVersion } = projectConfig !== null && projectConfig !== void 0 ? projectConfig : {};
|
|
47
|
+
if (!platformVersion) {
|
|
48
|
+
return constants_1.PLATFORM_VERSION.V20231;
|
|
49
|
+
}
|
|
50
|
+
switch (platformVersion) {
|
|
51
|
+
case constants_1.PLATFORM_VERSION.V20231:
|
|
52
|
+
return constants_1.PLATFORM_VERSION.V20231;
|
|
53
|
+
case constants_1.PLATFORM_VERSION.V20232:
|
|
54
|
+
return constants_1.PLATFORM_VERSION.V20232;
|
|
55
|
+
default:
|
|
56
|
+
return (0, utils_1.throwUnhandledPlatformVersionError)(platformVersion);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
51
59
|
setup({ components, debug = false, extensionConfig, onUploadRequired, promptUser, }) {
|
|
52
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
61
|
(0, logger_1.setLogLevel)(debug ? logger_1.LOG_LEVEL.DEBUG : logger_1.LOG_LEVEL.LOG);
|
|
54
62
|
this.onUploadRequired = onUploadRequired;
|
|
55
63
|
if (extensionConfig) {
|
|
56
|
-
this.
|
|
64
|
+
this.configs = [extensionConfig];
|
|
57
65
|
return;
|
|
58
66
|
}
|
|
59
67
|
const choices = this._generateAppExtensionMappings(components);
|
|
@@ -61,16 +69,22 @@ class DevModeInterface {
|
|
|
61
69
|
throw new Error('No extensions to run');
|
|
62
70
|
}
|
|
63
71
|
else if (choices.length === 1) {
|
|
64
|
-
this.
|
|
72
|
+
this.configs = [choices[0].value];
|
|
65
73
|
}
|
|
66
74
|
else {
|
|
67
75
|
const answers = yield promptUser({
|
|
68
|
-
type: '
|
|
69
|
-
name: '
|
|
70
|
-
message: 'Which extension would you like to run?',
|
|
76
|
+
type: 'checkbox',
|
|
77
|
+
name: 'extensions',
|
|
78
|
+
message: 'Which extension(s) would you like to run?',
|
|
79
|
+
validate: input => {
|
|
80
|
+
if (!input || input.length === 0) {
|
|
81
|
+
return 'Select at least one extension to run';
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
71
85
|
choices,
|
|
72
86
|
});
|
|
73
|
-
this.
|
|
87
|
+
this.configs = answers.extensions;
|
|
74
88
|
}
|
|
75
89
|
});
|
|
76
90
|
}
|
|
@@ -78,35 +92,31 @@ class DevModeInterface {
|
|
|
78
92
|
// eslint-disable-next-line require-await
|
|
79
93
|
fileChange(filePath, __event) {
|
|
80
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
if (this.
|
|
82
|
-
|
|
83
|
-
|
|
95
|
+
if (!this.devServerState || !this.devServerState.extensionsMetadata) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const relevantConfigFileChanged = this.devServerState.extensionsMetadata.some(metadata => metadata.config.extensionConfigPath === filePath);
|
|
99
|
+
if (relevantConfigFileChanged && this.onUploadRequired) {
|
|
84
100
|
this.onUploadRequired();
|
|
85
101
|
}
|
|
86
102
|
});
|
|
87
103
|
}
|
|
88
|
-
start({ accountId, debug, httpClient }) {
|
|
104
|
+
start({ accountId, debug, httpClient, projectConfig }) {
|
|
89
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
106
|
if (debug !== undefined) {
|
|
91
107
|
(0, logger_1.setLogLevel)(debug ? logger_1.LOG_LEVEL.DEBUG : logger_1.LOG_LEVEL.LOG);
|
|
92
108
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
const appPath = this.config.path;
|
|
97
|
-
// Pass options from the CLI for running app functions locally
|
|
98
|
-
const functionsConfig = {
|
|
99
|
-
app: { path: appPath },
|
|
109
|
+
this.devServerState = new DevServerState_1.DevServerState({
|
|
110
|
+
extensionConfigs: this.configs,
|
|
100
111
|
accountId,
|
|
101
112
|
httpClient,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
113
|
+
platformVersion: this._getPlatformVersion(projectConfig),
|
|
114
|
+
});
|
|
115
|
+
this.shutdown = yield (0, dev_1.startDevMode)(this.devServerState);
|
|
116
|
+
this.devServerState.extensionsMetadata.forEach(metadata => {
|
|
117
|
+
const { config: { data: { title, appName }, }, } = metadata;
|
|
118
|
+
logger_1.logger.info(`Running extension '${title}' from app '${appName}'`);
|
|
108
119
|
});
|
|
109
|
-
logger_1.logger.info(`Running extension '${this.title}' from app '${this.appName}'`);
|
|
110
120
|
});
|
|
111
121
|
}
|
|
112
122
|
cleanup() {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ExtensionConfig, ExtensionMetadata, PlatformVersion } from './types';
|
|
2
|
+
import { ServiceConfiguration } from '@hubspot/app-functions-dev-server/dist/types';
|
|
3
|
+
interface DevServerStateArgs {
|
|
4
|
+
extensionConfigs?: ExtensionConfig[];
|
|
5
|
+
accountId: number | undefined;
|
|
6
|
+
httpClient: ServiceConfiguration['httpClient'] | undefined;
|
|
7
|
+
expressPort?: number;
|
|
8
|
+
webSocketPort?: number;
|
|
9
|
+
platformVersion: PlatformVersion;
|
|
10
|
+
}
|
|
11
|
+
export declare class DevServerState {
|
|
12
|
+
private _webSocketPort;
|
|
13
|
+
private _expressPort;
|
|
14
|
+
private _functionsConfig;
|
|
15
|
+
private _outputDir;
|
|
16
|
+
private _appPath;
|
|
17
|
+
private _extensionsMetadata;
|
|
18
|
+
private _portalId?;
|
|
19
|
+
constructor({ extensionConfigs, accountId, httpClient, expressPort, webSocketPort, platformVersion, }: DevServerStateArgs);
|
|
20
|
+
get portalId(): number | undefined;
|
|
21
|
+
get webSocketPort(): number;
|
|
22
|
+
get expressPort(): number;
|
|
23
|
+
get extensionsMetadata(): ExtensionMetadata[];
|
|
24
|
+
get functionsConfig(): Partial<ServiceConfiguration>;
|
|
25
|
+
get outputDir(): string;
|
|
26
|
+
get appPath(): string;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DevServerState = void 0;
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
class DevServerState {
|
|
10
|
+
constructor({ extensionConfigs, accountId, httpClient, expressPort = constants_1.VITE_DEFAULT_PORT, webSocketPort = constants_1.WEBSOCKET_PORT, platformVersion, }) {
|
|
11
|
+
this._webSocketPort = constants_1.WEBSOCKET_PORT;
|
|
12
|
+
this._expressPort = constants_1.VITE_DEFAULT_PORT;
|
|
13
|
+
if (!extensionConfigs) {
|
|
14
|
+
throw new Error('Unable to load the required extension configuration files');
|
|
15
|
+
}
|
|
16
|
+
const extensionsMetadata = [];
|
|
17
|
+
extensionConfigs.forEach(config => {
|
|
18
|
+
const { appName, title, sourceId } = config.data;
|
|
19
|
+
extensionsMetadata.push({
|
|
20
|
+
config,
|
|
21
|
+
baseMessage: {
|
|
22
|
+
appName,
|
|
23
|
+
title,
|
|
24
|
+
sourceId,
|
|
25
|
+
callback: `http://hslocal.net:${expressPort}/${config.output}`,
|
|
26
|
+
portalId: accountId,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
this._webSocketPort = webSocketPort;
|
|
31
|
+
this._expressPort = expressPort;
|
|
32
|
+
this._extensionsMetadata = extensionsMetadata;
|
|
33
|
+
this._appPath = extensionConfigs[0].path;
|
|
34
|
+
this._portalId = accountId;
|
|
35
|
+
this._outputDir = path_1.default.join(this._appPath, constants_1.OUTPUT_DIR);
|
|
36
|
+
// Pass options from the CLI for running app functions locally
|
|
37
|
+
this._functionsConfig = {
|
|
38
|
+
app: { path: this._appPath },
|
|
39
|
+
accountId,
|
|
40
|
+
httpClient,
|
|
41
|
+
platformVersion,
|
|
42
|
+
};
|
|
43
|
+
Object.freeze(this);
|
|
44
|
+
}
|
|
45
|
+
get portalId() {
|
|
46
|
+
return this._portalId;
|
|
47
|
+
}
|
|
48
|
+
get webSocketPort() {
|
|
49
|
+
return this._webSocketPort;
|
|
50
|
+
}
|
|
51
|
+
get expressPort() {
|
|
52
|
+
return this._expressPort;
|
|
53
|
+
}
|
|
54
|
+
get extensionsMetadata() {
|
|
55
|
+
return this._extensionsMetadata;
|
|
56
|
+
}
|
|
57
|
+
get functionsConfig() {
|
|
58
|
+
return this._functionsConfig;
|
|
59
|
+
}
|
|
60
|
+
get outputDir() {
|
|
61
|
+
return this._outputDir;
|
|
62
|
+
}
|
|
63
|
+
get appPath() {
|
|
64
|
+
return this._appPath;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.DevServerState = DevServerState;
|
package/dist/lib/build.d.ts
CHANGED
|
@@ -6,9 +6,6 @@ interface BuildSingleExtensionArgs {
|
|
|
6
6
|
root?: string;
|
|
7
7
|
}
|
|
8
8
|
export declare const extensionErrorBaseMessage: string;
|
|
9
|
-
export declare function buildAllExtensions({ outputDir }: {
|
|
10
|
-
outputDir: string;
|
|
11
|
-
}): Promise<void>;
|
|
12
9
|
export declare function buildSingleExtension({ file, outputDir, emptyOutDir, minify, root, }: BuildSingleExtensionArgs): Promise<void>;
|
|
13
10
|
export declare function remoteBuild(root: string, entryPoint: string, outputDir?: string): Promise<void>;
|
|
14
11
|
export {};
|
package/dist/lib/build.js
CHANGED
|
@@ -12,31 +12,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.remoteBuild = exports.buildSingleExtension = exports.
|
|
15
|
+
exports.remoteBuild = exports.buildSingleExtension = exports.extensionErrorBaseMessage = void 0;
|
|
16
16
|
const vite_1 = require("vite");
|
|
17
17
|
const constants_1 = require("./constants");
|
|
18
18
|
const manifestPlugin_1 = __importDefault(require("./plugins/manifestPlugin"));
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
20
|
const utils_1 = require("./utils");
|
|
21
|
-
const config_1 = require("../cli/config");
|
|
22
21
|
const codeInjectionPlugin_1 = __importDefault(require("./plugins/codeInjectionPlugin"));
|
|
23
22
|
const allowedExtensions = ['.js', '.ts', '.tsx', '.jsx'];
|
|
24
23
|
exports.extensionErrorBaseMessage = `Supported file extensions are [${allowedExtensions.join(', ')}], received:`;
|
|
25
|
-
function buildAllExtensions({ outputDir }) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const config = (0, config_1.loadConfig)();
|
|
28
|
-
const extensionKeys = Object.keys(config);
|
|
29
|
-
for (let i = 0; i < extensionKeys.length; ++i) {
|
|
30
|
-
const { data } = config[extensionKeys[i]];
|
|
31
|
-
yield buildSingleExtension({
|
|
32
|
-
file: data.module.file,
|
|
33
|
-
outputDir,
|
|
34
|
-
emptyOutDir: i === 0,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
exports.buildAllExtensions = buildAllExtensions;
|
|
40
24
|
function buildSingleExtension({ file, outputDir = constants_1.OUTPUT_DIR, emptyOutDir = true, minify = false, root = process.cwd(), // This is the vite default, so using that as our default
|
|
41
25
|
}) {
|
|
42
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* hs-eslint ignored failing-rules */
|
|
3
|
+
/* eslint-disable hubspot-dev/no-unsupported-ts-syntax */
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.loadExtensionConfig = exports.loadConfigByPath = void 0;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
function loadConfigByPath(configPath) {
|
|
13
|
+
const source = fs_1.default.readFileSync(configPath).toString();
|
|
14
|
+
return JSON.parse(source);
|
|
15
|
+
}
|
|
16
|
+
exports.loadConfigByPath = loadConfigByPath;
|
|
17
|
+
function loadExtensionConfig(appConfig, appPath) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const crmCardsSubConfigFiles = (_b = (_a = appConfig === null || appConfig === void 0 ? void 0 : appConfig.extensions) === null || _a === void 0 ? void 0 : _a.crm) === null || _b === void 0 ? void 0 : _b.cards;
|
|
20
|
+
const outputConfig = {};
|
|
21
|
+
crmCardsSubConfigFiles.forEach(card => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const cardConfigPath = path_1.default.join(appPath, card.file);
|
|
24
|
+
try {
|
|
25
|
+
const cardConfig = loadConfigByPath(cardConfigPath);
|
|
26
|
+
if (cardConfig && cardConfig.data) {
|
|
27
|
+
const cardConfigDir = path_1.default.parse(cardConfigPath).dir;
|
|
28
|
+
const entryPointPath = path_1.default.join(cardConfigDir, (_b = (_a = cardConfig.data) === null || _a === void 0 ? void 0 : _a.module) === null || _b === void 0 ? void 0 : _b.file);
|
|
29
|
+
cardConfig.data.module.file = entryPointPath;
|
|
30
|
+
const sourceId = (0, utils_1.buildSourceId)(appConfig, cardConfig);
|
|
31
|
+
outputConfig[sourceId || `${entryPointPath}-${cardConfig.data.location}`] = Object.assign(Object.assign({}, cardConfig), { output: (0, utils_1.getUrlSafeFileName)(entryPointPath), path: appPath, extensionPath: path_1.default.parse(entryPointPath).dir, extensionConfigPath: cardConfigPath, data: Object.assign(Object.assign({}, cardConfig.data), { appName: appConfig.name, sourceId }) });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
throw new Error(`Unable to load ${cardConfigPath}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return outputConfig;
|
|
39
|
+
}
|
|
40
|
+
exports.loadExtensionConfig = loadExtensionConfig;
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -16,3 +16,7 @@ export declare const ROLLUP_OPTIONS: {
|
|
|
16
16
|
export declare const EXTENSIONS_MESSAGE_VERSION = 2;
|
|
17
17
|
export declare const WEBSOCKET_MESSAGE_VERSION = 1;
|
|
18
18
|
export declare const SERVER_CAPABILITIES: string[];
|
|
19
|
+
export declare const PLATFORM_VERSION: {
|
|
20
|
+
readonly V20231: "2023.1";
|
|
21
|
+
readonly V20232: "2023.2";
|
|
22
|
+
};
|
package/dist/lib/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SERVER_CAPABILITIES = exports.WEBSOCKET_MESSAGE_VERSION = exports.EXTENSIONS_MESSAGE_VERSION = exports.ROLLUP_OPTIONS = exports.WEBSOCKET_PORT = exports.VITE_DEFAULT_PORT = exports.MANIFEST_FILE = exports.MAIN_APP_CONFIG = exports.OUTPUT_DIR = void 0;
|
|
3
|
+
exports.PLATFORM_VERSION = exports.SERVER_CAPABILITIES = exports.WEBSOCKET_MESSAGE_VERSION = exports.EXTENSIONS_MESSAGE_VERSION = exports.ROLLUP_OPTIONS = exports.WEBSOCKET_PORT = exports.VITE_DEFAULT_PORT = exports.MANIFEST_FILE = exports.MAIN_APP_CONFIG = exports.OUTPUT_DIR = void 0;
|
|
4
4
|
exports.OUTPUT_DIR = 'dist';
|
|
5
5
|
exports.MAIN_APP_CONFIG = 'app.json';
|
|
6
6
|
exports.MANIFEST_FILE = 'manifest.json';
|
|
@@ -26,3 +26,7 @@ exports.SERVER_CAPABILITIES = [
|
|
|
26
26
|
'source-id',
|
|
27
27
|
'account-id',
|
|
28
28
|
];
|
|
29
|
+
exports.PLATFORM_VERSION = {
|
|
30
|
+
V20231: '2023.1',
|
|
31
|
+
V20232: '2023.2',
|
|
32
|
+
};
|
package/dist/lib/dev.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface StartDevModeArgs {
|
|
4
|
-
outputDir?: string;
|
|
5
|
-
extensionConfig: ExtensionConfig;
|
|
6
|
-
webSocketPort?: number;
|
|
7
|
-
expressPort?: number;
|
|
8
|
-
root?: string;
|
|
9
|
-
functionsConfig: Partial<ServiceConfiguration>;
|
|
10
|
-
}
|
|
11
|
-
export declare function startDevMode({ extensionConfig, functionsConfig, outputDir, expressPort, webSocketPort, root, }: StartDevModeArgs): Promise<() => Promise<void>>;
|
|
12
|
-
export {};
|
|
1
|
+
import { DevServerState } from './DevServerState';
|
|
2
|
+
export declare function startDevMode(devServerState: DevServerState): Promise<() => Promise<void>>;
|
package/dist/lib/dev.js
CHANGED
|
@@ -17,26 +17,25 @@ const vite_1 = require("vite");
|
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
18
|
const server_1 = __importDefault(require("./server"));
|
|
19
19
|
const devBuildPlugin_1 = __importDefault(require("./plugins/devBuildPlugin"));
|
|
20
|
-
const constants_1 = require("./constants");
|
|
21
20
|
// @ts-expect-error no type defs
|
|
22
21
|
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
23
22
|
// @ts-expect-error no type defs
|
|
24
23
|
const detect_port_1 = __importDefault(require("detect-port"));
|
|
25
|
-
function _createViteDevServer(
|
|
24
|
+
function _createViteDevServer(devServerState) {
|
|
26
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
26
|
return yield (0, vite_1.createServer)({
|
|
28
|
-
root,
|
|
27
|
+
root: devServerState.appPath,
|
|
29
28
|
logLevel: 'silent',
|
|
30
29
|
appType: 'custom',
|
|
31
30
|
mode: 'development',
|
|
32
31
|
server: {
|
|
33
32
|
middlewareMode: true,
|
|
34
33
|
hmr: {
|
|
35
|
-
port: webSocketPort,
|
|
34
|
+
port: devServerState.webSocketPort,
|
|
36
35
|
},
|
|
37
36
|
watch: {
|
|
38
37
|
ignored: [
|
|
39
|
-
path_1.default.join(outputDir, '/**/*'),
|
|
38
|
+
path_1.default.join(devServerState.outputDir, '/**/*'),
|
|
40
39
|
'**/src/app/app.functions/**/*',
|
|
41
40
|
'**/app.json',
|
|
42
41
|
'**/package.json',
|
|
@@ -46,9 +45,7 @@ function _createViteDevServer({ outputDir, extensionConfig, webSocketPort, baseM
|
|
|
46
45
|
},
|
|
47
46
|
plugins: [
|
|
48
47
|
(0, devBuildPlugin_1.default)({
|
|
49
|
-
|
|
50
|
-
outputDir,
|
|
51
|
-
baseMessage,
|
|
48
|
+
devServerState,
|
|
52
49
|
}),
|
|
53
50
|
],
|
|
54
51
|
clearScreen: false,
|
|
@@ -64,38 +61,21 @@ function throwIfPortTaken(port) {
|
|
|
64
61
|
}
|
|
65
62
|
});
|
|
66
63
|
}
|
|
67
|
-
function startDevMode(
|
|
64
|
+
function startDevMode(devServerState) {
|
|
68
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
if (!
|
|
66
|
+
if (!devServerState || !devServerState.extensionsMetadata) {
|
|
70
67
|
throw new Error('Unable to determine which extension to run');
|
|
71
68
|
}
|
|
69
|
+
const { expressPort, webSocketPort } = devServerState;
|
|
72
70
|
yield throwIfPortTaken(expressPort);
|
|
73
71
|
const actualWebSocketPort = yield (0, detect_port_1.default)(webSocketPort);
|
|
74
72
|
if (actualWebSocketPort !== webSocketPort) {
|
|
75
73
|
logger_1.logger.debug(`WebSocket port ${webSocketPort} is in use; using next available port ${actualWebSocketPort}`);
|
|
76
74
|
}
|
|
77
|
-
const
|
|
78
|
-
const baseMessage = Object.freeze({
|
|
79
|
-
appName,
|
|
80
|
-
title,
|
|
81
|
-
sourceId,
|
|
82
|
-
callback: `http://hslocal.net:${expressPort}/${extensionConfig.output}`,
|
|
83
|
-
portalId: functionsConfig.accountId,
|
|
84
|
-
});
|
|
85
|
-
const viteDevServer = yield _createViteDevServer({
|
|
86
|
-
outputDir,
|
|
87
|
-
extensionConfig,
|
|
88
|
-
webSocketPort: actualWebSocketPort,
|
|
89
|
-
baseMessage,
|
|
90
|
-
root,
|
|
91
|
-
});
|
|
75
|
+
const viteDevServer = yield _createViteDevServer(devServerState);
|
|
92
76
|
const shutdownServer = yield (0, server_1.default)({
|
|
93
|
-
|
|
94
|
-
expressPort,
|
|
95
|
-
webSocketPort: actualWebSocketPort,
|
|
96
|
-
baseMessage,
|
|
77
|
+
devServerState,
|
|
97
78
|
viteDevServer,
|
|
98
|
-
functionsConfig,
|
|
99
79
|
});
|
|
100
80
|
return shutdownServer;
|
|
101
81
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { BaseMessage } from './types';
|
|
2
1
|
import { Response } from 'express/lib/response';
|
|
3
2
|
import { Request } from 'express/lib/request';
|
|
4
3
|
import { Application } from 'express/lib/application';
|
|
4
|
+
import { DevServerState } from './DevServerState';
|
|
5
5
|
declare class ExtensionsService {
|
|
6
6
|
endpoint: string;
|
|
7
7
|
constructor();
|
|
8
|
-
add(server: Application,
|
|
9
|
-
generateExtensionsHandler(
|
|
8
|
+
add(server: Application, devServerState: DevServerState, capabilities: string[]): string[];
|
|
9
|
+
generateExtensionsHandler(devServerState: DevServerState, capabilities?: string[]): (_req: Request, res: Response) => void;
|
|
10
10
|
}
|
|
11
11
|
declare const _default: ExtensionsService;
|
|
12
12
|
export default _default;
|
|
@@ -3,6 +3,7 @@ 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
|
+
/* eslint-disable hubspot-dev/no-unsupported-ts-syntax */
|
|
6
7
|
const path_1 = __importDefault(require("path"));
|
|
7
8
|
const constants_1 = require("./constants");
|
|
8
9
|
const utils_1 = require("./utils");
|
|
@@ -10,22 +11,24 @@ class ExtensionsService {
|
|
|
10
11
|
constructor() {
|
|
11
12
|
this.endpoint = '/extensions';
|
|
12
13
|
}
|
|
13
|
-
add(server,
|
|
14
|
-
server.get(this.endpoint, this.generateExtensionsHandler(
|
|
14
|
+
add(server, devServerState, capabilities) {
|
|
15
|
+
server.get(this.endpoint, this.generateExtensionsHandler(devServerState, capabilities));
|
|
15
16
|
return [this.endpoint];
|
|
16
17
|
}
|
|
17
|
-
generateExtensionsHandler(
|
|
18
|
+
generateExtensionsHandler(devServerState, capabilities = []) {
|
|
18
19
|
return function extensionsHandler(_req, res) {
|
|
19
20
|
try {
|
|
20
|
-
const
|
|
21
|
+
const extensions = devServerState.extensionsMetadata.map(metadata => {
|
|
22
|
+
const { baseMessage } = metadata;
|
|
23
|
+
const output = path_1.default.parse(baseMessage.callback).name;
|
|
24
|
+
return Object.assign(Object.assign({}, baseMessage), { manifest: (0, utils_1.loadManifest)(devServerState.outputDir, output) });
|
|
25
|
+
});
|
|
21
26
|
const response = {
|
|
22
|
-
websocket: `ws://localhost:${webSocketPort}`,
|
|
27
|
+
websocket: `ws://localhost:${devServerState.webSocketPort}`,
|
|
23
28
|
version: constants_1.EXTENSIONS_MESSAGE_VERSION,
|
|
24
29
|
capabilities,
|
|
25
|
-
portalId:
|
|
26
|
-
extensions
|
|
27
|
-
Object.assign(Object.assign({}, baseMessage), { manifest: (0, utils_1.loadManifest)(outputDir, output) }),
|
|
28
|
-
],
|
|
30
|
+
portalId: devServerState.portalId,
|
|
31
|
+
extensions,
|
|
29
32
|
};
|
|
30
33
|
res.status(200).json(response);
|
|
31
34
|
}
|
|
@@ -14,7 +14,8 @@ const codeCheckingPlugin = options => {
|
|
|
14
14
|
writeBundle(__options, __bundle) {
|
|
15
15
|
try {
|
|
16
16
|
const code = fs_1.default.readFileSync(output).toString();
|
|
17
|
-
if (!code.includes('const extend = (...args) => self.extend(...args);')
|
|
17
|
+
if (!code.includes('const extend = (...args) => self.extend(...args);') &&
|
|
18
|
+
!code.includes('self.extend_V2(renderExtensionCallback)')) {
|
|
18
19
|
logger_1.logger.warn('Unable to determine if your extension entry point is calling hubspot.extend, this may prevent it from rendering as expected');
|
|
19
20
|
}
|
|
20
21
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import Vite from 'vite';
|
|
2
|
-
import {
|
|
2
|
+
import { DevServerState } from '../DevServerState';
|
|
3
3
|
export interface DevBuildPluginOptions {
|
|
4
|
-
|
|
5
|
-
outputDir: string;
|
|
6
|
-
baseMessage: BaseMessage;
|
|
4
|
+
devServerState: DevServerState;
|
|
7
5
|
}
|
|
8
6
|
export type DevBuildPlugin = (options: DevBuildPluginOptions) => Vite.Plugin;
|
|
9
7
|
declare const devBuildPlugin: DevBuildPlugin;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* hs-eslint ignored failing-rules */
|
|
3
|
+
/* eslint-disable hubspot-dev/no-unsupported-ts-syntax */
|
|
2
4
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
5
|
if (k2 === undefined) k2 = k;
|
|
4
6
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -45,16 +47,18 @@ const path_1 = __importDefault(require("path"));
|
|
|
45
47
|
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
46
48
|
const friendlyLoggingPlugin_1 = __importDefault(require("./friendlyLoggingPlugin"));
|
|
47
49
|
const relevantModulesPlugin_1 = __importStar(require("./relevantModulesPlugin"));
|
|
50
|
+
function addVersionToBaseMessage(baseMessage) {
|
|
51
|
+
return Object.assign(Object.assign({}, baseMessage), { version: constants_1.WEBSOCKET_MESSAGE_VERSION });
|
|
52
|
+
}
|
|
48
53
|
const devBuildPlugin = options => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const versionedBaseMessage = Object.assign(Object.assign({}, baseMessage), { version: constants_1.WEBSOCKET_MESSAGE_VERSION });
|
|
54
|
+
const { devServerState } = options;
|
|
55
|
+
let lastBuildErrorContext;
|
|
52
56
|
const handleBuildError = (error, server) => {
|
|
53
|
-
const { plugin, errors, frame, loc, id } = error;
|
|
57
|
+
const { error: { plugin, errors, frame, loc, id }, extensionMetadata, } = error;
|
|
54
58
|
// Filter out our custom plugins, but send everything else
|
|
55
59
|
if (!(plugin === null || plugin === void 0 ? void 0 : plugin.startsWith('ui-extensions'))) {
|
|
56
60
|
// @ts-expect-error Our websocket messages don't match Vite format
|
|
57
|
-
server.ws.send(Object.assign(Object.assign({},
|
|
61
|
+
server.ws.send(Object.assign(Object.assign({}, addVersionToBaseMessage(extensionMetadata.baseMessage)), { event: 'error', error: {
|
|
58
62
|
details: {
|
|
59
63
|
errors,
|
|
60
64
|
formattedError: (0, utils_1.stripAnsiColorCodes)(frame),
|
|
@@ -64,8 +68,9 @@ const devBuildPlugin = options => {
|
|
|
64
68
|
} }));
|
|
65
69
|
}
|
|
66
70
|
};
|
|
67
|
-
const devBuild = (server) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
const devBuild = (server, extensionMetadata, emptyOutDir = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
72
|
try {
|
|
73
|
+
const { config: extensionConfig } = extensionMetadata;
|
|
69
74
|
yield (0, vite_1.build)({
|
|
70
75
|
logLevel: 'warn',
|
|
71
76
|
mode: 'development',
|
|
@@ -93,24 +98,27 @@ const devBuildPlugin = options => {
|
|
|
93
98
|
extensionPath: extensionConfig.extensionPath,
|
|
94
99
|
}),
|
|
95
100
|
(0, codeCheckingPlugin_1.default)({
|
|
96
|
-
output: path_1.default.join(outputDir, extensionConfig.output),
|
|
101
|
+
output: path_1.default.join(devServerState.outputDir, extensionConfig.output),
|
|
97
102
|
}),
|
|
98
103
|
(0, friendlyLoggingPlugin_1.default)(),
|
|
99
104
|
(0, relevantModulesPlugin_1.default)({ output: extensionConfig.output }),
|
|
100
105
|
], output: Object.assign(Object.assign({}, constants_1.ROLLUP_OPTIONS.output), { sourcemap: 'inline' }) }),
|
|
101
|
-
outDir: outputDir,
|
|
102
|
-
emptyOutDir
|
|
106
|
+
outDir: devServerState.outputDir,
|
|
107
|
+
emptyOutDir,
|
|
103
108
|
minify: false,
|
|
104
109
|
},
|
|
105
110
|
clearScreen: false,
|
|
106
111
|
});
|
|
107
|
-
|
|
112
|
+
lastBuildErrorContext = null;
|
|
108
113
|
return true;
|
|
109
114
|
}
|
|
110
115
|
catch (error) {
|
|
111
|
-
|
|
116
|
+
lastBuildErrorContext = {
|
|
117
|
+
error: error,
|
|
118
|
+
extensionMetadata,
|
|
119
|
+
};
|
|
112
120
|
logger_1.logger.debug(error);
|
|
113
|
-
handleBuildError(
|
|
121
|
+
handleBuildError(lastBuildErrorContext, server);
|
|
114
122
|
return false;
|
|
115
123
|
}
|
|
116
124
|
});
|
|
@@ -124,41 +132,52 @@ const devBuildPlugin = options => {
|
|
|
124
132
|
localServer = server;
|
|
125
133
|
localServer.ws.on('connection', () => {
|
|
126
134
|
logger_1.logger.info('Browser connected and listening for bundle updates');
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
135
|
+
devServerState.extensionsMetadata.forEach(metadata => {
|
|
136
|
+
// @ts-expect-error Our websocket messages don't match Vite format
|
|
137
|
+
localServer.ws.send(Object.assign(Object.assign({}, addVersionToBaseMessage(metadata.baseMessage)), { event: 'start' }));
|
|
138
|
+
});
|
|
139
|
+
if (lastBuildErrorContext) {
|
|
140
|
+
handleBuildError(lastBuildErrorContext, server);
|
|
131
141
|
}
|
|
132
142
|
});
|
|
133
|
-
|
|
143
|
+
for (let i = 0; i < devServerState.extensionsMetadata.length; ++i) {
|
|
144
|
+
yield devBuild(localServer, devServerState.extensionsMetadata[i], i === 0);
|
|
145
|
+
}
|
|
134
146
|
}),
|
|
135
147
|
handleHotUpdate: ({ file, server }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
136
148
|
// If the file is not in the relevantModules list, it's update is inconsequential
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
const extensionsToRebuild = devServerState.extensionsMetadata.filter(metadata => {
|
|
150
|
+
const { config } = metadata;
|
|
151
|
+
return (0, relevantModulesPlugin_1.getRelevantModules)(config.output).includes(file);
|
|
152
|
+
});
|
|
153
|
+
for (let i = 0; i < extensionsToRebuild.length; ++i) {
|
|
154
|
+
const toRebuild = extensionsToRebuild[i];
|
|
155
|
+
const successful = yield devBuild(server, toRebuild);
|
|
156
|
+
if (!successful) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
const { config: extensionConfig } = toRebuild;
|
|
160
|
+
logger_1.logger.info(`Extension ${extensionConfig.data.title} updated, compiled`);
|
|
161
|
+
if (server.ws.clients.size === 0) {
|
|
162
|
+
logger_1.logger.debug('Bundle updated, no browsers connected to notify');
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
logger_1.logger.debug('Bundle updated, notifying connected browsers');
|
|
166
|
+
// @ts-expect-error Our websocket messages don't match Vite format
|
|
167
|
+
server.ws.send(Object.assign(Object.assign({}, addVersionToBaseMessage(toRebuild.baseMessage)), { event: 'update' }));
|
|
148
168
|
}
|
|
149
|
-
logger_1.logger.debug('Bundle updated, notifying connected browsers');
|
|
150
|
-
// @ts-expect-error Our websocket messages don't match Vite format
|
|
151
|
-
server.ws.send(Object.assign(Object.assign({}, versionedBaseMessage), { event: 'update' }));
|
|
152
169
|
return [];
|
|
153
170
|
}),
|
|
154
171
|
buildEnd(error) {
|
|
155
172
|
if (error) {
|
|
156
173
|
logger_1.logger.error(error);
|
|
157
174
|
}
|
|
158
|
-
logger_1.logger.debug('Sending shutdown message to connected browsers');
|
|
159
175
|
if (localServer && localServer.ws) {
|
|
160
|
-
|
|
161
|
-
|
|
176
|
+
logger_1.logger.debug('Sending shutdown message to connected browsers');
|
|
177
|
+
devServerState.extensionsMetadata.forEach(metadata => {
|
|
178
|
+
// @ts-expect-error Our websocket messages don't match Vite format
|
|
179
|
+
localServer.ws.send(Object.assign(Object.assign({}, addVersionToBaseMessage(metadata.baseMessage)), { event: 'shutdown' }));
|
|
180
|
+
});
|
|
162
181
|
}
|
|
163
182
|
},
|
|
164
183
|
};
|
package/dist/lib/server.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { BaseMessage } from './types';
|
|
2
1
|
import { ViteDevServer } from 'vite';
|
|
3
|
-
import {
|
|
2
|
+
import { DevServerState } from './DevServerState';
|
|
4
3
|
interface StartDevServerArgs {
|
|
5
|
-
|
|
6
|
-
expressPort: number;
|
|
7
|
-
webSocketPort: number;
|
|
8
|
-
baseMessage: BaseMessage;
|
|
4
|
+
devServerState: DevServerState;
|
|
9
5
|
viteDevServer: ViteDevServer;
|
|
10
|
-
functionsConfig: Partial<ServiceConfiguration>;
|
|
11
6
|
}
|
|
12
|
-
declare function startDevServer({
|
|
7
|
+
declare function startDevServer({ devServerState, viteDevServer, }: StartDevServerArgs): Promise<() => Promise<void>>;
|
|
13
8
|
export default startDevServer;
|
package/dist/lib/server.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable hubspot-dev/no-unsupported-ts-syntax */
|
|
3
|
+
/* eslint-disable no-unused-expressions */
|
|
2
4
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
5
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
6
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -30,15 +32,17 @@ function listen(app, port) {
|
|
|
30
32
|
});
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
|
-
function startDevServer({
|
|
35
|
+
function startDevServer({ devServerState, viteDevServer, }) {
|
|
36
|
+
var _a;
|
|
34
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
38
|
const app = (0, express_1.default)();
|
|
36
39
|
// Setup middleware
|
|
37
40
|
app.use((0, cors_1.default)());
|
|
38
|
-
app.use(express_1.default.static(outputDir));
|
|
39
|
-
app.use('/api/crm-extensibility/execution/internal/v3', (0, app_functions_dev_server_1.AppFunctionExecutionService)(Object.assign(Object.assign({}, functionsConfig), { logger: logger_1.logger })));
|
|
40
|
-
logger_1.logger.info(
|
|
41
|
-
const endpointsAdded = extensionsService_1.default.add(app,
|
|
41
|
+
app.use(express_1.default.static(devServerState.outputDir));
|
|
42
|
+
app.use('/api/crm-extensibility/execution/internal/v3', (0, app_functions_dev_server_1.AppFunctionExecutionService)(Object.assign(Object.assign({}, devServerState.functionsConfig), { logger: logger_1.logger })));
|
|
43
|
+
logger_1.logger.info(`Serving app functions locally (platform version ${devServerState.functionsConfig.platformVersion})`);
|
|
44
|
+
const endpointsAdded = extensionsService_1.default.add(app, devServerState, constants_1.SERVER_CAPABILITIES);
|
|
45
|
+
const { expressPort } = devServerState;
|
|
42
46
|
endpointsAdded.forEach(endpoint => {
|
|
43
47
|
logger_1.logger.debug(`Listening at http://hslocal.net:${expressPort}${endpoint}`);
|
|
44
48
|
});
|
|
@@ -46,15 +50,18 @@ function startDevServer({ outputDir, expressPort, webSocketPort, baseMessage, vi
|
|
|
46
50
|
app.use(viteDevServer.middlewares);
|
|
47
51
|
let server;
|
|
48
52
|
try {
|
|
49
|
-
server = yield listen(app, expressPort);
|
|
53
|
+
server = yield listen(app, devServerState.expressPort);
|
|
50
54
|
}
|
|
51
55
|
catch (e) {
|
|
52
56
|
if (e.code === 'EADDRINUSE') {
|
|
53
|
-
throw new Error(`Port ${expressPort} is already in use.`);
|
|
57
|
+
throw new Error(`Port ${devServerState.expressPort} is already in use.`);
|
|
54
58
|
}
|
|
55
59
|
throw new Error(e);
|
|
56
60
|
}
|
|
57
|
-
|
|
61
|
+
(_a = devServerState.extensionsMetadata) === null || _a === void 0 ? void 0 : _a.forEach(metadata => {
|
|
62
|
+
const { baseMessage } = metadata;
|
|
63
|
+
logger_1.logger.debug(`Listening at ${baseMessage.callback}`);
|
|
64
|
+
});
|
|
58
65
|
return function shutdown() {
|
|
59
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
67
|
yield viteDevServer.pluginContainer.close();
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PLATFORM_VERSION } from './constants';
|
|
1
2
|
export interface ObjectTypes {
|
|
2
3
|
name: string;
|
|
3
4
|
}
|
|
@@ -51,4 +52,9 @@ export interface BaseMessage {
|
|
|
51
52
|
sourceId?: string | null;
|
|
52
53
|
portalId?: number;
|
|
53
54
|
}
|
|
55
|
+
export interface ExtensionMetadata {
|
|
56
|
+
baseMessage: BaseMessage;
|
|
57
|
+
config: ExtensionConfig;
|
|
58
|
+
}
|
|
59
|
+
export type PlatformVersion = typeof PLATFORM_VERSION[keyof typeof PLATFORM_VERSION];
|
|
54
60
|
export {};
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -4,3 +4,7 @@ export declare function stripAnsiColorCodes(stringWithColorCodes: string | undef
|
|
|
4
4
|
export declare function loadManifest(outputDir: string, output: string): any;
|
|
5
5
|
export declare function buildSourceId(appConfig: AppConfig, extensionConfig: ExtensionConfig): string | null;
|
|
6
6
|
export declare function isNodeModule(filepath: string | undefined): boolean;
|
|
7
|
+
export declare class UnhandledPlatformVersionError extends Error {
|
|
8
|
+
constructor(platformVersion: never);
|
|
9
|
+
}
|
|
10
|
+
export declare function throwUnhandledPlatformVersionError(platformVersion: never): never;
|
package/dist/lib/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.isNodeModule = exports.buildSourceId = exports.loadManifest = exports.stripAnsiColorCodes = exports.getUrlSafeFileName = void 0;
|
|
6
|
+
exports.throwUnhandledPlatformVersionError = exports.UnhandledPlatformVersionError = exports.isNodeModule = exports.buildSourceId = exports.loadManifest = exports.stripAnsiColorCodes = exports.getUrlSafeFileName = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const constants_1 = require("./constants");
|
|
@@ -48,3 +48,13 @@ function isNodeModule(filepath) {
|
|
|
48
48
|
return directory.includes('node_modules');
|
|
49
49
|
}
|
|
50
50
|
exports.isNodeModule = isNodeModule;
|
|
51
|
+
class UnhandledPlatformVersionError extends Error {
|
|
52
|
+
constructor(platformVersion) {
|
|
53
|
+
super(`Unsupported platform version "${platformVersion}"`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.UnhandledPlatformVersionError = UnhandledPlatformVersionError;
|
|
57
|
+
function throwUnhandledPlatformVersionError(platformVersion) {
|
|
58
|
+
throw new UnhandledPlatformVersionError(platformVersion);
|
|
59
|
+
}
|
|
60
|
+
exports.throwUnhandledPlatformVersionError = throwUnhandledPlatformVersionError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/ui-extensions-dev-server",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@hubspot/app-functions-dev-server": "^0.8.
|
|
27
|
+
"@hubspot/app-functions-dev-server": "^0.8.3",
|
|
28
28
|
"@hubspot/cli-lib": "^4.1.6",
|
|
29
29
|
"command-line-args": "^5.2.1",
|
|
30
30
|
"command-line-usage": "^7.0.1",
|
|
@@ -45,9 +45,6 @@
|
|
|
45
45
|
"typescript": "^5.1.6",
|
|
46
46
|
"ws": "^8.13.0"
|
|
47
47
|
},
|
|
48
|
-
"bin": {
|
|
49
|
-
"hs-ui-extensions-dev-server": "./dist/cli/run.js"
|
|
50
|
-
},
|
|
51
48
|
"eslintConfig": {
|
|
52
49
|
"env": {
|
|
53
50
|
"node": true,
|
|
@@ -66,5 +63,5 @@
|
|
|
66
63
|
"optional": true
|
|
67
64
|
}
|
|
68
65
|
},
|
|
69
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "41e3484343d34136e81540d774a101ccf99642b3"
|
|
70
67
|
}
|
package/dist/cli/config.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { AppConfig, ExtensionConfigMap } from '../lib/types';
|
|
2
|
-
export declare function loadConfigByPath<T = unknown>(configPath: string): T;
|
|
3
|
-
export declare function loadExtensionConfig(appConfig: AppConfig, appPath: string): ExtensionConfigMap;
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated Will be removed after integration with hubspot-cli is complete
|
|
6
|
-
* This version of load config makes assumptions about the location it is being ran from where the others do not
|
|
7
|
-
*/
|
|
8
|
-
export declare function loadConfig(): ExtensionConfigMap;
|
package/dist/cli/config.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loadConfig = exports.loadExtensionConfig = exports.loadConfigByPath = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const utils_1 = require("../lib/utils");
|
|
10
|
-
const constants_1 = require("../lib/constants");
|
|
11
|
-
function loadConfigByPath(configPath) {
|
|
12
|
-
const source = fs_1.default.readFileSync(configPath).toString();
|
|
13
|
-
return JSON.parse(source);
|
|
14
|
-
}
|
|
15
|
-
exports.loadConfigByPath = loadConfigByPath;
|
|
16
|
-
function loadExtensionConfig(appConfig, appPath) {
|
|
17
|
-
var _a, _b;
|
|
18
|
-
const crmCardsSubConfigFiles = (_b = (_a = appConfig === null || appConfig === void 0 ? void 0 : appConfig.extensions) === null || _a === void 0 ? void 0 : _a.crm) === null || _b === void 0 ? void 0 : _b.cards;
|
|
19
|
-
const outputConfig = {};
|
|
20
|
-
crmCardsSubConfigFiles.forEach(card => {
|
|
21
|
-
var _a, _b;
|
|
22
|
-
const cardConfigPath = path_1.default.join(appPath, card.file);
|
|
23
|
-
try {
|
|
24
|
-
const cardConfig = loadConfigByPath(cardConfigPath);
|
|
25
|
-
if (cardConfig && cardConfig.data) {
|
|
26
|
-
const cardConfigDir = path_1.default.parse(cardConfigPath).dir;
|
|
27
|
-
const entryPointPath = path_1.default.join(cardConfigDir, (_b = (_a = cardConfig.data) === null || _a === void 0 ? void 0 : _a.module) === null || _b === void 0 ? void 0 : _b.file);
|
|
28
|
-
cardConfig.data.module.file = entryPointPath;
|
|
29
|
-
const sourceId = (0, utils_1.buildSourceId)(appConfig, cardConfig);
|
|
30
|
-
outputConfig[sourceId || `${entryPointPath}-${cardConfig.data.location}`] = Object.assign(Object.assign({}, cardConfig), { output: (0, utils_1.getUrlSafeFileName)(entryPointPath), path: appPath, extensionPath: path_1.default.parse(entryPointPath).dir, extensionConfigPath: cardConfigPath, data: Object.assign(Object.assign({}, cardConfig.data), { appName: appConfig.name, sourceId }) });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
throw new Error(`Unable to load ${cardConfigPath}`);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
return outputConfig;
|
|
38
|
-
}
|
|
39
|
-
exports.loadExtensionConfig = loadExtensionConfig;
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated Will be removed after integration with hubspot-cli is complete
|
|
42
|
-
* This version of load config makes assumptions about the location it is being ran from where the others do not
|
|
43
|
-
*/
|
|
44
|
-
function loadConfig() {
|
|
45
|
-
var _a, _b;
|
|
46
|
-
// app.json is one level up from the extensions directory, which is where these commands
|
|
47
|
-
// will need to be ran from, the extensions directory
|
|
48
|
-
const configPath = path_1.default.join(process.cwd(), '..', constants_1.MAIN_APP_CONFIG);
|
|
49
|
-
const mainAppConfig = loadConfigByPath(configPath);
|
|
50
|
-
const crmCardsSubConfigFiles = (_b = (_a = mainAppConfig === null || mainAppConfig === void 0 ? void 0 : mainAppConfig.extensions) === null || _a === void 0 ? void 0 : _a.crm) === null || _b === void 0 ? void 0 : _b.cards;
|
|
51
|
-
if (!crmCardsSubConfigFiles || crmCardsSubConfigFiles.length === 0) {
|
|
52
|
-
throw new Error(`The "extensions.crm.cards" array in ${configPath} is missing or empty, it is a required configuration property`);
|
|
53
|
-
}
|
|
54
|
-
const outputConfig = {};
|
|
55
|
-
crmCardsSubConfigFiles.forEach(card => {
|
|
56
|
-
const cardConfigPath = path_1.default.join(process.cwd(), '..', card.file);
|
|
57
|
-
try {
|
|
58
|
-
const cardConfig = loadConfigByPath(cardConfigPath);
|
|
59
|
-
if (!cardConfig.data) {
|
|
60
|
-
throw new Error(`Invalid config file at path ${cardConfigPath}, data is a required config property`);
|
|
61
|
-
}
|
|
62
|
-
if (!cardConfig.data.module) {
|
|
63
|
-
throw new Error(`Invalid config file at path ${cardConfigPath}, data.module is a require property`);
|
|
64
|
-
}
|
|
65
|
-
// Path.join with a single argument will strip off any relative prefixing such as './'
|
|
66
|
-
const entryPointPath = path_1.default.join(cardConfig.data.module.file);
|
|
67
|
-
cardConfig.data.module.file = entryPointPath;
|
|
68
|
-
outputConfig[entryPointPath] = cardConfig;
|
|
69
|
-
outputConfig[entryPointPath].data.appName = mainAppConfig.name;
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
if ((e === null || e === void 0 ? void 0 : e.code) === 'MODULE_NOT_FOUND') {
|
|
73
|
-
throw new Error(`Unable to load "${cardConfigPath}" file. \nPlease make sure you are running the command from the src/app/extensions directory and that your card JSON config exists within it.`);
|
|
74
|
-
}
|
|
75
|
-
throw e;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
return outputConfig;
|
|
79
|
-
}
|
|
80
|
-
exports.loadConfig = loadConfig;
|
package/dist/cli/run.d.ts
DELETED
package/dist/cli/run.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const utils_1 = require("../cli/utils");
|
|
17
|
-
const index_1 = require("../index");
|
|
18
|
-
const console_log_colors_1 = require("console-log-colors");
|
|
19
|
-
const path_1 = __importDefault(require("path"));
|
|
20
|
-
const constants_1 = require("../lib/constants");
|
|
21
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
22
|
-
const config_1 = require("./config");
|
|
23
|
-
// eslint-disable-next-line no-floating-promise/no-floating-promise
|
|
24
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
const { DEV_MODE, BUILD_MODE, extension, location, help, force, account, } = (0, utils_1.parseArgs)();
|
|
26
|
-
if (!force) {
|
|
27
|
-
console.warn((0, console_log_colors_1.yellow)(`"hs-ui-extensions-dev-server" is deprecated, please use "hs project dev" for local development.
|
|
28
|
-
\nSee our Getting Started guide for detailed instructions: https://app.hubspot.com/l/docs/doc/platform/create-a-project-for-ui-extensions\n`));
|
|
29
|
-
process.exit(0);
|
|
30
|
-
}
|
|
31
|
-
if (help || !(DEV_MODE || BUILD_MODE)) {
|
|
32
|
-
(0, utils_1.showHelp)(constants_1.OUTPUT_DIR);
|
|
33
|
-
}
|
|
34
|
-
else if (DEV_MODE) {
|
|
35
|
-
const extensionPath = process.cwd(); // Assumed to be /path/to/src/app/extensions
|
|
36
|
-
const appPath = path_1.default.join(extensionPath, '..');
|
|
37
|
-
const appConfig = (0, config_1.loadConfigByPath)(path_1.default.join(appPath, constants_1.MAIN_APP_CONFIG));
|
|
38
|
-
let extensionConfig;
|
|
39
|
-
if (extension) {
|
|
40
|
-
const allExtensionsConfig = (0, config_1.loadExtensionConfig)(appConfig, appPath);
|
|
41
|
-
const matchingConfigs = Object.values(allExtensionsConfig).filter(config => {
|
|
42
|
-
const entrypoint = path_1.default.parse(config.data.module.file).base;
|
|
43
|
-
return entrypoint === path_1.default.join(extension);
|
|
44
|
-
});
|
|
45
|
-
if (matchingConfigs.length === 1) {
|
|
46
|
-
extensionConfig = matchingConfigs[0];
|
|
47
|
-
}
|
|
48
|
-
else if (matchingConfigs.length > 1 && location) {
|
|
49
|
-
// We need to do some tie breaking
|
|
50
|
-
const filteredByLocation = matchingConfigs.filter(config => config.data.location === location);
|
|
51
|
-
if (filteredByLocation.length === 1) {
|
|
52
|
-
extensionConfig = filteredByLocation[0];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
yield index_1.DevModeInterface.setup({
|
|
57
|
-
promptUser: inquirer_1.default.createPromptModule(),
|
|
58
|
-
components: {
|
|
59
|
-
[appConfig.name]: {
|
|
60
|
-
config: appConfig,
|
|
61
|
-
path: path_1.default.join(extensionPath, '..'),
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
extensionConfig,
|
|
65
|
-
});
|
|
66
|
-
yield index_1.DevModeInterface.start({
|
|
67
|
-
accountId: account,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
else if (BUILD_MODE) {
|
|
71
|
-
if (extension) {
|
|
72
|
-
(0, index_1.buildSingleExtension)({
|
|
73
|
-
file: extension,
|
|
74
|
-
outputDir: constants_1.OUTPUT_DIR,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
(0, index_1.buildAllExtensions)({ outputDir: constants_1.OUTPUT_DIR });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}))();
|
|
82
|
-
function shutdown() {
|
|
83
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
yield index_1.DevModeInterface.cleanup();
|
|
85
|
-
process.exit(0);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
process.on('SIGINT', shutdown);
|
|
89
|
-
process.on('SIGTERM', shutdown);
|
package/dist/cli/utils.d.ts
DELETED
package/dist/cli/utils.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.showHelp = exports.parseArgs = void 0;
|
|
7
|
-
// @ts-expect-error no type defs
|
|
8
|
-
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
9
|
-
// @ts-expect-error no type defs
|
|
10
|
-
const command_line_args_1 = __importDefault(require("command-line-args"));
|
|
11
|
-
// @ts-expect-error no type defs
|
|
12
|
-
const command_line_usage_1 = __importDefault(require("command-line-usage"));
|
|
13
|
-
function parseArgs() {
|
|
14
|
-
const mainDefinitions = [{ name: 'command', defaultOption: true }];
|
|
15
|
-
const mainOptions = (0, command_line_args_1.default)(mainDefinitions, {
|
|
16
|
-
stopAtFirstUnknown: true,
|
|
17
|
-
});
|
|
18
|
-
const argv = mainOptions._unknown || [];
|
|
19
|
-
const DEV_MODE = mainOptions.command === 'dev';
|
|
20
|
-
const BUILD_MODE = mainOptions.command === 'build';
|
|
21
|
-
const optionDefinitions = [
|
|
22
|
-
{ name: 'port', alias: 'p', type: Number },
|
|
23
|
-
{ name: 'extension', alias: 'e', type: String },
|
|
24
|
-
{ name: 'location', alias: 'l', type: String },
|
|
25
|
-
{ name: 'help', alias: 'h', type: Boolean },
|
|
26
|
-
{ name: 'force', alias: 'f', type: Boolean },
|
|
27
|
-
{ name: 'account', alias: 'a', type: Number },
|
|
28
|
-
];
|
|
29
|
-
const options = (0, command_line_args_1.default)(optionDefinitions, DEV_MODE || BUILD_MODE ? { argv } : {});
|
|
30
|
-
return Object.assign({ DEV_MODE, BUILD_MODE }, options);
|
|
31
|
-
}
|
|
32
|
-
exports.parseArgs = parseArgs;
|
|
33
|
-
function showHelp(OUTPUT_DIR) {
|
|
34
|
-
const sections = [
|
|
35
|
-
{
|
|
36
|
-
header: 'HubSpot UI Extensions Local Dev Server',
|
|
37
|
-
content: `Used for local development of HubSpot extensions. Built assets can be found in the ${OUTPUT_DIR} directory`,
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
header: 'Available Commands',
|
|
41
|
-
content: [
|
|
42
|
-
{ name: 'dev', summary: 'starts the local development server' },
|
|
43
|
-
{ name: 'build', summary: 'runs a build of your extensions' },
|
|
44
|
-
],
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
header: 'Options',
|
|
48
|
-
optionList: [
|
|
49
|
-
{
|
|
50
|
-
name: 'extension',
|
|
51
|
-
alias: 'e',
|
|
52
|
-
typeLabel: '{underline file}',
|
|
53
|
-
description: 'The extension entrypoint file to build or start local development for',
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: 'location',
|
|
57
|
-
alias: 'l',
|
|
58
|
-
typeLabel: '{underline string}',
|
|
59
|
-
description: 'The the location of the extension to run, this is only needed if two extensions use the same entrypoint file and do not have uids',
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: 'account',
|
|
63
|
-
alias: 'a',
|
|
64
|
-
typeLabel: '{underline number}',
|
|
65
|
-
description: 'The accountId you would like to use to run the extension',
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
name: 'help',
|
|
69
|
-
alias: 'h',
|
|
70
|
-
description: 'Print this usage guide.',
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
},
|
|
74
|
-
];
|
|
75
|
-
const usage = (0, command_line_usage_1.default)(sections);
|
|
76
|
-
logger_1.logger.info(usage);
|
|
77
|
-
process.exit(0);
|
|
78
|
-
}
|
|
79
|
-
exports.showHelp = showHelp;
|