@hubspot/ui-extensions-dev-server 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/cli/config.d.ts +9 -0
  2. package/dist/cli/config.js +79 -0
  3. package/dist/cli/run.d.ts +2 -0
  4. package/dist/cli/run.js +75 -0
  5. package/dist/cli/utils.d.ts +3 -0
  6. package/dist/cli/utils.js +65 -0
  7. package/dist/index.d.ts +3 -0
  8. package/dist/index.js +14 -0
  9. package/dist/lib/DevModeInterface.d.ts +35 -0
  10. package/dist/lib/DevModeInterface.js +121 -0
  11. package/dist/lib/build.d.ts +14 -0
  12. package/dist/lib/build.js +80 -0
  13. package/dist/lib/constants.d.ts +19 -0
  14. package/dist/lib/constants.js +35 -0
  15. package/dist/lib/dev.d.ts +13 -0
  16. package/dist/lib/dev.js +109 -0
  17. package/dist/lib/extensionsService.d.ts +12 -0
  18. package/dist/lib/extensionsService.js +39 -0
  19. package/dist/lib/plugins/codeCheckingPlugin.d.ts +7 -0
  20. package/dist/lib/plugins/codeCheckingPlugin.js +27 -0
  21. package/dist/lib/plugins/codeInjectionPlugin.d.ts +8 -0
  22. package/dist/lib/plugins/codeInjectionPlugin.js +30 -0
  23. package/dist/lib/plugins/devBuildPlugin.d.ts +11 -0
  24. package/dist/lib/plugins/devBuildPlugin.js +139 -0
  25. package/dist/lib/plugins/friendlyLoggingPlugin.d.ts +11 -0
  26. package/dist/lib/plugins/friendlyLoggingPlugin.js +44 -0
  27. package/dist/lib/plugins/manifestPlugin.d.ts +8 -0
  28. package/dist/lib/plugins/manifestPlugin.js +95 -0
  29. package/dist/lib/self.d.ts +0 -0
  30. package/{lib → dist/lib}/self.js +1 -1
  31. package/dist/lib/server.d.ts +13 -0
  32. package/dist/lib/server.js +68 -0
  33. package/dist/lib/types.d.ts +48 -0
  34. package/dist/lib/types.js +2 -0
  35. package/dist/lib/utils.d.ts +4 -0
  36. package/dist/lib/utils.js +35 -0
  37. package/package.json +20 -23
  38. package/cli/config.js +0 -111
  39. package/cli/run.js +0 -62
  40. package/cli/utils.js +0 -67
  41. package/index.js +0 -14
  42. package/lib/DevModeInterface.js +0 -131
  43. package/lib/build.js +0 -86
  44. package/lib/constants.js +0 -39
  45. package/lib/dev.js +0 -98
  46. package/lib/extensionsService.js +0 -54
  47. package/lib/plugins/codeCheckingPlugin.js +0 -26
  48. package/lib/plugins/codeInjectionPlugin.js +0 -30
  49. package/lib/plugins/devBuildPlugin.js +0 -153
  50. package/lib/plugins/manifestPlugin.js +0 -109
  51. package/lib/server.js +0 -57
  52. package/lib/utils.js +0 -36
