@hubspot/cli 7.2.0-experimental.0 → 7.2.2-experimental.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/bin/cli.js +52 -3
- package/commands/account/auth.d.ts +10 -0
- package/commands/account/auth.js +154 -0
- package/commands/account/createOverride.d.ts +10 -0
- package/commands/account/createOverride.js +62 -0
- package/commands/account/list.js +4 -0
- package/commands/account.js +4 -0
- package/commands/auth.js +9 -5
- package/commands/config/migrate.d.ts +10 -0
- package/commands/config/migrate.js +86 -0
- package/commands/config/set.d.ts +12 -0
- package/commands/config/set.js +30 -29
- package/commands/config.d.ts +4 -1
- package/commands/config.js +45 -10
- package/commands/create/api-sample.js +4 -14
- package/commands/customObject/create.d.ts +0 -11
- package/commands/customObject/create.js +28 -37
- package/commands/customObject/schema/create.d.ts +0 -10
- package/commands/customObject/schema/create.js +42 -40
- package/commands/customObject/schema/delete.d.ts +0 -11
- package/commands/customObject/schema/delete.js +27 -34
- package/commands/customObject/schema/fetch-all.d.ts +0 -10
- package/commands/customObject/schema/fetch-all.js +24 -31
- package/commands/customObject/schema/fetch.d.ts +0 -11
- package/commands/customObject/schema/fetch.js +42 -34
- package/commands/customObject/schema/list.d.ts +0 -7
- package/commands/customObject/schema/list.js +14 -23
- package/commands/customObject/schema/update.d.ts +0 -11
- package/commands/customObject/schema/update.js +46 -44
- package/commands/customObject/schema.d.ts +1 -5
- package/commands/customObject/schema.js +11 -49
- package/commands/customObject.d.ts +1 -4
- package/commands/customObject.js +21 -54
- package/commands/filemanager/fetch.d.ts +0 -12
- package/commands/filemanager/fetch.js +30 -33
- package/commands/filemanager/upload.d.ts +0 -11
- package/commands/filemanager/upload.js +47 -53
- package/commands/filemanager.d.ts +1 -4
- package/commands/filemanager.js +7 -41
- package/commands/init.js +15 -26
- package/commands/project/add.js +16 -62
- package/commands/project/cloneApp.js +3 -3
- package/commands/project/create.js +15 -70
- package/commands/project/dev.d.ts +0 -7
- package/commands/project/dev.js +75 -96
- package/commands/project/migrateApp.js +3 -3
- package/commands/project/upload.js +2 -7
- package/commands/sandbox/create.d.ts +0 -12
- package/commands/sandbox/create.js +72 -90
- package/commands/sandbox/delete.d.ts +0 -11
- package/commands/sandbox/delete.js +95 -112
- package/commands/sandbox.d.ts +1 -4
- package/commands/sandbox.js +10 -44
- package/commands/theme/generate-selectors.d.ts +0 -9
- package/commands/theme/generate-selectors.js +43 -61
- package/commands/theme/marketplace-validate.d.ts +0 -10
- package/commands/theme/marketplace-validate.js +26 -32
- package/commands/theme/preview.d.ts +0 -16
- package/commands/theme/preview.js +97 -104
- package/commands/theme.d.ts +1 -4
- package/commands/theme.js +10 -44
- package/lang/en.lyaml +67 -39
- package/lib/LocalDevManager.d.ts +2 -2
- package/lib/buildAccount.d.ts +3 -2
- package/lib/configMigrate.d.ts +2 -0
- package/lib/configMigrate.js +83 -0
- package/lib/constants.d.ts +3 -0
- package/lib/constants.js +4 -1
- package/lib/doctor/Diagnosis.d.ts +1 -0
- package/lib/doctor/Diagnosis.js +7 -0
- package/lib/doctor/DiagnosticInfoBuilder.d.ts +1 -6
- package/lib/doctor/DiagnosticInfoBuilder.js +1 -5
- package/lib/doctor/Doctor.d.ts +1 -1
- package/lib/doctor/Doctor.js +14 -6
- package/lib/localDev.d.ts +1 -2
- package/lib/marketplaceValidate.d.ts +2 -2
- package/lib/projects/buildAndDeploy.js +1 -4
- package/lib/projects/index.d.ts +5 -1
- package/lib/projects/index.js +62 -1
- package/lib/projects/upload.d.ts +1 -1
- package/lib/projects/upload.js +2 -2
- package/lib/prompts/accountNamePrompt.d.ts +1 -1
- package/lib/prompts/createProjectPrompt.d.ts +8 -6
- package/lib/prompts/createProjectPrompt.js +54 -26
- package/lib/prompts/projectAddPrompt.d.ts +3 -3
- package/lib/prompts/projectAddPrompt.js +6 -16
- package/lib/prompts/projectDevTargetAccountPrompt.d.ts +2 -3
- package/lib/prompts/sandboxesPrompt.d.ts +2 -3
- package/lib/prompts/sandboxesPrompt.js +1 -1
- package/lib/sandboxSync.js +2 -6
- package/lib/sandboxes.d.ts +5 -2
- package/lib/ui/index.d.ts +1 -1
- package/lib/ui/index.js +0 -1
- package/lib/upload.d.ts +1 -1
- package/lib/upload.js +20 -20
- package/lib/usageTracking.d.ts +1 -1
- package/lib/validation.d.ts +1 -1
- package/package.json +3 -4
- package/types/Projects.d.ts +6 -1
- package/types/Prompts.d.ts +0 -7
- package/types/Sandboxes.d.ts +0 -2
- package/types/Yargs.d.ts +0 -7
- package/lib/customObject.d.ts +0 -3
- package/lib/customObject.js +0 -15
- package/lib/projects/create.d.ts +0 -5
- package/lib/projects/create.js +0 -51
- package/lib/testUtils.d.ts +0 -12
- package/lib/testUtils.js +0 -10
|
@@ -1,78 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const usageTracking_1 = require("../../lib/usageTracking");
|
|
20
|
-
const lang_1 = require("../../lib/lang");
|
|
21
|
-
const exitCodes_1 = require("../../lib/enums/exitCodes");
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { uploadFolder } = require('@hubspot/local-dev-lib/fileManager');
|
|
7
|
+
const { uploadFile } = require('@hubspot/local-dev-lib/api/fileManager');
|
|
8
|
+
const { getCwd, convertToUnixPath } = require('@hubspot/local-dev-lib/path');
|
|
9
|
+
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
10
|
+
const { validateSrcAndDestPaths, } = require('@hubspot/local-dev-lib/cms/modules');
|
|
11
|
+
const { shouldIgnoreFile } = require('@hubspot/local-dev-lib/ignoreRules');
|
|
12
|
+
const { ApiErrorContext, logError } = require('../../lib/errorHandlers/index');
|
|
13
|
+
const { addConfigOptions, addGlobalOptions, addAccountOptions, addUseEnvironmentOptions, } = require('../../lib/commonOpts');
|
|
14
|
+
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
15
|
+
const { i18n } = require('../../lib/lang');
|
|
22
16
|
const i18nKey = 'commands.filemanager.subcommands.upload';
|
|
17
|
+
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
|
|
23
18
|
exports.command = 'upload <src> <dest>';
|
|
24
|
-
exports.describe =
|
|
25
|
-
async
|
|
26
|
-
const { src, dest, derivedAccountId } =
|
|
27
|
-
const absoluteSrcPath =
|
|
19
|
+
exports.describe = i18n(`${i18nKey}.describe`);
|
|
20
|
+
exports.handler = async (options) => {
|
|
21
|
+
const { src, dest, derivedAccountId } = options;
|
|
22
|
+
const absoluteSrcPath = path.resolve(getCwd(), src);
|
|
28
23
|
let stats;
|
|
29
24
|
try {
|
|
30
|
-
stats =
|
|
25
|
+
stats = fs.statSync(absoluteSrcPath);
|
|
31
26
|
if (!stats.isFile() && !stats.isDirectory()) {
|
|
32
|
-
|
|
27
|
+
logger.error(i18n(`${i18nKey}.errors.invalidPath`, {
|
|
33
28
|
path: src,
|
|
34
29
|
}));
|
|
35
30
|
return;
|
|
36
31
|
}
|
|
37
32
|
}
|
|
38
33
|
catch (e) {
|
|
39
|
-
|
|
34
|
+
logger.error(i18n(`${i18nKey}.errors.invalidPath`, {
|
|
40
35
|
path: src,
|
|
41
36
|
}));
|
|
42
37
|
return;
|
|
43
38
|
}
|
|
44
39
|
if (!dest) {
|
|
45
|
-
|
|
40
|
+
logger.error(i18n(`${i18nKey}.errors.destinationRequired`));
|
|
46
41
|
return;
|
|
47
42
|
}
|
|
48
|
-
const normalizedDest =
|
|
49
|
-
|
|
50
|
-
const srcDestIssues = await
|
|
43
|
+
const normalizedDest = convertToUnixPath(dest);
|
|
44
|
+
trackCommandUsage('filemanager-upload', { type: stats.isFile() ? 'file' : 'folder' }, derivedAccountId);
|
|
45
|
+
const srcDestIssues = await validateSrcAndDestPaths({ isLocal: true, path: src }, { isHubSpot: true, path: dest });
|
|
51
46
|
if (srcDestIssues.length) {
|
|
52
|
-
srcDestIssues.forEach(({ message }) =>
|
|
53
|
-
process.exit(
|
|
47
|
+
srcDestIssues.forEach(({ message }) => logger.error(message));
|
|
48
|
+
process.exit(EXIT_CODES.ERROR);
|
|
54
49
|
}
|
|
55
50
|
if (stats.isFile()) {
|
|
56
|
-
if (
|
|
57
|
-
|
|
51
|
+
if (shouldIgnoreFile(absoluteSrcPath)) {
|
|
52
|
+
logger.error(i18n(`${i18nKey}.errors.fileIgnored`, {
|
|
58
53
|
path: src,
|
|
59
54
|
}));
|
|
60
55
|
return;
|
|
61
56
|
}
|
|
62
|
-
|
|
57
|
+
uploadFile(derivedAccountId, absoluteSrcPath, normalizedDest)
|
|
63
58
|
.then(() => {
|
|
64
|
-
|
|
59
|
+
logger.success(i18n(`${i18nKey}.success.upload`, {
|
|
65
60
|
accountId: derivedAccountId,
|
|
66
61
|
dest: normalizedDest,
|
|
67
62
|
src,
|
|
68
63
|
}));
|
|
69
64
|
})
|
|
70
65
|
.catch(error => {
|
|
71
|
-
|
|
66
|
+
logger.error(i18n(`${i18nKey}.errors.upload`, {
|
|
72
67
|
dest: normalizedDest,
|
|
73
68
|
src,
|
|
74
69
|
}));
|
|
75
|
-
|
|
70
|
+
logError(error, new ApiErrorContext({
|
|
76
71
|
accountId: derivedAccountId,
|
|
77
72
|
request: normalizedDest,
|
|
78
73
|
payload: src,
|
|
@@ -80,37 +75,36 @@ async function handler(args) {
|
|
|
80
75
|
});
|
|
81
76
|
}
|
|
82
77
|
else {
|
|
83
|
-
|
|
78
|
+
logger.log(i18n(`${i18nKey}.logs.uploading`, {
|
|
84
79
|
accountId: derivedAccountId,
|
|
85
80
|
dest,
|
|
86
81
|
src,
|
|
87
82
|
}));
|
|
88
|
-
|
|
83
|
+
uploadFolder(derivedAccountId, absoluteSrcPath, dest)
|
|
89
84
|
.then(() => {
|
|
90
|
-
|
|
85
|
+
logger.success(i18n(`${i18nKey}.success.uploadComplete`, {
|
|
91
86
|
dest,
|
|
92
87
|
}));
|
|
93
88
|
})
|
|
94
89
|
.catch(error => {
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
logger.error(i18n(`${i18nKey}.errors.uploadingFailed`));
|
|
91
|
+
logError(error, {
|
|
97
92
|
accountId: derivedAccountId,
|
|
98
93
|
});
|
|
99
94
|
});
|
|
100
95
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
96
|
+
};
|
|
97
|
+
exports.builder = yargs => {
|
|
98
|
+
addGlobalOptions(yargs);
|
|
99
|
+
addConfigOptions(yargs);
|
|
100
|
+
addAccountOptions(yargs);
|
|
101
|
+
addUseEnvironmentOptions(yargs);
|
|
107
102
|
yargs.positional('src', {
|
|
108
|
-
describe:
|
|
103
|
+
describe: i18n(`${i18nKey}.positionals.src.describe`),
|
|
109
104
|
type: 'string',
|
|
110
105
|
});
|
|
111
106
|
yargs.positional('dest', {
|
|
112
|
-
describe:
|
|
107
|
+
describe: i18n(`${i18nKey}.positionals.dest.describe`),
|
|
113
108
|
type: 'string',
|
|
114
109
|
});
|
|
115
|
-
|
|
116
|
-
}
|
|
110
|
+
};
|
package/commands/filemanager.js
CHANGED
|
@@ -1,47 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const lang_1 = require("../lib/lang");
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
const upload = require('./filemanager/upload');
|
|
5
|
+
const fetch = require('./filemanager/fetch');
|
|
6
|
+
const { i18n } = require('../lib/lang');
|
|
41
7
|
const i18nKey = 'commands.filemanager';
|
|
42
8
|
exports.command = 'filemanager';
|
|
43
|
-
exports.describe =
|
|
44
|
-
|
|
9
|
+
exports.describe = i18n(`${i18nKey}.describe`);
|
|
10
|
+
exports.builder = yargs => {
|
|
45
11
|
yargs.command(upload).command(fetch).demandCommand(1, '');
|
|
46
12
|
return yargs;
|
|
47
|
-
}
|
|
13
|
+
};
|
package/commands/init.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
// @ts-nocheck
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const fs = require('fs-extra');
|
|
6
|
-
const { getConfigPath, createEmptyConfigFile, deleteEmptyConfigFile, updateDefaultAccount,
|
|
6
|
+
const { getConfigPath, createEmptyConfigFile, deleteEmptyConfigFile, updateDefaultAccount, configFileExists, } = require('@hubspot/local-dev-lib/config');
|
|
7
7
|
const { addConfigOptions, addGlobalOptions } = require('../lib/commonOpts');
|
|
8
8
|
const { handleExit } = require('../lib/process');
|
|
9
9
|
const { checkAndAddConfigToGitignore, } = require('@hubspot/local-dev-lib/gitignore');
|
|
@@ -67,11 +67,11 @@ exports.describe = i18n(`${i18nKey}.describe`, {
|
|
|
67
67
|
configName: DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
68
68
|
});
|
|
69
69
|
exports.handler = async (options) => {
|
|
70
|
-
const { authType: authTypeFlagValue, c: configFlagValue, providedAccountId, disableTracking,
|
|
70
|
+
const { authType: authTypeFlagValue, c: configFlagValue, providedAccountId, disableTracking, } = options;
|
|
71
71
|
const authType = (authTypeFlagValue && authTypeFlagValue.toLowerCase()) ||
|
|
72
72
|
PERSONAL_ACCESS_KEY_AUTH_METHOD.value;
|
|
73
73
|
const configPath = (configFlagValue && path.join(getCwd(), configFlagValue)) ||
|
|
74
|
-
getConfigPath(
|
|
74
|
+
getConfigPath();
|
|
75
75
|
setLogLevel(options);
|
|
76
76
|
if (!disableTracking) {
|
|
77
77
|
trackCommandUsage('init', {
|
|
@@ -79,6 +79,13 @@ exports.handler = async (options) => {
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
const env = options.qa ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD;
|
|
82
|
+
if (configFileExists(true)) {
|
|
83
|
+
const centralConfigPath = getConfigPath('', true);
|
|
84
|
+
logger.error(i18n(`${i18nKey}.errors.globalConfigFileExists`, {
|
|
85
|
+
configPath: centralConfigPath,
|
|
86
|
+
}));
|
|
87
|
+
process.exit(EXIT_CODES.ERROR);
|
|
88
|
+
}
|
|
82
89
|
if (fs.existsSync(configPath)) {
|
|
83
90
|
logger.error(i18n(`${i18nKey}.errors.configFileExists`, {
|
|
84
91
|
configPath,
|
|
@@ -89,32 +96,21 @@ exports.handler = async (options) => {
|
|
|
89
96
|
if (!disableTracking) {
|
|
90
97
|
await trackAuthAction('init', authType, TRACKING_STATUS.STARTED);
|
|
91
98
|
}
|
|
92
|
-
const doesOtherConfigFileExist = configFileExists(!useHiddenConfig);
|
|
93
|
-
if (doesOtherConfigFileExist) {
|
|
94
|
-
const path = getConfigPath('', !useHiddenConfig);
|
|
95
|
-
logger.error(i18n(`${i18nKey}.errors.bothConfigFilesNotAllowed`, { path }));
|
|
96
|
-
process.exit(EXIT_CODES.ERROR);
|
|
97
|
-
}
|
|
98
99
|
trackAuthAction('init', authType, TRACKING_STATUS.STARTED);
|
|
99
|
-
createEmptyConfigFile({ path: configPath }
|
|
100
|
-
//Needed to load deprecated config
|
|
101
|
-
loadConfig(configPath, options);
|
|
100
|
+
createEmptyConfigFile({ path: configPath });
|
|
102
101
|
handleExit(deleteEmptyConfigFile);
|
|
103
102
|
try {
|
|
104
103
|
const { accountId, name } = await CONFIG_CREATION_FLOWS[authType](env, providedAccountId);
|
|
104
|
+
const configPath = getConfigPath();
|
|
105
105
|
try {
|
|
106
106
|
checkAndAddConfigToGitignore(configPath);
|
|
107
107
|
}
|
|
108
108
|
catch (e) {
|
|
109
109
|
debugError(e);
|
|
110
110
|
}
|
|
111
|
-
let newConfigPath = configPath;
|
|
112
|
-
if (!newConfigPath && !useHiddenConfig) {
|
|
113
|
-
newConfigPath = `${getCwd()}/${DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}`;
|
|
114
|
-
}
|
|
115
111
|
logger.log('');
|
|
116
112
|
logger.success(i18n(`${i18nKey}.success.configFileCreated`, {
|
|
117
|
-
configPath
|
|
113
|
+
configPath,
|
|
118
114
|
}));
|
|
119
115
|
logger.success(i18n(`${i18nKey}.success.configFileUpdated`, {
|
|
120
116
|
authType: AUTH_TYPE_NAMES[authType],
|
|
@@ -135,8 +131,7 @@ exports.handler = async (options) => {
|
|
|
135
131
|
}
|
|
136
132
|
};
|
|
137
133
|
exports.builder = yargs => {
|
|
138
|
-
yargs
|
|
139
|
-
.options({
|
|
134
|
+
yargs.options({
|
|
140
135
|
'auth-type': {
|
|
141
136
|
describe: i18n(`${i18nKey}.options.authType.describe`),
|
|
142
137
|
type: 'string',
|
|
@@ -159,13 +154,7 @@ exports.builder = yargs => {
|
|
|
159
154
|
hidden: true,
|
|
160
155
|
default: false,
|
|
161
156
|
},
|
|
162
|
-
|
|
163
|
-
describe: i18n(`${i18nKey}.options.useHiddenConfig.describe`),
|
|
164
|
-
hidden: true,
|
|
165
|
-
type: 'boolean',
|
|
166
|
-
},
|
|
167
|
-
})
|
|
168
|
-
.conflicts('use-hidden-config', 'config');
|
|
157
|
+
});
|
|
169
158
|
addConfigOptions(yargs);
|
|
170
159
|
addTestingOptions(yargs);
|
|
171
160
|
addGlobalOptions(yargs);
|
package/commands/project/add.js
CHANGED
|
@@ -1,88 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
// @ts-nocheck
|
|
4
|
-
const path = require('path');
|
|
5
4
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
6
|
-
const {
|
|
7
|
-
const {
|
|
5
|
+
const { logError } = require('../../lib/errorHandlers/index');
|
|
6
|
+
const { fetchReleaseData } = require('@hubspot/local-dev-lib/github');
|
|
8
7
|
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
9
8
|
const { i18n } = require('../../lib/lang');
|
|
10
9
|
const { projectAddPrompt } = require('../../lib/prompts/projectAddPrompt');
|
|
11
|
-
const {
|
|
12
|
-
const { getProjectComponentListFromRepo, } = require('../../lib/projects/create');
|
|
13
|
-
const { findProjectComponents } = require('../../lib/projects/structure');
|
|
14
|
-
const { ComponentTypes } = require('../../types/Projects');
|
|
10
|
+
const { createProjectComponent, getProjectComponentsByVersion, } = require('../../lib/projects');
|
|
15
11
|
const { uiBetaTag } = require('../../lib/ui');
|
|
16
12
|
const { HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, } = require('../../lib/constants');
|
|
17
|
-
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
|
|
18
13
|
const i18nKey = 'commands.project.subcommands.add';
|
|
19
14
|
exports.command = 'add';
|
|
20
15
|
exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false);
|
|
21
16
|
exports.handler = async (options) => {
|
|
22
17
|
const { derivedAccountId } = options;
|
|
23
|
-
trackCommandUsage('project-add', null, derivedAccountId);
|
|
24
|
-
const { projectConfig, projectDir } = await getProjectConfig();
|
|
25
|
-
if (!projectDir || !projectConfig) {
|
|
26
|
-
logger.error(i18n(`${i18nKey}.error.locationInProject`));
|
|
27
|
-
process.exit(EXIT_CODES.ERROR);
|
|
28
|
-
}
|
|
29
|
-
// We currently only support adding private apps to projects
|
|
30
|
-
let projectContainsPublicApp = false;
|
|
31
|
-
try {
|
|
32
|
-
const components = await findProjectComponents(projectDir);
|
|
33
|
-
projectContainsPublicApp = components.some(c => c.type === ComponentTypes.PublicApp);
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
debugError(err);
|
|
37
|
-
}
|
|
38
|
-
if (projectContainsPublicApp) {
|
|
39
|
-
logger.error(i18n(`${i18nKey}.error.projectContainsPublicApp`));
|
|
40
|
-
process.exit(EXIT_CODES.ERROR);
|
|
41
|
-
}
|
|
42
18
|
logger.log('');
|
|
43
|
-
logger.log(i18n(`${i18nKey}.creatingComponent
|
|
44
|
-
projectName: projectConfig.name,
|
|
45
|
-
}));
|
|
19
|
+
logger.log(i18n(`${i18nKey}.creatingComponent.message`));
|
|
46
20
|
logger.log('');
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
debugError(err);
|
|
57
|
-
}
|
|
58
|
-
if (!latestRepoReleaseTag) {
|
|
59
|
-
logger.error(i18n(`${i18nKey}.error.failedToFetchComponentList`));
|
|
60
|
-
process.exit(EXIT_CODES.ERROR);
|
|
21
|
+
const releaseData = await fetchReleaseData(HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH);
|
|
22
|
+
const projectComponentsVersion = releaseData.tag_name;
|
|
23
|
+
const components = await getProjectComponentsByVersion(projectComponentsVersion);
|
|
24
|
+
let { component, name } = await projectAddPrompt(components, options);
|
|
25
|
+
name = name || options.name;
|
|
26
|
+
if (!component) {
|
|
27
|
+
component = components.find(t => t.path === options.type);
|
|
61
28
|
}
|
|
62
|
-
|
|
63
|
-
if (!components.length) {
|
|
64
|
-
logger.error(i18n(`${i18nKey}.error.failedToFetchComponentList`));
|
|
65
|
-
process.exit(EXIT_CODES.ERROR);
|
|
66
|
-
}
|
|
67
|
-
const projectAddPromptResponse = await projectAddPrompt(components, options);
|
|
29
|
+
trackCommandUsage('project-add', null, derivedAccountId);
|
|
68
30
|
try {
|
|
69
|
-
|
|
70
|
-
await cloneGithubRepo(HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, componentPath, {
|
|
71
|
-
sourceDir: projectAddPromptResponse.componentTemplate.path,
|
|
72
|
-
tag: latestRepoReleaseTag,
|
|
73
|
-
hideLogs: true,
|
|
74
|
-
});
|
|
31
|
+
await createProjectComponent(component, name, projectComponentsVersion);
|
|
75
32
|
logger.log('');
|
|
76
|
-
logger.
|
|
77
|
-
componentName:
|
|
33
|
+
logger.log(i18n(`${i18nKey}.success.message`, {
|
|
34
|
+
componentName: name,
|
|
78
35
|
}));
|
|
79
36
|
}
|
|
80
37
|
catch (error) {
|
|
81
|
-
|
|
82
|
-
logger.error(i18n(`${i18nKey}.error.failedToDownloadComponent`));
|
|
83
|
-
process.exit(EXIT_CODES.ERROR);
|
|
38
|
+
logError(error);
|
|
84
39
|
}
|
|
85
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
86
40
|
};
|
|
87
41
|
exports.builder = yargs => {
|
|
88
42
|
yargs.options({
|
|
@@ -53,9 +53,9 @@ exports.handler = async (options) => {
|
|
|
53
53
|
});
|
|
54
54
|
appId = appIdResponse.appId;
|
|
55
55
|
}
|
|
56
|
-
const
|
|
57
|
-
projectName =
|
|
58
|
-
projectDest =
|
|
56
|
+
const { name, dest } = await createProjectPrompt('', options, true);
|
|
57
|
+
projectName = name;
|
|
58
|
+
projectDest = options.dest || dest;
|
|
59
59
|
}
|
|
60
60
|
catch (error) {
|
|
61
61
|
logError(error, new ApiErrorContext({ accountId: derivedAccountId }));
|
|
@@ -1,86 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
// @ts-nocheck
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const fs = require('fs-extra');
|
|
6
|
-
const chalk = require('chalk');
|
|
7
|
-
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
8
|
-
const { fetchReleaseData, cloneGithubRepo, } = require('@hubspot/local-dev-lib/github');
|
|
9
|
-
const { getCwd } = require('@hubspot/local-dev-lib/path');
|
|
10
4
|
const { addAccountOptions, addConfigOptions, addUseEnvironmentOptions, } = require('../../lib/commonOpts');
|
|
11
5
|
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
6
|
+
const { getCwd } = require('@hubspot/local-dev-lib/path');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const chalk = require('chalk');
|
|
12
9
|
const { createProjectPrompt, } = require('../../lib/prompts/createProjectPrompt');
|
|
13
|
-
const {
|
|
14
|
-
const { getProjectTemplateListFromRepo, EMPTY_PROJECT_TEMPLATE_NAME, } = require('../../lib/projects/create');
|
|
10
|
+
const { createProjectConfig } = require('../../lib/projects');
|
|
15
11
|
const { i18n } = require('../../lib/lang');
|
|
16
12
|
const { uiBetaTag, uiFeatureHighlight } = require('../../lib/ui');
|
|
17
|
-
const {
|
|
18
|
-
const {
|
|
19
|
-
const {
|
|
13
|
+
const { HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, } = require('../../lib/constants');
|
|
14
|
+
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
15
|
+
const { fetchReleaseData } = require('@hubspot/local-dev-lib/github');
|
|
20
16
|
const i18nKey = 'commands.project.subcommands.create';
|
|
21
17
|
exports.command = 'create';
|
|
22
18
|
exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false);
|
|
23
19
|
exports.handler = async (options) => {
|
|
24
20
|
const { derivedAccountId } = options;
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
if (!
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const releaseData = await fetchReleaseData(HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH);
|
|
31
|
-
if (releaseData) {
|
|
32
|
-
latestRepoReleaseTag = releaseData.tag_name;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
logger.error(i18n(`${i18nKey}.error.failedToFetchProjectList`));
|
|
37
|
-
process.exit(EXIT_CODES.ERROR);
|
|
38
|
-
}
|
|
21
|
+
const hasCustomTemplateSource = Boolean(options.templateSource);
|
|
22
|
+
let githubRef = '';
|
|
23
|
+
if (!hasCustomTemplateSource) {
|
|
24
|
+
const releaseData = await fetchReleaseData(HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH);
|
|
25
|
+
githubRef = releaseData.tag_name;
|
|
39
26
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
process.exit(EXIT_CODES.ERROR);
|
|
44
|
-
}
|
|
45
|
-
const createProjectPromptResponse = await createProjectPrompt(options, projectTemplates);
|
|
46
|
-
const projectDest = path.resolve(getCwd(), createProjectPromptResponse.dest);
|
|
47
|
-
trackCommandUsage('project-create', { type: createProjectPromptResponse.projectTemplate.name }, derivedAccountId);
|
|
48
|
-
const { projectConfig: existingProjectConfig, projectDir: existingProjectDir, } = await getProjectConfig(projectDest);
|
|
49
|
-
// Exit if the target destination is within an existing project
|
|
50
|
-
if (existingProjectConfig && projectDest.startsWith(existingProjectDir)) {
|
|
51
|
-
logger.error(i18n(`${i18nKey}.errors.cannotNestProjects`, {
|
|
52
|
-
projectDir: existingProjectDir,
|
|
53
|
-
}));
|
|
54
|
-
process.exit(EXIT_CODES.ERROR);
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
await cloneGithubRepo(templateSource, projectDest, {
|
|
58
|
-
sourceDir: createProjectPromptResponse.projectTemplate.path,
|
|
59
|
-
tag: latestRepoReleaseTag,
|
|
60
|
-
hideLogs: true,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
debugError(err);
|
|
65
|
-
logger.error(i18n(`${i18nKey}.errors.failedToDownloadProject`));
|
|
66
|
-
process.exit(EXIT_CODES.ERROR);
|
|
67
|
-
}
|
|
68
|
-
const projectConfigPath = path.join(projectDest, PROJECT_CONFIG_FILE);
|
|
69
|
-
const parsedConfigFile = JSON.parse(fs.readFileSync(projectConfigPath).toString());
|
|
70
|
-
writeProjectConfig(projectConfigPath, {
|
|
71
|
-
...parsedConfigFile,
|
|
72
|
-
name: createProjectPromptResponse.name,
|
|
73
|
-
});
|
|
74
|
-
// If the template is 'no-template', we need to manually create a src directory
|
|
75
|
-
if (createProjectPromptResponse.projectTemplate.name ===
|
|
76
|
-
EMPTY_PROJECT_TEMPLATE_NAME) {
|
|
77
|
-
fs.ensureDirSync(path.join(projectDest, 'src'));
|
|
78
|
-
}
|
|
79
|
-
logger.log('');
|
|
80
|
-
logger.success(i18n(`${i18nKey}.logs.success`, {
|
|
81
|
-
projectName: createProjectPromptResponse.name,
|
|
82
|
-
projectDest,
|
|
83
|
-
}));
|
|
27
|
+
const { name, template, dest } = await createProjectPrompt(githubRef, options);
|
|
28
|
+
trackCommandUsage('project-create', { type: template.name }, derivedAccountId);
|
|
29
|
+
await createProjectConfig(path.resolve(getCwd(), options.dest || dest), options.name || name, template, options.templateSource, githubRef);
|
|
84
30
|
logger.log('');
|
|
85
31
|
logger.log(chalk.bold(i18n(`${i18nKey}.logs.welcomeMessage`)));
|
|
86
32
|
uiFeatureHighlight([
|
|
@@ -89,7 +35,6 @@ exports.handler = async (options) => {
|
|
|
89
35
|
'feedbackCommand',
|
|
90
36
|
'sampleProjects',
|
|
91
37
|
]);
|
|
92
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
93
38
|
};
|
|
94
39
|
exports.builder = yargs => {
|
|
95
40
|
yargs.options({
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
import { ArgumentsCamelCase, Argv } from 'yargs';
|
|
2
|
-
import { CommonArgs, ConfigArgs, EnvironmentArgs } from '../../types/Yargs';
|
|
3
|
-
export declare const command = "dev";
|
|
4
|
-
export declare const describe: string | undefined;
|
|
5
|
-
type ProjectDevArgs = CommonArgs & ConfigArgs & EnvironmentArgs;
|
|
6
|
-
export declare function handler(args: ArgumentsCamelCase<ProjectDevArgs>): Promise<void>;
|
|
7
|
-
export declare function builder(yargs: Argv): Argv<ProjectDevArgs>;
|
|
8
1
|
export {};
|