@hubspot/local-dev-lib 0.0.3 → 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 +6 -6
- package/config/CLIConfiguration.js +11 -11
- package/config/configFile.js +1 -2
- package/constants/extensions.d.ts +1 -0
- package/constants/extensions.js +2 -1
- package/errors/fileSystemErrors.d.ts +7 -1
- package/errors/fileSystemErrors.js +1 -2
- package/errors/standardErrors.d.ts +14 -4
- package/errors/standardErrors.js +38 -34
- package/{src/http → http}/requestOptions.js +1 -1
- package/lib/archive.js +2 -4
- package/lib/path.d.ts +0 -3
- package/lib/path.js +2 -19
- package/package.json +8 -8
- package/types/Config.d.ts +1 -1
- package/types/Error.d.ts +6 -13
- package/utils/git.d.ts +2 -1
- package/utils/git.js +4 -68
- package/utils/lang.d.ts +5 -0
- package/utils/lang.js +30 -5
- package/errors/cmsFieldsJsErrors.d.ts +0 -9
- package/errors/cmsFieldsJsErrors.js +0 -31
- package/index.d.ts +0 -2
- package/index.js +0 -5
- package/src/config/CLIConfiguration.d.ts +0 -55
- package/src/config/CLIConfiguration.js +0 -392
- package/src/config/configFile.d.ts +0 -21
- package/src/config/configFile.js +0 -109
- package/src/config/configUtils.d.ts +0 -24
- package/src/config/configUtils.js +0 -85
- package/src/config/environment.d.ts +0 -3
- package/src/config/environment.js +0 -64
- package/src/constants/auth.d.ts +0 -24
- package/src/constants/auth.js +0 -31
- package/src/constants/config.d.ts +0 -8
- package/src/constants/config.js +0 -12
- package/src/constants/environments.d.ts +0 -13
- package/src/constants/environments.js +0 -16
- package/src/constants/extensions.d.ts +0 -2
- package/src/constants/extensions.js +0 -23
- package/src/constants/index.d.ts +0 -16
- package/src/constants/index.js +0 -12
- package/src/errors/HubSpotAuthError.d.ts +0 -3
- package/src/errors/HubSpotAuthError.js +0 -6
- package/src/errors/cmsFieldsJsErrors.d.ts +0 -9
- package/src/errors/cmsFieldsJsErrors.js +0 -31
- package/src/errors/fileSystemErrors.d.ts +0 -8
- package/src/errors/fileSystemErrors.js +0 -28
- package/src/errors/standardErrors.d.ts +0 -19
- package/src/errors/standardErrors.js +0 -67
- package/src/index.d.ts +0 -2
- package/src/index.js +0 -5
- package/src/lib/archive.d.ts +0 -7
- package/src/lib/archive.js +0 -111
- package/src/lib/modules.d.ts +0 -28
- package/src/lib/modules.js +0 -174
- package/src/lib/path.d.ts +0 -10
- package/src/lib/path.js +0 -84
- package/src/types/Accounts.d.ts +0 -50
- package/src/types/Accounts.js +0 -2
- package/src/types/CLIOptions.d.ts +0 -3
- package/src/types/CLIOptions.js +0 -2
- package/src/types/Config.d.ts +0 -10
- package/src/types/Config.js +0 -2
- package/src/types/Error.d.ts +0 -31
- package/src/types/Error.js +0 -2
- package/src/types/LogCallbacks.d.ts +0 -6
- package/src/types/LogCallbacks.js +0 -2
- package/src/types/Utils.d.ts +0 -1
- package/src/types/Utils.js +0 -2
- package/src/utils/encoding.d.ts +0 -1
- package/src/utils/encoding.js +0 -11
- package/src/utils/environment.d.ts +0 -1
- package/src/utils/environment.js +0 -16
- package/src/utils/escapeRegExp.d.ts +0 -1
- package/src/utils/escapeRegExp.js +0 -7
- package/src/utils/files.d.ts +0 -3
- package/src/utils/files.js +0 -35
- package/src/utils/fs/read.d.ts +0 -4
- package/src/utils/fs/read.js +0 -55
- package/src/utils/fs/walk.d.ts +0 -2
- package/src/utils/fs/walk.js +0 -44
- package/src/utils/git.d.ts +0 -4
- package/src/utils/git.js +0 -40
- package/src/utils/handleFieldsJS.d.ts +0 -35
- package/src/utils/handleFieldsJS.js +0 -158
- package/src/utils/interpolation.d.ts +0 -5
- package/src/utils/interpolation.js +0 -31
- package/src/utils/lang.d.ts +0 -8
- package/src/utils/lang.js +0 -83
- package/src/utils/logger.d.ts +0 -10
- package/src/utils/logger.js +0 -22
- package/src/utils/text.d.ts +0 -1
- package/src/utils/text.js +0 -16
- package/src/utils/urls.d.ts +0 -2
- package/src/utils/urls.js +0 -20
- package/utils/encoding.d.ts +0 -1
- package/utils/encoding.js +0 -11
- package/utils/environment.d.ts +0 -1
- package/utils/environment.js +0 -16
- package/utils/interpolation.d.ts +0 -5
- package/utils/interpolation.js +0 -31
- package/utils/text.d.ts +0 -1
- package/utils/text.js +0 -16
- /package/{src/constants → constants}/files.d.ts +0 -0
- /package/{src/constants → constants}/files.js +0 -0
- /package/{src/constants → constants}/github.d.ts +0 -0
- /package/{src/constants → constants}/github.js +0 -0
- /package/{src/http → http}/requestOptions.d.ts +0 -0
- /package/{src/lib → lib}/cms/handleFieldsJS.d.ts +0 -0
- /package/{src/lib → lib}/cms/handleFieldsJS.js +0 -0
- /package/{src/lib → lib}/cms/index.d.ts +0 -0
- /package/{src/lib → lib}/cms/index.js +0 -0
- /package/{src/lib → lib}/cms/modules.d.ts +0 -0
- /package/{src/lib → lib}/cms/modules.js +0 -0
- /package/{src/lib → lib}/cms/themes.d.ts +0 -0
- /package/{src/lib → lib}/cms/themes.js +0 -0
- /package/{src/lib → lib}/environment.d.ts +0 -0
- /package/{src/lib → lib}/environment.js +0 -0
- /package/{src/lib → lib}/fs.d.ts +0 -0
- /package/{src/lib → lib}/fs.js +0 -0
- /package/{src/lib → lib}/github.d.ts +0 -0
- /package/{src/lib → lib}/github.js +0 -0
- /package/{src/lib → lib}/gitignore.d.ts +0 -0
- /package/{src/lib → lib}/gitignore.js +0 -0
- /package/{src/lib → lib}/index.d.ts +0 -0
- /package/{src/lib → lib}/index.js +0 -0
- /package/{src/lib → lib}/text.d.ts +0 -0
- /package/{src/lib → lib}/text.js +0 -0
- /package/{src/lib → lib}/urls.d.ts +0 -0
- /package/{src/lib → lib}/urls.js +0 -0
- /package/{src/types → types}/Files.d.ts +0 -0
- /package/{src/types → types}/Files.js +0 -0
- /package/{src/types → types}/Github.d.ts +0 -0
- /package/{src/types → types}/Github.js +0 -0
- /package/{src/types → types}/Modules.d.ts +0 -0
- /package/{src/types → types}/Modules.js +0 -0
- /package/{src/utils → utils}/fieldsJS.d.ts +0 -0
- /package/{src/utils → utils}/fieldsJS.js +0 -0
- /package/{src/utils → utils}/modules.d.ts +0 -0
- /package/{src/utils → utils}/modules.js +0 -0
package/src/lib/modules.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
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.createModule = exports.isModuleCSSFile = exports.isModuleHTMLFile = exports.validateSrcAndDestPaths = exports.ValidationIds = exports.isModuleFolderChild = exports.isModuleFolder = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const path_2 = require("./path");
|
|
10
|
-
const walk_1 = require("../utils/fs/walk");
|
|
11
|
-
const extensions_1 = require("../constants/extensions");
|
|
12
|
-
const github_1 = require("./github");
|
|
13
|
-
const standardErrors_1 = require("../errors/standardErrors");
|
|
14
|
-
const logger_1 = require("../utils/logger");
|
|
15
|
-
// Matches files named module.html
|
|
16
|
-
const MODULE_HTML_EXTENSION_REGEX = new RegExp(/\.module(?:\/|\\)module\.html$/);
|
|
17
|
-
// Matches files named module.css
|
|
18
|
-
const MODULE_CSS_EXTENSION_REGEX = new RegExp(/\.module(?:\/|\\)module\.css$/);
|
|
19
|
-
const isBool = (x) => !!x === x;
|
|
20
|
-
function isPathInput(pathInput) {
|
|
21
|
-
return !!(pathInput &&
|
|
22
|
-
typeof pathInput.path === 'string' &&
|
|
23
|
-
(isBool(pathInput.isLocal) || isBool(pathInput.isHubSpot)));
|
|
24
|
-
}
|
|
25
|
-
function throwInvalidPathInput(pathInput) {
|
|
26
|
-
if (isPathInput(pathInput))
|
|
27
|
-
return;
|
|
28
|
-
(0, standardErrors_1.throwTypeErrorWithMessage)('modules.throwInvalidPathInput');
|
|
29
|
-
}
|
|
30
|
-
function isModuleFolder(pathInput) {
|
|
31
|
-
throwInvalidPathInput(pathInput);
|
|
32
|
-
const _path = pathInput.isHubSpot
|
|
33
|
-
? path_1.default.posix.normalize(pathInput.path)
|
|
34
|
-
: path_1.default.normalize(pathInput.path);
|
|
35
|
-
return (0, path_2.getExt)(_path) === extensions_1.MODULE_EXTENSION;
|
|
36
|
-
}
|
|
37
|
-
exports.isModuleFolder = isModuleFolder;
|
|
38
|
-
function isModuleFolderChild(pathInput, ignoreLocales = false) {
|
|
39
|
-
throwInvalidPathInput(pathInput);
|
|
40
|
-
let pathParts = [];
|
|
41
|
-
if (pathInput.isLocal) {
|
|
42
|
-
pathParts = (0, path_2.splitLocalPath)(pathInput.path);
|
|
43
|
-
}
|
|
44
|
-
else if (pathInput.isHubSpot) {
|
|
45
|
-
pathParts = (0, path_2.splitHubSpotPath)(pathInput.path);
|
|
46
|
-
}
|
|
47
|
-
const { length } = pathParts;
|
|
48
|
-
// Not a child path?
|
|
49
|
-
if (length <= 1)
|
|
50
|
-
return false;
|
|
51
|
-
// Check if we should ignore this file
|
|
52
|
-
if (ignoreLocales && pathParts.find(part => part === '_locales')) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
// Check if any parent folders are module folders.
|
|
56
|
-
return pathParts
|
|
57
|
-
.slice(0, length - 1)
|
|
58
|
-
.some(part => isModuleFolder({ ...pathInput, path: part }));
|
|
59
|
-
}
|
|
60
|
-
exports.isModuleFolderChild = isModuleFolderChild;
|
|
61
|
-
// Ids for testing
|
|
62
|
-
exports.ValidationIds = {
|
|
63
|
-
SRC_REQUIRED: 'SRC_REQUIRED',
|
|
64
|
-
DEST_REQUIRED: 'DEST_REQUIRED',
|
|
65
|
-
MODULE_FOLDER_REQUIRED: 'MODULE_FOLDER_REQUIRED',
|
|
66
|
-
MODULE_TO_MODULE_NESTING: 'MODULE_TO_MODULE_NESTING',
|
|
67
|
-
MODULE_NESTING: 'MODULE_NESTING',
|
|
68
|
-
};
|
|
69
|
-
const getValidationResult = (id, message) => ({ id, message });
|
|
70
|
-
async function validateSrcAndDestPaths(src, dest) {
|
|
71
|
-
const results = [];
|
|
72
|
-
if (!isPathInput(src)) {
|
|
73
|
-
results.push(getValidationResult(exports.ValidationIds.SRC_REQUIRED, '`src` is required.'));
|
|
74
|
-
}
|
|
75
|
-
if (!isPathInput(dest)) {
|
|
76
|
-
results.push(getValidationResult(exports.ValidationIds.DEST_REQUIRED, '`dest` is required.'));
|
|
77
|
-
}
|
|
78
|
-
if (results.length || !src || !dest) {
|
|
79
|
-
return results;
|
|
80
|
-
}
|
|
81
|
-
const [_src, _dest] = [src, dest].map(inputPath => {
|
|
82
|
-
const result = { ...inputPath };
|
|
83
|
-
if (result.isLocal) {
|
|
84
|
-
result.path = path_1.default.resolve((0, path_2.getCwd)(), result.path);
|
|
85
|
-
}
|
|
86
|
-
else if (result.isHubSpot) {
|
|
87
|
-
result.path = path_1.default.posix.normalize(result.path);
|
|
88
|
-
}
|
|
89
|
-
return result;
|
|
90
|
-
});
|
|
91
|
-
// src is a .module folder and dest is within a module. (Nesting)
|
|
92
|
-
// e.g. `upload foo.module bar.module/zzz`
|
|
93
|
-
if (isModuleFolder(_src) && isModuleFolderChild(_dest)) {
|
|
94
|
-
return results.concat(getValidationResult(exports.ValidationIds.MODULE_TO_MODULE_NESTING, '`src` is a module path and `dest` is within a module.'));
|
|
95
|
-
}
|
|
96
|
-
// src is a .module folder but dest is not
|
|
97
|
-
// e.g. `upload foo.module bar`
|
|
98
|
-
if (isModuleFolder(_src) && !isModuleFolder(_dest)) {
|
|
99
|
-
return results.concat(getValidationResult(exports.ValidationIds.MODULE_FOLDER_REQUIRED, '`src` is a module path but `dest` is not.'));
|
|
100
|
-
}
|
|
101
|
-
// src is a folder that includes modules and dest is within a module. (Nesting)
|
|
102
|
-
if (_src.isLocal && isModuleFolderChild(_dest)) {
|
|
103
|
-
const stat = await fs_extra_1.default.stat(_src.path);
|
|
104
|
-
if (stat.isDirectory()) {
|
|
105
|
-
const files = await (0, walk_1.walk)(_src.path + 'l');
|
|
106
|
-
const srcHasModulesChildren = files.some(file => isModuleFolderChild({ ..._src, path: file }));
|
|
107
|
-
if (srcHasModulesChildren) {
|
|
108
|
-
return results.concat(getValidationResult(exports.ValidationIds.MODULE_NESTING, '`src` contains modules and `dest` is within a module.'));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return results;
|
|
113
|
-
}
|
|
114
|
-
exports.validateSrcAndDestPaths = validateSrcAndDestPaths;
|
|
115
|
-
const isModuleHTMLFile = (filePath) => MODULE_HTML_EXTENSION_REGEX.test(filePath);
|
|
116
|
-
exports.isModuleHTMLFile = isModuleHTMLFile;
|
|
117
|
-
const isModuleCSSFile = (filePath) => MODULE_CSS_EXTENSION_REGEX.test(filePath);
|
|
118
|
-
exports.isModuleCSSFile = isModuleCSSFile;
|
|
119
|
-
const createModuleCallbackKeys = ['creatingPath', 'creatingModule'];
|
|
120
|
-
async function createModule(moduleDefinition, name, dest, options = {
|
|
121
|
-
allowExistingDir: false,
|
|
122
|
-
}, logCallbacks) {
|
|
123
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks, 'modules.createModule');
|
|
124
|
-
const writeModuleMeta = ({ contentTypes, moduleLabel, global }, dest) => {
|
|
125
|
-
const metaData = {
|
|
126
|
-
label: moduleLabel,
|
|
127
|
-
css_assets: [],
|
|
128
|
-
external_js: [],
|
|
129
|
-
global: global,
|
|
130
|
-
help_text: '',
|
|
131
|
-
host_template_types: contentTypes,
|
|
132
|
-
js_assets: [],
|
|
133
|
-
other_assets: [],
|
|
134
|
-
smart_type: 'NOT_SMART',
|
|
135
|
-
tags: [],
|
|
136
|
-
is_available_for_new_content: false,
|
|
137
|
-
};
|
|
138
|
-
fs_extra_1.default.writeJSONSync(dest, metaData, { spaces: 2 });
|
|
139
|
-
};
|
|
140
|
-
const moduleFileFilter = (src, dest) => {
|
|
141
|
-
const emailEnabled = moduleDefinition.contentTypes.includes('EMAIL');
|
|
142
|
-
switch (path_1.default.basename(src)) {
|
|
143
|
-
case 'meta.json':
|
|
144
|
-
writeModuleMeta(moduleDefinition, dest);
|
|
145
|
-
return false;
|
|
146
|
-
case 'module.js':
|
|
147
|
-
case 'module.css':
|
|
148
|
-
if (emailEnabled) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
return true;
|
|
152
|
-
default:
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
const folderName = !name || name.endsWith('.module') ? name : `${name}.module`;
|
|
157
|
-
const destPath = path_1.default.join(dest, folderName);
|
|
158
|
-
if (!options.allowExistingDir && fs_extra_1.default.existsSync(destPath)) {
|
|
159
|
-
(0, standardErrors_1.throwErrorWithMessage)('modules.createModule', {
|
|
160
|
-
path: destPath,
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
logger('creatingPath', {
|
|
165
|
-
path: destPath,
|
|
166
|
-
});
|
|
167
|
-
fs_extra_1.default.ensureDirSync(destPath);
|
|
168
|
-
}
|
|
169
|
-
logger('creatingModule', {
|
|
170
|
-
path: destPath,
|
|
171
|
-
});
|
|
172
|
-
await (0, github_1.downloadGithubRepoContents)('cms-sample-assets', 'modules/Sample.module', destPath, moduleFileFilter);
|
|
173
|
-
}
|
|
174
|
-
exports.createModule = createModule;
|
package/src/lib/path.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import path from 'path';
|
|
3
|
-
export declare function convertToUnixPath(_path: string): string;
|
|
4
|
-
export declare function convertToLocalFileSystemPath(_path: string): string;
|
|
5
|
-
export declare function splitLocalPath(filepath: string, pathImplementation?: path.PlatformPath): Array<string>;
|
|
6
|
-
export declare function splitHubSpotPath(filepath: string): Array<string>;
|
|
7
|
-
export declare function getCwd(): string;
|
|
8
|
-
export declare function getExt(filepath: string): string;
|
|
9
|
-
export declare function isAllowedExtension(filepath: string): boolean;
|
|
10
|
-
export declare function getAbsoluteFilePath(_path: string): string;
|
package/src/lib/path.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
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.getAbsoluteFilePath = exports.isAllowedExtension = exports.getExt = exports.getCwd = exports.splitHubSpotPath = exports.splitLocalPath = exports.convertToLocalFileSystemPath = exports.convertToUnixPath = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const unixify_1 = __importDefault(require("unixify"));
|
|
9
|
-
const extensions_1 = require("../constants/extensions");
|
|
10
|
-
function convertToUnixPath(_path) {
|
|
11
|
-
return (0, unixify_1.default)(path_1.default.normalize(_path));
|
|
12
|
-
}
|
|
13
|
-
exports.convertToUnixPath = convertToUnixPath;
|
|
14
|
-
function convertToWindowsPath(_path) {
|
|
15
|
-
const rgx = new RegExp(`\\${path_1.default.posix.sep}`, 'g');
|
|
16
|
-
return path_1.default.normalize(_path).replace(rgx, path_1.default.win32.sep);
|
|
17
|
-
}
|
|
18
|
-
function convertToLocalFileSystemPath(_path) {
|
|
19
|
-
switch (path_1.default.sep) {
|
|
20
|
-
case path_1.default.posix.sep:
|
|
21
|
-
return convertToUnixPath(_path);
|
|
22
|
-
case path_1.default.win32.sep:
|
|
23
|
-
return convertToWindowsPath(_path);
|
|
24
|
-
default:
|
|
25
|
-
return path_1.default.normalize(_path);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.convertToLocalFileSystemPath = convertToLocalFileSystemPath;
|
|
29
|
-
function removeTrailingSlashFromSplits(parts) {
|
|
30
|
-
if (parts.length > 1 && parts[parts.length - 1] === '') {
|
|
31
|
-
return parts.slice(0, parts.length - 1);
|
|
32
|
-
}
|
|
33
|
-
return parts;
|
|
34
|
-
}
|
|
35
|
-
// Splits a filepath for local file system sources.
|
|
36
|
-
function splitLocalPath(filepath, pathImplementation = path_1.default) {
|
|
37
|
-
if (!filepath)
|
|
38
|
-
return [];
|
|
39
|
-
const { sep } = pathImplementation;
|
|
40
|
-
const rgx = new RegExp(`\\${sep}+`, 'g');
|
|
41
|
-
const parts = pathImplementation.normalize(filepath).split(rgx);
|
|
42
|
-
// Restore posix root if present
|
|
43
|
-
if (sep === path_1.default.posix.sep && parts[0] === '') {
|
|
44
|
-
parts[0] = '/';
|
|
45
|
-
}
|
|
46
|
-
return removeTrailingSlashFromSplits(parts);
|
|
47
|
-
}
|
|
48
|
-
exports.splitLocalPath = splitLocalPath;
|
|
49
|
-
// Splits a filepath for remote sources (HubSpot).
|
|
50
|
-
function splitHubSpotPath(filepath) {
|
|
51
|
-
if (!filepath)
|
|
52
|
-
return [];
|
|
53
|
-
const rgx = new RegExp(`\\${path_1.default.posix.sep}+`, 'g');
|
|
54
|
-
const parts = convertToUnixPath(filepath).split(rgx);
|
|
55
|
-
// Restore root if present
|
|
56
|
-
if (parts[0] === '') {
|
|
57
|
-
parts[0] = '/';
|
|
58
|
-
}
|
|
59
|
-
return removeTrailingSlashFromSplits(parts);
|
|
60
|
-
}
|
|
61
|
-
exports.splitHubSpotPath = splitHubSpotPath;
|
|
62
|
-
function getCwd() {
|
|
63
|
-
if (process.env.INIT_CWD) {
|
|
64
|
-
return process.env.INIT_CWD;
|
|
65
|
-
}
|
|
66
|
-
return process.cwd();
|
|
67
|
-
}
|
|
68
|
-
exports.getCwd = getCwd;
|
|
69
|
-
function getExt(filepath) {
|
|
70
|
-
if (typeof filepath !== 'string')
|
|
71
|
-
return '';
|
|
72
|
-
const ext = path_1.default.extname(filepath).trim().toLowerCase();
|
|
73
|
-
return ext[0] === '.' ? ext.slice(1) : ext;
|
|
74
|
-
}
|
|
75
|
-
exports.getExt = getExt;
|
|
76
|
-
function isAllowedExtension(filepath) {
|
|
77
|
-
const ext = getExt(filepath);
|
|
78
|
-
return extensions_1.ALLOWED_EXTENSIONS.has(ext);
|
|
79
|
-
}
|
|
80
|
-
exports.isAllowedExtension = isAllowedExtension;
|
|
81
|
-
function getAbsoluteFilePath(_path) {
|
|
82
|
-
return path_1.default.resolve(getCwd(), _path);
|
|
83
|
-
}
|
|
84
|
-
exports.getAbsoluteFilePath = getAbsoluteFilePath;
|
package/src/types/Accounts.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_MODES } from '../constants/config';
|
|
2
|
-
import { ValueOf } from './Utils';
|
|
3
|
-
export type AuthType = 'personalaccesskey' | 'apikey' | 'oauth2';
|
|
4
|
-
export interface CLIAccount {
|
|
5
|
-
name?: string;
|
|
6
|
-
accountId: number;
|
|
7
|
-
defaultMode?: ValueOf<typeof DEFAULT_MODES>;
|
|
8
|
-
env?: string;
|
|
9
|
-
authType?: AuthType;
|
|
10
|
-
auth?: object;
|
|
11
|
-
sandboxAccountType?: string | null;
|
|
12
|
-
parentAccountId?: number | null;
|
|
13
|
-
apiKey?: string;
|
|
14
|
-
personalAccessKey?: string;
|
|
15
|
-
}
|
|
16
|
-
export type PersonalAccessKeyTokenInfo = {
|
|
17
|
-
accessToken: string;
|
|
18
|
-
expiresAt: string;
|
|
19
|
-
};
|
|
20
|
-
export type OauthTokenInfo = {
|
|
21
|
-
refreshToken?: string;
|
|
22
|
-
};
|
|
23
|
-
export interface PersonalAccessKeyAccount extends CLIAccount {
|
|
24
|
-
authType: 'personalaccesskey';
|
|
25
|
-
auth?: {
|
|
26
|
-
tokenInfo: PersonalAccessKeyTokenInfo;
|
|
27
|
-
};
|
|
28
|
-
personalAccessKey: string;
|
|
29
|
-
}
|
|
30
|
-
export interface OAuthAccount extends CLIAccount {
|
|
31
|
-
authType: 'oauth2';
|
|
32
|
-
auth?: {
|
|
33
|
-
clientId?: string;
|
|
34
|
-
clientSecret?: string;
|
|
35
|
-
scopes?: Array<string>;
|
|
36
|
-
tokenInfo?: OauthTokenInfo;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export interface APIKeyAccount extends CLIAccount {
|
|
40
|
-
authType: 'apikey';
|
|
41
|
-
apiKey: string;
|
|
42
|
-
}
|
|
43
|
-
export interface FlatAccountFields<T extends OauthTokenInfo | PersonalAccessKeyTokenInfo> extends CLIAccount {
|
|
44
|
-
tokenInfo?: T;
|
|
45
|
-
clientId?: string;
|
|
46
|
-
clientSecret?: string;
|
|
47
|
-
scopes?: Array<string>;
|
|
48
|
-
apiKey?: string;
|
|
49
|
-
personalAccessKey?: string;
|
|
50
|
-
}
|
package/src/types/Accounts.js
DELETED
package/src/types/CLIOptions.js
DELETED
package/src/types/Config.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { CLIAccount } from './Accounts';
|
|
2
|
-
export interface CLIConfig {
|
|
3
|
-
accounts: Array<CLIAccount>;
|
|
4
|
-
allowUsageTracking?: boolean;
|
|
5
|
-
defaultAccount?: string | number;
|
|
6
|
-
defaultMode?: string;
|
|
7
|
-
httpTimeout?: number;
|
|
8
|
-
env?: string;
|
|
9
|
-
httpUseLocalhost?: boolean;
|
|
10
|
-
}
|
package/src/types/Config.js
DELETED
package/src/types/Error.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export interface BaseError extends Error {
|
|
2
|
-
name: string;
|
|
3
|
-
message: string;
|
|
4
|
-
errno?: number | null;
|
|
5
|
-
code?: string | null;
|
|
6
|
-
syscall?: string | null;
|
|
7
|
-
reason?: string;
|
|
8
|
-
statusCode?: number;
|
|
9
|
-
}
|
|
10
|
-
export interface StatusCodeError extends BaseError {
|
|
11
|
-
name: 'StatusCodeError';
|
|
12
|
-
statusCode: number;
|
|
13
|
-
message: string;
|
|
14
|
-
response: {
|
|
15
|
-
request: {
|
|
16
|
-
href: string;
|
|
17
|
-
method: string;
|
|
18
|
-
};
|
|
19
|
-
body: {
|
|
20
|
-
[key: string]: string;
|
|
21
|
-
};
|
|
22
|
-
headers: {
|
|
23
|
-
[key: string]: string;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
export interface GithubError extends BaseError {
|
|
28
|
-
error: {
|
|
29
|
-
message?: string;
|
|
30
|
-
};
|
|
31
|
-
}
|
package/src/types/Error.js
DELETED
package/src/types/Utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type ValueOf<T> = T[keyof T];
|
package/src/types/Utils.js
DELETED
package/src/utils/encoding.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function base64EncodeString(valueToEncode: string): string;
|
package/src/utils/encoding.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.base64EncodeString = void 0;
|
|
4
|
-
function base64EncodeString(valueToEncode) {
|
|
5
|
-
if (typeof valueToEncode !== 'string') {
|
|
6
|
-
return valueToEncode;
|
|
7
|
-
}
|
|
8
|
-
const stringBuffer = Buffer.from(valueToEncode);
|
|
9
|
-
return encodeURIComponent(stringBuffer.toString('base64'));
|
|
10
|
-
}
|
|
11
|
-
exports.base64EncodeString = base64EncodeString;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getValidEnv(env: string, maskedProductionValue?: string): string;
|
package/src/utils/environment.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getValidEnv = void 0;
|
|
4
|
-
const environments_1 = require("../constants/environments");
|
|
5
|
-
function getValidEnv(env, maskedProductionValue) {
|
|
6
|
-
const prodValue = maskedProductionValue
|
|
7
|
-
? maskedProductionValue
|
|
8
|
-
: environments_1.ENVIRONMENTS.PROD;
|
|
9
|
-
const returnVal = typeof env &&
|
|
10
|
-
typeof env === 'string' &&
|
|
11
|
-
env.toLowerCase() === environments_1.ENVIRONMENTS.QA
|
|
12
|
-
? environments_1.ENVIRONMENTS.QA
|
|
13
|
-
: prodValue;
|
|
14
|
-
return returnVal;
|
|
15
|
-
}
|
|
16
|
-
exports.getValidEnv = getValidEnv;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function escapeRegExp(string: string): string;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.escapeRegExp = void 0;
|
|
4
|
-
function escapeRegExp(string) {
|
|
5
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
6
|
-
}
|
|
7
|
-
exports.escapeRegExp = escapeRegExp;
|
package/src/utils/files.d.ts
DELETED
package/src/utils/files.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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.getThemePreviewUrl = exports.getThemeNameFromPath = exports.getThemeJSONPath = void 0;
|
|
7
|
-
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
8
|
-
const urls_1 = require("./urls");
|
|
9
|
-
const environments_1 = require("../constants/environments");
|
|
10
|
-
const CLIConfiguration_1 = __importDefault(require("../config/CLIConfiguration"));
|
|
11
|
-
function getThemeJSONPath(path) {
|
|
12
|
-
return (0, findup_sync_1.default)('theme.json', {
|
|
13
|
-
cwd: path,
|
|
14
|
-
nocase: true,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
exports.getThemeJSONPath = getThemeJSONPath;
|
|
18
|
-
function getThemeNameFromPath(filePath) {
|
|
19
|
-
const themeJSONPath = getThemeJSONPath(filePath);
|
|
20
|
-
if (!themeJSONPath)
|
|
21
|
-
return;
|
|
22
|
-
const pathParts = themeJSONPath.split('/');
|
|
23
|
-
if (pathParts.length < 2)
|
|
24
|
-
return;
|
|
25
|
-
return pathParts[pathParts.length - 2];
|
|
26
|
-
}
|
|
27
|
-
exports.getThemeNameFromPath = getThemeNameFromPath;
|
|
28
|
-
function getThemePreviewUrl(filePath, accountId) {
|
|
29
|
-
const themeName = getThemeNameFromPath(filePath);
|
|
30
|
-
if (!themeName)
|
|
31
|
-
return;
|
|
32
|
-
const baseUrl = (0, urls_1.getHubSpotWebsiteOrigin)(CLIConfiguration_1.default.getEnv() === 'qa' ? environments_1.ENVIRONMENTS.QA : environments_1.ENVIRONMENTS.PROD);
|
|
33
|
-
return `${baseUrl}/theme-previewer/${accountId}/edit/${encodeURIComponent(themeName)}`;
|
|
34
|
-
}
|
|
35
|
-
exports.getThemePreviewUrl = getThemePreviewUrl;
|
package/src/utils/fs/read.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { FileData } from '../../types/Files';
|
|
2
|
-
export declare function getFileInfoAsync(dir: string, file: string): Promise<FileData>;
|
|
3
|
-
export declare function flattenAndRemoveSymlinks(filesData: Array<FileData>): Array<string>;
|
|
4
|
-
export declare function read(dir: string): Promise<Array<string>>;
|
package/src/utils/fs/read.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
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.read = exports.flattenAndRemoveSymlinks = exports.getFileInfoAsync = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const files_1 = require("../../constants/files");
|
|
10
|
-
function getFileInfoAsync(dir, file) {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
const filepath = path_1.default.join(dir, file);
|
|
13
|
-
fs_1.default.lstat(filepath, (error, stats) => {
|
|
14
|
-
if (error) {
|
|
15
|
-
reject(error);
|
|
16
|
-
}
|
|
17
|
-
let type = files_1.STAT_TYPES.FILE;
|
|
18
|
-
if (stats.isSymbolicLink()) {
|
|
19
|
-
type = files_1.STAT_TYPES.SYMBOLIC_LINK;
|
|
20
|
-
}
|
|
21
|
-
else if (stats.isDirectory()) {
|
|
22
|
-
type = files_1.STAT_TYPES.DIRECTORY;
|
|
23
|
-
}
|
|
24
|
-
resolve({ filepath, type });
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
exports.getFileInfoAsync = getFileInfoAsync;
|
|
29
|
-
function flattenAndRemoveSymlinks(filesData) {
|
|
30
|
-
return filesData.reduce((acc, fileData) => {
|
|
31
|
-
switch (fileData.type) {
|
|
32
|
-
case files_1.STAT_TYPES.FILE:
|
|
33
|
-
return acc.concat(fileData.filepath);
|
|
34
|
-
case files_1.STAT_TYPES.DIRECTORY:
|
|
35
|
-
return acc.concat(fileData.files || []);
|
|
36
|
-
case files_1.STAT_TYPES.SYMBOLIC_LINK:
|
|
37
|
-
return acc;
|
|
38
|
-
default:
|
|
39
|
-
return acc;
|
|
40
|
-
}
|
|
41
|
-
}, []);
|
|
42
|
-
}
|
|
43
|
-
exports.flattenAndRemoveSymlinks = flattenAndRemoveSymlinks;
|
|
44
|
-
async function read(dir) {
|
|
45
|
-
const processFiles = (files) => Promise.all(files.map(file => getFileInfoAsync(dir, file)));
|
|
46
|
-
return fs_1.default.promises
|
|
47
|
-
.readdir(dir)
|
|
48
|
-
.then(processFiles)
|
|
49
|
-
.then(flattenAndRemoveSymlinks)
|
|
50
|
-
.catch(err => {
|
|
51
|
-
console.debug(err);
|
|
52
|
-
return [];
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
exports.read = read;
|
package/src/utils/fs/walk.d.ts
DELETED
package/src/utils/fs/walk.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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.walk = exports.listFilesInDir = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const read_1 = require("./read");
|
|
9
|
-
const files_1 = require("../../constants/files");
|
|
10
|
-
const standardErrors_1 = require("../../errors/standardErrors");
|
|
11
|
-
function listFilesInDir(dir) {
|
|
12
|
-
return fs_1.default
|
|
13
|
-
.readdirSync(dir, { withFileTypes: true })
|
|
14
|
-
.filter(file => !file.isDirectory())
|
|
15
|
-
.map(file => file.name);
|
|
16
|
-
}
|
|
17
|
-
exports.listFilesInDir = listFilesInDir;
|
|
18
|
-
const generateRecursiveFilePromise = async (dir, file) => {
|
|
19
|
-
return (0, read_1.getFileInfoAsync)(dir, file).then(fileData => {
|
|
20
|
-
return new Promise(resolve => {
|
|
21
|
-
if (fileData.type === files_1.STAT_TYPES.DIRECTORY) {
|
|
22
|
-
walk(fileData.filepath).then(files => {
|
|
23
|
-
resolve({ ...fileData, files });
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
resolve(fileData);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
async function walk(dir) {
|
|
33
|
-
function processFiles(files) {
|
|
34
|
-
return Promise.all(files.map(file => generateRecursiveFilePromise(dir, file)));
|
|
35
|
-
}
|
|
36
|
-
return fs_1.default.promises
|
|
37
|
-
.readdir(dir)
|
|
38
|
-
.then(processFiles)
|
|
39
|
-
.then(read_1.flattenAndRemoveSymlinks)
|
|
40
|
-
.catch(err => {
|
|
41
|
-
(0, standardErrors_1.throwError)(err);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
exports.walk = walk;
|
package/src/utils/git.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare function makeComparisonDir(filepath: string | null): string | null;
|
|
2
|
-
export declare const getGitComparisonDir: () => string | null;
|
|
3
|
-
export declare function isConfigPathInGitRepo(configPath: string): boolean;
|
|
4
|
-
export declare function configFilenameIsIgnoredByGitignore(ignoreFiles: Array<string>, configPath: string): boolean;
|
package/src/utils/git.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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.configFilenameIsIgnoredByGitignore = exports.isConfigPathInGitRepo = exports.getGitComparisonDir = exports.makeComparisonDir = void 0;
|
|
7
|
-
const fs_extra_1 = require("fs-extra");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const ignore_1 = __importDefault(require("ignore"));
|
|
10
|
-
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
11
|
-
function makeComparisonDir(filepath) {
|
|
12
|
-
if (typeof filepath !== 'string')
|
|
13
|
-
return null;
|
|
14
|
-
// Append sep to make comparisons easier e.g. 'foos'.startsWith('foo')
|
|
15
|
-
return path_1.default.dirname(path_1.default.resolve(filepath)).toLowerCase() + path_1.default.sep;
|
|
16
|
-
}
|
|
17
|
-
exports.makeComparisonDir = makeComparisonDir;
|
|
18
|
-
const getGitComparisonDir = () => makeComparisonDir((0, findup_sync_1.default)('.git'));
|
|
19
|
-
exports.getGitComparisonDir = getGitComparisonDir;
|
|
20
|
-
function isConfigPathInGitRepo(configPath) {
|
|
21
|
-
const gitDir = (0, exports.getGitComparisonDir)();
|
|
22
|
-
if (!gitDir)
|
|
23
|
-
return false;
|
|
24
|
-
const configDir = makeComparisonDir(configPath);
|
|
25
|
-
if (!configDir)
|
|
26
|
-
return false;
|
|
27
|
-
return configDir.startsWith(gitDir);
|
|
28
|
-
}
|
|
29
|
-
exports.isConfigPathInGitRepo = isConfigPathInGitRepo;
|
|
30
|
-
function configFilenameIsIgnoredByGitignore(ignoreFiles, configPath) {
|
|
31
|
-
return ignoreFiles.some(gitignore => {
|
|
32
|
-
const gitignoreContents = (0, fs_extra_1.readFileSync)(gitignore).toString();
|
|
33
|
-
const gitignoreConfig = (0, ignore_1.default)().add(gitignoreContents);
|
|
34
|
-
if (gitignoreConfig.ignores(path_1.default.relative(path_1.default.dirname(gitignore), configPath))) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
exports.configFilenameIsIgnoredByGitignore = configFilenameIsIgnoredByGitignore;
|