@hubspot/ui-extensions-dev-server 0.8.2 → 0.8.3

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 CHANGED
@@ -1,29 +1,7 @@
1
1
  # UI Extensions – Dev Server
2
2
 
3
- Development server to run and test your HubSpot UI Extensions.
3
+ Development server library to run your HubSpot UI Extensions.
4
4
 
5
5
  ## Overview
6
- This package contains the cli for running HubSpot UI extensions locally, as well as running a production build for debugging purposes.
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, buildAllExtensions, buildSingleExtension } from './lib/build';
1
+ import { remoteBuild, buildSingleExtension } from './lib/build';
2
2
  import DevModeInterface from './lib/DevModeInterface';
3
- export { remoteBuild, buildAllExtensions, buildSingleExtension, DevModeInterface, };
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.buildAllExtensions = exports.remoteBuild = void 0;
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,5 +1,5 @@
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
4
  interface SetupArguments {
5
5
  components: ProjectComponentMap;
@@ -8,10 +8,16 @@ interface SetupArguments {
8
8
  onUploadRequired?: VoidFunction;
9
9
  promptUser: PromptModule;
10
10
  }
11
+ interface ProjectConfig {
12
+ name: string;
13
+ srcDir: string;
14
+ platformVersion?: PlatformVersion;
15
+ }
11
16
  interface StartArguments {
12
17
  accountId?: number;
13
18
  debug?: boolean;
14
19
  httpClient?: ServiceConfiguration['httpClient'];
20
+ projectConfig?: ProjectConfig;
15
21
  }
16
22
  interface AppExtensionMapping {
17
23
  name: string;
@@ -26,9 +32,10 @@ declare class DevModeInterface {
26
32
  shutdown?: () => Promise<void>;
27
33
  _setDataFromExtensionConfig(extensionConfig: ExtensionConfig): void;
28
34
  _generateAppExtensionMappings(components: ProjectComponentMap): AppExtensionMapping[];
35
+ _getPlatformVersion(projectConfig?: ProjectConfig): PlatformVersion;
29
36
  setup({ components, debug, extensionConfig, onUploadRequired, promptUser, }: SetupArguments): Promise<void>;
30
37
  fileChange(filePath: string, __event: unknown): Promise<void>;
31
- start({ accountId, debug, httpClient }: StartArguments): Promise<void>;
38
+ start({ accountId, debug, httpClient, projectConfig }: StartArguments): Promise<void>;
32
39
  cleanup(): Promise<void>;
33
40
  }
34
41
  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) {
@@ -15,9 +17,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
17
  const dev_1 = require("./dev");
16
18
  const path_1 = __importDefault(require("path"));
17
19
  const constants_1 = require("./constants");
18
- const config_1 = require("../cli/config");
20
+ const config_1 = require("./config");
19
21
  // @ts-expect-error no type defs
20
22
  const logger_1 = require("@hubspot/cli-lib/logger");
23
+ const utils_1 = require("./utils");
21
24
  class DevModeInterface {
22
25
  _setDataFromExtensionConfig(extensionConfig) {
23
26
  this.config = extensionConfig;
@@ -48,6 +51,20 @@ class DevModeInterface {
48
51
  return appExtensionMappings;
49
52
  }, []);
50
53
  }
54
+ _getPlatformVersion(projectConfig) {
55
+ const { platformVersion } = projectConfig !== null && projectConfig !== void 0 ? projectConfig : {};
56
+ if (!platformVersion) {
57
+ return constants_1.PLATFORM_VERSION.V20231;
58
+ }
59
+ switch (platformVersion) {
60
+ case constants_1.PLATFORM_VERSION.V20231:
61
+ return constants_1.PLATFORM_VERSION.V20231;
62
+ case constants_1.PLATFORM_VERSION.V20232:
63
+ return constants_1.PLATFORM_VERSION.V20232;
64
+ default:
65
+ return (0, utils_1.throwUnhandledPlatformVersionError)(platformVersion);
66
+ }
67
+ }
51
68
  setup({ components, debug = false, extensionConfig, onUploadRequired, promptUser, }) {
52
69
  return __awaiter(this, void 0, void 0, function* () {
53
70
  (0, logger_1.setLogLevel)(debug ? logger_1.LOG_LEVEL.DEBUG : logger_1.LOG_LEVEL.LOG);
@@ -85,7 +102,7 @@ class DevModeInterface {
85
102
  }
86
103
  });
87
104
  }
88
- start({ accountId, debug, httpClient }) {
105
+ start({ accountId, debug, httpClient, projectConfig }) {
89
106
  return __awaiter(this, void 0, void 0, function* () {
90
107
  if (debug !== undefined) {
91
108
  (0, logger_1.setLogLevel)(debug ? logger_1.LOG_LEVEL.DEBUG : logger_1.LOG_LEVEL.LOG);
@@ -99,6 +116,7 @@ class DevModeInterface {
99
116
  app: { path: appPath },
100
117
  accountId,
101
118
  httpClient,
119
+ platformVersion: this._getPlatformVersion(projectConfig),
102
120
  };
103
121
  this.shutdown = yield (0, dev_1.startDevMode)({
104
122
  extensionConfig: this.config,
@@ -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.buildAllExtensions = exports.extensionErrorBaseMessage = void 0;
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,3 @@
1
+ import { AppConfig, ExtensionConfigMap } from './types';
2
+ export declare function loadConfigByPath<T = unknown>(configPath: string): T;
3
+ export declare function loadExtensionConfig(appConfig: AppConfig, appPath: string): ExtensionConfigMap;
@@ -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;
@@ -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
+ };
@@ -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
+ };
@@ -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);
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
3
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
6
  };
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
3
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
6
  };
@@ -37,7 +37,7 @@ function startDevServer({ outputDir, expressPort, webSocketPort, baseMessage, vi
37
37
  app.use((0, cors_1.default)());
38
38
  app.use(express_1.default.static(outputDir));
39
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('Serving app functions locally');
40
+ logger_1.logger.info(`Serving app functions locally (platform version ${functionsConfig.platformVersion})`);
41
41
  const endpointsAdded = extensionsService_1.default.add(app, webSocketPort, outputDir, baseMessage, constants_1.SERVER_CAPABILITIES);
42
42
  endpointsAdded.forEach(endpoint => {
43
43
  logger_1.logger.debug(`Listening at http://hslocal.net:${expressPort}${endpoint}`);
@@ -1,3 +1,4 @@
1
+ import { PLATFORM_VERSION } from './constants';
1
2
  export interface ObjectTypes {
2
3
  name: string;
3
4
  }
@@ -51,4 +52,5 @@ export interface BaseMessage {
51
52
  sourceId?: string | null;
52
53
  portalId?: number;
53
54
  }
55
+ export type PlatformVersion = typeof PLATFORM_VERSION[keyof typeof PLATFORM_VERSION];
54
56
  export {};
@@ -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.2",
3
+ "version": "0.8.3",
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.2",
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": "19c43b6956e7a2397e0b4435b3829bd3e3b5e5bc"
66
+ "gitHead": "ab25629916c542f19bf8cde83a10ad8bd225078f"
70
67
  }
@@ -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;
@@ -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
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
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);
@@ -1,3 +0,0 @@
1
- declare function parseArgs(): any;
2
- declare function showHelp(OUTPUT_DIR: string): void;
3
- export { parseArgs, showHelp };
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;