@hubspot/local-dev-lib 0.0.2 → 0.0.4
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/CLIConfiguration.d.ts +55 -0
- package/config/CLIConfiguration.js +392 -0
- package/config/configFile.d.ts +21 -0
- package/config/configFile.js +109 -0
- package/config/configUtils.d.ts +24 -0
- package/config/configUtils.js +85 -0
- package/config/environment.d.ts +3 -0
- package/config/environment.js +64 -0
- package/constants/auth.d.ts +24 -0
- package/constants/auth.js +31 -0
- package/constants/config.d.ts +8 -0
- package/constants/config.js +12 -0
- package/constants/environments.d.ts +13 -0
- package/constants/environments.js +16 -0
- package/constants/extensions.d.ts +2 -0
- package/constants/extensions.js +23 -0
- package/constants/files.d.ts +5 -0
- package/constants/files.js +8 -0
- package/constants/github.d.ts +4 -0
- package/constants/github.js +7 -0
- package/constants/index.d.ts +16 -0
- package/constants/index.js +12 -0
- package/errors/HubSpotAuthError.d.ts +3 -0
- package/errors/HubSpotAuthError.js +6 -0
- package/errors/fileSystemErrors.d.ts +8 -0
- package/errors/fileSystemErrors.js +28 -0
- package/errors/standardErrors.d.ts +19 -0
- package/errors/standardErrors.js +67 -0
- package/http/requestOptions.d.ts +20 -0
- package/http/requestOptions.js +27 -0
- package/lib/archive.d.ts +7 -0
- package/lib/archive.js +111 -0
- package/lib/cms/handleFieldsJS.d.ts +32 -0
- package/lib/cms/handleFieldsJS.js +143 -0
- package/lib/cms/index.d.ts +10 -0
- package/lib/cms/index.js +13 -0
- package/lib/cms/modules.d.ts +24 -0
- package/lib/cms/modules.js +124 -0
- package/lib/cms/themes.d.ts +2 -0
- package/lib/cms/themes.js +34 -0
- package/lib/environment.d.ts +1 -0
- package/lib/environment.js +16 -0
- package/lib/fs.d.ts +4 -0
- package/lib/fs.js +71 -0
- package/lib/github.d.ts +17 -0
- package/lib/github.js +133 -0
- package/lib/gitignore.d.ts +1 -0
- package/lib/gitignore.js +76 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +14 -0
- package/lib/path.d.ts +10 -0
- package/lib/path.js +84 -0
- package/lib/text.d.ts +1 -0
- package/lib/text.js +16 -0
- package/lib/urls.d.ts +2 -0
- package/lib/urls.js +20 -0
- package/package.json +8 -11
- package/types/Accounts.d.ts +50 -0
- package/types/Accounts.js +2 -0
- package/types/CLIOptions.d.ts +3 -0
- package/types/CLIOptions.js +2 -0
- package/types/Config.d.ts +10 -0
- package/types/Config.js +2 -0
- package/types/Error.d.ts +31 -0
- package/types/Error.js +2 -0
- package/types/Files.d.ts +8 -0
- package/types/Files.js +2 -0
- package/types/Github.d.ts +58 -0
- package/types/Github.js +2 -0
- package/types/LogCallbacks.d.ts +6 -0
- package/types/LogCallbacks.js +2 -0
- package/types/Modules.d.ts +5 -0
- package/types/Modules.js +2 -0
- package/types/Utils.d.ts +1 -0
- package/types/Utils.js +2 -0
- package/utils/escapeRegExp.d.ts +1 -0
- package/utils/escapeRegExp.js +7 -0
- package/utils/fieldsJS.d.ts +3 -0
- package/utils/fieldsJS.js +18 -0
- package/utils/git.d.ts +4 -0
- package/utils/git.js +40 -0
- package/utils/lang.d.ts +8 -0
- package/utils/lang.js +83 -0
- package/utils/logger.d.ts +10 -0
- package/utils/logger.js +22 -0
- package/utils/modules.d.ts +4 -0
- package/utils/modules.js +53 -0
package/utils/lang.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.i18n = exports.interpolate = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_extra_1 = require("fs-extra");
|
|
6
|
+
const js_yaml_1 = require("js-yaml");
|
|
7
|
+
const MISSING_LANGUAGE_DATA_PREFIX = '[Missing language data]';
|
|
8
|
+
let locale = '';
|
|
9
|
+
let languageObj;
|
|
10
|
+
function loadLanguageFromYaml() {
|
|
11
|
+
if (languageObj)
|
|
12
|
+
return;
|
|
13
|
+
try {
|
|
14
|
+
const nodeLocale = Intl.DateTimeFormat()
|
|
15
|
+
.resolvedOptions()
|
|
16
|
+
.locale.split('-')[0];
|
|
17
|
+
const languageFilePath = (0, path_1.join)(__dirname, `../lang/${nodeLocale}.lyaml`);
|
|
18
|
+
const languageFileExists = (0, fs_extra_1.existsSync)(languageFilePath);
|
|
19
|
+
// Fall back to using the default language file
|
|
20
|
+
locale = languageFileExists ? nodeLocale : 'en';
|
|
21
|
+
languageObj = (0, js_yaml_1.load)((0, fs_extra_1.readFileSync)((0, path_1.join)(__dirname, `../lang/${locale}.lyaml`), 'utf8'));
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
throw new Error(`Error loading language data: ${e}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function getTextValue(lookupDotNotation) {
|
|
28
|
+
const lookupProps = [locale, ...lookupDotNotation.split('.')];
|
|
29
|
+
const missingTextData = `${MISSING_LANGUAGE_DATA_PREFIX}: ${lookupProps.join('.')}`;
|
|
30
|
+
let textValue = languageObj;
|
|
31
|
+
let previouslyCheckedProp = lookupProps[0];
|
|
32
|
+
lookupProps.forEach(prop => {
|
|
33
|
+
previouslyCheckedProp = prop;
|
|
34
|
+
if (typeof textValue === 'object') {
|
|
35
|
+
textValue = textValue[prop];
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.debug(`Unable to access language property: ${lookupProps.join('.')}. Failed to access prop "${previouslyCheckedProp}".`);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (typeof textValue !== 'string') {
|
|
42
|
+
return missingTextData;
|
|
43
|
+
}
|
|
44
|
+
return textValue;
|
|
45
|
+
}
|
|
46
|
+
const delimiters = {
|
|
47
|
+
interpolation: {
|
|
48
|
+
start: '{{',
|
|
49
|
+
end: '}}',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
function generateReplaceFn(matchedText, startIndex, replacementString) {
|
|
53
|
+
return function (currentStringValue) {
|
|
54
|
+
return `${currentStringValue.slice(0, startIndex)}${replacementString || ''}${currentStringValue.slice(startIndex + matchedText.length)}`;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function interpolate(stringValue, interpolationData) {
|
|
58
|
+
const interpolationIdentifierRegEx = new RegExp(`${delimiters.interpolation.start}(.*?)${delimiters.interpolation.end}`, 'g');
|
|
59
|
+
const replaceQueue = [];
|
|
60
|
+
let match;
|
|
61
|
+
// while & reduce necessary because RegExp.exec is stateful and only runs
|
|
62
|
+
// from beginning to end of string
|
|
63
|
+
while ((match = interpolationIdentifierRegEx.exec(stringValue)) != null) {
|
|
64
|
+
const { 0: matchedText, 1: rawIdentifier, index } = match;
|
|
65
|
+
const identifier = rawIdentifier.trim();
|
|
66
|
+
if (identifier) {
|
|
67
|
+
replaceQueue.unshift(generateReplaceFn(matchedText, index, interpolationData[identifier]));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const compiledString = replaceQueue.reduce((currentValue, replaceFn) => replaceFn(currentValue), stringValue);
|
|
71
|
+
return compiledString;
|
|
72
|
+
}
|
|
73
|
+
exports.interpolate = interpolate;
|
|
74
|
+
function i18n(lookupDotNotation, options = {}) {
|
|
75
|
+
if (typeof lookupDotNotation !== 'string') {
|
|
76
|
+
throw new Error(`i18n must be passed a string value for lookupDotNotation, received ${typeof lookupDotNotation}`);
|
|
77
|
+
}
|
|
78
|
+
const textValue = getTextValue(lookupDotNotation);
|
|
79
|
+
const shouldInterpolate = !textValue.startsWith(MISSING_LANGUAGE_DATA_PREFIX);
|
|
80
|
+
return shouldInterpolate ? interpolate(textValue, options) : textValue;
|
|
81
|
+
}
|
|
82
|
+
exports.i18n = i18n;
|
|
83
|
+
loadLanguageFromYaml();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogCallbacks } from '../types/LogCallbacks';
|
|
2
|
+
export declare function log<T extends string>(key: T, callbacks?: LogCallbacks<T>, debugKey?: string, debugInterpolation?: {
|
|
3
|
+
[key: string]: string | number;
|
|
4
|
+
}): void;
|
|
5
|
+
export declare function makeTypedLogger<T extends readonly string[]>(callbacks?: LogCallbacks<T[number]>, debugKey?: string): (key: T[number], debugInterpolation?: {
|
|
6
|
+
[key: string]: string | number;
|
|
7
|
+
} | undefined) => void;
|
|
8
|
+
export declare function debug(identifier: string, interpolation?: {
|
|
9
|
+
[key: string]: string | number;
|
|
10
|
+
}): void;
|
package/utils/logger.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debug = exports.makeTypedLogger = exports.log = void 0;
|
|
4
|
+
const lang_1 = require("./lang");
|
|
5
|
+
function log(key, callbacks, debugKey, debugInterpolation) {
|
|
6
|
+
if (callbacks && callbacks[key]) {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
8
|
+
callbacks[key]();
|
|
9
|
+
}
|
|
10
|
+
else if (debugKey) {
|
|
11
|
+
debug(debugKey, debugInterpolation);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.log = log;
|
|
15
|
+
function makeTypedLogger(callbacks, debugKey) {
|
|
16
|
+
return (key, debugInterpolation) => log(key, callbacks, `${debugKey}.${key}`, debugInterpolation);
|
|
17
|
+
}
|
|
18
|
+
exports.makeTypedLogger = makeTypedLogger;
|
|
19
|
+
function debug(identifier, interpolation) {
|
|
20
|
+
console.debug((0, lang_1.i18n)(`debug.${identifier}`, interpolation));
|
|
21
|
+
}
|
|
22
|
+
exports.debug = debug;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PathInput } from '../types/Modules';
|
|
2
|
+
export declare function isPathInput(pathInput?: PathInput): boolean;
|
|
3
|
+
export declare function isModuleFolder(pathInput: PathInput): boolean;
|
|
4
|
+
export declare function isModuleFolderChild(pathInput: PathInput, ignoreLocales?: boolean): boolean;
|
package/utils/modules.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isModuleFolderChild = exports.isModuleFolder = exports.isPathInput = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const path_2 = require("../lib/path");
|
|
9
|
+
const extensions_1 = require("../constants/extensions");
|
|
10
|
+
const standardErrors_1 = require("../errors/standardErrors");
|
|
11
|
+
const isBool = (x) => !!x === x;
|
|
12
|
+
function isPathInput(pathInput) {
|
|
13
|
+
return !!(pathInput &&
|
|
14
|
+
typeof pathInput.path === 'string' &&
|
|
15
|
+
(isBool(pathInput.isLocal) || isBool(pathInput.isHubSpot)));
|
|
16
|
+
}
|
|
17
|
+
exports.isPathInput = isPathInput;
|
|
18
|
+
function throwInvalidPathInput(pathInput) {
|
|
19
|
+
if (isPathInput(pathInput))
|
|
20
|
+
return;
|
|
21
|
+
(0, standardErrors_1.throwTypeErrorWithMessage)('modules.throwInvalidPathInput');
|
|
22
|
+
}
|
|
23
|
+
function isModuleFolder(pathInput) {
|
|
24
|
+
throwInvalidPathInput(pathInput);
|
|
25
|
+
const _path = pathInput.isHubSpot
|
|
26
|
+
? path_1.default.posix.normalize(pathInput.path)
|
|
27
|
+
: path_1.default.normalize(pathInput.path);
|
|
28
|
+
return (0, path_2.getExt)(_path) === extensions_1.MODULE_EXTENSION;
|
|
29
|
+
}
|
|
30
|
+
exports.isModuleFolder = isModuleFolder;
|
|
31
|
+
function isModuleFolderChild(pathInput, ignoreLocales = false) {
|
|
32
|
+
throwInvalidPathInput(pathInput);
|
|
33
|
+
let pathParts = [];
|
|
34
|
+
if (pathInput.isLocal) {
|
|
35
|
+
pathParts = (0, path_2.splitLocalPath)(pathInput.path);
|
|
36
|
+
}
|
|
37
|
+
else if (pathInput.isHubSpot) {
|
|
38
|
+
pathParts = (0, path_2.splitHubSpotPath)(pathInput.path);
|
|
39
|
+
}
|
|
40
|
+
const { length } = pathParts;
|
|
41
|
+
// Not a child path?
|
|
42
|
+
if (length <= 1)
|
|
43
|
+
return false;
|
|
44
|
+
// Check if we should ignore this file
|
|
45
|
+
if (ignoreLocales && pathParts.find(part => part === '_locales')) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
// Check if any parent folders are module folders.
|
|
49
|
+
return pathParts
|
|
50
|
+
.slice(0, length - 1)
|
|
51
|
+
.some(part => isModuleFolder({ ...pathInput, path: part }));
|
|
52
|
+
}
|
|
53
|
+
exports.isModuleFolderChild = isModuleFolderChild;
|