@@ -0,0 +1,48 @@
1
+ export interface ObjectTypes {
2
+ name: string;
3
+ }
4
+ export interface ExtensionConfig {
5
+ type: string;
6
+ output: string;
7
+ path: string;
8
+ extensionPath: string;
9
+ data: {
10
+ appName: string;
11
+ title: string;
12
+ location: string;
13
+ module: {
14
+ file: string;
15
+ };
16
+ objectTypes: ObjectTypes[];
17
+ };
18
+ }
19
+ export interface ExtensionConfigMap {
20
+ [key: string]: ExtensionConfig;
21
+ }
22
+ interface CardConfig {
23
+ file: string;
24
+ }
25
+ export interface AppConfig {
26
+ name: string;
27
+ description: string;
28
+ scopes: string[];
29
+ public: boolean;
30
+ extensions: {
31
+ crm: {
32
+ cards: CardConfig[];
33
+ };
34
+ };
35
+ }
36
+ export interface ProjectComponent {
37
+ config: AppConfig;
38
+ path: string;
39
+ }
40
+ export interface ProjectComponentMap {
41
+ [key: string]: ProjectComponent;
42
+ }
43
+ export interface BaseMessage {
44
+ appName: string;
45
+ title: string;
46
+ callback: string;
47
+ }
48
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ declare function getUrlSafeFileName(filePath: string): string;
2
+ declare function stripAnsiColorCodes(stringWithColorCodes: string | undefined): string | null;
3
+ declare function loadManifest(outputDir: string, output: string): any;
4
+ export { getUrlSafeFileName, stripAnsiColorCodes, loadManifest };
@@ -0,0 +1,35 @@
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.loadManifest = exports.stripAnsiColorCodes = exports.getUrlSafeFileName = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const constants_1 = require("./constants");
10
+ function getUrlSafeFileName(filePath) {
11
+ const { name } = path_1.default.parse(filePath);
12
+ return encodeURIComponent(`${name}.js`);
13
+ }
14
+ exports.getUrlSafeFileName = getUrlSafeFileName;
15
+ // Strips ANSI color codes out of strings because we don't want to pass them to the browser
16
+ function stripAnsiColorCodes(stringWithColorCodes) {
17
+ if (!stringWithColorCodes) {
18
+ return null;
19
+ }
20
+ return stringWithColorCodes.replace(
21
+ // eslint-disable-next-line no-control-regex
22
+ /[\u001b][[]*([0-9]{1,4};?)*[m]/g, '');
23
+ }
24
+ exports.stripAnsiColorCodes = stripAnsiColorCodes;
25
+ function loadManifest(outputDir, output) {
26
+ try {
27
+ return JSON.parse(fs_1.default
28
+ .readFileSync(path_1.default.join(outputDir, `${output}-${constants_1.MANIFEST_FILE}`))
29
+ .toString());
30
+ }
31
+ catch (e) {
32
+ return {};
33
+ }
34
+ }
35
+ exports.loadManifest = loadManifest;
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions-dev-server",
3
- "version": "0.7.3",
3
+ "version": "0.8.0",
4
4
  "description": "",
5
- "main": "index.js",
6
5
  "scripts": {
7
6
  "test": "jest",
8
- "build": "echo 'no build step for @hubspot/ui-extensions-dev-server'",
7
+ "clean": "rm -rf dist/",
8
+ "build": "npm run clean && tsc",
9
+ "watch": "npm run clean && tsc --watch",
10
+ "prepare": "npm run build",
9
11
  "lint": "echo 'no lint step for @hubspot/ui-extensions-dev-server'",
10
12
  "jest": "jest --watch"
11
13
  },
@@ -13,44 +15,38 @@
13
15
  "access": "public"
14
16
  },
15
17
  "exports": {
16
- ".": "./index.js",
17
- "./self": "./lib/self.js"
18
+ ".": "./dist/index.js",
19
+ "./self": "./dist/lib/self.js"
18
20
  },
19
21
  "files": [
20
- "cli/config.js",
21
- "cli/run.js",
22
- "cli/utils.js",
23
- "lib/plugins/*",
24
- "lib/build.js",
25
- "lib/constants.js",
26
- "lib/dev.js",
27
- "lib/extensionsService.js",
28
- "lib/DevModeInterface.js",
29
- "lib/self.js",
30
- "lib/server.js",
31
- "lib/utils.js",
32
- "index.js",
22
+ "dist",
33
23
  "README.md"
34
24
  ],
35
25
  "license": "MIT",
