@hubspot/local-dev-lib 0.5.0-experimental.10 → 0.5.0-experimental.11
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/index.d.ts +3 -1
- package/config/index.js +30 -12
- package/config/migrate.d.ts +1 -0
- package/config/migrate.js +10 -4
- package/config/utils.d.ts +0 -2
- package/config/utils.js +1 -13
- package/package.json +1 -1
package/config/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { HubSpotConfigAccount } from '../types/Accounts';
|
|
|
2
2
|
import { HubSpotConfig, ConfigFlag } from '../types/Config';
|
|
3
3
|
import { CmsPublishMode } from '../types/Files';
|
|
4
4
|
import { Environment } from '../types/Config';
|
|
5
|
+
export declare function getGlobalConfigFilePath(): string;
|
|
6
|
+
export declare function getLocalConfigFilePathIfExists(): string | null;
|
|
5
7
|
export declare function localConfigFileExists(): boolean;
|
|
6
8
|
export declare function globalConfigFileExists(): boolean;
|
|
7
9
|
export declare function configFileExists(): boolean;
|
|
@@ -9,7 +11,7 @@ export declare function getConfigFilePath(): string;
|
|
|
9
11
|
export declare function getConfig(): HubSpotConfig;
|
|
10
12
|
export declare function isConfigValid(): boolean;
|
|
11
13
|
export declare function createEmptyConfigFile(useGlobalConfig?: boolean): void;
|
|
12
|
-
export declare function
|
|
14
|
+
export declare function deleteConfigFileIfEmpty(): void;
|
|
13
15
|
export declare function getConfigAccountById(accountId: number): HubSpotConfigAccount;
|
|
14
16
|
export declare function getConfigAccountByName(accountName: string): HubSpotConfigAccount;
|
|
15
17
|
export declare function getConfigAccountIfExists(identifier: number | string): HubSpotConfigAccount | undefined;
|
package/config/index.js
CHANGED
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.removeLocalStateFlag = exports.addLocalStateFlag = exports.hasLocalStateFlag = exports.isConfigFlagEnabled = exports.updateDefaultCmsPublishMode = exports.updateAutoOpenBrowser = exports.updateAllowAutoUpdates = exports.updateAllowUsageTracking = exports.updateHttpTimeout = exports.removeAccountFromConfig = exports.renameConfigAccount = exports.setConfigAccountAsDefault = exports.updateConfigAccount = exports.addConfigAccount = exports.getConfigAccountEnvironment = exports.getAllConfigAccounts = exports.getConfigDefaultAccountIfExists = exports.getConfigDefaultAccount = exports.getConfigAccountIfExists = exports.getConfigAccountByName = exports.getConfigAccountById = exports.
|
|
6
|
+
exports.removeLocalStateFlag = exports.addLocalStateFlag = exports.hasLocalStateFlag = exports.isConfigFlagEnabled = exports.updateDefaultCmsPublishMode = exports.updateAutoOpenBrowser = exports.updateAllowAutoUpdates = exports.updateAllowUsageTracking = exports.updateHttpTimeout = exports.removeAccountFromConfig = exports.renameConfigAccount = exports.setConfigAccountAsDefault = exports.updateConfigAccount = exports.addConfigAccount = exports.getConfigAccountEnvironment = exports.getAllConfigAccounts = exports.getConfigDefaultAccountIfExists = exports.getConfigDefaultAccount = exports.getConfigAccountIfExists = exports.getConfigAccountByName = exports.getConfigAccountById = exports.deleteConfigFileIfEmpty = exports.createEmptyConfigFile = exports.isConfigValid = exports.getConfig = exports.getConfigFilePath = exports.configFileExists = exports.globalConfigFileExists = exports.localConfigFileExists = exports.getLocalConfigFilePathIfExists = exports.getGlobalConfigFilePath = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
8
9
|
const config_1 = require("../constants/config");
|
|
9
10
|
const logger_1 = require("../lib/logger");
|
|
10
11
|
const utils_1 = require("./utils");
|
|
@@ -14,12 +15,26 @@ const defaultAccountOverride_1 = require("./defaultAccountOverride");
|
|
|
14
15
|
const environment_1 = require("../lib/environment");
|
|
15
16
|
const HubSpotConfigError_1 = require("../models/HubSpotConfigError");
|
|
16
17
|
const config_2 = require("../constants/config");
|
|
18
|
+
const isDeepEqual_1 = require("../lib/isDeepEqual");
|
|
19
|
+
const path_1 = require("../lib/path");
|
|
20
|
+
const EMPTY_CONFIG = { accounts: [] };
|
|
21
|
+
function getGlobalConfigFilePath() {
|
|
22
|
+
return config_1.GLOBAL_CONFIG_PATH;
|
|
23
|
+
}
|
|
24
|
+
exports.getGlobalConfigFilePath = getGlobalConfigFilePath;
|
|
25
|
+
function getLocalConfigFilePathIfExists() {
|
|
26
|
+
return (0, findup_sync_1.default)([
|
|
27
|
+
config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
28
|
+
config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME.replace('.yml', '.yaml'),
|
|
29
|
+
], { cwd: (0, path_1.getCwd)() });
|
|
30
|
+
}
|
|
31
|
+
exports.getLocalConfigFilePathIfExists = getLocalConfigFilePathIfExists;
|
|
17
32
|
function localConfigFileExists() {
|
|
18
|
-
return Boolean((
|
|
33
|
+
return Boolean(getLocalConfigFilePathIfExists());
|
|
19
34
|
}
|
|
20
35
|
exports.localConfigFileExists = localConfigFileExists;
|
|
21
36
|
function globalConfigFileExists() {
|
|
22
|
-
return (0, utils_1.doesConfigFileExistAtPath)(
|
|
37
|
+
return (0, utils_1.doesConfigFileExistAtPath)(getGlobalConfigFilePath());
|
|
23
38
|
}
|
|
24
39
|
exports.globalConfigFileExists = globalConfigFileExists;
|
|
25
40
|
function configFileExists() {
|
|
@@ -32,11 +47,11 @@ function configFileExists() {
|
|
|
32
47
|
}
|
|
33
48
|
exports.configFileExists = configFileExists;
|
|
34
49
|
function getConfigDefaultFilePath() {
|
|
35
|
-
const globalConfigFilePath =
|
|
50
|
+
const globalConfigFilePath = getGlobalConfigFilePath();
|
|
36
51
|
if ((0, utils_1.doesConfigFileExistAtPath)(globalConfigFilePath)) {
|
|
37
52
|
return globalConfigFilePath;
|
|
38
53
|
}
|
|
39
|
-
const localConfigFilePath = (
|
|
54
|
+
const localConfigFilePath = getLocalConfigFilePathIfExists();
|
|
40
55
|
if (!localConfigFilePath) {
|
|
41
56
|
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getDefaultConfigFilePath.error'), config_2.HUBSPOT_CONFIG_ERROR_TYPES.CONFIG_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
42
57
|
}
|
|
@@ -107,16 +122,19 @@ exports.isConfigValid = isConfigValid;
|
|
|
107
122
|
function createEmptyConfigFile(useGlobalConfig = false) {
|
|
108
123
|
const { configFilePathFromEnvironment } = (0, utils_1.getConfigPathEnvironmentVariables)();
|
|
109
124
|
const defaultPath = useGlobalConfig
|
|
110
|
-
?
|
|
125
|
+
? getGlobalConfigFilePath()
|
|
111
126
|
: (0, utils_1.getLocalConfigDefaultFilePath)();
|
|
112
127
|
const pathToWrite = configFilePathFromEnvironment || defaultPath;
|
|
113
|
-
(0, utils_1.writeConfigFile)(
|
|
128
|
+
(0, utils_1.writeConfigFile)(EMPTY_CONFIG, pathToWrite);
|
|
114
129
|
}
|
|
115
130
|
exports.createEmptyConfigFile = createEmptyConfigFile;
|
|
116
|
-
function
|
|
131
|
+
function deleteConfigFileIfEmpty() {
|
|
117
132
|
const pathToDelete = getConfigFilePath();
|
|
118
133
|
try {
|
|
119
|
-
|
|
134
|
+
const config = getConfig();
|
|
135
|
+
if ((0, isDeepEqual_1.isDeepEqual)(config, EMPTY_CONFIG)) {
|
|
136
|
+
fs_extra_1.default.unlinkSync(pathToDelete);
|
|
137
|
+
}
|
|
120
138
|
}
|
|
121
139
|
catch (error) {
|
|
122
140
|
const { message, type } = (0, utils_1.handleConfigFileSystemError)(error, pathToDelete);
|
|
@@ -125,7 +143,7 @@ function deleteConfigFile() {
|
|
|
125
143
|
});
|
|
126
144
|
}
|
|
127
145
|
}
|
|
128
|
-
exports.
|
|
146
|
+
exports.deleteConfigFileIfEmpty = deleteConfigFileIfEmpty;
|
|
129
147
|
function getConfigAccountById(accountId) {
|
|
130
148
|
const { accounts } = getConfig();
|
|
131
149
|
const account = (0, utils_1.getConfigAccountByIdentifier)(accounts, config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountId);
|
|
@@ -153,7 +171,7 @@ function getConfigDefaultAccount() {
|
|
|
153
171
|
const { accounts, defaultAccount } = getConfig();
|
|
154
172
|
let defaultAccountToUse = defaultAccount;
|
|
155
173
|
const currentConfigPath = getConfigFilePath();
|
|
156
|
-
const globalConfigPath =
|
|
174
|
+
const globalConfigPath = getGlobalConfigFilePath();
|
|
157
175
|
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
158
176
|
const defaultAccountOverrideAccountId = (0, defaultAccountOverride_1.getDefaultAccountOverrideAccountId)();
|
|
159
177
|
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
@@ -175,7 +193,7 @@ function getConfigDefaultAccountIfExists() {
|
|
|
175
193
|
let defaultAccountToUse = defaultAccount;
|
|
176
194
|
// Only check for default account override if we're using the global config
|
|
177
195
|
const currentConfigPath = getConfigFilePath();
|
|
178
|
-
const globalConfigPath =
|
|
196
|
+
const globalConfigPath = getGlobalConfigFilePath();
|
|
179
197
|
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
180
198
|
const defaultAccountOverrideAccountId = (0, defaultAccountOverride_1.getDefaultAccountOverrideAccountId)();
|
|
181
199
|
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
package/config/migrate.d.ts
CHANGED
package/config/migrate.js
CHANGED
|
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.mergeConfigAccounts = exports.mergeConfigProperties = exports.migrateConfigAtPath = exports.getConfigAtPath = void 0;
|
|
6
|
+
exports.archiveConfigAtPath = exports.mergeConfigAccounts = exports.mergeConfigProperties = exports.migrateConfigAtPath = exports.getConfigAtPath = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const index_1 = require("./index");
|
|
9
9
|
const config_1 = require("../constants/config");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
11
12
|
function getConfigAtPath(path) {
|
|
12
13
|
const configFileSource = (0, utils_1.readConfigFile)(path);
|
|
13
14
|
return (0, utils_1.parseConfig)(configFileSource, path);
|
|
@@ -16,8 +17,7 @@ exports.getConfigAtPath = getConfigAtPath;
|
|
|
16
17
|
function migrateConfigAtPath(path) {
|
|
17
18
|
(0, index_1.createEmptyConfigFile)(true);
|
|
18
19
|
const configToMigrate = getConfigAtPath(path);
|
|
19
|
-
(0, utils_1.writeConfigFile)(configToMigrate, (0,
|
|
20
|
-
fs_1.default.unlinkSync(path);
|
|
20
|
+
(0, utils_1.writeConfigFile)(configToMigrate, (0, index_1.getGlobalConfigFilePath)());
|
|
21
21
|
}
|
|
22
22
|
exports.migrateConfigAtPath = migrateConfigAtPath;
|
|
23
23
|
function mergeConfigProperties(toConfig, fromConfig, force) {
|
|
@@ -98,7 +98,13 @@ function buildConfigWithMergedAccounts(toConfig, fromConfig) {
|
|
|
98
98
|
}
|
|
99
99
|
function mergeConfigAccounts(toConfig, fromConfig) {
|
|
100
100
|
const { configWithMergedAccounts, skippedAccountIds } = buildConfigWithMergedAccounts(toConfig, fromConfig);
|
|
101
|
-
(0, utils_1.writeConfigFile)(configWithMergedAccounts, (0,
|
|
101
|
+
(0, utils_1.writeConfigFile)(configWithMergedAccounts, (0, index_1.getGlobalConfigFilePath)());
|
|
102
102
|
return { configWithMergedAccounts, skippedAccountIds };
|
|
103
103
|
}
|
|
104
104
|
exports.mergeConfigAccounts = mergeConfigAccounts;
|
|
105
|
+
function archiveConfigAtPath(configPath) {
|
|
106
|
+
const dir = path_1.default.dirname(configPath);
|
|
107
|
+
const archivedConfigPath = path_1.default.join(dir, config_1.ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME);
|
|
108
|
+
fs_1.default.renameSync(configPath, archivedConfigPath);
|
|
109
|
+
}
|
|
110
|
+
exports.archiveConfigAtPath = archiveConfigAtPath;
|
package/config/utils.d.ts
CHANGED
|
@@ -2,8 +2,6 @@ import { ACCOUNT_IDENTIFIERS } from '../constants/config';
|
|
|
2
2
|
import { HubSpotConfig, DeprecatedHubSpotConfigFields, HubSpotConfigErrorType } from '../types/Config';
|
|
3
3
|
import { HubSpotConfigAccount, AccountType, TokenInfo } from '../types/Accounts';
|
|
4
4
|
import { ValueOf } from '../types/Utils';
|
|
5
|
-
export declare function getGlobalConfigFilePath(): string;
|
|
6
|
-
export declare function getLocalConfigFilePath(): string | null;
|
|
7
5
|
export declare function getLocalConfigDefaultFilePath(): string;
|
|
8
6
|
export declare function getConfigPathEnvironmentVariables(): {
|
|
9
7
|
useEnvironmentConfig: boolean;
|
package/config/utils.js
CHANGED
|
@@ -3,10 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.handleConfigFileSystemError = exports.isConfigAccountValid = exports.getConfigAccountIndexById = exports.getConfigAccountByInferredIdentifier = exports.getConfigAccountByIdentifier = exports.getAccountIdentifierAndType = exports.buildConfigFromEnvironment = exports.parseConfig = exports.normalizeParsedConfig = exports.writeConfigFile = exports.formatConfigForWrite = exports.removeUndefinedFieldsFromConfigAccount = exports.readConfigFile = exports.doesConfigFileExistAtPath = exports.getConfigPathEnvironmentVariables = exports.getLocalConfigDefaultFilePath =
|
|
6
|
+
exports.handleConfigFileSystemError = exports.isConfigAccountValid = exports.getConfigAccountIndexById = exports.getConfigAccountByInferredIdentifier = exports.getConfigAccountByIdentifier = exports.getAccountIdentifierAndType = exports.buildConfigFromEnvironment = exports.parseConfig = exports.normalizeParsedConfig = exports.writeConfigFile = exports.formatConfigForWrite = exports.removeUndefinedFieldsFromConfigAccount = exports.readConfigFile = exports.doesConfigFileExistAtPath = exports.getConfigPathEnvironmentVariables = exports.getLocalConfigDefaultFilePath = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
9
|
-
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
10
9
|
const config_1 = require("../constants/config");
|
|
11
10
|
const auth_1 = require("../constants/auth");
|
|
12
11
|
const FileSystemError_1 = require("../models/FileSystemError");
|
|
@@ -16,17 +15,6 @@ const path_1 = require("../lib/path");
|
|
|
16
15
|
const files_1 = require("../constants/files");
|
|
17
16
|
const lang_1 = require("../utils/lang");
|
|
18
17
|
const HubSpotConfigError_1 = require("../models/HubSpotConfigError");
|
|
19
|
-
function getGlobalConfigFilePath() {
|
|
20
|
-
return config_1.GLOBAL_CONFIG_PATH;
|
|
21
|
-
}
|
|
22
|
-
exports.getGlobalConfigFilePath = getGlobalConfigFilePath;
|
|
23
|
-
function getLocalConfigFilePath() {
|
|
24
|
-
return (0, findup_sync_1.default)([
|
|
25
|
-
config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
26
|
-
config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME.replace('.yml', '.yaml'),
|
|
27
|
-
], { cwd: (0, path_1.getCwd)() });
|
|
28
|
-
}
|
|
29
|
-
exports.getLocalConfigFilePath = getLocalConfigFilePath;
|
|
30
18
|
function getLocalConfigDefaultFilePath() {
|
|
31
19
|
return `${(0, path_1.getCwd)()}/${config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}`;
|
|
32
20
|
}
|
package/package.json
CHANGED