@hubspot/local-dev-lib 5.3.3-beta.0 → 5.4.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/config/defaultAccountOverride.d.ts +1 -0
- package/config/defaultAccountOverride.js +15 -0
- package/config/hsSettings.d.ts +4 -0
- package/config/hsSettings.js +55 -0
- package/config/index.d.ts +1 -0
- package/config/index.js +31 -11
- package/constants/config.d.ts +8 -0
- package/constants/config.js +8 -0
- package/lib/gitignore.d.ts +1 -0
- package/lib/gitignore.js +22 -1
- package/package.json +2 -1
- package/types/HsSettings.d.ts +4 -0
- package/types/HsSettings.js +1 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { HubSpotConfigAccount } from '../types/Accounts.js';
|
|
2
2
|
export declare function getDefaultAccountOverrideAccountId(accounts: Array<HubSpotConfigAccount>): number | null;
|
|
3
|
+
export declare function removeDefaultAccountOverrideFile(): void;
|
|
3
4
|
export declare function getDefaultAccountOverrideFilePath(): string | null;
|
|
@@ -40,6 +40,21 @@ export function getDefaultAccountOverrideAccountId(accounts) {
|
|
|
40
40
|
}
|
|
41
41
|
return account.accountId;
|
|
42
42
|
}
|
|
43
|
+
export function removeDefaultAccountOverrideFile() {
|
|
44
|
+
const filePath = getDefaultAccountOverrideFilePath();
|
|
45
|
+
if (!filePath) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
fs.unlinkSync(filePath);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
throw new FileSystemError({ cause: e }, {
|
|
53
|
+
filepath: filePath,
|
|
54
|
+
operation: 'write',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
43
58
|
export function getDefaultAccountOverrideFilePath() {
|
|
44
59
|
return findup([DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME], {
|
|
45
60
|
cwd: getCwd(),
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { HsSettingsFile } from '../types/HsSettings.js';
|
|
2
|
+
export declare function getHsSettingsFilePath(): string | null;
|
|
3
|
+
export declare function getHsSettingsFileIfExists(): HsSettingsFile | null;
|
|
4
|
+
export declare function writeHsSettingsFile(settingsFile: HsSettingsFile): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import findupSync from 'findup-sync';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { HS_FOLDER, HS_README_FILENAME, HS_SETTINGS_FILENAME, } from '../constants/config.js';
|
|
5
|
+
import { getCwd } from '../lib/path.js';
|
|
6
|
+
import { FileSystemError } from '../models/FileSystemError.js';
|
|
7
|
+
const HS_README_CONTENTS = `Why do I have a folder named ".hs" in my project?
|
|
8
|
+
The ".hs" folder is created when you link a directory to a HubSpot project.
|
|
9
|
+
|
|
10
|
+
What does the "settings.json" file contain?
|
|
11
|
+
The "settings.json" file contains:
|
|
12
|
+
- The ID(s) of the HubSpot account(s) that you linked ("accounts")
|
|
13
|
+
- The ID of the HubSpot account that you set as the default for this directory ("linkedDefaultAccount")
|
|
14
|
+
|
|
15
|
+
Should I commit the ".hs" folder?
|
|
16
|
+
No, the ".hs" folder should not be committed to version control. It is automatically added to your .gitignore file when the directory is linked.
|
|
17
|
+
`;
|
|
18
|
+
export function getHsSettingsFilePath() {
|
|
19
|
+
return findupSync([`${HS_FOLDER}/${HS_SETTINGS_FILENAME}`], {
|
|
20
|
+
cwd: getCwd(),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function getHsSettingsFileIfExists() {
|
|
24
|
+
const hsSettingsFilePath = getHsSettingsFilePath();
|
|
25
|
+
if (!hsSettingsFilePath) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(fs.readFileSync(hsSettingsFilePath, 'utf-8'));
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
throw new FileSystemError({ cause: e }, {
|
|
33
|
+
filepath: hsSettingsFilePath,
|
|
34
|
+
operation: 'read',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function writeHsSettingsFile(settingsFile) {
|
|
39
|
+
const dir = getCwd();
|
|
40
|
+
const hsFolderPath = path.join(dir, HS_FOLDER);
|
|
41
|
+
const isFirstScaffold = !fs.existsSync(hsFolderPath);
|
|
42
|
+
try {
|
|
43
|
+
fs.mkdirSync(hsFolderPath, { recursive: true });
|
|
44
|
+
fs.writeFileSync(path.join(dir, HS_FOLDER, HS_SETTINGS_FILENAME), JSON.stringify(settingsFile, null, 2), 'utf8');
|
|
45
|
+
if (isFirstScaffold) {
|
|
46
|
+
fs.writeFileSync(path.join(hsFolderPath, HS_README_FILENAME), HS_README_CONTENTS, 'utf8');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
throw new FileSystemError({ cause: err }, {
|
|
51
|
+
filepath: dir,
|
|
52
|
+
operation: 'write',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
package/config/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare function getConfigAccountIfExists(identifier: number | string): H
|
|
|
18
18
|
export declare function getConfigDefaultAccount(): HubSpotConfigAccount;
|
|
19
19
|
export declare function getConfigDefaultAccountIfExists(): HubSpotConfigAccount | undefined;
|
|
20
20
|
export declare function getAllConfigAccounts(): HubSpotConfigAccount[];
|
|
21
|
+
export declare function getLinkedOrAllConfigAccounts(): HubSpotConfigAccount[];
|
|
21
22
|
export declare function getConfigAccountEnvironment(identifier: number | string): Environment;
|
|
22
23
|
export declare function addConfigAccount(accountToAdd: HubSpotConfigAccount): void;
|
|
23
24
|
export declare function updateConfigAccount(updatedAccount: HubSpotConfigAccount): void;
|
package/config/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { HubSpotConfigError } from '../models/HubSpotConfigError.js';
|
|
|
11
11
|
import { HUBSPOT_CONFIG_ERROR_TYPES } from '../constants/config.js';
|
|
12
12
|
import { isDeepEqual } from '../lib/isDeepEqual.js';
|
|
13
13
|
import { getCwd } from '../lib/path.js';
|
|
14
|
+
import { getHsSettingsFileIfExists } from './hsSettings.js';
|
|
14
15
|
const EMPTY_CONFIG = { accounts: [] };
|
|
15
16
|
export function getGlobalConfigFilePath() {
|
|
16
17
|
return GLOBAL_CONFIG_PATH;
|
|
@@ -152,11 +153,17 @@ export function getConfigAccountIfExists(identifier) {
|
|
|
152
153
|
export function getConfigDefaultAccount() {
|
|
153
154
|
const { accounts, defaultAccount } = getConfig();
|
|
154
155
|
let defaultAccountToUse = defaultAccount;
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
const hsSettingsFile = getHsSettingsFileIfExists();
|
|
157
|
+
if (hsSettingsFile && hsSettingsFile.localDefaultAccount) {
|
|
158
|
+
defaultAccountToUse = hsSettingsFile.localDefaultAccount;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
const currentConfigPath = getConfigFilePath();
|
|
162
|
+
const globalConfigPath = getGlobalConfigFilePath();
|
|
163
|
+
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
164
|
+
const defaultAccountOverrideAccountId = getDefaultAccountOverrideAccountId(accounts);
|
|
165
|
+
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
166
|
+
}
|
|
160
167
|
}
|
|
161
168
|
if (!defaultAccountToUse) {
|
|
162
169
|
throw new HubSpotConfigError(i18n('config.getConfigDefaultAccount.fieldMissingError'), HUBSPOT_CONFIG_ERROR_TYPES.NO_DEFAULT_ACCOUNT, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
@@ -172,12 +179,17 @@ export function getConfigDefaultAccount() {
|
|
|
172
179
|
export function getConfigDefaultAccountIfExists() {
|
|
173
180
|
const { accounts, defaultAccount } = getConfig();
|
|
174
181
|
let defaultAccountToUse = defaultAccount;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
const hsSettingsFile = getHsSettingsFileIfExists();
|
|
183
|
+
if (hsSettingsFile && hsSettingsFile.localDefaultAccount) {
|
|
184
|
+
defaultAccountToUse = hsSettingsFile.localDefaultAccount;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
const currentConfigPath = getConfigFilePath();
|
|
188
|
+
const globalConfigPath = getGlobalConfigFilePath();
|
|
189
|
+
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
190
|
+
const defaultAccountOverrideAccountId = getDefaultAccountOverrideAccountId(accounts);
|
|
191
|
+
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
192
|
+
}
|
|
181
193
|
}
|
|
182
194
|
if (!defaultAccountToUse) {
|
|
183
195
|
return;
|
|
@@ -189,6 +201,14 @@ export function getAllConfigAccounts() {
|
|
|
189
201
|
const { accounts } = getConfig();
|
|
190
202
|
return accounts;
|
|
191
203
|
}
|
|
204
|
+
export function getLinkedOrAllConfigAccounts() {
|
|
205
|
+
const { accounts } = getConfig();
|
|
206
|
+
const hsSettingsFile = getHsSettingsFileIfExists();
|
|
207
|
+
if (!hsSettingsFile || hsSettingsFile.accounts.length === 0) {
|
|
208
|
+
return accounts;
|
|
209
|
+
}
|
|
210
|
+
return accounts.filter(a => hsSettingsFile.accounts.includes(a.accountId));
|
|
211
|
+
}
|
|
192
212
|
export function getConfigAccountEnvironment(identifier) {
|
|
193
213
|
const config = getConfig();
|
|
194
214
|
const account = getConfigAccountByInferredIdentifier(config.accounts, identifier);
|
package/constants/config.d.ts
CHANGED
|
@@ -103,3 +103,11 @@ export declare const HUBSPOT_CONFIG_OPERATIONS: {
|
|
|
103
103
|
readonly WRITE: "WRITE";
|
|
104
104
|
readonly DELETE: "DELETE";
|
|
105
105
|
};
|
|
106
|
+
export declare const HS_FOLDER = ".hs";
|
|
107
|
+
export declare const HS_SETTINGS_FILENAME = "settings.json";
|
|
108
|
+
export declare const HS_README_FILENAME = "README.txt";
|
|
109
|
+
export declare const DEFAULT_HS_SETTINGS_PATH = ".hs/settings.json";
|
|
110
|
+
export declare const EMPTY_HS_SETTINGS_FILE: {
|
|
111
|
+
localDefaultAccount: undefined;
|
|
112
|
+
accounts: never[];
|
|
113
|
+
};
|
package/constants/config.js
CHANGED
|
@@ -106,3 +106,11 @@ export const HUBSPOT_CONFIG_OPERATIONS = {
|
|
|
106
106
|
WRITE: 'WRITE',
|
|
107
107
|
DELETE: 'DELETE',
|
|
108
108
|
};
|
|
109
|
+
export const HS_FOLDER = '.hs';
|
|
110
|
+
export const HS_SETTINGS_FILENAME = 'settings.json';
|
|
111
|
+
export const HS_README_FILENAME = 'README.txt';
|
|
112
|
+
export const DEFAULT_HS_SETTINGS_PATH = `${HS_FOLDER}/${HS_SETTINGS_FILENAME}`;
|
|
113
|
+
export const EMPTY_HS_SETTINGS_FILE = {
|
|
114
|
+
localDefaultAccount: undefined,
|
|
115
|
+
accounts: [],
|
|
116
|
+
};
|
package/lib/gitignore.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { GitInclusionResult } from '../types/Config.js';
|
|
2
2
|
export declare function checkAndAddConfigToGitignore(configPath: string): void;
|
|
3
|
+
export declare function checkAndAddHsFolderToGitignore(settingsPath: string): void;
|
|
3
4
|
export declare function checkGitInclusion(configPath: string): GitInclusionResult;
|
package/lib/gitignore.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { isConfigPathInGitRepo, getGitignoreFiles, configFilenameIsIgnoredByGitignore, } from '../utils/git.js';
|
|
4
|
-
import { DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME } from '../constants/config.js';
|
|
4
|
+
import { DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME, HS_FOLDER, } from '../constants/config.js';
|
|
5
5
|
import { i18n } from '../utils/lang.js';
|
|
6
6
|
const i18nKey = 'lib.gitignore';
|
|
7
7
|
const GITIGNORE_FILE = '.gitignore';
|
|
@@ -23,6 +23,27 @@ export function checkAndAddConfigToGitignore(configPath) {
|
|
|
23
23
|
throw new Error(i18n(`${i18nKey}.errors.configIgnore`), { cause: e });
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
export function checkAndAddHsFolderToGitignore(settingsPath) {
|
|
27
|
+
try {
|
|
28
|
+
const hsDirPath = path.resolve(path.dirname(settingsPath));
|
|
29
|
+
const { configIgnored, gitignoreFiles } = checkGitInclusion(hsDirPath);
|
|
30
|
+
if (configIgnored)
|
|
31
|
+
return;
|
|
32
|
+
let gitignoreFilePath = gitignoreFiles && gitignoreFiles.length ? gitignoreFiles[0] : null;
|
|
33
|
+
if (!gitignoreFilePath) {
|
|
34
|
+
gitignoreFilePath = path.join(path.dirname(hsDirPath), GITIGNORE_FILE);
|
|
35
|
+
fs.writeFileSync(gitignoreFilePath, '');
|
|
36
|
+
}
|
|
37
|
+
const gitignoreContents = fs.readFileSync(gitignoreFilePath).toString();
|
|
38
|
+
if (gitignoreContents.includes(HS_FOLDER))
|
|
39
|
+
return;
|
|
40
|
+
const updatedContents = `${gitignoreContents.trim()}\n\n# HubSpot link folder\n${HS_FOLDER}\n`;
|
|
41
|
+
fs.writeFileSync(gitignoreFilePath, updatedContents);
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
throw new Error(i18n(`${i18nKey}.errors.configIgnore`), { cause: e });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
26
47
|
export function checkGitInclusion(configPath) {
|
|
27
48
|
const result = {
|
|
28
49
|
inGit: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/local-dev-lib",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
|
|
6
6
|
"files": [
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"./config/defaultAccountOverride": "./config/defaultAccountOverride.js",
|
|
60
60
|
"./config/migrate": "./config/migrate.js",
|
|
61
61
|
"./config/state": "./config/state.js",
|
|
62
|
+
"./config/hsSettings": "./config/hsSettings.js",
|
|
62
63
|
"./config": "./config/index.js",
|
|
63
64
|
"./constants/*": "./constants/*.js",
|
|
64
65
|
"./enums/*": "./enums/*.js",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|