36
26
  "dependencies": {
37
- "@hubspot/app-functions-dev-server": "^0.7.3",
27
+ "@hubspot/app-functions-dev-server": "^0.8.0",
38
28
  "@hubspot/cli-lib": "^4.1.6",
39
29
  "command-line-args": "^5.2.1",
40
30
  "command-line-usage": "^7.0.1",
41
31
  "console-log-colors": "^0.4.0",
42
32
  "cors": "^2.8.5",
33
+ "detect-port": "1.5.1",
43
34
  "express": "^4.18.2",
44
35
  "inquirer": "8.2.0",
45
- "vite": "^4.0.4"
36
+ "vite": "^4.4.9"
46
37
  },
47
38
  "devDependencies": {
39
+ "@types/express": "types/express",
40
+ "@types/inquirer": "^9.0.3",
41
+ "@types/jest": "^29.5.4",
48
42
  "axios": "^1.4.0",
49
43
  "jest": "^29.5.0",
44
+ "ts-jest": "^29.1.1",
45
+ "typescript": "^5.1.6",
50
46
  "ws": "^8.13.0"
51
47
  },
52
48
  "bin": {
53
- "hs-ui-extensions-dev-server": "./cli/run.js"
49
+ "hs-ui-extensions-dev-server": "./dist/cli/run.js"
54
50
  },
55
51
  "eslintConfig": {
56
52
  "env": {
@@ -62,12 +58,13 @@
62
58
  "node": ">=16"
63
59
  },
64
60
  "peerDependencies": {
65
- "typescript": "^5.0.4"
61
+ "typescript": "^5.1.6",
62
+ "vite": "^4.4.9"
66
63
  },
67
64
  "peerDependenciesMeta": {
68
65
  "typescript": {
69
66
  "optional": true
70
67
  }
71
68
  },
72
- "gitHead": "663cfa5f4b81bb923da5e8679e5be5437d1ddd00"
69
+ "gitHead": "80535f127c717f76d07fca05c9f676ec29ad5d18"
73
70
  }
