@hubspot/cli 8.1.0-beta.0 → 8.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/cms/__tests__/watch.test.js +0 -8
- package/commands/cms/function/logs.js +1 -0
- package/commands/cms/theme/preview.js +9 -64
- package/commands/cms/watch.d.ts +0 -1
- package/commands/cms/watch.js +2 -8
- package/commands/feedback.js +1 -1
- package/commands/mcp/__tests__/start.test.js +8 -1
- package/commands/mcp/setup.js +1 -9
- package/commands/mcp/start.js +0 -1
- package/commands/project/__tests__/create.test.js +1 -1
- package/commands/project/create.js +2 -2
- package/commands/project/watch.js +15 -2
- package/lang/en.d.ts +17 -6
- package/lang/en.js +18 -7
- package/lib/__tests__/commandSuggestion.test.js +2 -0
- package/lib/__tests__/serverlessLogs.test.js +79 -64
- package/lib/commandSuggestion.js +1 -7
- package/lib/constants.d.ts +1 -1
- package/lib/constants.js +1 -1
- package/lib/generateSelectors.js +1 -2
- package/lib/getStartedV2Actions.d.ts +13 -0
- package/lib/getStartedV2Actions.js +53 -0
- package/lib/mcp/__tests__/setup.test.js +357 -28
- package/lib/mcp/setup.d.ts +1 -0
- package/lib/mcp/setup.js +77 -30
- package/lib/projects/create/__tests__/legacy.test.js +6 -24
- package/lib/projects/create/index.js +1 -4
- package/lib/projects/create/legacy.js +3 -8
- package/lib/projects/create/v2.js +1 -9
- package/lib/projects/ensureProjectExists.js +1 -2
- package/lib/projects/pollProjectBuildAndDeploy.js +90 -85
- package/lib/projects/upload.d.ts +1 -0
- package/lib/projects/upload.js +37 -46
- package/lib/projects/watch.d.ts +2 -1
- package/lib/projects/watch.js +32 -24
- package/lib/serverlessLogs.js +50 -44
- package/lib/theme/cmsDevServerProcess.d.ts +12 -0
- package/lib/theme/cmsDevServerProcess.js +148 -0
- package/lib/theme/cmsDevServerRunner.d.ts +14 -0
- package/lib/theme/cmsDevServerRunner.js +90 -0
- package/lib/usageTracking.js +8 -5
- package/mcp-server/tools/cms/HsCreateFunctionTool.js +1 -1
- package/mcp-server/tools/cms/HsCreateModuleTool.js +1 -1
- package/mcp-server/tools/cms/HsCreateTemplateTool.js +1 -1
- package/mcp-server/tools/cms/HsFunctionLogsTool.js +1 -1
- package/mcp-server/tools/cms/HsListFunctionsTool.js +1 -1
- package/mcp-server/tools/cms/HsListTool.js +1 -1
- package/mcp-server/tools/cms/__tests__/HsCreateFunctionTool.test.js +1 -2
- package/mcp-server/tools/cms/__tests__/HsCreateModuleTool.test.js +1 -2
- package/mcp-server/tools/cms/__tests__/HsCreateTemplateTool.test.js +1 -2
- package/mcp-server/tools/cms/__tests__/HsFunctionLogsTool.test.js +1 -2
- package/mcp-server/tools/cms/__tests__/HsListFunctionsTool.test.js +1 -2
- package/mcp-server/tools/cms/__tests__/HsListTool.test.js +1 -2
- package/mcp-server/tools/project/AddFeatureToProjectTool.d.ts +20 -3
- package/mcp-server/tools/project/AddFeatureToProjectTool.js +7 -11
- package/mcp-server/tools/project/CreateProjectTool.d.ts +24 -4
- package/mcp-server/tools/project/CreateProjectTool.js +6 -11
- package/mcp-server/tools/project/CreateTestAccountTool.js +1 -1
- package/mcp-server/tools/project/DeployProjectTool.js +1 -1
- package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.js +5 -8
- package/mcp-server/tools/project/GetBuildLogsTool.d.ts +2 -2
- package/mcp-server/tools/project/GetBuildLogsTool.js +6 -7
- package/mcp-server/tools/project/GetBuildStatusTool.d.ts +1 -1
- package/mcp-server/tools/project/GetBuildStatusTool.js +3 -4
- package/mcp-server/tools/project/GuidedWalkthroughTool.d.ts +6 -1
- package/mcp-server/tools/project/GuidedWalkthroughTool.js +1 -6
- package/mcp-server/tools/project/UploadProjectTools.js +1 -1
- package/mcp-server/tools/project/ValidateProjectTool.js +1 -1
- package/mcp-server/tools/project/__tests__/AddFeatureToProjectTool.test.js +1 -2
- package/mcp-server/tools/project/__tests__/CreateProjectTool.test.js +1 -2
- package/mcp-server/tools/project/__tests__/CreateTestAccountTool.test.js +1 -2
- package/mcp-server/tools/project/__tests__/DeployProjectTool.test.js +1 -2
- package/mcp-server/tools/project/__tests__/GetApiUsagePatternsByAppIdTool.test.js +0 -32
- package/mcp-server/tools/project/__tests__/UploadProjectTools.test.js +10 -2
- package/mcp-server/tools/project/__tests__/ValidateProjectTool.test.js +2 -2
- package/mcp-server/tools/project/constants.d.ts +12 -1
- package/mcp-server/tools/project/constants.js +12 -16
- package/mcp-server/utils/__tests__/command.test.js +233 -3
- package/mcp-server/utils/__tests__/feedbackTracking.test.js +9 -64
- package/mcp-server/utils/command.d.ts +5 -0
- package/mcp-server/utils/command.js +24 -0
- package/mcp-server/utils/feedbackTracking.js +2 -17
- package/package.json +4 -5
- package/ui/components/getStarted/GetStartedFlow.js +79 -2
- package/ui/components/getStarted/reducer.d.ts +20 -0
- package/ui/components/getStarted/reducer.js +36 -0
- package/ui/components/getStarted/screens/InstallationScreen.d.ts +7 -0
- package/ui/components/getStarted/screens/InstallationScreen.js +16 -0
- package/ui/components/getStarted/screens/ProjectSetupScreen.js +2 -1
- package/ui/lib/constants.d.ts +1 -0
- package/ui/lib/constants.js +1 -0
- package/mcp-server/utils/__tests__/project.test.d.ts +0 -1
- package/mcp-server/utils/__tests__/project.test.js +0 -140
- package/mcp-server/utils/project.d.ts +0 -5
- package/mcp-server/utils/project.js +0 -18
package/lib/projects/watch.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ProjectConfig } from '../../types/Projects.js';
|
|
2
2
|
type ProjectWatchHandlerFunction = (accountId: number, projectName: string, currentBuildId: number) => Promise<void> | void;
|
|
3
|
-
|
|
3
|
+
type WatchTerminationHandler = (error?: unknown) => void;
|
|
4
|
+
export declare function createWatcher(accountId: number, projectConfig: ProjectConfig, projectDir: string, handleBuildStatusFn: ProjectWatchHandlerFunction, handleUserInputFn: ProjectWatchHandlerFunction, handleWatchTerminationFn: WatchTerminationHandler): Promise<void>;
|
|
4
5
|
export {};
|
package/lib/projects/watch.js
CHANGED
|
@@ -18,6 +18,7 @@ const standbyQueue = [];
|
|
|
18
18
|
let currentBuildId;
|
|
19
19
|
let handleBuildStatus;
|
|
20
20
|
let handleUserInput;
|
|
21
|
+
let handleWatchTermination = () => { };
|
|
21
22
|
let timer;
|
|
22
23
|
async function processStandByQueue(accountId, projectName, platformVersion) {
|
|
23
24
|
queue.addAll(standbyQueue.map(({ filePath, remotePath, action }) => {
|
|
@@ -37,33 +38,39 @@ function debounceQueueBuild(accountId, projectName, platformVersion) {
|
|
|
37
38
|
clearTimeout(timer);
|
|
38
39
|
}
|
|
39
40
|
timer = setTimeout(async () => {
|
|
40
|
-
uiLogger.debug(commands.project.watch.debug.pause);
|
|
41
|
-
queue.pause();
|
|
42
|
-
await queue.onIdle();
|
|
43
41
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
uiLogger.debug(commands.project.watch.debug.pause);
|
|
43
|
+
queue.pause();
|
|
44
|
+
await queue.onIdle();
|
|
45
|
+
try {
|
|
46
|
+
await queueBuild(accountId, projectName, platformVersion);
|
|
47
|
+
uiLogger.debug(commands.project.watch.debug.buildStarted);
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
if (isSpecifiedError(err, {
|
|
51
|
+
subCategory: PROJECT_ERROR_TYPES.MISSING_PROJECT_PROVISION,
|
|
52
|
+
})) {
|
|
53
|
+
uiLogger.log(commands.project.watch.logs.watchCancelledFromUi);
|
|
54
|
+
handleWatchTermination();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
logError(err, new ApiErrorContext({ accountId }));
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
53
61
|
}
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
await handleBuildStatus(accountId, projectName, currentBuildId);
|
|
63
|
+
await createNewStagingBuild(accountId, projectName, platformVersion);
|
|
64
|
+
if (standbyQueue.length > 0) {
|
|
65
|
+
await processStandByQueue(accountId, projectName, platformVersion);
|
|
56
66
|
}
|
|
57
|
-
|
|
67
|
+
queue.start();
|
|
68
|
+
uiLogger.log(commands.project.watch.logs.resuming);
|
|
69
|
+
uiLogger.log(`\n> Press ${chalk.bold('q')} to quit watching\n`);
|
|
58
70
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (standbyQueue.length > 0) {
|
|
62
|
-
await processStandByQueue(accountId, projectName, platformVersion);
|
|
71
|
+
catch (err) {
|
|
72
|
+
handleWatchTermination(err);
|
|
63
73
|
}
|
|
64
|
-
queue.start();
|
|
65
|
-
uiLogger.log(commands.project.watch.logs.resuming);
|
|
66
|
-
uiLogger.log(`\n> Press ${chalk.bold('q')} to quit watching\n`);
|
|
67
74
|
}, 2000);
|
|
68
75
|
}
|
|
69
76
|
async function queueFileOrFolder(accountId, projectName, platformVersion, filePath, remotePath, action) {
|
|
@@ -111,7 +118,7 @@ async function createNewBuild(accountId, projectName, platformVersion) {
|
|
|
111
118
|
await cancelStagedBuild(accountId, projectName);
|
|
112
119
|
uiLogger.log(commands.project.watch.logs.previousStagingBuildCancelled);
|
|
113
120
|
}
|
|
114
|
-
|
|
121
|
+
throw err;
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
async function handleWatchEvent(accountId, projectName, platformVersion, projectSourceDir, filePath, action = 'upload') {
|
|
@@ -132,10 +139,11 @@ async function handleWatchEvent(accountId, projectName, platformVersion, project
|
|
|
132
139
|
await queueFileOrFolder(accountId, projectName, platformVersion, filePath, remotePath, action);
|
|
133
140
|
}
|
|
134
141
|
}
|
|
135
|
-
export async function createWatcher(accountId, projectConfig, projectDir, handleBuildStatusFn, handleUserInputFn) {
|
|
142
|
+
export async function createWatcher(accountId, projectConfig, projectDir, handleBuildStatusFn, handleUserInputFn, handleWatchTerminationFn) {
|
|
136
143
|
const projectSourceDir = path.join(projectDir, projectConfig.srcDir);
|
|
137
144
|
handleBuildStatus = handleBuildStatusFn;
|
|
138
145
|
handleUserInput = handleUserInputFn;
|
|
146
|
+
handleWatchTermination = handleWatchTerminationFn;
|
|
139
147
|
await createNewStagingBuild(accountId, projectConfig.name, projectConfig.platformVersion);
|
|
140
148
|
const watcher = chokidar.watch(projectSourceDir, {
|
|
141
149
|
ignoreInitial: true,
|
package/lib/serverlessLogs.js
CHANGED
|
@@ -9,7 +9,6 @@ import { outputLogs } from './ui/serverlessFunctionLogs.js';
|
|
|
9
9
|
import { logError, ApiErrorContext } from './errorHandlers/index.js';
|
|
10
10
|
import SpinniesManager from './ui/SpinniesManager.js';
|
|
11
11
|
import { handleExit, handleKeypress } from './process.js';
|
|
12
|
-
import { EXIT_CODES } from './enums/exitCodes.js';
|
|
13
12
|
import { lib } from '../lang/en.js';
|
|
14
13
|
const TAIL_DELAY = 5000;
|
|
15
14
|
function base64EncodeString(valueToEncode) {
|
|
@@ -19,19 +18,6 @@ function base64EncodeString(valueToEncode) {
|
|
|
19
18
|
const stringBuffer = Buffer.from(valueToEncode);
|
|
20
19
|
return encodeURIComponent(stringBuffer.toString('base64'));
|
|
21
20
|
}
|
|
22
|
-
function handleUserInput() {
|
|
23
|
-
const onTerminate = async () => {
|
|
24
|
-
SpinniesManager.remove('tailLogs');
|
|
25
|
-
SpinniesManager.remove('stopMessage');
|
|
26
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
27
|
-
};
|
|
28
|
-
handleExit(onTerminate);
|
|
29
|
-
handleKeypress(key => {
|
|
30
|
-
if ((key.ctrl && key.name == 'c') || key.name === 'q') {
|
|
31
|
-
onTerminate();
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
21
|
async function verifyAccessKeyAndUserAccess(accountId, scopeGroup) {
|
|
36
22
|
const accountConfig = getConfigAccountById(accountId);
|
|
37
23
|
if (!accountConfig) {
|
|
@@ -80,40 +66,60 @@ export async function tailLogs(accountId, name, fetchLatest, tailCall, compact =
|
|
|
80
66
|
}
|
|
81
67
|
}
|
|
82
68
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const { data } = await tailCall(after);
|
|
88
|
-
latestLog = data;
|
|
89
|
-
nextAfter = latestLog.paging.next.after;
|
|
69
|
+
return new Promise(resolve => {
|
|
70
|
+
function cleanup() {
|
|
71
|
+
SpinniesManager.remove('tailLogs');
|
|
72
|
+
SpinniesManager.remove('stopMessage');
|
|
90
73
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
74
|
+
let resolved = false;
|
|
75
|
+
const onTerminate = async () => {
|
|
76
|
+
if (resolved)
|
|
77
|
+
return;
|
|
78
|
+
resolved = true;
|
|
79
|
+
cleanup();
|
|
80
|
+
resolve();
|
|
81
|
+
};
|
|
82
|
+
handleExit(onTerminate);
|
|
83
|
+
handleKeypress(key => {
|
|
84
|
+
if ((key.ctrl && key.name == 'c') || key.name === 'q') {
|
|
85
|
+
onTerminate();
|
|
96
86
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
87
|
+
});
|
|
88
|
+
async function tail(after) {
|
|
89
|
+
let latestLog;
|
|
90
|
+
let nextAfter;
|
|
91
|
+
try {
|
|
92
|
+
const { data } = await tailCall(after);
|
|
93
|
+
latestLog = data;
|
|
94
|
+
nextAfter = latestLog.paging.next.after;
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
if (isHubSpotHttpError(e) && e.status !== 404) {
|
|
98
|
+
logError(e, new ApiErrorContext({
|
|
99
|
+
accountId,
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
await onTerminate();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (latestLog && latestLog.results.length) {
|
|
106
|
+
outputLogs(latestLog, {
|
|
107
|
+
compact,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
setTimeout(async () => {
|
|
111
|
+
await tail(nextAfter);
|
|
112
|
+
}, TAIL_DELAY);
|
|
103
113
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
text: `> Press ${chalk.bold('q')} to stop following`,
|
|
113
|
-
status: 'non-spinnable',
|
|
114
|
+
SpinniesManager.add('tailLogs', {
|
|
115
|
+
text: `Following logs for ${name}`,
|
|
116
|
+
});
|
|
117
|
+
SpinniesManager.add('stopMessage', {
|
|
118
|
+
text: `> Press ${chalk.bold('q')} to stop following`,
|
|
119
|
+
status: 'non-spinnable',
|
|
120
|
+
});
|
|
121
|
+
tail(initialAfter);
|
|
114
122
|
});
|
|
115
|
-
handleUserInput();
|
|
116
|
-
await tail(initialAfter);
|
|
117
123
|
}
|
|
118
124
|
export async function outputBuildLog(buildLogUrl) {
|
|
119
125
|
if (!buildLogUrl) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChildProcess } from 'child_process';
|
|
2
|
+
interface DevServerOptions {
|
|
3
|
+
absoluteSrc: string;
|
|
4
|
+
accountName?: string;
|
|
5
|
+
noSsl?: boolean;
|
|
6
|
+
port?: number;
|
|
7
|
+
generateFieldsTypes?: boolean;
|
|
8
|
+
resetSession?: boolean;
|
|
9
|
+
dest: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function spawnDevServer(options: DevServerOptions): Promise<ChildProcess>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import { getConfigFilePath } from '@hubspot/local-dev-lib/config';
|
|
7
|
+
import SpinniesManager from '../ui/SpinniesManager.js';
|
|
8
|
+
import { lib } from '../../lang/en.js';
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
// cms-dev-server version to install to isolated cache
|
|
12
|
+
const TARGET_CMS_DEV_SERVER_VERSION = '1.2.16';
|
|
13
|
+
/**
|
|
14
|
+
* Ensures cms-dev-server is installed in an isolated cache directory.
|
|
15
|
+
* This prevents React version conflicts with the CLI.
|
|
16
|
+
*/
|
|
17
|
+
async function ensureCmsDevServerCache(targetVersion) {
|
|
18
|
+
const cacheDir = path.join(os.homedir(), '.hscli', '.module-cache');
|
|
19
|
+
const packageJsonPath = path.join(cacheDir, 'node_modules', '@hubspot', 'cms-dev-server', 'package.json');
|
|
20
|
+
// Check if already installed with correct version
|
|
21
|
+
let needsInstall = true;
|
|
22
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
23
|
+
try {
|
|
24
|
+
const installedPackage = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
25
|
+
if (installedPackage.version === targetVersion) {
|
|
26
|
+
needsInstall = false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
// If we can't read the package.json, reinstall
|
|
31
|
+
needsInstall = true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (needsInstall) {
|
|
35
|
+
// Show spinner during install (can take 10-30 seconds)
|
|
36
|
+
SpinniesManager.init({
|
|
37
|
+
succeedColor: 'white',
|
|
38
|
+
});
|
|
39
|
+
SpinniesManager.add('cms-dev-server-install', {
|
|
40
|
+
text: lib.theme.cmsDevServerProcess.installStarted(targetVersion),
|
|
41
|
+
});
|
|
42
|
+
// Create cache directory
|
|
43
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
44
|
+
// Clear old installation if exists
|
|
45
|
+
const nodeModulesDir = path.join(cacheDir, 'node_modules');
|
|
46
|
+
if (fs.existsSync(nodeModulesDir)) {
|
|
47
|
+
fs.rmSync(nodeModulesDir, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
// Install cms-dev-server with production dependencies only (async to allow spinner)
|
|
50
|
+
await new Promise((resolve, reject) => {
|
|
51
|
+
const installProcess = spawn('npm', [
|
|
52
|
+
'install',
|
|
53
|
+
`@hubspot/cms-dev-server@${targetVersion}`,
|
|
54
|
+
'--production',
|
|
55
|
+
'--no-save',
|
|
56
|
+
'--loglevel=error',
|
|
57
|
+
], {
|
|
58
|
+
cwd: cacheDir,
|
|
59
|
+
stdio: 'ignore', // Suppress npm output
|
|
60
|
+
});
|
|
61
|
+
installProcess.on('close', code => {
|
|
62
|
+
if (code === 0) {
|
|
63
|
+
SpinniesManager.succeed('cms-dev-server-install', {
|
|
64
|
+
text: lib.theme.cmsDevServerProcess.installSucceeded,
|
|
65
|
+
});
|
|
66
|
+
resolve();
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
SpinniesManager.fail('cms-dev-server-install', {
|
|
70
|
+
text: lib.theme.cmsDevServerProcess.installFailed,
|
|
71
|
+
});
|
|
72
|
+
reject(new Error(lib.theme.cmsDevServerProcess.installFailed));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
installProcess.on('error', error => {
|
|
76
|
+
SpinniesManager.fail('cms-dev-server-install', {
|
|
77
|
+
text: lib.theme.cmsDevServerProcess.installFailed,
|
|
78
|
+
});
|
|
79
|
+
reject(error);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return cacheDir;
|
|
84
|
+
}
|
|
85
|
+
export async function spawnDevServer(options) {
|
|
86
|
+
const { absoluteSrc, accountName, noSsl, port, generateFieldsTypes, resetSession, dest, } = options;
|
|
87
|
+
// Ensure cms-dev-server is installed in isolated cache
|
|
88
|
+
const cacheDir = await ensureCmsDevServerCache(TARGET_CMS_DEV_SERVER_VERSION);
|
|
89
|
+
// Get config path to pass to createDevServer
|
|
90
|
+
let configPath = '';
|
|
91
|
+
try {
|
|
92
|
+
configPath = process.env.HUBSPOT_CONFIG_PATH || getConfigFilePath();
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
// Config file doesn't exist - cms-dev-server will handle this gracefully
|
|
96
|
+
}
|
|
97
|
+
// Copy the runner script to the cache directory so imports resolve from there
|
|
98
|
+
// This is critical: Node resolves ES module imports relative to the script location,
|
|
99
|
+
// not the cwd. By copying the script to the cache directory, imports will resolve
|
|
100
|
+
// from the cache's node_modules (React 18) instead of the CLI's node_modules (React 19)
|
|
101
|
+
const sourceRunnerPath = path.join(__dirname, 'cmsDevServerRunner.js');
|
|
102
|
+
const targetRunnerPath = path.join(cacheDir, 'cmsPreviewRunner.js');
|
|
103
|
+
fs.copyFileSync(sourceRunnerPath, targetRunnerPath);
|
|
104
|
+
// Set environment variables to pass configuration to the runner script
|
|
105
|
+
const env = { ...process.env };
|
|
106
|
+
env.CMS_DEV_SERVER_SRC = absoluteSrc;
|
|
107
|
+
env.CMS_DEV_SERVER_DEST = dest;
|
|
108
|
+
env.CMS_DEV_SERVER_CONFIG = configPath;
|
|
109
|
+
env.CMS_DEV_SERVER_ACCOUNT = accountName || '';
|
|
110
|
+
env.CMS_DEV_SERVER_SSL = (!noSsl).toString();
|
|
111
|
+
env.CMS_DEV_SERVER_FIELD_GEN = Boolean(generateFieldsTypes).toString();
|
|
112
|
+
env.CMS_DEV_SERVER_RESET_SESSION = Boolean(resetSession).toString();
|
|
113
|
+
if (port) {
|
|
114
|
+
env.PORT = port.toString();
|
|
115
|
+
}
|
|
116
|
+
// Suppress Node.js deprecation warnings
|
|
117
|
+
env.NODE_NO_WARNINGS = '1';
|
|
118
|
+
// Spawn Node with the runner script from the isolated cache directory
|
|
119
|
+
// This ensures complete isolation from CLI's React 19
|
|
120
|
+
const devServer = spawn('node', [targetRunnerPath], {
|
|
121
|
+
stdio: 'inherit',
|
|
122
|
+
env,
|
|
123
|
+
cwd: cacheDir,
|
|
124
|
+
});
|
|
125
|
+
// Handle process events
|
|
126
|
+
devServer.on('error', error => {
|
|
127
|
+
console.error(lib.theme.cmsDevServerProcess.serverStartError(error));
|
|
128
|
+
process.exit(1);
|
|
129
|
+
});
|
|
130
|
+
devServer.on('exit', (code, signal) => {
|
|
131
|
+
if (code !== 0 && code !== null) {
|
|
132
|
+
console.error(lib.theme.cmsDevServerProcess.serverExit(code));
|
|
133
|
+
process.exit(code);
|
|
134
|
+
}
|
|
135
|
+
if (signal) {
|
|
136
|
+
console.error(lib.theme.cmsDevServerProcess.serverKill(signal));
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
// Handle CLI termination
|
|
141
|
+
process.once('SIGINT', () => {
|
|
142
|
+
devServer.kill('SIGINT');
|
|
143
|
+
});
|
|
144
|
+
process.once('SIGTERM', () => {
|
|
145
|
+
devServer.kill('SIGTERM');
|
|
146
|
+
});
|
|
147
|
+
return devServer;
|
|
148
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This script runs in an isolated cache directory with cms-dev-server installed.
|
|
3
|
+
* It is spawned as a separate process to avoid React version conflicts with the CLI.
|
|
4
|
+
*
|
|
5
|
+
* Arguments are passed via environment variables:
|
|
6
|
+
* - CMS_DEV_SERVER_SRC: Source directory path
|
|
7
|
+
* - CMS_DEV_SERVER_DEST: Destination path
|
|
8
|
+
* - CMS_DEV_SERVER_CONFIG: Config file path (optional)
|
|
9
|
+
* - CMS_DEV_SERVER_ACCOUNT: Account name (optional)
|
|
10
|
+
* - CMS_DEV_SERVER_SSL: 'true' or 'false'
|
|
11
|
+
* - CMS_DEV_SERVER_FIELD_GEN: 'true' or 'false'
|
|
12
|
+
* - CMS_DEV_SERVER_RESET_SESSION: 'true' or 'false'
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* This script runs in an isolated cache directory with cms-dev-server installed.
|
|
4
|
+
* It is spawned as a separate process to avoid React version conflicts with the CLI.
|
|
5
|
+
*
|
|
6
|
+
* Arguments are passed via environment variables:
|
|
7
|
+
* - CMS_DEV_SERVER_SRC: Source directory path
|
|
8
|
+
* - CMS_DEV_SERVER_DEST: Destination path
|
|
9
|
+
* - CMS_DEV_SERVER_CONFIG: Config file path (optional)
|
|
10
|
+
* - CMS_DEV_SERVER_ACCOUNT: Account name (optional)
|
|
11
|
+
* - CMS_DEV_SERVER_SSL: 'true' or 'false'
|
|
12
|
+
* - CMS_DEV_SERVER_FIELD_GEN: 'true' or 'false'
|
|
13
|
+
* - CMS_DEV_SERVER_RESET_SESSION: 'true' or 'false'
|
|
14
|
+
*/
|
|
15
|
+
// Suppress library deprecation warnings (e.g., body-parser)
|
|
16
|
+
process.noDeprecation = true;
|
|
17
|
+
// Dynamic imports to use the isolated cms-dev-server installation
|
|
18
|
+
const { createDevServer } = await import('@hubspot/cms-dev-server');
|
|
19
|
+
const { walk } = await import('@hubspot/local-dev-lib/fs');
|
|
20
|
+
const { createIgnoreFilter } = await import('@hubspot/local-dev-lib/ignoreRules');
|
|
21
|
+
const { isAllowedExtension } = await import('@hubspot/local-dev-lib/path');
|
|
22
|
+
const { FILE_UPLOAD_RESULT_TYPES } = await import('@hubspot/local-dev-lib/constants/files');
|
|
23
|
+
const cliProgress = (await import('cli-progress')).default;
|
|
24
|
+
// Read configuration from environment variables
|
|
25
|
+
const src = process.env.CMS_DEV_SERVER_SRC;
|
|
26
|
+
const dest = process.env.CMS_DEV_SERVER_DEST;
|
|
27
|
+
const configPath = process.env.CMS_DEV_SERVER_CONFIG || '';
|
|
28
|
+
const accountName = process.env.CMS_DEV_SERVER_ACCOUNT || '';
|
|
29
|
+
const sslEnabled = process.env.CMS_DEV_SERVER_SSL === 'true';
|
|
30
|
+
const fieldGenEnabled = process.env.CMS_DEV_SERVER_FIELD_GEN === 'true';
|
|
31
|
+
const resetSession = process.env.CMS_DEV_SERVER_RESET_SESSION === 'true';
|
|
32
|
+
// Get uploadable files for preview
|
|
33
|
+
let filePaths = [];
|
|
34
|
+
try {
|
|
35
|
+
filePaths = await walk(src);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
console.error('Error walking directory:', e);
|
|
39
|
+
}
|
|
40
|
+
filePaths = filePaths
|
|
41
|
+
.filter(file => isAllowedExtension(file))
|
|
42
|
+
.filter(createIgnoreFilter(false));
|
|
43
|
+
// Create progress bar for initial upload
|
|
44
|
+
function startProgressBar(numFiles) {
|
|
45
|
+
const initialUploadProgressBar = new cliProgress.SingleBar({
|
|
46
|
+
gracefulExit: true,
|
|
47
|
+
format: '[{bar}] {percentage}% | {value}/{total} | {label}',
|
|
48
|
+
hideCursor: true,
|
|
49
|
+
}, cliProgress.Presets.rect);
|
|
50
|
+
initialUploadProgressBar.start(numFiles, 0, {
|
|
51
|
+
label: 'Preparing upload...',
|
|
52
|
+
});
|
|
53
|
+
let uploadsHaveStarted = false;
|
|
54
|
+
return {
|
|
55
|
+
onAttemptCallback: () => { },
|
|
56
|
+
onSuccessCallback: () => {
|
|
57
|
+
initialUploadProgressBar.increment();
|
|
58
|
+
if (!uploadsHaveStarted) {
|
|
59
|
+
uploadsHaveStarted = true;
|
|
60
|
+
initialUploadProgressBar.update(0, {
|
|
61
|
+
label: 'Uploading files...',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
onFirstErrorCallback: () => { },
|
|
66
|
+
onRetryCallback: () => { },
|
|
67
|
+
onFinalErrorCallback: () => initialUploadProgressBar.increment(),
|
|
68
|
+
// eslint-disable-next-line
|
|
69
|
+
onFinishCallback: (results) => {
|
|
70
|
+
initialUploadProgressBar.update(numFiles, {
|
|
71
|
+
label: 'Upload complete',
|
|
72
|
+
});
|
|
73
|
+
initialUploadProgressBar.stop();
|
|
74
|
+
results.forEach(result => {
|
|
75
|
+
if (result.resultType === FILE_UPLOAD_RESULT_TYPES.FAILURE) {
|
|
76
|
+
console.error(`Failed to upload ${result.file}`);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const themePreviewOptions = {
|
|
83
|
+
filePaths,
|
|
84
|
+
startProgressBar,
|
|
85
|
+
resetSession,
|
|
86
|
+
dest,
|
|
87
|
+
};
|
|
88
|
+
createDevServer(src, false, // storybook
|
|
89
|
+
configPath, accountName, sslEnabled, fieldGenEnabled, themePreviewOptions);
|
|
90
|
+
export {};
|
package/lib/usageTracking.js
CHANGED
|
@@ -44,11 +44,14 @@ export async function trackCommandUsage(command, meta = {}, accountId) {
|
|
|
44
44
|
uiLogger.debug(`Attempting to track usage of "${command}" command`);
|
|
45
45
|
let authType = 'unknown';
|
|
46
46
|
if (accountId) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
try {
|
|
48
|
+
const accountConfig = getConfigAccountById(accountId);
|
|
49
|
+
authType =
|
|
50
|
+
accountConfig && accountConfig.authType
|
|
51
|
+
? accountConfig.authType
|
|
52
|
+
: API_KEY_AUTH_METHOD.value;
|
|
53
|
+
}
|
|
54
|
+
catch (e) { }
|
|
52
55
|
}
|
|
53
56
|
return trackCliInteraction({
|
|
54
57
|
action: 'cli-command',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Tool } from '../../types.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { absoluteCurrentWorkingDirectory } from '../project/constants.js';
|
|
4
|
-
import { runCommandInDir } from '../../utils/
|
|
4
|
+
import { runCommandInDir } from '../../utils/command.js';
|
|
5
5
|
import { formatTextContents, formatTextContent } from '../../utils/content.js';
|
|
6
6
|
import { trackToolUsage } from '../../utils/toolUsageTracking.js';
|
|
7
7
|
import { addFlag } from '../../utils/command.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Tool } from '../../types.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { absoluteCurrentWorkingDirectory } from '../project/constants.js';
|
|
4
|
-
import { runCommandInDir } from '../../utils/
|
|
4
|
+
import { runCommandInDir } from '../../utils/command.js';
|
|
5
5
|
import { formatTextContents, formatTextContent } from '../../utils/content.js';
|
|
6
6
|
import { trackToolUsage } from '../../utils/toolUsageTracking.js';
|
|
7
7
|
import { addFlag } from '../../utils/command.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Tool } from '../../types.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { absoluteCurrentWorkingDirectory } from '../project/constants.js';
|
|
4
|
-
import { runCommandInDir } from '../../utils/
|
|
4
|
+
import { runCommandInDir } from '../../utils/command.js';
|
|
5
5
|
import { formatTextContents, formatTextContent } from '../../utils/content.js';
|
|
6
6
|
import { trackToolUsage } from '../../utils/toolUsageTracking.js';
|
|
7
7
|
import { addFlag } from '../../utils/command.js';
|
|
@@ -2,7 +2,7 @@ import { Tool } from '../../types.js';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { addFlag } from '../../utils/command.js';
|
|
4
4
|
import { absoluteCurrentWorkingDirectory } from '../project/constants.js';
|
|
5
|
-
import { runCommandInDir } from '../../utils/
|
|
5
|
+
import { runCommandInDir } from '../../utils/command.js';
|
|
6
6
|
import { formatTextContents } from '../../utils/content.js';
|
|
7
7
|
import { trackToolUsage } from '../../utils/toolUsageTracking.js';
|
|
8
8
|
import { setupHubSpotConfig } from '../../utils/config.js';
|
|
@@ -2,7 +2,7 @@ import { Tool } from '../../types.js';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { addFlag } from '../../utils/command.js';
|
|
4
4
|
import { absoluteCurrentWorkingDirectory } from '../project/constants.js';
|
|
5
|
-
import { runCommandInDir } from '../../utils/
|
|
5
|
+
import { runCommandInDir } from '../../utils/command.js';
|
|
6
6
|
import { formatTextContents } from '../../utils/content.js';
|
|
7
7
|
import { trackToolUsage } from '../../utils/toolUsageTracking.js';
|
|
8
8
|
import { setupHubSpotConfig } from '../../utils/config.js';
|
|
@@ -2,7 +2,7 @@ import { Tool } from '../../types.js';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { addFlag } from '../../utils/command.js';
|
|
4
4
|
import { absoluteCurrentWorkingDirectory } from '../project/constants.js';
|
|
5
|
-
import { runCommandInDir } from '../../utils/
|
|
5
|
+
import { runCommandInDir } from '../../utils/command.js';
|
|
6
6
|
import { formatTextContents } from '../../utils/content.js';
|
|
7
7
|
import { trackToolUsage } from '../../utils/toolUsageTracking.js';
|
|
8
8
|
import { setupHubSpotConfig } from '../../utils/config.js';
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
import { HsCreateFunctionTool } from '../HsCreateFunctionTool.js';
|
|
3
|
-
import { runCommandInDir } from '../../../utils/
|
|
3
|
+
import { runCommandInDir } from '../../../utils/command.js';
|
|
4
4
|
import { addFlag } from '../../../utils/command.js';
|
|
5
5
|
import { mcpFeedbackRequest } from '../../../utils/feedbackTracking.js';
|
|
6
6
|
import { trackToolUsage } from '../../../utils/toolUsageTracking.js';
|
|
7
7
|
vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
|
|
8
|
-
vi.mock('../../../utils/project');
|
|
9
8
|
vi.mock('../../../utils/command');
|
|
10
9
|
vi.mock('../../../utils/toolUsageTracking');
|
|
11
10
|
vi.mock('../../../utils/feedbackTracking');
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
import { HsCreateModuleTool } from '../HsCreateModuleTool.js';
|
|
3
|
-
import { runCommandInDir } from '../../../utils/
|
|
3
|
+
import { runCommandInDir } from '../../../utils/command.js';
|
|
4
4
|
import { addFlag } from '../../../utils/command.js';
|
|
5
5
|
import { mcpFeedbackRequest } from '../../../utils/feedbackTracking.js';
|
|
6
6
|
import { trackToolUsage } from '../../../utils/toolUsageTracking.js';
|
|
7
7
|
vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
|
|
8
|
-
vi.mock('../../../utils/project');
|
|
9
8
|
vi.mock('../../../utils/command');
|
|
10
9
|
vi.mock('../../../utils/toolUsageTracking');
|
|
11
10
|
vi.mock('../../../utils/feedbackTracking');
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
import { HsCreateTemplateTool } from '../HsCreateTemplateTool.js';
|
|
3
|
-
import { runCommandInDir } from '../../../utils/
|
|
3
|
+
import { runCommandInDir } from '../../../utils/command.js';
|
|
4
4
|
import { addFlag } from '../../../utils/command.js';
|
|
5
5
|
import { mcpFeedbackRequest } from '../../../utils/feedbackTracking.js';
|
|
6
6
|
import { trackToolUsage } from '../../../utils/toolUsageTracking.js';
|
|
7
7
|
vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
|
|
8
|
-
vi.mock('../../../utils/project');
|
|
9
8
|
vi.mock('../../../utils/command');
|
|
10
9
|
vi.mock('../../../utils/toolUsageTracking');
|
|
11
10
|
vi.mock('../../../utils/feedbackTracking');
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
import { HsFunctionLogsTool } from '../HsFunctionLogsTool.js';
|
|
3
|
-
import { runCommandInDir } from '../../../utils/
|
|
3
|
+
import { runCommandInDir } from '../../../utils/command.js';
|
|
4
4
|
import { addFlag } from '../../../utils/command.js';
|
|
5
5
|
import { mcpFeedbackRequest } from '../../../utils/feedbackTracking.js';
|
|
6
6
|
import { trackToolUsage } from '../../../utils/toolUsageTracking.js';
|
|
7
7
|
vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
|
|
8
|
-
vi.mock('../../../utils/project');
|
|
9
8
|
vi.mock('../../../utils/command');
|
|
10
9
|
vi.mock('../../../utils/toolUsageTracking');
|
|
11
10
|
vi.mock('../../../utils/feedbackTracking');
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
import { HsListFunctionsTool } from '../HsListFunctionsTool.js';
|
|
3
|
-
import { runCommandInDir } from '../../../utils/
|
|
3
|
+
import { runCommandInDir } from '../../../utils/command.js';
|
|
4
4
|
import { addFlag } from '../../../utils/command.js';
|
|
5
5
|
import { mcpFeedbackRequest } from '../../../utils/feedbackTracking.js';
|
|
6
6
|
import { trackToolUsage } from '../../../utils/toolUsageTracking.js';
|
|
7
7
|
vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
|
|
8
|
-
vi.mock('../../../utils/project');
|
|
9
8
|
vi.mock('../../../utils/command');
|
|
10
9
|
vi.mock('../../../utils/toolUsageTracking');
|
|
11
10
|
vi.mock('../../../utils/feedbackTracking');
|