@hubspot/cli 8.16.0 → 8.17.0-beta.1

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 (39) hide show
  1. package/bin/cli.js +19 -1
  2. package/commands/cms/lighthouseScore.js +1 -1
  3. package/commands/mcp/setup.d.ts +1 -0
  4. package/commands/mcp/setup.js +8 -1
  5. package/commands/project/download.d.ts +2 -0
  6. package/commands/project/download.js +56 -16
  7. package/lang/en.d.ts +61 -6
  8. package/lang/en.js +168 -11
  9. package/lib/agentHelp.d.ts +17 -0
  10. package/lib/agentHelp.js +90 -0
  11. package/lib/app/migrate.js +2 -5
  12. package/lib/commonOpts.js +4 -0
  13. package/lib/jsonOutput/projectDownload.d.ts +1 -0
  14. package/lib/jsonOutput/projectDownload.js +1 -0
  15. package/lib/mcp/clients.d.ts +2 -1
  16. package/lib/mcp/clients.js +7 -7
  17. package/lib/mcp/setup.d.ts +1 -1
  18. package/lib/mcp/setup.js +21 -36
  19. package/lib/mcp/skills.d.ts +8 -0
  20. package/lib/mcp/skills.js +64 -0
  21. package/lib/projects/archive.d.ts +8 -0
  22. package/lib/projects/archive.js +104 -0
  23. package/lib/projects/archiveDiff.d.ts +12 -0
  24. package/lib/projects/archiveDiff.js +68 -0
  25. package/lib/projects/config.js +1 -1
  26. package/lib/projects/download.d.ts +37 -0
  27. package/lib/projects/download.js +123 -0
  28. package/lib/projects/localDev/LocalDevWatcher.js +2 -1
  29. package/lib/prompts/importDataTestAccountSelectPrompt.js +1 -1
  30. package/lib/validation.js +16 -1
  31. package/lib/yargs/makeWrappedYargsHandler.d.ts +1 -0
  32. package/lib/yargs/makeWrappedYargsHandler.js +7 -0
  33. package/mcp-server/skills/hubspot-fix-build/SKILL.md +61 -0
  34. package/mcp-server/skills/hubspot-new-app/SKILL.md +84 -0
  35. package/mcp-server/tools/project/DocFetchTool.d.ts +4 -1
  36. package/mcp-server/tools/project/DocFetchTool.js +52 -7
  37. package/mcp-server/tools/project/FindProjectsTool.js +4 -1
  38. package/mcp-server/tools/project/GetBuildLogsTool.d.ts +1 -1
  39. package/package.json +6 -8
package/lib/mcp/setup.js CHANGED
@@ -5,6 +5,7 @@ import SpinniesManager from '../ui/SpinniesManager.js';
5
5
  import { logError, getErrorMessage } from '../errorHandlers/index.js';
6
6
  import { execAsync } from '../../mcp-server/utils/command.js';
7
7
  import { MCP_CLIENTS, MCP_SERVER_NAME, getMcpClientPathSegments, } from './clients.js';
8
+ import { MCP_SKILLS, SKILLS_SOURCE_DIR, installSkills } from './skills.js';
8
9
  import path from 'path';
9
10
  import os from 'os';
10
11
  import fs from 'fs-extra';
@@ -16,7 +17,6 @@ const cursor = 'cursor';
16
17
  const devin = 'devin';
17
18
  const vscode = 'vscode';
18
19
  const codex = 'codex';
19
- const gemini = 'gemini';
20
20
  const opencode = 'opencode';
21
21
  const OTHER_TOOL = 'other';
22
22
  const MINIMUM_VSCODE_VERSION = '1.99.0';
@@ -25,7 +25,6 @@ const clientLabels = {
25
25
  claude: commands.mcp.setup.claudeCode,
26
26
  cursor: commands.mcp.setup.cursor,
27
27
  devin: commands.mcp.setup.devin,
28
- gemini: commands.mcp.setup.gemini,
29
28
  opencode: commands.mcp.setup.opencode,
30
29
  vscode: commands.mcp.setup.vsCode,
31
30
  };
@@ -42,7 +41,7 @@ const defaultMcpCommand = {
42
41
  };
