@hubspot/cli 3.0.12 → 3.0.13-beta.2
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/bin/cli.js +28 -2
- package/commands/accounts/use.js +82 -0
- package/commands/accounts.js +2 -0
- package/commands/config/set/allowUsageTracking.js +12 -19
- package/commands/config/set/defaultMode.js +11 -35
- package/commands/config/set/httpTimeout.js +27 -24
- package/commands/config/set.js +81 -13
- package/commands/logs.js +1 -7
- package/commands/module/marketplace-validate.js +77 -0
- package/commands/module.js +17 -0
- package/commands/project/logs.js +124 -60
- package/commands/project/open.js +75 -0
- package/commands/project.js +2 -0
- package/commands/sandbox/create.js +2 -2
- package/commands/sandbox.js +3 -1
- package/commands/theme/marketplace-validate.js +4 -2
- package/commands/upload.js +21 -10
- package/lib/projects.js +10 -7
- package/lib/prompts/personalAccessKeyPrompt.js +1 -1
- package/lib/prompts/projectNamePrompt.js +29 -0
- package/lib/prompts/projectsLogsPrompt.js +57 -0
- package/lib/serverlessLogs.js +25 -11
- package/lib/validators/__tests__/{BaseValidator.js → AbsoluteValidator.js} +3 -3
- package/lib/validators/__tests__/ModuleDependencyValidator.js +79 -0
- package/lib/validators/__tests__/ModuleValidator.js +22 -55
- package/lib/validators/__tests__/RelativeValidator.js +28 -0
- package/lib/validators/__tests__/TemplateValidator.js +1 -1
- package/lib/validators/__tests__/ThemeConfigValidator.js +1 -1
- package/lib/validators/__tests__/{DependencyValidator.js → ThemeDependencyValidator.js} +14 -12
- package/lib/validators/__tests__/ThemeModuleValidator.js +84 -0
- package/lib/validators/__tests__/validatorTestUtils.js +2 -0
- package/lib/validators/applyValidators.js +20 -4
- package/lib/validators/constants.js +4 -2
- package/lib/validators/index.js +8 -4
- package/lib/validators/marketplaceValidators/{BaseValidator.js → AbsoluteValidator.js} +8 -8
- package/lib/validators/marketplaceValidators/RelativeValidator.js +46 -0
- package/lib/validators/marketplaceValidators/module/ModuleDependencyValidator.js +101 -0
- package/lib/validators/marketplaceValidators/module/ModuleValidator.js +102 -0
- package/lib/validators/marketplaceValidators/theme/SectionValidator.js +2 -2
- package/lib/validators/marketplaceValidators/theme/TemplateValidator.js +2 -2
- package/lib/validators/marketplaceValidators/theme/ThemeConfigValidator.js +3 -3
- package/lib/validators/marketplaceValidators/theme/{DependencyValidator.js → ThemeDependencyValidator.js} +15 -12
- package/lib/validators/marketplaceValidators/theme/{ModuleValidator.js → ThemeModuleValidator.js} +5 -5
- package/package.json +4 -5
- package/bin/hubspot +0 -3
- package/commands/config/set/defaultAccount.js +0 -94
- package/commands/server.js +0 -80
- package/lib/server/updateContext.js +0 -105
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
const { logger } = require('@hubspot/cli-lib/logger');
|
|
4
|
+
const { HUBSPOT_FOLDER } = require('@hubspot/cli-lib/lib/constants');
|
|
5
|
+
const { fetchModuleDependencies } = require('@hubspot/cli-lib/api/marketplace');
|
|
6
|
+
const { isRelativePath } = require('@hubspot/cli-lib/path');
|
|
7
|
+
|
|
8
|
+
const RelativeValidator = require('../RelativeValidator');
|
|
9
|
+
const { VALIDATOR_KEYS } = require('../../constants');
|
|
10
|
+
|
|
11
|
+
class ModuleDependencyValidator extends RelativeValidator {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
|
|
15
|
+
this.errors = {
|
|
16
|
+
FAILED_TO_FETCH_DEPS: {
|
|
17
|
+
key: 'failedDepFetch',
|
|
18
|
+
getCopy: ({ filePath }) =>
|
|
19
|
+
`Internal Error. Failed to fetch dependencies for ${filePath}. Please try again`,
|
|
20
|
+
},
|
|
21
|
+
EXTERNAL_DEPENDENCY: {
|
|
22
|
+
key: 'externalDependency',
|
|
23
|
+
getCopy: ({ filePath, referencedFilePath }) =>
|
|
24
|
+
`External dependency. ${filePath} references a file (${referencedFilePath}) that is outside of the module's immediate folder.`,
|
|
25
|
+
},
|
|
26
|
+
ABSOLUTE_DEPENDENCY_PATH: {
|
|
27
|
+
key: 'absoluteDependencyPath',
|
|
28
|
+
getCopy: ({ filePath, referencedFilePath }) =>
|
|
29
|
+
`Relative path required. ${filePath} references a file (${referencedFilePath}) using an absolute path`,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
failedToFetchDependencies(err, relativePath, validationErrors) {
|
|
35
|
+
logger.debug(
|
|
36
|
+
`Failed to fetch dependencies for ${relativePath}: `,
|
|
37
|
+
err.error
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
validationErrors.push(
|
|
41
|
+
this.getError(this.errors.FAILED_TO_FETCH_DEPS, relativePath)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async getAllDependenciesByPath(relativePath, accountId, validationErrors) {
|
|
46
|
+
let deps = [];
|
|
47
|
+
const file_deps = await fetchModuleDependencies(
|
|
48
|
+
accountId,
|
|
49
|
+
relativePath
|
|
50
|
+
).catch(err => {
|
|
51
|
+
this.failedToFetchDependencies(err, relativePath, validationErrors);
|
|
52
|
+
return null;
|
|
53
|
+
});
|
|
54
|
+
if (file_deps) {
|
|
55
|
+
deps = file_deps.dependencies || [];
|
|
56
|
+
}
|
|
57
|
+
return deps;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
isExternalDep(relPath, relativeDepPath) {
|
|
61
|
+
const moduleDir = path.parse(relPath).dir;
|
|
62
|
+
const depDir = path.parse(relativeDepPath).dir;
|
|
63
|
+
return !depDir.startsWith(moduleDir);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Validates:
|
|
67
|
+
// - Module does not contain external dependencies
|
|
68
|
+
// - All paths are either @hubspot or relative
|
|
69
|
+
async validate(relativePath, accountId) {
|
|
70
|
+
let validationErrors = [];
|
|
71
|
+
|
|
72
|
+
const dependencyData = await this.getAllDependenciesByPath(
|
|
73
|
+
relativePath,
|
|
74
|
+
accountId,
|
|
75
|
+
validationErrors
|
|
76
|
+
);
|
|
77
|
+
dependencyData.forEach(dependency => {
|
|
78
|
+
if (!dependency.startsWith(HUBSPOT_FOLDER)) {
|
|
79
|
+
if (!isRelativePath(dependency)) {
|
|
80
|
+
validationErrors.push(
|
|
81
|
+
this.getError(this.errors.ABSOLUTE_DEPENDENCY_PATH, relativePath, {
|
|
82
|
+
referencedFilePath: dependency,
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
} else if (this.isExternalDep(relativePath, dependency)) {
|
|
86
|
+
validationErrors.push(
|
|
87
|
+
this.getError(this.errors.EXTERNAL_DEPENDENCY, relativePath, {
|
|
88
|
+
referencedFilePath: dependency,
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return validationErrors;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = new ModuleDependencyValidator({
|
|
99
|
+
name: 'Module dependency',
|
|
100
|
+
key: VALIDATOR_KEYS.moduleDependency,
|
|
101
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const { logger } = require('@hubspot/cli-lib/logger');
|
|
2
|
+
const { fetchModuleMeta } = require('@hubspot/cli-lib/api/marketplace');
|
|
3
|
+
const RelativeValidator = require('../RelativeValidator');
|
|
4
|
+
const { VALIDATOR_KEYS } = require('../../constants');
|
|
5
|
+
|
|
6
|
+
class ModuleValidator extends RelativeValidator {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super(options);
|
|
9
|
+
|
|
10
|
+
this.errors = {
|
|
11
|
+
FAILED_TO_FETCH_META_JSON: {
|
|
12
|
+
key: 'failedMetaFetch',
|
|
13
|
+
getCopy: ({ filePath }) =>
|
|
14
|
+
`Internal error. Failed to fetch meta.json for ${filePath}. Please try again.`,
|
|
15
|
+
},
|
|
16
|
+
MISSING_META_JSON: {
|
|
17
|
+
key: 'missingMetaJSON',
|
|
18
|
+
getCopy: ({ filePath }) =>
|
|
19
|
+
`Module ${filePath} is missing the meta.json file`,
|
|
20
|
+
},
|
|
21
|
+
INVALID_META_JSON: {
|
|
22
|
+
key: 'invalidMetaJSON',
|
|
23
|
+
getCopy: ({ filePath }) =>
|
|
24
|
+
`Module ${filePath} has invalid json in the meta.json file`,
|
|
25
|
+
},
|
|
26
|
+
MISSING_LABEL: {
|
|
27
|
+
key: 'missingLabel',
|
|
28
|
+
getCopy: ({ filePath }) =>
|
|
29
|
+
`Missing required property for ${filePath}. The meta.json file is missing the "label" property`,
|
|
30
|
+
},
|
|
31
|
+
MISSING_ICON: {
|
|
32
|
+
key: 'missingIcon',
|
|
33
|
+
getCopy: ({ filePath }) =>
|
|
34
|
+
`Missing required property for ${filePath}. The meta.json file is missing the "icon" property`,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
failedToFetchDependencies(err, relativePath, validationErrors) {
|
|
39
|
+
logger.debug(
|
|
40
|
+
`Failed to fetch dependencies for ${relativePath}: `,
|
|
41
|
+
err.error
|
|
42
|
+
);
|
|
43
|
+
validationErrors.push(
|
|
44
|
+
this.getError(this.errors.FAILED_TO_FETCH_META_JSON, relativePath)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async getModuleMetaByPath(relativePath, accountId, validationErrors) {
|
|
49
|
+
const moduleMeta = await fetchModuleMeta(accountId, relativePath).catch(
|
|
50
|
+
err => {
|
|
51
|
+
this.failedToFetchDependencies(err, relativePath, validationErrors);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
return moduleMeta;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Validates:
|
|
59
|
+
// - Module folder contains a meta.json file
|
|
60
|
+
// - Module meta.json file contains valid json
|
|
61
|
+
// - Module meta.json file has a "label" field
|
|
62
|
+
// - Module meta.json file has an "icon" field
|
|
63
|
+
async validate(relativePath, accountId) {
|
|
64
|
+
let validationErrors = [];
|
|
65
|
+
const metaJSONFile = await this.getModuleMetaByPath(
|
|
66
|
+
relativePath,
|
|
67
|
+
accountId,
|
|
68
|
+
validationErrors
|
|
69
|
+
);
|
|
70
|
+
if (!metaJSONFile) {
|
|
71
|
+
validationErrors.push(
|
|
72
|
+
this.getError(this.errors.MISSING_META_JSON, relativePath)
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
let metaJSON;
|
|
76
|
+
try {
|
|
77
|
+
metaJSON = JSON.parse(metaJSONFile.source);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
validationErrors.push(
|
|
80
|
+
this.getError(this.errors.INVALID_META_JSON, relativePath)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (metaJSON) {
|
|
84
|
+
if (!metaJSON.label) {
|
|
85
|
+
validationErrors.push(
|
|
86
|
+
this.getError(this.errors.MISSING_LABEL, relativePath)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (!metaJSON.icon) {
|
|
90
|
+
validationErrors.push(
|
|
91
|
+
this.getError(this.errors.MISSING_ICON, relativePath)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return validationErrors;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = new ModuleValidator({
|
|
100
|
+
name: 'Module',
|
|
101
|
+
key: VALIDATOR_KEYS.module,
|
|
102
|
+
});
|
|
@@ -2,12 +2,12 @@ const {
|
|
|
2
2
|
ANNOTATION_KEYS,
|
|
3
3
|
buildAnnotationValueGetter,
|
|
4
4
|
} = require('@hubspot/cli-lib/templates');
|
|
5
|
-
const
|
|
5
|
+
const AbsoluteValidator = require('../AbsoluteValidator');
|
|
6
6
|
const { VALIDATOR_KEYS } = require('../../constants');
|
|
7
7
|
|
|
8
8
|
const SECTION_LIMIT = 50;
|
|
9
9
|
|
|
10
|
-
class SectionValidator extends
|
|
10
|
+
class SectionValidator extends AbsoluteValidator {
|
|
11
11
|
constructor(options) {
|
|
12
12
|
super(options);
|
|
13
13
|
|
|
@@ -3,7 +3,7 @@ const {
|
|
|
3
3
|
buildAnnotationValueGetter,
|
|
4
4
|
isCodedFile,
|
|
5
5
|
} = require('@hubspot/cli-lib/templates');
|
|
6
|
-
const
|
|
6
|
+
const AbsoluteValidator = require('../AbsoluteValidator');
|
|
7
7
|
const { VALIDATOR_KEYS } = require('../../constants');
|
|
8
8
|
|
|
9
9
|
const TEMPLATE_LIMIT = 50;
|
|
@@ -50,7 +50,7 @@ const VALIDATIONS_BY_TYPE = {
|
|
|
50
50
|
blog_post: { allowed: true, label: true, screenshot: true },
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
class TemplateValidator extends
|
|
53
|
+
class TemplateValidator extends AbsoluteValidator {
|
|
54
54
|
constructor(options) {
|
|
55
55
|
super(options);
|
|
56
56
|
|
|
@@ -2,10 +2,10 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
4
|
const { isRelativePath } = require('@hubspot/cli-lib/path');
|
|
5
|
-
const
|
|
5
|
+
const AbsoluteValidator = require('../AbsoluteValidator');
|
|
6
6
|
const { VALIDATOR_KEYS } = require('../../constants');
|
|
7
7
|
|
|
8
|
-
class ThemeValidator extends
|
|
8
|
+
class ThemeValidator extends AbsoluteValidator {
|
|
9
9
|
constructor(options) {
|
|
10
10
|
super(options);
|
|
11
11
|
|
|
@@ -84,7 +84,7 @@ class ThemeValidator extends BaseValidator {
|
|
|
84
84
|
);
|
|
85
85
|
} else {
|
|
86
86
|
const absoluteScreenshotPath = path.resolve(
|
|
87
|
-
this.
|
|
87
|
+
this._absolutePath,
|
|
88
88
|
themeJSON.screenshot_path
|
|
89
89
|
);
|
|
90
90
|
if (!fs.existsSync(absoluteScreenshotPath)) {
|
|
@@ -6,13 +6,15 @@ const {
|
|
|
6
6
|
HUBL_EXTENSIONS,
|
|
7
7
|
HUBSPOT_FOLDER,
|
|
8
8
|
} = require('@hubspot/cli-lib/lib/constants');
|
|
9
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
fetchTemplateDependencies,
|
|
11
|
+
} = require('@hubspot/cli-lib/api/marketplace');
|
|
10
12
|
const { getExt, isRelativePath } = require('@hubspot/cli-lib/path');
|
|
11
13
|
|
|
12
|
-
const
|
|
14
|
+
const AbsoluteValidator = require('../AbsoluteValidator');
|
|
13
15
|
const { VALIDATOR_KEYS } = require('../../constants');
|
|
14
16
|
|
|
15
|
-
class
|
|
17
|
+
class ThemeDependencyValidator extends AbsoluteValidator {
|
|
16
18
|
constructor(options) {
|
|
17
19
|
super(options);
|
|
18
20
|
|
|
@@ -53,12 +55,13 @@ class DependencyValidator extends BaseValidator {
|
|
|
53
55
|
if (!(source && source.trim())) {
|
|
54
56
|
return { file, deps };
|
|
55
57
|
}
|
|
56
|
-
const file_deps = await
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
const file_deps = await fetchTemplateDependencies(
|
|
59
|
+
accountId,
|
|
60
|
+
source
|
|
61
|
+
).catch(err => {
|
|
62
|
+
this.failedToFetchDependencies(err, file, validationErrors);
|
|
63
|
+
return null;
|
|
64
|
+
});
|
|
62
65
|
if (file_deps) {
|
|
63
66
|
deps = file_deps.dependencies || [];
|
|
64
67
|
}
|
|
@@ -117,7 +120,7 @@ class DependencyValidator extends BaseValidator {
|
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
module.exports = new
|
|
121
|
-
name: '
|
|
122
|
-
key: VALIDATOR_KEYS.
|
|
123
|
+
module.exports = new ThemeDependencyValidator({
|
|
124
|
+
name: 'Theme dependency',
|
|
125
|
+
key: VALIDATOR_KEYS.themeDependency,
|
|
123
126
|
});
|
package/lib/validators/marketplaceValidators/theme/{ModuleValidator.js → ThemeModuleValidator.js}
RENAMED
|
@@ -2,12 +2,12 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
4
|
const { isModuleFolderChild } = require('@hubspot/cli-lib/modules');
|
|
5
|
-
const
|
|
5
|
+
const AbsoluteValidator = require('../AbsoluteValidator');
|
|
6
6
|
const { VALIDATOR_KEYS } = require('../../constants');
|
|
7
7
|
|
|
8
8
|
const MODULE_LIMIT = 50;
|
|
9
9
|
|
|
10
|
-
class
|
|
10
|
+
class ThemeModuleValidator extends AbsoluteValidator {
|
|
11
11
|
constructor(options) {
|
|
12
12
|
super(options);
|
|
13
13
|
|
|
@@ -111,7 +111,7 @@ class ModuleValidator extends BaseValidator {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
module.exports = new
|
|
115
|
-
name: '
|
|
116
|
-
key: VALIDATOR_KEYS.
|
|
114
|
+
module.exports = new ThemeModuleValidator({
|
|
115
|
+
name: 'Theme modules',
|
|
116
|
+
key: VALIDATOR_KEYS.themeModule,
|
|
117
117
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cli",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.13-beta.2",
|
|
4
4
|
"description": "CLI for working with HubSpot",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"url": "https://github.com/HubSpot/hubspot-cms-tools"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@hubspot/cli-lib": "
|
|
12
|
-
"@hubspot/serverless-dev-runtime": "
|
|
11
|
+
"@hubspot/cli-lib": "3.0.13-beta.2",
|
|
12
|
+
"@hubspot/serverless-dev-runtime": "3.0.13-beta.2",
|
|
13
13
|
"archiver": "^5.3.0",
|
|
14
14
|
"chalk": "^4.1.2",
|
|
15
15
|
"express": "^4.17.1",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"moment": "^2.29.1",
|
|
20
20
|
"open": "^7.0.3",
|
|
21
21
|
"ora": "^4.0.3",
|
|
22
|
-
"shelljs": "0.8.3",
|
|
23
22
|
"spinnies": "^0.5.1",
|
|
24
23
|
"supports-hyperlinks": "^2.2.0",
|
|
25
24
|
"tmp": "^0.2.1",
|
|
@@ -39,5 +38,5 @@
|
|
|
39
38
|
"publishConfig": {
|
|
40
39
|
"access": "public"
|
|
41
40
|
},
|
|
42
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "ff694f8c61c2326159f7ad4d3f2cfdb18f8c1875"
|
|
43
42
|
}
|
package/bin/hubspot
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
const { logger } = require('@hubspot/cli-lib/logger');
|
|
2
|
-
const {
|
|
3
|
-
getConfig,
|
|
4
|
-
getConfigPath,
|
|
5
|
-
updateDefaultAccount,
|
|
6
|
-
} = require('@hubspot/cli-lib/lib/config');
|
|
7
|
-
const { loadAndValidateOptions } = require('../../../lib/validation');
|
|
8
|
-
|
|
9
|
-
const { getAccountId } = require('../../../lib/commonOpts');
|
|
10
|
-
const { trackCommandUsage } = require('../../../lib/usageTracking');
|
|
11
|
-
const { promptUser } = require('../../../lib/prompts/promptUtils');
|
|
12
|
-
const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
13
|
-
|
|
14
|
-
const i18nKey =
|
|
15
|
-
'cli.commands.config.subcommands.set.subcommands.defaultAccount';
|
|
16
|
-
|
|
17
|
-
const selectAccountFromConfig = async config => {
|
|
18
|
-
const { default: selectedDefault } = await promptUser([
|
|
19
|
-
{
|
|
20
|
-
type: 'list',
|
|
21
|
-
look: false,
|
|
22
|
-
name: 'default',
|
|
23
|
-
pageSize: 20,
|
|
24
|
-
message: i18n(`${i18nKey}.promptMessage`),
|
|
25
|
-
choices: config.portals.map(p => p.name || p.portalId),
|
|
26
|
-
default: config.defaultPortal,
|
|
27
|
-
},
|
|
28
|
-
]);
|
|
29
|
-
|
|
30
|
-
return selectedDefault;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
exports.command = 'default-account [newDefault]';
|
|
34
|
-
exports.describe = i18n(`${i18nKey}.describe`);
|
|
35
|
-
|
|
36
|
-
exports.handler = async options => {
|
|
37
|
-
await loadAndValidateOptions(options);
|
|
38
|
-
|
|
39
|
-
const accountId = getAccountId(options);
|
|
40
|
-
const config = getConfig();
|
|
41
|
-
const configPath = getConfigPath();
|
|
42
|
-
const { newDefault: specifiedNewDefault } = options;
|
|
43
|
-
let newDefault;
|
|
44
|
-
|
|
45
|
-
trackCommandUsage('config-set-default-account', {}, accountId);
|
|
46
|
-
|
|
47
|
-
if (!specifiedNewDefault) {
|
|
48
|
-
newDefault = await selectAccountFromConfig(config);
|
|
49
|
-
} else if (
|
|
50
|
-
specifiedNewDefault &&
|
|
51
|
-
config.portals.find(
|
|
52
|
-
p => p.name === specifiedNewDefault || p.portalId === specifiedNewDefault
|
|
53
|
-
)
|
|
54
|
-
) {
|
|
55
|
-
newDefault = specifiedNewDefault;
|
|
56
|
-
} else {
|
|
57
|
-
logger.error(
|
|
58
|
-
i18n(`${i18nKey}.errors.accountNotFound`, {
|
|
59
|
-
specifiedAccount: specifiedNewDefault,
|
|
60
|
-
configPath,
|
|
61
|
-
})
|
|
62
|
-
);
|
|
63
|
-
newDefault = await selectAccountFromConfig(config);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
updateDefaultAccount(newDefault);
|
|
67
|
-
|
|
68
|
-
return logger.success(
|
|
69
|
-
i18n(`${i18nKey}.success.defaultAccountUpdated`, {
|
|
70
|
-
accountName: newDefault,
|
|
71
|
-
})
|
|
72
|
-
);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
exports.builder = yargs => {
|
|
76
|
-
yargs.positional('newDefault', {
|
|
77
|
-
describe: i18n(`${i18nKey}.positionals.newDefault.describe`),
|
|
78
|
-
type: 'string',
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
yargs.example([
|
|
82
|
-
['$0 config set default-account', i18n(`${i18nKey}.examples.default`)],
|
|
83
|
-
[
|
|
84
|
-
'$0 config set default-account MyAccount',
|
|
85
|
-
i18n(`${i18nKey}.examples.nameBased`),
|
|
86
|
-
],
|
|
87
|
-
[
|
|
88
|
-
'$0 config set default-account 1234567',
|
|
89
|
-
i18n(`${i18nKey}.examples.idBased`),
|
|
90
|
-
],
|
|
91
|
-
]);
|
|
92
|
-
|
|
93
|
-
return yargs;
|
|
94
|
-
};
|
package/commands/server.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const shell = require('shelljs');
|
|
4
|
-
const {
|
|
5
|
-
loadConfig,
|
|
6
|
-
validateConfig,
|
|
7
|
-
checkAndWarnGitInclusion,
|
|
8
|
-
getConfigPath,
|
|
9
|
-
} = require('@hubspot/cli-lib');
|
|
10
|
-
const { logger } = require('@hubspot/cli-lib/logger');
|
|
11
|
-
const { getCwd } = require('@hubspot/cli-lib/path');
|
|
12
|
-
|
|
13
|
-
const { version } = require('../package.json');
|
|
14
|
-
const { updateServerContext } = require('../lib/server/updateContext');
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
addConfigOptions,
|
|
18
|
-
addLoggerOptions,
|
|
19
|
-
addAccountOptions,
|
|
20
|
-
addUseEnvironmentOptions,
|
|
21
|
-
setLogLevel,
|
|
22
|
-
getAccountId,
|
|
23
|
-
} = require('../lib/commonOpts');
|
|
24
|
-
const { logDebugInfo } = require('../lib/debugInfo');
|
|
25
|
-
const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
26
|
-
|
|
27
|
-
const i18nKey = 'cli.commands.server';
|
|
28
|
-
const { EXIT_CODES } = require('../lib/enums/exitCodes');
|
|
29
|
-
|
|
30
|
-
function configureServerCommand(program) {
|
|
31
|
-
program
|
|
32
|
-
.version(version)
|
|
33
|
-
.description(i18n(`${i18nKey}.description`))
|
|
34
|
-
.option('--serverConfig <serverConfig>')
|
|
35
|
-
.option('--contextDir [contextDir]')
|
|
36
|
-
.arguments('<src>')
|
|
37
|
-
.action(async (src, options) => {
|
|
38
|
-
setLogLevel(options);
|
|
39
|
-
logDebugInfo(options);
|
|
40
|
-
const { config: configPath, serverConfig, contextDir } = options;
|
|
41
|
-
loadConfig(configPath, options);
|
|
42
|
-
checkAndWarnGitInclusion(getConfigPath());
|
|
43
|
-
|
|
44
|
-
if (!validateConfig()) {
|
|
45
|
-
process.exit(EXIT_CODES.ERROR);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const accountId = getAccountId(options);
|
|
49
|
-
|
|
50
|
-
// TODO: add flag to bypass
|
|
51
|
-
logger.log(i18n(`${i18nKey}.fetching`, { accountId }));
|
|
52
|
-
await updateServerContext(accountId, path.join(getCwd(), contextDir));
|
|
53
|
-
|
|
54
|
-
const cwd = getCwd();
|
|
55
|
-
const cmd = `
|
|
56
|
-
docker run -p 8080:8080 \
|
|
57
|
-
-v ${cwd}/${src}:/local-cms-server/${src} \
|
|
58
|
-
-v ${cwd}/${contextDir}:/local-cms-server/${contextDir} \
|
|
59
|
-
-v ${cwd}/${serverConfig}:/local-cms-server/${serverConfig} \
|
|
60
|
-
hubspot/local-cms-server
|
|
61
|
-
`;
|
|
62
|
-
|
|
63
|
-
logger.log(i18n(`${i18nKey}.startingServer`));
|
|
64
|
-
logger.debug(
|
|
65
|
-
i18n(`${i18nKey}.runningServer`, {
|
|
66
|
-
cmd,
|
|
67
|
-
})
|
|
68
|
-
);
|
|
69
|
-
shell.exec(cmd, { async: true });
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
addLoggerOptions(program);
|
|
73
|
-
addAccountOptions(program);
|
|
74
|
-
addConfigOptions(program);
|
|
75
|
-
addUseEnvironmentOptions(program);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
module.exports = {
|
|
79
|
-
configureServerCommand,
|
|
80
|
-
};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs-extra');
|
|
3
|
-
const { logger } = require('@hubspot/cli-lib/logger');
|
|
4
|
-
const {
|
|
5
|
-
logErrorInstance,
|
|
6
|
-
ApiErrorContext,
|
|
7
|
-
} = require('@hubspot/cli-lib/errorHandlers');
|
|
8
|
-
const { fetchContent } = require('@hubspot/cli-lib/api/content');
|
|
9
|
-
const { fetchBlogs } = require('@hubspot/cli-lib/api/blogs');
|
|
10
|
-
const { fetchMenus } = require('@hubspot/cli-lib/api/designManager');
|
|
11
|
-
|
|
12
|
-
async function writeObjects(accountId, contextPath, objectType, objects) {
|
|
13
|
-
const dest = path.join(contextPath, objectType, accountId.toString());
|
|
14
|
-
logger.debug('Writing %s data to %s', objectType, dest);
|
|
15
|
-
fs.mkdirpSync(dest);
|
|
16
|
-
return Promise.all(
|
|
17
|
-
objects.map(async object => {
|
|
18
|
-
const filepath = path.join(dest, `${object.id}.json`);
|
|
19
|
-
return fs.writeJson(filepath, object);
|
|
20
|
-
})
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function fetchAll(accountId, apiHelper, params) {
|
|
25
|
-
let objects = [];
|
|
26
|
-
let count = 0;
|
|
27
|
-
let totalObjects = null;
|
|
28
|
-
let offset = 0;
|
|
29
|
-
|
|
30
|
-
while (totalObjects === null || count < totalObjects) {
|
|
31
|
-
const response = await apiHelper(accountId, { ...params, offset });
|
|
32
|
-
if (totalObjects === null) {
|
|
33
|
-
totalObjects = response.total;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
logger.debug(`Fetched ${response.objects.length} objects`);
|
|
37
|
-
count += response.objects.length;
|
|
38
|
-
offset += response.objects.length;
|
|
39
|
-
objects = objects.concat(response.objects);
|
|
40
|
-
}
|
|
41
|
-
return Promise.resolve(objects);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function copyDefaultContext(contextPath) {
|
|
45
|
-
const defaultContextPath = path.resolve(__dirname, '../../defaults/context');
|
|
46
|
-
const files = fs.readdirSync(defaultContextPath);
|
|
47
|
-
files.forEach(file => {
|
|
48
|
-
if (path.extname(file) !== '.json') {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const destPath = path.join(contextPath, file);
|
|
52
|
-
if (!fs.existsSync(destPath)) {
|
|
53
|
-
logger.debug(`Copying context file "${file}" to "${destPath}"`);
|
|
54
|
-
fs.copySync(path.resolve(defaultContextPath, file), destPath);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function updateServerContext(accountId, contextPath) {
|
|
60
|
-
copyDefaultContext(contextPath);
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const blogs = await fetchAll(accountId, fetchBlogs, { casing: 'snake_r' });
|
|
64
|
-
await writeObjects(accountId, contextPath, 'blogs', blogs);
|
|
65
|
-
} catch (e) {
|
|
66
|
-
logErrorInstance(
|
|
67
|
-
e,
|
|
68
|
-
new ApiErrorContext({
|
|
69
|
-
accountId,
|
|
70
|
-
})
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
try {
|
|
74
|
-
const contentObjects = await fetchAll(accountId, fetchContent, {
|
|
75
|
-
casing: 'snake_r',
|
|
76
|
-
});
|
|
77
|
-
await writeObjects(accountId, contextPath, 'content', contentObjects);
|
|
78
|
-
} catch (e) {
|
|
79
|
-
logErrorInstance(
|
|
80
|
-
e,
|
|
81
|
-
new ApiErrorContext({
|
|
82
|
-
accountId,
|
|
83
|
-
})
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
const menus = await fetchAll(accountId, fetchMenus, {
|
|
88
|
-
casing: 'snake_r',
|
|
89
|
-
});
|
|
90
|
-
await writeObjects(accountId, contextPath, 'menus', menus);
|
|
91
|
-
} catch (e) {
|
|
92
|
-
logErrorInstance(
|
|
93
|
-
e,
|
|
94
|
-
new ApiErrorContext({
|
|
95
|
-
accountId,
|
|
96
|
-
})
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return Promise.resolve();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
module.exports = {
|
|
104
|
-
updateServerContext,
|
|
105
|
-
};
|