package/cli/config.js DELETED
@@ -1,111 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { getUrlSafeFileName } = require('../lib/utils');
4
- const { MAIN_APP_CONFIG } = require('../lib/constants');
5
-
6
- function loadConfigByPath(configPath) {
7
- const source = fs.readFileSync(configPath);
8
- return JSON.parse(source);
9
- }
10
-
11
- function loadExtensionConfig(appConfig, appPath) {
12
- const crmCardsSubConfigFiles = appConfig?.extensions?.crm?.cards;
13
-
14
- const outputConfig = {};
15
-
16
- crmCardsSubConfigFiles.forEach(card => {
17
- const cardConfigPath = path.join(appPath, card.file);
18
-
19
- try {
20
- const cardConfig = loadConfigByPath(cardConfigPath);
21
-
22
- if (cardConfig && cardConfig.data) {
23
- const cardConfigDir = path.parse(cardConfigPath).dir;
24
-
25
- const entryPointPath = path.join(
26
- cardConfigDir,
27
- cardConfig.data?.module?.file
28
- );
29
-
30
- cardConfig.data.module.file = entryPointPath;
31
-
32
- outputConfig[entryPointPath] = {
33
- ...cardConfig,
34
- output: getUrlSafeFileName(entryPointPath),
35
- path: appPath,
36
- extensionPath: path.parse(entryPointPath).dir,
37
- data: {
38
- ...cardConfig.data,
39
- appName: appConfig.name,
40
- },
41
- };
42
- }
43
- } catch (e) {
44
- throw new Error(`Unable to load ${cardConfigPath}`);
45
- }
46
- });
47
-
48
- return outputConfig;
49
- }
50
-
51
- /**
52
- * @deprecated Will be removed after integration with hubspot-cli is complete
53
- * This version of load config makes assumptions about the location it is being ran from where the others do not
54
- */
55
- function loadConfig() {
56
- // app.json is one level up from the extensions directory, which is where these commands
57
- // will need to be ran from, the extensions directory
58
- const configPath = path.join(process.cwd(), '..', MAIN_APP_CONFIG);
59
-
60
- const mainAppConfig = loadConfigByPath(configPath);
61
-
62
- const crmCardsSubConfigFiles = mainAppConfig?.extensions?.crm?.cards;
63
- if (!crmCardsSubConfigFiles || crmCardsSubConfigFiles.length === 0) {
64
- throw new Error(
65
- `The "extensions.crm.cards" array in ${configPath} is missing or empty, it is a required configuration property`
66
- );
67
- }
68
-
69
- const outputConfig = {};
70
-
71
- crmCardsSubConfigFiles.forEach(card => {
72
- const cardConfigPath = path.join(process.cwd(), '..', card.file);
73
- try {
74
- const cardConfig = loadConfigByPath(cardConfigPath);
75
- if (!cardConfig.data) {
76
- throw new Error(
77
- `Invalid config file at path ${cardConfigPath}, data is a required config property`
78
- );
79
- }
80
-
81
- if (!cardConfig.data.module) {
82
- throw new Error(
83
- `Invalid config file at path ${cardConfigPath}, data.module is a require property`
84
- );
85
- }
86
-
87
- // Path.join with a single argument will strip off any relative prefixing such as './'
88
- const entryPointPath = path.join(cardConfig.data.module.file);
89
-
90
- cardConfig.data.module.file = entryPointPath;
91
-
92
- outputConfig[entryPointPath] = cardConfig;
93
- outputConfig[entryPointPath].data.appName = mainAppConfig.name;
94
- } catch (e) {
95
- if (e?.code === 'MODULE_NOT_FOUND') {
96
- throw new Error(
97
- `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.`
98
- );
99
- }
100
- throw e;
101
- }
102
- });
103
-
104
- return outputConfig;
105
- }
106
-
107
- module.exports = {
108
- loadConfigByPath,
109
- loadExtensionConfig,
110
- loadConfig,
111
- };
package/cli/run.js DELETED
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { parseArgs, showHelp } = require('../cli/utils');
4
- const {
5
- buildAllExtensions,
6
- buildSingleExtension,
7
- DevModeInterface,
8
- } = require('../index');
9
-
10
- const path = require('path');
11
- const { MAIN_APP_CONFIG, OUTPUT_DIR } = require('../lib/constants');
12
- const inquirer = require('inquirer');
13
- const { loadConfigByPath, loadExtensionConfig } = require('./config');
14
-
15
- // eslint-disable-next-line no-floating-promise/no-floating-promise
16
- (async () => {
17
- const { DEV_MODE, BUILD_MODE, extension, help } = parseArgs();
18
-
19
- if (help || !(DEV_MODE || BUILD_MODE)) {
20
- showHelp(OUTPUT_DIR);
21
- } else if (DEV_MODE) {
22
- const extensionPath = process.cwd(); // Assumed to be /path/to/src/app/extensions
23
- const appPath = path.join(extensionPath, '..');
24
- const appConfig = loadConfigByPath(path.join(appPath, MAIN_APP_CONFIG));
25
-
26
- let extensionConfig;
27
- if (extension) {
28
- const allExtensionsConfig = loadExtensionConfig(appConfig, appPath);
29
- extensionConfig =
30
- allExtensionsConfig[path.join(extensionPath, extension)];
31
- }
32
- await DevModeInterface.setup({
33
- promptUser: inquirer.createPromptModule(),
34
- components: {
35
- [appConfig.name]: {
36
- config: appConfig,
37
- path: path.join(extensionPath, '..'),
38
- },
39
- },
40
- extensionConfig,
41
- });
42
-
43
- await DevModeInterface.start({});
44
- } else if (BUILD_MODE) {
45
- if (extension) {
46
- buildSingleExtension({
47
- file: extension,
48
- outputDir: OUTPUT_DIR,
49
- });
50
- } else {
51
- buildAllExtensions({ outputDir: OUTPUT_DIR });
52
- }
53
- }
54
- })();
55
-
56
- async function shutdown() {
57
- await DevModeInterface.cleanup();
58
- process.exit(0);
59
- }
60
-
61
- process.on('SIGINT', shutdown);
62
- process.on('SIGTERM', shutdown);
package/cli/utils.js DELETED
@@ -1,67 +0,0 @@
1
- const { logger } = require('@hubspot/cli-lib/logger');
2
- const commandLineArgs = require('command-line-args');
3
- const commandLineUsage = require('command-line-usage');
4
-
5
- function parseArgs() {
6
- const mainDefinitions = [{ name: 'command', defaultOption: true }];
7
- const mainOptions = commandLineArgs(mainDefinitions, {
8
- stopAtFirstUnknown: true,
9
- });
10
- const argv = mainOptions._unknown || [];
11
- const DEV_MODE = mainOptions.command === 'dev';
12
- const BUILD_MODE = mainOptions.command === 'build';
13
-
14
- const optionDefinitions = [
15
- { name: 'port', alias: 'p', type: Number },
16
- { name: 'extension', alias: 'e', type: String },
17
- { name: 'help', alias: 'h', type: Boolean },
18
- ];
19
-
20
- const options = commandLineArgs(
21
- optionDefinitions,
22
- DEV_MODE || BUILD_MODE ? { argv } : {}
23
- );
24
-
25
- return { DEV_MODE, BUILD_MODE, ...options };
26
- }
27
-
28
- function showHelp(OUTPUT_DIR) {
29
- const sections = [
30
- {
31
- header: 'HubSpot UI Extensions Local Dev Server',
32
- content: `Used for local development of HubSpot extensions. Built assets can be found in the ${OUTPUT_DIR} directory`,
33
- },
34
- {
35
- header: 'Available Commands',
36
- content: [
37
- { name: 'dev', summary: 'starts the local development server' },
38
- { name: 'build', summary: 'runs a build of your extensions' },
39
- ],
40
- },
41
- {
42
- header: 'Options',
43
- optionList: [
44
- {
45
- name: 'extension',
46
- alias: 'e',
47
- typeLabel: '{underline file}',
48
- description:
49
- 'The extension entrypoint file to build or start local development for',
50
- },
51
- {
52
- name: 'help',
53
- alias: 'h',
54
- description: 'Print this usage guide.',
55
- },
56
- ],
57
- },
58
- ];
59
- const usage = commandLineUsage(sections);
60
- logger.info(usage);
61
- process.exit(0);
62
- }
63
-
64
- module.exports = {
65
- parseArgs,
66
- showHelp,
67
- };
package/index.js DELETED
@@ -1,14 +0,0 @@
1
- const {
2
- remoteBuild,
3
- buildAllExtensions,
4
- buildSingleExtension,
5
- } = require('./lib/build');
6
-
7
- const DevModeInterface = require('./lib/DevModeInterface');
8
-
9
- module.exports = {
10
- remoteBuild,
11
- buildAllExtensions,
12
- buildSingleExtension,
13
- DevModeInterface,
14
- };
@@ -1,131 +0,0 @@
1
- const { startDevMode } = require('./dev');
2
- const path = require('path');
3
- const { OUTPUT_DIR } = require('./constants');
4
- const { loadExtensionConfig } = require('../cli/config');
5
- const { logger, setLogLevel, LOG_LEVEL } = require('@hubspot/cli-lib/logger');
6
-
7
- class DevModeInterface {
8
- _setDataFromExtensionConfig(extensionConfig) {
9
- this.config = extensionConfig;
10
- this.appName = extensionConfig.data.appName;
11
- this.title = extensionConfig.data.title;
12
- }
13
-
14
- _generateAppExtensionMappings(components) {
15
- // Loop over all of the app configs that are passed in
16
- const allComponentNames = Object.keys(components);
17
-
18
- return allComponentNames.reduce((appExtensionMappings, componentName) => {
19
- const component = components[componentName];
20
- if (!component.config.extensions?.crm?.cards) {
21
- return appExtensionMappings; // It's not an app
22
- }
23
-
24
- this.cardConfigs = component.config.extensions.crm.cards.map(card =>
25
- path.join(component.path, card.file)
26
- );
27
-
28
- // Load all of the extension configs for a particular app.json file
29
- const extensionsConfigForApp = loadExtensionConfig(
30
- component.config,
31
- component.path
32
- );
33
-
34
- const extensionFilePaths = Object.keys(extensionsConfigForApp);
35
- // Loop over the loaded extension configs and generate the list of choices to use to prompt the user for input
36
- extensionFilePaths.forEach(extensionPath => {
37
- const extensionConfig = extensionsConfigForApp[extensionPath];
38
- appExtensionMappings.push({
39
- name: `${componentName}/${extensionConfig.data.title}`,
40
- value: extensionConfig,
41
- });
42
- });
43
-
44
- return appExtensionMappings;
45
- }, []);
46
- }
47
-
48
- async setup({
49
- debug = false,
50
- accountId,
51
- httpClient,
52
- promptUser,
53
- components,
54
- extensionConfig,
55
- onUploadRequired,
56
- }) {
57
- setLogLevel(debug ? LOG_LEVEL.DEBUG : LOG_LEVEL.LOG);
58
- this.accountId = accountId;
59
- this.httpClient = httpClient;
60
- this.onUploadRequired = onUploadRequired;
61
- if (extensionConfig) {
62
- this._setDataFromExtensionConfig(extensionConfig);
63
- return;
64
- }
65
-
66
- const choices = this._generateAppExtensionMappings(components);
67
-
68
- if (choices.length === 0) {
69
- throw new Error('No extensions to run');
70
- } else if (choices.length === 1) {
71
- this._setDataFromExtensionConfig(choices[0].value);
72
- } else {
73
- const answers = await promptUser({
74
- type: 'list',
75
- name: 'extension',
76
- message: 'Which extension would you like to run?',
77
- choices,
78
- });
79
- this._setDataFromExtensionConfig(answers.extension);
80
- }
81
- }
82
-
83
- // The contract is for this to be async, so eslint can chill
84
- // eslint-disable-next-line require-await
85
- async fileChange(filePath, __event) {
86
- if (
87
- this.cardConfigs &&
88
- this.cardConfigs.includes(filePath) &&
89
- this.onUploadRequired
90
- ) {
91
- this.onUploadRequired();
92
- }
93
- }
94
-
95
- async start({ debug = null }) {
96
- if (debug !== null) {
97
- setLogLevel(debug ? LOG_LEVEL.DEBUG : LOG_LEVEL.LOG);
98
- }
99
- if (!this.config || !this.config.path) {
100
- throw new Error(
101
- 'Unable to load the required extension configuration files'
102
- );
103
- }
104
- const appPath = this.config.path;
105
-
106
- // Pass options from the CLI for running app functions locally
107
- const functionsConfig = {
108
- app: { path: appPath },
109
- accountId: this.accountId,
110
- httpClient: this.httpClient,
111
- };
112
-
113
- this.shutdown = await startDevMode({
114
- extensionConfig: this.config,
115
- outputDir: path.join(this.config.extensionPath, OUTPUT_DIR),
116
- functionsConfig,
117
- root: appPath,
118
- cardConfigs: this.cardConfigs || [],
119
- });
120
-
121
- logger.info(`Running extension '${this.title}' from app '${this.appName}'`);
122
- }
123
-
124
- async cleanup() {
125
- if (this.shutdown) {
126
- await this.shutdown();
127
- }
128
- }
129
- }
130
-
131
- module.exports = new DevModeInterface();
package/lib/build.js DELETED
@@ -1,86 +0,0 @@
1
- const { build } = require('vite');
2
- const { ROLLUP_OPTIONS, OUTPUT_DIR } = require('./constants');
3
- const manifestPlugin = require('./plugins/manifestPlugin');
4
- const path = require('path');
5
- const { getUrlSafeFileName } = require('./utils');
6
- const { loadConfig } = require('../cli/config');
7
- const codeInjectionPlugin = require('./plugins/codeInjectionPlugin');
8
-
9
- const allowedExtensions = ['.js', '.ts', '.tsx', '.jsx'];
10
- const extensionErrorBaseMessage = `Supported file extensions are [${allowedExtensions.join(
11
- ', '
12
- )}], received:`;
13
-
14
- async function buildAllExtensions({ outputDir }) {
15
- const config = loadConfig();
16
- const extensionKeys = Object.keys(config);
17
- for (let i = 0; i < extensionKeys.length; ++i) {
18
- const { data } = config[extensionKeys[i]];
19
-
20
- await buildSingleExtension({
21
- file: data.module.file,
22
- outputDir,
23
- emptyOutDir: i === 0,
24
- });
25
- }
26
- }
27
-
28
- async function buildSingleExtension({
29
- file,
30
- outputDir = OUTPUT_DIR,
31
- emptyOutDir = true,
32
- minify = false,
33
- root = process.cwd(), // This is the vite default, so using that as our default
34
- }) {
35
- const output = getUrlSafeFileName(file);
36
- await build({
37
- root,
38
- define: {
39
- 'process.env.NODE_ENV': JSON.stringify(
40
- process.env.NODE_ENV || 'production'
41
- ),
42
- },
43
- build: {
44
- lib: {
45
- entry: file,
46
- name: output,
47
- formats: ['iife'],
48
- fileName: () => output,
49
- },
50
- rollupOptions: {
51
- ...ROLLUP_OPTIONS,
52
- plugins: [manifestPlugin({ output }), codeInjectionPlugin({ file })],
53
- },
54
- outDir: outputDir,
55
- emptyOutDir,
56
- minify,
57
- },
58
- });
59
- }
60
-
61
- async function remoteBuild(root, entryPoint, outputDir = OUTPUT_DIR) {
62
- const fileInfo = path.parse(entryPoint);
63
-
64
- if (!allowedExtensions.includes(fileInfo.ext)) {
65
- throw new Error(`${extensionErrorBaseMessage} ${fileInfo.ext}`);
66
- }
67
-
68
- const output = getUrlSafeFileName(entryPoint);
69
- await buildSingleExtension({
70
- file: entryPoint,
71
- outputFileName: output,
72
- outputDir,
73
- plugins: {
74
- rollup: [manifestPlugin({ minify: true, output })],
75
- },
76
- minify: true,
77
- root,
78
- });
79
- }
80
-
81
- module.exports = {
82
- buildAllExtensions,
83
- buildSingleExtension,
84
- remoteBuild,
85
- extensionErrorBaseMessage,
86
- };
package/lib/constants.js DELETED
@@ -1,39 +0,0 @@
1
- const OUTPUT_DIR = 'dist';
2
- const MAIN_APP_CONFIG = 'app.json';
3
- const MANIFEST_FILE = 'manifest.json';
4
-
5
- const VITE_DEFAULT_PORT = 5173;
6
- const WEBSOCKET_PORT = 5174;
7
-
8
- const ROLLUP_OPTIONS = {
9
- // Deps to exclude from the bundle
10
- external: ['react', 'react-dom', '@remote-ui/react'],
11
- output: {
12
- // Maps libs to the variables to be injected via the window
13
- globals: {
14
- react: 'React',
15
- '@remote-ui/react': 'RemoteUI',
16
- },
17
- extend: true,
18
- },
19
- };
20
-
21
- const EXTENSIONS_MESSAGE_VERSION = 1;
22
- const WEBSOCKET_MESSAGE_VERSION = 0;
23
-
24
- const SERVER_CAPABILITIES = [
25
- // Supports running app functions locally
26
- 'app-functions-local-dev',
27
- ];
28
-
29
- module.exports = {
30
- ROLLUP_OPTIONS,
31
- OUTPUT_DIR,
32
- MAIN_APP_CONFIG,
33
- MANIFEST_FILE,
34
- EXTENSIONS_MESSAGE_VERSION,
35
- VITE_DEFAULT_PORT,
36
- WEBSOCKET_MESSAGE_VERSION,
37
- WEBSOCKET_PORT,
38
- SERVER_CAPABILITIES,
39
- };