43
42
  export async function configureMcpServer(options) {
44
43
  try {
45
- const { targets, standalone, cliVersion: cliVersionFlag } = options;
44
+ const { targets, standalone, cliVersion: cliVersionFlag, skills } = options;
46
45
  let derivedTargets = [];
47
46
  if (!targets || targets.length === 0) {
48
47
  const { selectedTargets } = await promptUser({
@@ -90,6 +89,20 @@ export async function configureMcpServer(options) {
90
89
  cliVersion = response.cliVersion;
91
90
  }
92
91
  }
92
+ const configuredTargets = derivedTargets.filter((target) => target !== OTHER_TOOL);
93
+ let selectedSkills = configuredTargets.length > 0 ? skills : [];
94
+ if (selectedSkills === undefined) {
95
+ const response = await promptUser({
96
+ name: 'selectedSkills',
97
+ type: 'checkbox',
98
+ message: commands.mcp.setup.prompts.selectSkills,
99
+ choices: MCP_SKILLS.map(skill => ({
100
+ name: `${skill.name} - ${skill.description}`,
101
+ value: skill.name,
102
+ })),
103
+ });
104
+ selectedSkills = response.selectedSkills;
105
+ }
93
106
  const cliPackage = cliVersion
94
107
  ? `@hubspot/cli@${cliVersion}`
95
108
  : '@hubspot/cli';
@@ -121,16 +134,15 @@ export async function configureMcpServer(options) {
121
134
  if (derivedTargets.includes(codex)) {
122
135
  await runSetupFunction(() => setupCodex(mcpCommand));
123
136
  }
124
- if (derivedTargets.includes(gemini)) {
125
- await runSetupFunction(() => setupGemini(mcpCommand));
126
- }
127
137
  if (derivedTargets.includes(opencode)) {
128
138
  await runSetupFunction(() => setupOpenCode(mcpCommand));
129
139
  }
140
+ if (selectedSkills.length > 0) {
141
+ await runSetupFunction(() => installSkills(configuredTargets, selectedSkills));
142
+ }
130
143
  if (derivedTargets.includes(OTHER_TOOL)) {
131
144
  logOtherToolInstructions(mcpCommand);
132
145
  }
133
- const configuredTargets = derivedTargets.filter(t => t !== OTHER_TOOL);
134
146
  if (configuredTargets.length > 0) {
135
147
  uiLogger.info(commands.mcp.setup.success(configuredTargets));
136
148
  }
@@ -339,35 +351,6 @@ export async function setupCodex(mcpCommand = defaultMcpCommand) {
339
351
  return false;
340
352
  }
341
353
  }
342
- export async function setupGemini(mcpCommand = defaultMcpCommand) {
343
- try {
344
- SpinniesManager.add('geminiSpinner', {
345
- text: commands.mcp.setup.spinners.configuringGemini,
346
- });
347
- try {
348
- await execAsync('gemini --version');
349
- }
350
- catch (e) {
351
- SpinniesManager.fail('geminiSpinner', {
352
- text: commands.mcp.setup.spinners.geminiNotFound,
353
- });
354
- return false;
355
- }
356
- const mcpCommandWithAgent = buildCommandWithAgentString(mcpCommand, gemini);
357
- await execAsync(`gemini mcp add -s user${buildEnvFlagString(mcpCommand)} "${mcpServerName}" ${mcpCommandWithAgent.command} ${mcpCommandWithAgent.args.join(' ')}`);
358
- SpinniesManager.succeed('geminiSpinner', {
359
- text: commands.mcp.setup.spinners.configuredGemini,
360
- });
361
- return true;
362
- }
363
- catch (error) {
364
- SpinniesManager.fail('geminiSpinner', {
365
- text: commands.mcp.setup.spinners.geminiInstallFailed,
366
- });
367
- logError(error);
368
- return false;
369
- }
370
- }
371
354
  export async function setupOpenCode(mcpCommand = defaultMcpCommand) {
372
355
  try {
373
356
  SpinniesManager.add('openCodeSpinner', {
@@ -419,6 +402,8 @@ function logOtherToolInstructions(mcpCommand) {
419
402
  .join('\n');
420
403
  uiLogger.log(indented);
421
404
  uiLogger.log('');
405
+ uiLogger.log(otherInstructions.skillsNote(SKILLS_SOURCE_DIR));
406
+ uiLogger.log('');
422
407
  }
423
408
  function buildCommandWithAgentString(mcpCommand, agent) {
424
409
  const mcpCommandCopy = structuredClone(mcpCommand);
@@ -0,0 +1,8 @@
1
+ import { McpClientId } from './clients.js';
2
+ export declare const SKILLS_SOURCE_DIR: string;
3
+ export declare const MCP_SKILLS: {
4
+ name: string;
5
+ description: string;
6
+ }[];
7
+ export declare const MCP_SKILL_NAMES: string[];
8
+ export declare function installSkills(targets: McpClientId[], skillNames: string[]): boolean;
@@ -0,0 +1,64 @@
1
+ import path from 'path';
2
+ import os from 'os';
3
+ import fs from 'fs-extra';
4
+ import { fileURLToPath } from 'url';
5
+ import { commands } from '../../lang/en.js';
6
+ import SpinniesManager from '../ui/SpinniesManager.js';
7
+ import { logError } from '../errorHandlers/index.js';
8
+ import { MCP_CLIENTS } from './clients.js';
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+ export const SKILLS_SOURCE_DIR = path.join(__dirname, '..', '..', 'mcp-server', 'skills');
12
+ export const MCP_SKILLS = [
13
+ {
14
+ name: 'hubspot-new-app',
15
+ description: commands.mcp.setup.skillDescriptions.newApp,
16
+ },
17
+ {
18
+ name: 'hubspot-fix-build',
19
+ description: commands.mcp.setup.skillDescriptions.fixBuild,
20
+ },
21
+ ];
22
+ export const MCP_SKILL_NAMES = MCP_SKILLS.map(skill => skill.name);
23
+ const INSTALLED_SKILL_MARKER = '.installed-by-hubspot-cli';
24
+ function getInstalledSkillNames(targetDir) {
25
+ if (!fs.existsSync(targetDir)) {
26
+ return [];
27
+ }
28
+ return fs
29
+ .readdirSync(targetDir, { withFileTypes: true })
30
+ .filter(entry => entry.isDirectory())
31
+ .map(entry => entry.name)
32
+ .filter(name => fs.existsSync(path.join(targetDir, name, INSTALLED_SKILL_MARKER)));
33
+ }
34
+ function installSkillsInDir(targetDir, skillNames) {
35
+ new Set([...getInstalledSkillNames(targetDir), ...skillNames]).forEach(name => fs.rmSync(path.join(targetDir, name), { recursive: true, force: true }));
36
+ skillNames.forEach(skillName => {
37
+ const destination = path.join(targetDir, skillName);
38
+ fs.copySync(path.join(SKILLS_SOURCE_DIR, skillName), destination);
39
+ fs.writeFileSync(path.join(destination, INSTALLED_SKILL_MARKER), '');
40
+ });
41
+ }
42
+ export function installSkills(targets, skillNames) {
43
+ const skillsToInstall = MCP_SKILL_NAMES.filter(skillName => skillNames.includes(skillName));
44
+ const targetDirs = [
45
+ ...new Set(MCP_CLIENTS.filter(client => targets.includes(client.id)).map(client => path.join(os.homedir(), ...client.skillsPathSegments))),
46
+ ];
47
+ SpinniesManager.add('mcpSkills', {
48
+ text: commands.mcp.setup.spinners.installingSkills,
49
+ });
50
+ try {
51
+ targetDirs.forEach(targetDir => installSkillsInDir(targetDir, skillsToInstall));
52
+ SpinniesManager.succeed('mcpSkills', {
53
+ text: commands.mcp.setup.spinners.installedSkills(skillsToInstall, targetDirs),
54
+ });
55
+ return true;
56
+ }
57
+ catch (error) {
58
+ SpinniesManager.fail('mcpSkills', {
59
+ text: commands.mcp.setup.spinners.failedToInstallSkills,
60
+ });
61
+ logError(error);
62
+ return false;
63
+ }
64
+ }
@@ -0,0 +1,8 @@
1
+ export declare const ARCHIVE_DIR_NAME = "archive";
2
+ export declare const ROOT_SRC_DIR = ".";
3
+ export declare function getArchiveDest(projectDir: string, srcDir: string): string;
4
+ export declare function archiveDestExists(archiveDest: string): boolean;
5
+ export declare function archiveProjectSource(projectDir: string, srcDir: string): string;
6
+ export declare function getProjectArchiveDest(projectDir: string): string;
7
+ export declare function moveSourceToProjectArchive(projectDir: string, srcDir: string): string;
8
+ export declare function restoreSourceFromProjectArchive(projectDir: string, srcDir: string): void;
@@ -0,0 +1,104 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { lib } from '../../lang/en.js';
4
+ export const ARCHIVE_DIR_NAME = 'archive';
5
+ export const ROOT_SRC_DIR = '.';
6
+ const ROOT_ENTRIES_KEPT_IN_PLACE = new Set([
7
+ '.git',
8
+ 'node_modules',
9
+ 'dist',
10
+ 'hsproject.json',
11
+ ]);
12
+ export function getArchiveDest(projectDir, srcDir) {
13
+ if (srcDir === ROOT_SRC_DIR) {
14
+ return path.join(path.dirname(projectDir), `${path.basename(projectDir)}-${ARCHIVE_DIR_NAME}`);
15
+ }
16
+ return path.join(projectDir, ARCHIVE_DIR_NAME);
17
+ }
18
+ export function archiveDestExists(archiveDest) {
19
+ return fs.existsSync(archiveDest);
20
+ }
21
+ export function archiveProjectSource(projectDir, srcDir) {
22
+ const archiveDest = getArchiveDest(projectDir, srcDir);
23
+ fs.renameSync(path.join(projectDir, srcDir), archiveDest);
24
+ return archiveDest;
25
+ }
26
+ export function getProjectArchiveDest(projectDir) {
27
+ return path.join(projectDir, ARCHIVE_DIR_NAME);
28
+ }
29
+ function assertSrcDirOutsideArchive(projectDir, srcDir) {
30
+ const archiveDest = path.resolve(getProjectArchiveDest(projectDir));
31
+ const srcPath = path.resolve(projectDir, srcDir);
32
+ const isInsideArchive = srcPath === archiveDest || srcPath.startsWith(archiveDest + path.sep);
33
+ if (isInsideArchive) {
34
+ throw new Error(lib.projects.archive.errors.srcDirInsideArchive(srcDir));
35
+ }
36
+ }
37
+ function assertArchiveExists(archiveDest) {
38
+ if (!fs.existsSync(archiveDest)) {
39
+ throw new Error(lib.projects.archive.errors.archiveNotFound(archiveDest));
40
+ }
41
+ }
42
+ function getMovableRootEntries(projectDir) {
43
+ return fs
44
+ .readdirSync(projectDir)
45
+ .filter(name => name !== ARCHIVE_DIR_NAME && !ROOT_ENTRIES_KEPT_IN_PLACE.has(name));
46
+ }
47
+ function moveEntries(names, fromDir, toDir) {
48
+ const moved = [];
49
+ try {
50
+ names.forEach(name => {
51
+ fs.renameSync(path.join(fromDir, name), path.join(toDir, name));
52
+ moved.push(name);
53
+ });
54
+ }
55
+ catch (error) {
56
+ moved.forEach(name => {
57
+ fs.renameSync(path.join(toDir, name), path.join(fromDir, name));
58
+ });
59
+ throw error;
60
+ }
61
+ return moved;
62
+ }
63
+ function archiveRootEntries(projectDir, archiveDest) {
64
+ fs.mkdirSync(archiveDest);
65
+ try {
66
+ moveEntries(getMovableRootEntries(projectDir), projectDir, archiveDest);
67
+ }
68
+ catch (error) {
69
+ fs.rmdirSync(archiveDest);
70
+ throw error;
71
+ }
72
+ }
73
+ export function moveSourceToProjectArchive(projectDir, srcDir) {
74
+ assertSrcDirOutsideArchive(projectDir, srcDir);
75
+ const archiveDest = getProjectArchiveDest(projectDir);
76
+ if (srcDir === ROOT_SRC_DIR) {
77
+ archiveRootEntries(projectDir, archiveDest);
78
+ return archiveDest;
79
+ }
80
+ fs.renameSync(path.join(projectDir, srcDir), archiveDest);
81
+ return archiveDest;
82
+ }
83
+ function restoreRootEntries(projectDir, archiveDest) {
84
+ getMovableRootEntries(projectDir).forEach(name => {
85
+ fs.rmSync(path.join(projectDir, name), { recursive: true, force: true });
86
+ });
87
+ fs.readdirSync(archiveDest).forEach(name => {
88
+ fs.cpSync(path.join(archiveDest, name), path.join(projectDir, name), {
89
+ recursive: true,
90
+ });
91
+ });
92
+ }
93
+ export function restoreSourceFromProjectArchive(projectDir, srcDir) {
94
+ const archiveDest = getProjectArchiveDest(projectDir);
95
+ assertArchiveExists(archiveDest);
96
+ assertSrcDirOutsideArchive(projectDir, srcDir);
97
+ if (srcDir === ROOT_SRC_DIR) {
98
+ restoreRootEntries(projectDir, archiveDest);
99
+ return;
100
+ }
101
+ const srcPath = path.join(projectDir, srcDir);
102
+ fs.rmSync(srcPath, { recursive: true, force: true });
103
+ fs.cpSync(archiveDest, srcPath, { recursive: true });
104
+ }
@@ -0,0 +1,12 @@
1
+ export declare function getFilesOnlyInArchive(projectDir: string, srcDir: string): Promise<string[]>;
2
+ export declare function writeArchiveDiffFile(archiveDest: string, files: string[]): string;
3
+ type FailedFileCopy = {
4
+ file: string;
5
+ error: unknown;
6
+ };
7
+ type CopyArchivedFilesResult = {
8
+ copiedCount: number;
9
+ failures: FailedFileCopy[];
10
+ };
11
+ export declare function copyArchivedFilesToSource(projectDir: string, srcDir: string, files: string[]): CopyArchivedFilesResult;
12
+ export {};
@@ -0,0 +1,68 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { ARCHIVE_DIR_NAME, ROOT_SRC_DIR, getProjectArchiveDest, } from './archive.js';
4
+ const DIFF_FILE_NAME = 'diff.json';
5
+ const IGNORED_DIR_NAMES = new Set(['node_modules', 'dist', '.git']);
6
+ function toPosixPath(filePath) {
7
+ return filePath.split(path.sep).join('/');
8
+ }
9
+ function isIgnoredDir(entry, { rootDir, currentDir, ignoredRootEntry }) {
10
+ const isIgnoredRootEntry = currentDir === rootDir && entry.name === ignoredRootEntry;
11
+ return isIgnoredRootEntry || IGNORED_DIR_NAMES.has(entry.name);
12
+ }
13
+ async function listEntryFiles(options, entry) {
14
+ const { rootDir, currentDir = rootDir } = options;
15
+ const entryPath = path.join(currentDir, entry.name);
16
+ if (entry.isDirectory() && !isIgnoredDir(entry, { ...options, currentDir })) {
17
+ return listFiles({ ...options, currentDir: entryPath });
18
+ }
19
+ if (entry.isFile()) {
20
+ return [toPosixPath(path.relative(rootDir, entryPath))];
21
+ }
22
+ return [];
23
+ }
24
+ async function listFiles(options) {
25
+ const { rootDir, currentDir = rootDir } = options;
26
+ if (!fs.existsSync(currentDir)) {
27
+ return [];
28
+ }
29
+ const entries = await fs.promises.readdir(currentDir, {
30
+ withFileTypes: true,
31
+ });
32
+ const nestedFiles = await Promise.all(entries.map(entry => listEntryFiles({ ...options, currentDir }, entry)));
33
+ return nestedFiles.flat();
34
+ }
35
+ export async function getFilesOnlyInArchive(projectDir, srcDir) {
36
+ const archiveFiles = await listFiles({
37
+ rootDir: getProjectArchiveDest(projectDir),
38
+ });
39
+ const downloadedFiles = new Set(await listFiles({
40
+ rootDir: path.join(projectDir, srcDir),
41
+ ignoredRootEntry: srcDir === ROOT_SRC_DIR ? ARCHIVE_DIR_NAME : undefined,
42
+ }));
43
+ return archiveFiles.filter(file => !downloadedFiles.has(file)).sort();
44
+ }
45
+ export function writeArchiveDiffFile(archiveDest, files) {
46
+ const diffFilePath = path.join(archiveDest, DIFF_FILE_NAME);
47
+ fs.writeFileSync(diffFilePath, `${JSON.stringify(files, null, 2)}\n`);
48
+ return diffFilePath;
49
+ }
50
+ function copyArchivedFile(archiveDest, srcPath, file) {
51
+ const destination = path.join(srcPath, file);
52
+ fs.mkdirSync(path.dirname(destination), { recursive: true });
53
+ fs.copyFileSync(path.join(archiveDest, file), destination, fs.constants.COPYFILE_EXCL);
54
+ }
55
+ export function copyArchivedFilesToSource(projectDir, srcDir, files) {
56
+ const archiveDest = getProjectArchiveDest(projectDir);
57
+ const srcPath = path.join(projectDir, srcDir);
58
+ const failures = [];
59
+ files.forEach(file => {
60
+ try {
61
+ copyArchivedFile(archiveDest, srcPath, file);
62
+ }
63
+ catch (error) {
64
+ failures.push({ file, error });
65
+ }
66
+ });
67
+ return { copiedCount: files.length - failures.length, failures };
68
+ }
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
- import findup from 'findup-sync';
3
+ import { findup } from '@hubspot/local-dev-lib/findup';
4
4
  import { getAbsoluteFilePath, getCwd } from '@hubspot/local-dev-lib/path';
5
5
  import { parseProjectConfig, ProjectConfigValidationError, } from '@hubspot/project-parsing-lib/projects';
6
6
  import { PROJECT_CONFIG_FILE } from '../constants.js';
@@ -0,0 +1,37 @@
1
+ export type LocalProject = {
2
+ projectName: string;
3
+ projectDir: string;
4
+ srcDir: string;
5
+ };
6
+ export type ArchivePlan = {
7
+ projectDir: string;
8
+ srcDir: string;
9
+ archiveDest: string;
10
+ };
11
+ type DownloadDestination = {
12
+ absoluteDestPath: string;
13
+ archivePlan?: ArchivePlan;
14
+ };
15
+ type ResolveDownloadDestinationOptions = {
16
+ projectName: string;
17
+ dest?: string;
18
+ localProject?: LocalProject;
19
+ };
20
+ export declare function getLocalProject(): LocalProject | undefined;
21
+ export declare function resolveDownloadDestination({ projectName, dest, localProject, }: ResolveDownloadDestinationOptions): DownloadDestination;
22
+ export declare function getDisplayPath(absolutePath: string): string;
23
+ export declare function describeArchiveLocation({ archiveDest }: ArchivePlan): string;
24
+ type HandleArchivedSourceOptions = {
25
+ archivePlan: ArchivePlan;
26
+ keepLocalFiles?: boolean;
27
+ canPrompt: boolean;
28
+ };
29
+ export declare function handleArchivedSource({ archivePlan, keepLocalFiles, canPrompt, }: HandleArchivedSourceOptions): Promise<void>;
30
+ type ExtractBuildOptions = {
31
+ zippedProject: Buffer;
32
+ projectName: string;
33
+ absoluteDestPath: string;
34
+ archivePlan?: ArchivePlan;
35
+ };
36
+ export declare function extractBuild({ zippedProject, projectName, absoluteDestPath, archivePlan, }: ExtractBuildOptions): Promise<void>;
37
+ export {};
@@ -0,0 +1,123 @@
1
+ import path from 'path';
2
+ import { getCwd, sanitizeFileName } from '@hubspot/local-dev-lib/path';
3
+ import { extractZipArchive } from '@hubspot/local-dev-lib/archive';
4
+ import { commands } from '../../lang/en.js';
5
+ import { debugError } from '../errorHandlers/index.js';
6
+ import { confirmPrompt } from '../prompts/promptUtils.js';
7
+ import { uiLogger } from '../ui/logger.js';
8
+ import { getIsInProject, getProjectConfig } from './config.js';
9
+ import { getProjectArchiveDest, restoreSourceFromProjectArchive, } from './archive.js';
10
+ import { copyArchivedFilesToSource, getFilesOnlyInArchive, writeArchiveDiffFile, } from './archiveDiff.js';
11
+ const MAX_LISTED_ARCHIVE_ONLY_FILES = 25;
12
+ export function getLocalProject() {
13
+ if (!getIsInProject()) {
14
+ return undefined;
15
+ }
16
+ const { projectConfig, projectDir } = getProjectConfig();
17
+ return {
18
+ projectName: projectConfig.name,
19
+ projectDir,
20
+ srcDir: projectConfig.srcDir,
21
+ };
22
+ }
23
+ export function resolveDownloadDestination({ projectName, dest, localProject, }) {
24
+ if (localProject && !dest && localProject.projectName === projectName) {
25
+ const { projectDir, srcDir } = localProject;
26
+ return {
27
+ absoluteDestPath: projectDir,
28
+ archivePlan: {
29
+ projectDir,
30
+ srcDir,
31
+ archiveDest: getProjectArchiveDest(projectDir),
32
+ },
33
+ };
34
+ }
35
+ const sanitizedProjectName = sanitizeFileName(projectName);
36
+ const absoluteDestPath = dest
37
+ ? path.resolve(getCwd(), dest, sanitizedProjectName)
38
+ : path.resolve(getCwd(), sanitizedProjectName);
39
+ return { absoluteDestPath };
40
+ }
41
+ export function getDisplayPath(absolutePath) {
42
+ return path.relative(getCwd(), absolutePath) || '.';
43
+ }
44
+ export function describeArchiveLocation({ archiveDest }) {
45
+ return commands.project.download.archiveLocation(getDisplayPath(archiveDest));
46
+ }
47
+ function restoreArchivedSource({ projectDir, srcDir, archiveDest, }) {
48
+ try {
49
+ restoreSourceFromProjectArchive(projectDir, srcDir);
50
+ uiLogger.warn(commands.project.download.warnings.sourceRestored);
51
+ }
52
+ catch (error) {
53
+ debugError(error);
54
+ uiLogger.error(commands.project.download.errors.restoreFailed(getDisplayPath(archiveDest)));
55
+ }
56
+ }
57
+ function tryWriteArchiveDiffFile(archiveDest, files) {
58
+ try {
59
+ return writeArchiveDiffFile(archiveDest, files);
60
+ }
61
+ catch (error) {
62
+ debugError(error);
63
+ return undefined;
64
+ }
65
+ }
66
+ async function logFilesOnlyInArchive({ projectDir, srcDir, archiveDest, }) {
67
+ let files;
68
+ try {
69
+ files = await getFilesOnlyInArchive(projectDir, srcDir);
70
+ }
71
+ catch (error) {
72
+ debugError(error);
73
+ return [];
74
+ }
75
+ if (files.length === 0) {
76
+ return [];
77
+ }
78
+ const diffFilePath = tryWriteArchiveDiffFile(archiveDest, files);
79
+ uiLogger.log('');
80
+ uiLogger.log(commands.project.download.logs.filesOnlyInArchive(files.slice(0, MAX_LISTED_ARCHIVE_ONLY_FILES), Math.max(files.length - MAX_LISTED_ARCHIVE_ONLY_FILES, 0), diffFilePath ? getDisplayPath(diffFilePath) : undefined));
81
+ return files;
82
+ }
83
+ async function shouldCopyFilesBack({ files, keepLocalFiles, canPrompt, }) {
84
+ if (keepLocalFiles !== undefined) {
85
+ return keepLocalFiles;
86
+ }
87
+ if (!canPrompt) {
88
+ return false;
89
+ }
90
+ uiLogger.log('');
91
+ return confirmPrompt(commands.project.download.prompts.confirmCopyFilesBack(files.length));
92
+ }
93
+ async function copyFilesBack(options) {
94
+ const { archivePlan, files } = options;
95
+ if (files.length === 0 || !(await shouldCopyFilesBack(options))) {
96
+ return;
97
+ }
98
+ const { projectDir, srcDir } = archivePlan;
99
+ const { copiedCount, failures } = copyArchivedFilesToSource(projectDir, srcDir, files);
100
+ failures.forEach(({ error }) => debugError(error));
101
+ if (copiedCount > 0) {
102
+ uiLogger.success(commands.project.download.logs.filesCopiedBack(copiedCount, getDisplayPath(path.join(projectDir, srcDir))));
103
+ }
104
+ if (failures.length > 0) {
105
+ uiLogger.warn(commands.project.download.warnings.filesNotCopiedBack(failures.length));
106
+ }
107
+ }
108
+ export async function handleArchivedSource({ archivePlan, keepLocalFiles, canPrompt, }) {
109
+ uiLogger.info(commands.project.download.logs.sourceContentsArchived(describeArchiveLocation(archivePlan)));
110
+ const files = await logFilesOnlyInArchive(archivePlan);
111
+ await copyFilesBack({ archivePlan, files, keepLocalFiles, canPrompt });
112
+ }
113
+ export async function extractBuild({ zippedProject, projectName, absoluteDestPath, archivePlan, }) {
114
+ try {
115
+ await extractZipArchive(zippedProject, sanitizeFileName(projectName), absoluteDestPath);
116
+ }
117
+ catch (error) {
118
+ if (archivePlan) {
119
+ restoreArchivedSource(archivePlan);
120
+ }
121
+ throw error;
122
+ }
123
+ }
@@ -7,6 +7,7 @@ const WATCH_EVENTS = {
7
7
  unlink: 'unlink',
8
8
  unlinkDir: 'unlinkDir',
9
9
  };
10
+ const IGNORED_DIRECTORIES = ['dist', 'node_modules'];
10
11
  class LocalDevWatcher {
11
12
  localDevProcess;
12
13
  watcher;
@@ -23,7 +24,7 @@ class LocalDevWatcher {
23
24
  start() {
24
25
  this.watcher = chokidar.watch(this.localDevProcess.projectDir, {
25
26
  ignoreInitial: true,
26
- ignored: ['**/dist', '**/node_modules'],
27
+ ignored: filePath => IGNORED_DIRECTORIES.includes(path.basename(filePath)),
27
28
  });
28
29
  const configPaths = Object.values(this.localDevProcess.projectNodes).map(component => component.localDev.componentConfigPath);
29
30
  const projectConfigPath = path.join(this.localDevProcess.projectDir, PROJECT_CONFIG_FILE);
@@ -22,7 +22,7 @@ export async function importDataTestAccountSelectPrompt(parentAccountId) {
22
22
  return promptUser({
23
23
  type: 'list',
24
24
  name: 'selectedAccountId',
25
- message: '[--account] Select a developer test account:',
25
+ message: lib.prompts.importDataTestAccountSelectPrompt.message,
26
26
  choices: childAccounts,
27
27
  });
28
28
  }
package/lib/validation.js CHANGED
@@ -2,11 +2,12 @@ import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { uiLogger } from '../lib/ui/logger.js';
4
4
  import { CMS_PUBLISH_MODE } from '@hubspot/local-dev-lib/constants/files';
5
- import { API_KEY_AUTH_METHOD, OAUTH_AUTH_METHOD, PERSONAL_ACCESS_KEY_AUTH_METHOD, } from '@hubspot/local-dev-lib/constants/auth';
5
+ import { ACCESS_TOKEN_AUTH_METHOD, API_KEY_AUTH_METHOD, OAUTH_AUTH_METHOD, PERSONAL_ACCESS_KEY_AUTH_METHOD, } from '@hubspot/local-dev-lib/constants/auth';
6
6
  import { commaSeparatedValues } from '@hubspot/local-dev-lib/text';
7
7
  import { getConfigFilePath, getConfigAccountById, } from '@hubspot/local-dev-lib/config';
8
8
  import { getOauthManager } from '@hubspot/local-dev-lib/oauth';
9
9
  import { accessTokenForPersonalAccessKey } from '@hubspot/local-dev-lib/personalAccessKey';
10
+ import { accessTokenForInjectedAccessToken } from '@hubspot/local-dev-lib/accessToken';
10
11
  import { getAbsoluteFilePath, getCwd, getExt, } from '@hubspot/local-dev-lib/path';
11
12
  import { ENVIRONMENT_VARIABLES } from '@hubspot/local-dev-lib/constants/config';
12
13
  import { getCmsPublishMode } from './commonOpts.js';
@@ -39,6 +40,7 @@ export async function validateAccount(options) {
39
40
  PERSONAL_ACCESS_KEY_AUTH_METHOD,
40
41
  OAUTH_AUTH_METHOD,
41
42
  API_KEY_AUTH_METHOD,
43
+ ACCESS_TOKEN_AUTH_METHOD,
42
44
  ].map(method => method.value))));
43
45
  }
44
46
  if (authType === 'oauth2') {
@@ -84,6 +86,19 @@ export async function validateAccount(options) {
84
86
  return false;
85
87
  }
86
88
  }
89
+ else if (authType === ACCESS_TOKEN_AUTH_METHOD.value) {
90
+ if (!accountConfig.auth.tokenInfo.accessToken) {
91
+ uiLogger.error(lib.validation.accessTokenMissing(accountId));
92
+ return false;
93
+ }
94
+ try {
95
+ accessTokenForInjectedAccessToken(accountId);
96
+ }
97
+ catch (e) {
98
+ logError(e);
99
+ return false;
100
+ }
101
+ }
87
102
  else if (!accountConfig.apiKey) {
88
103
  uiLogger.error(lib.validation.authConfigurationMissing(accountId));
89
104
  return false;
@@ -4,4 +4,5 @@ import { CommonArgs } from '../../types/Yargs.js';
4
4
  export type WrappedHandlerOptions = {
5
5
  jsonOutputSchema?: z.ZodType;
6
6
  };
7
+ export declare function getJsonOutputSchema(trackingName: string): z.ZodType | undefined;
7
8
  export declare function makeWrappedYargsHandler<T extends CommonArgs>(trackingName: string, handler: (args: ArgumentsCamelCase<T>) => Promise<void>, options?: WrappedHandlerOptions): (args: ArgumentsCamelCase<T>) => Promise<void>;
@@ -14,6 +14,10 @@ import { isPromptExitError } from '../errors/PromptExitError.js';
14
14
  import { debugError } from '../errorHandlers/index.js';
15
15
  import { MAX_LOG_FILES } from '../constants.js';
16
16
  const HANDLER_LOG_DIR = path.join(os.homedir(), '.hscli', 'logs', 'cli');
17
+ const jsonOutputSchemas = new Map();
18
+ export function getJsonOutputSchema(trackingName) {
19
+ return jsonOutputSchemas.get(trackingName);
20
+ }
17
21
  function logUsageTrackingMessage(isJsonOutput) {
18
22
  if (isJsonOutput) {
19
23
  return;
@@ -119,6 +123,9 @@ function createLogFileWriter(trackingName, isJsonOutput) {
119
123
  return { writeLogFile, writeFailureLogFile };
120
124
  }
121
125
  export function makeWrappedYargsHandler(trackingName, handler, options) {
126
+ if (options?.jsonOutputSchema) {
127
+ jsonOutputSchemas.set(trackingName, options.jsonOutputSchema);
128
+ }
122
129
  return async (args) => {
123
130
  const wrappedHandlerArgs = args;
124
131
  const isJsonOutput = Boolean(wrappedHandlerArgs.json || wrappedHandlerArgs.formatOutputAsJson);