@hubspot/cli 7.7.0-experimental.3 → 7.7.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 +96 -94
- package/commands/account/auth.js +51 -82
- package/commands/account.js +0 -2
- package/commands/app.js +0 -2
- package/commands/auth.js +2 -17
- package/commands/cms.js +0 -2
- package/commands/completion.js +0 -2
- package/commands/config/migrate.js +17 -36
- package/commands/config.js +0 -2
- package/commands/create.js +0 -2
- package/commands/customObject.js +0 -2
- package/commands/doctor.js +0 -2
- package/commands/feedback.js +0 -2
- package/commands/filemanager.js +0 -2
- package/commands/function.js +0 -2
- package/commands/hubdb.js +0 -2
- package/commands/init.js +1 -4
- package/commands/lint.js +0 -2
- package/commands/list.js +0 -2
- package/commands/module/marketplace-validate.js +6 -8
- package/commands/module.js +2 -1
- package/commands/mv.js +0 -2
- package/commands/open.js +0 -2
- package/commands/project/add.d.ts +5 -2
- package/commands/project/add.js +43 -80
- package/commands/project/create.d.ts +2 -8
- package/commands/project/create.js +84 -55
- package/commands/project/dev/deprecatedFlow.d.ts +8 -2
- package/commands/project/dev/deprecatedFlow.js +9 -1
- package/commands/project/dev/index.js +59 -34
- package/commands/project/dev/unifiedFlow.d.ts +10 -2
- package/commands/project/dev/unifiedFlow.js +28 -41
- package/commands/project.js +0 -2
- package/commands/remove.js +6 -14
- package/commands/sandbox.js +0 -2
- package/commands/secret.js +0 -2
- package/commands/theme/generate-selectors.js +7 -10
- package/commands/theme/marketplace-validate.js +6 -8
- package/commands/theme/preview.js +17 -18
- package/commands/theme.js +2 -4
- package/commands/upload.js +26 -65
- package/commands/watch.js +20 -32
- package/lang/en.d.ts +154 -95
- package/lang/en.js +156 -100
- package/lang/en.lyaml +3 -186
- package/lib/accountTypes.js +1 -3
- package/lib/commonOpts.d.ts +1 -3
- package/lib/commonOpts.js +1 -1
- package/lib/configMigrate.d.ts +2 -2
- package/lib/configMigrate.js +34 -69
- package/lib/constants.d.ts +23 -5
- package/lib/constants.js +24 -6
- package/lib/generateSelectors.js +3 -5
- package/lib/marketplaceValidate.d.ts +12 -2
- package/lib/marketplaceValidate.js +22 -29
- package/lib/middleware/configMiddleware.js +1 -0
- package/lib/middleware/fireAlarmMiddleware.d.ts +2 -2
- package/lib/middleware/fireAlarmMiddleware.js +5 -3
- package/lib/projects/add/legacyAddComponent.d.ts +5 -0
- package/lib/projects/add/legacyAddComponent.js +48 -0
- package/lib/projects/add/v3AddComponent.d.ts +8 -0
- package/lib/projects/add/v3AddComponent.js +85 -0
- package/lib/projects/components.d.ts +2 -0
- package/lib/projects/components.js +82 -0
- package/lib/projects/create/index.d.ts +23 -0
- package/lib/projects/create/index.js +33 -0
- package/lib/projects/create/legacy.d.ts +6 -0
- package/lib/projects/{create.js → create/legacy.js} +20 -11
- package/lib/projects/create/v3.d.ts +27 -0
- package/lib/projects/create/v3.js +158 -0
- package/lib/projects/localDev/AppDevModeInterface.d.ts +3 -2
- package/lib/projects/localDev/AppDevModeInterface.js +38 -8
- package/lib/projects/localDev/LocalDevProcess.d.ts +12 -5
- package/lib/projects/localDev/LocalDevProcess.js +47 -17
- package/lib/projects/localDev/LocalDevState.d.ts +16 -3
- package/lib/projects/localDev/LocalDevState.js +43 -2
- package/lib/projects/localDev/LocalDevWatcher.js +3 -6
- package/lib/projects/localDev/LocalDevWebsocketServer.d.ts +3 -0
- package/lib/projects/localDev/LocalDevWebsocketServer.js +48 -9
- package/lib/projects/upload.js +6 -0
- package/lib/prompts/createProjectPrompt.d.ts +14 -5
- package/lib/prompts/createProjectPrompt.js +36 -13
- package/lib/prompts/projectAddPrompt.d.ts +5 -1
- package/lib/prompts/projectAddPrompt.js +35 -7
- package/lib/prompts/promptUtils.d.ts +0 -1
- package/lib/prompts/promptUtils.js +0 -2
- package/lib/prompts/setAsDefaultAccountPrompt.js +10 -0
- package/package.json +7 -6
- package/types/LocalDev.d.ts +11 -1
- package/types/Projects.d.ts +19 -2
- package/types/Yargs.d.ts +2 -0
- package/commands/testAccount/create.d.ts +0 -7
- package/commands/testAccount/create.js +0 -118
- package/commands/testAccount/delete.d.ts +0 -6
- package/commands/testAccount/delete.js +0 -42
- package/commands/testAccount.d.ts +0 -3
- package/commands/testAccount.js +0 -27
- package/lib/projects/create.d.ts +0 -5
|
@@ -10,8 +10,7 @@ exports.processValidationErrors = processValidationErrors;
|
|
|
10
10
|
exports.displayValidationResults = displayValidationResults;
|
|
11
11
|
const chalk_1 = __importDefault(require("chalk"));
|
|
12
12
|
const marketplaceValidation_1 = require("@hubspot/local-dev-lib/api/marketplaceValidation");
|
|
13
|
-
const logger_1 = require("
|
|
14
|
-
const lang_1 = require("./lang");
|
|
13
|
+
const logger_1 = require("./ui/logger");
|
|
15
14
|
const exitCodes_1 = require("./enums/exitCodes");
|
|
16
15
|
const SLEEP_TIME = 2000;
|
|
17
16
|
async function kickOffValidation(accountId, assetType, src) {
|
|
@@ -25,7 +24,7 @@ async function kickOffValidation(accountId, assetType, src) {
|
|
|
25
24
|
return requestResult;
|
|
26
25
|
}
|
|
27
26
|
catch (err) {
|
|
28
|
-
logger_1.
|
|
27
|
+
logger_1.uiLogger.debug(err);
|
|
29
28
|
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
30
29
|
}
|
|
31
30
|
}
|
|
@@ -43,7 +42,7 @@ async function pollForValidationFinish(accountId, validationId) {
|
|
|
43
42
|
await checkValidationStatus();
|
|
44
43
|
}
|
|
45
44
|
catch (err) {
|
|
46
|
-
logger_1.
|
|
45
|
+
logger_1.uiLogger.debug(err);
|
|
47
46
|
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
48
47
|
}
|
|
49
48
|
}
|
|
@@ -55,69 +54,63 @@ async function fetchValidationResults(accountId, validationId) {
|
|
|
55
54
|
return validationResults;
|
|
56
55
|
}
|
|
57
56
|
catch (err) {
|
|
58
|
-
logger_1.
|
|
57
|
+
logger_1.uiLogger.debug(err);
|
|
59
58
|
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
|
-
function processValidationErrors(
|
|
61
|
+
function processValidationErrors(invalidPathError, validationResults) {
|
|
63
62
|
if (validationResults.errors.length) {
|
|
64
63
|
const { assetPath, errors } = validationResults;
|
|
65
64
|
errors.forEach(err => {
|
|
66
65
|
if (err.failureReasonType === 'DOWNLOAD_EMPTY') {
|
|
67
|
-
logger_1.
|
|
68
|
-
path: assetPath,
|
|
69
|
-
}));
|
|
66
|
+
logger_1.uiLogger.error(invalidPathError(assetPath));
|
|
70
67
|
}
|
|
71
68
|
else {
|
|
72
|
-
logger_1.
|
|
69
|
+
logger_1.uiLogger.error(`${err.context}`);
|
|
73
70
|
}
|
|
74
71
|
});
|
|
75
72
|
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
|
-
function displayFileInfo(file, line,
|
|
75
|
+
function displayFileInfo(file, line, resultsCopy) {
|
|
79
76
|
if (file) {
|
|
80
|
-
logger_1.
|
|
81
|
-
file,
|
|
82
|
-
}));
|
|
77
|
+
logger_1.uiLogger.log(resultsCopy.warnings.file(file));
|
|
83
78
|
}
|
|
84
79
|
if (line) {
|
|
85
|
-
logger_1.
|
|
86
|
-
line,
|
|
87
|
-
}));
|
|
80
|
+
logger_1.uiLogger.log(resultsCopy.warnings.lineNumber(line.toString()));
|
|
88
81
|
}
|
|
89
82
|
}
|
|
90
|
-
function displayResults(checks,
|
|
83
|
+
function displayResults(checks, resultsCopy) {
|
|
91
84
|
if (checks) {
|
|
92
85
|
const { status, results } = checks;
|
|
93
86
|
if (status === 'FAIL') {
|
|
94
87
|
const failedValidations = results.filter(test => test.status === 'FAIL');
|
|
95
88
|
const warningValidations = results.filter(test => test.status === 'WARN');
|
|
96
89
|
failedValidations.forEach(val => {
|
|
97
|
-
logger_1.
|
|
98
|
-
displayFileInfo(val.file, val.line,
|
|
90
|
+
logger_1.uiLogger.error(`${val.message}`);
|
|
91
|
+
displayFileInfo(val.file, val.line, resultsCopy);
|
|
99
92
|
});
|
|
100
93
|
warningValidations.forEach(val => {
|
|
101
|
-
logger_1.
|
|
102
|
-
displayFileInfo(val.file, val.line,
|
|
94
|
+
logger_1.uiLogger.warn(`${val.message}`);
|
|
95
|
+
displayFileInfo(val.file, val.line, resultsCopy);
|
|
103
96
|
});
|
|
104
97
|
}
|
|
105
98
|
if (status === 'PASS') {
|
|
106
|
-
logger_1.
|
|
99
|
+
logger_1.uiLogger.success(resultsCopy.noErrors);
|
|
107
100
|
results.forEach(test => {
|
|
108
101
|
if (test.status === 'WARN') {
|
|
109
|
-
logger_1.
|
|
110
|
-
displayFileInfo(test.file, test.line,
|
|
102
|
+
logger_1.uiLogger.warn(`${test.message}`);
|
|
103
|
+
displayFileInfo(test.file, test.line, resultsCopy);
|
|
111
104
|
}
|
|
112
105
|
});
|
|
113
106
|
}
|
|
114
107
|
}
|
|
115
108
|
return;
|
|
116
109
|
}
|
|
117
|
-
function displayValidationResults(
|
|
110
|
+
function displayValidationResults(resultsCopy, validationResults) {
|
|
118
111
|
Object.keys(validationResults.results).forEach(type => {
|
|
119
|
-
logger_1.
|
|
120
|
-
displayResults(validationResults.results[type],
|
|
121
|
-
logger_1.
|
|
112
|
+
logger_1.uiLogger.log(chalk_1.default.bold(resultsCopy[type.toLowerCase()]));
|
|
113
|
+
displayResults(validationResults.results[type], resultsCopy);
|
|
114
|
+
logger_1.uiLogger.log('');
|
|
122
115
|
});
|
|
123
116
|
}
|
|
@@ -112,10 +112,12 @@ async function logFireAlarms(accountId, command, version) {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
async function checkFireAlarms(
|
|
116
|
-
const { derivedAccountId } =
|
|
115
|
+
async function checkFireAlarms(argv) {
|
|
116
|
+
const { derivedAccountId } = argv;
|
|
117
117
|
try {
|
|
118
|
-
|
|
118
|
+
if (derivedAccountId) {
|
|
119
|
+
await logFireAlarms(derivedAccountId, argv._.join(' '), package_json_1.default.version);
|
|
120
|
+
}
|
|
119
121
|
}
|
|
120
122
|
catch (error) {
|
|
121
123
|
(0, errorHandlers_1.debugError)(error);
|
|
@@ -0,0 +1,48 @@
|
|
|
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.legacyAddComponent = legacyAddComponent;
|
|
7
|
+
const Projects_1 = require("../../../types/Projects");
|
|
8
|
+
const structure_1 = require("../structure");
|
|
9
|
+
const errorHandlers_1 = require("../../errorHandlers");
|
|
10
|
+
const en_1 = require("../../../lang/en");
|
|
11
|
+
const legacy_1 = require("../create/legacy");
|
|
12
|
+
const projectAddPrompt_1 = require("../../prompts/projectAddPrompt");
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const constants_1 = require("../../constants");
|
|
15
|
+
const github_1 = require("@hubspot/local-dev-lib/github");
|
|
16
|
+
const logger_1 = require("../../ui/logger");
|
|
17
|
+
async function legacyAddComponent(args, projectDir, projectConfig) {
|
|
18
|
+
// We currently only support adding private apps to projects
|
|
19
|
+
let projectContainsPublicApp = false;
|
|
20
|
+
try {
|
|
21
|
+
const components = await (0, structure_1.findProjectComponents)(projectDir);
|
|
22
|
+
projectContainsPublicApp = components.some(c => c.type === Projects_1.ComponentTypes.PublicApp);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
(0, errorHandlers_1.debugError)(err);
|
|
26
|
+
}
|
|
27
|
+
if (projectContainsPublicApp) {
|
|
28
|
+
throw new Error(en_1.commands.project.add.error.projectContainsPublicApp);
|
|
29
|
+
}
|
|
30
|
+
logger_1.uiLogger.log(en_1.commands.project.add.creatingComponent(projectConfig.name));
|
|
31
|
+
const components = await (0, legacy_1.getProjectComponentListFromRepo)(projectConfig.platformVersion);
|
|
32
|
+
if (!components || !components.length) {
|
|
33
|
+
throw new Error(en_1.commands.project.add.error.failedToFetchComponentList);
|
|
34
|
+
}
|
|
35
|
+
const projectAddPromptResponse = await (0, projectAddPrompt_1.projectAddPrompt)(components, args);
|
|
36
|
+
try {
|
|
37
|
+
const componentPath = path_1.default.join(projectDir, projectConfig.srcDir, projectAddPromptResponse.name);
|
|
38
|
+
await (0, github_1.cloneGithubRepo)(constants_1.HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, componentPath, {
|
|
39
|
+
sourceDir: projectAddPromptResponse.componentTemplate.path,
|
|
40
|
+
branch: 'main',
|
|
41
|
+
hideLogs: true,
|
|
42
|
+
});
|
|
43
|
+
logger_1.uiLogger.success(en_1.commands.project.add.success(projectAddPromptResponse.name));
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw new Error(en_1.commands.project.add.error.failedToDownloadComponent);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ProjectConfig } from '../../../types/Projects';
|
|
2
|
+
export declare function v3AddComponent(args: {
|
|
3
|
+
name?: string;
|
|
4
|
+
type?: string;
|
|
5
|
+
features?: string[];
|
|
6
|
+
auth?: string;
|
|
7
|
+
distribution?: string;
|
|
8
|
+
}, projectDir: string, projectConfig: ProjectConfig): Promise<void>;
|
|
@@ -0,0 +1,85 @@
|
|
|
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.v3AddComponent = v3AddComponent;
|
|
7
|
+
const en_1 = require("../../../lang/en");
|
|
8
|
+
const legacy_1 = require("../create/legacy");
|
|
9
|
+
const v3_1 = require("../create/v3");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
|
+
const projectAddPrompt_1 = require("../../prompts/projectAddPrompt");
|
|
13
|
+
const constants_1 = require("../../constants");
|
|
14
|
+
const components_1 = require("../components");
|
|
15
|
+
const project_1 = require("@hubspot/project-parsing-lib/src/lib/project");
|
|
16
|
+
const constants_2 = require("@hubspot/project-parsing-lib/src/lib/constants");
|
|
17
|
+
const github_1 = require("@hubspot/local-dev-lib/github");
|
|
18
|
+
const errorHandlers_1 = require("../../errorHandlers");
|
|
19
|
+
const logger_1 = require("../../ui/logger");
|
|
20
|
+
async function v3AddComponent(args, projectDir, projectConfig) {
|
|
21
|
+
logger_1.uiLogger.log(en_1.commands.project.add.creatingComponent(projectConfig.name));
|
|
22
|
+
const config = await (0, legacy_1.getConfigForPlatformVersion)(projectConfig.platformVersion);
|
|
23
|
+
const { components, parentComponents } = config;
|
|
24
|
+
if (!components || !components.length) {
|
|
25
|
+
throw new Error(en_1.commands.project.add.error.failedToFetchComponentList);
|
|
26
|
+
}
|
|
27
|
+
const projectSrcDirectory = path_1.default.join(projectDir, projectConfig.srcDir);
|
|
28
|
+
const projectMetadata = await (0, project_1.getProjectMetadata)(projectSrcDirectory);
|
|
29
|
+
let derivedAuthType;
|
|
30
|
+
let derivedDistribution;
|
|
31
|
+
const appsMetadata = projectMetadata.components[constants_2.AppKey];
|
|
32
|
+
const shouldCreateApp = appsMetadata.count === 0;
|
|
33
|
+
if (shouldCreateApp) {
|
|
34
|
+
const { authType, distribution } = await (0, v3_1.createV3App)(args.auth, args.distribution);
|
|
35
|
+
derivedDistribution = distribution;
|
|
36
|
+
derivedAuthType = authType;
|
|
37
|
+
}
|
|
38
|
+
else if (appsMetadata.count > appsMetadata.maxCount) {
|
|
39
|
+
throw new Error(en_1.lib.projects.create.errors.exceededMaxNumberOfApps(appsMetadata.maxCount));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const apps = appsMetadata.hsMetaFiles.map(appLoc => {
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(fs_1.default.readFileSync(appLoc, 'utf8'));
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
throw new Error(en_1.lib.projects.create.errors.unableToParseAppConfig(appLoc));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
derivedDistribution = apps[0].config?.distribution;
|
|
51
|
+
derivedAuthType = apps[0].config?.auth?.type;
|
|
52
|
+
}
|
|
53
|
+
const componentTemplateChoices = (0, v3_1.calculateComponentTemplateChoices)(components, derivedAuthType, derivedDistribution, projectMetadata);
|
|
54
|
+
const projectAddPromptResponse = await (0, projectAddPrompt_1.projectAddPromptV3)(componentTemplateChoices, args.features);
|
|
55
|
+
try {
|
|
56
|
+
const components = projectAddPromptResponse.componentTemplate?.map((componentTemplate) => {
|
|
57
|
+
return path_1.default.join(projectConfig.platformVersion, componentTemplate.path);
|
|
58
|
+
}) || [];
|
|
59
|
+
if (shouldCreateApp) {
|
|
60
|
+
const parentComponent = parentComponents?.find(possibleParent => {
|
|
61
|
+
return (possibleParent.type === v3_1.PROJECT_WITH_APP &&
|
|
62
|
+
possibleParent.authType === derivedAuthType &&
|
|
63
|
+
possibleParent.distribution === derivedDistribution);
|
|
64
|
+
});
|
|
65
|
+
if (parentComponent) {
|
|
66
|
+
components.push(path_1.default.join(projectConfig.platformVersion, parentComponent.path));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
await (0, github_1.cloneGithubRepo)(constants_1.HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, projectDir, {
|
|
70
|
+
sourceDir: components,
|
|
71
|
+
hideLogs: true,
|
|
72
|
+
branch: 'main',
|
|
73
|
+
handleCollision: components_1.handleComponentCollision,
|
|
74
|
+
});
|
|
75
|
+
logger_1.uiLogger.success(en_1.commands.project.add.success(projectAddPromptResponse.componentTemplate
|
|
76
|
+
.map(template => `'${template.label}'`)
|
|
77
|
+
.join(', '), projectAddPromptResponse.componentTemplate.length > 1));
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
(0, errorHandlers_1.debugError)(error);
|
|
81
|
+
throw new Error(en_1.commands.project.add.error.failedToDownloadComponent, {
|
|
82
|
+
cause: error,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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.handleComponentCollision = handleComponentCollision;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const project_parsing_lib_1 = require("@hubspot/project-parsing-lib");
|
|
10
|
+
// Handles a collision between component source files
|
|
11
|
+
function handleComponentCollision({ dest, src, collisions }) {
|
|
12
|
+
const hsMetaFiles = [];
|
|
13
|
+
const packageJsonFiles = [];
|
|
14
|
+
const sourceFiles = [];
|
|
15
|
+
collisions.forEach(collision => {
|
|
16
|
+
if (collision.endsWith(project_parsing_lib_1.metafileExtension)) {
|
|
17
|
+
hsMetaFiles.push(collision);
|
|
18
|
+
}
|
|
19
|
+
else if (path_1.default.parse(collision).base === 'package.json') {
|
|
20
|
+
packageJsonFiles.push(collision);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
sourceFiles.push(collision);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const sourceFilenameMapping = sourceFiles.reduce((acc, filename) => {
|
|
27
|
+
const { name, ext, dir } = path_1.default.parse(filename);
|
|
28
|
+
return {
|
|
29
|
+
...acc,
|
|
30
|
+
[filename]: path_1.default.join(dir, `${name}-${Date.now()}${ext}`),
|
|
31
|
+
};
|
|
32
|
+
}, {});
|
|
33
|
+
const metafileExtensionPrefix = path_1.default.parse(project_parsing_lib_1.metafileExtension).name;
|
|
34
|
+
const metaFilenameMapping = hsMetaFiles.reduce((acc, filename) => {
|
|
35
|
+
const { name, dir } = path_1.default.parse(filename);
|
|
36
|
+
return {
|
|
37
|
+
...acc,
|
|
38
|
+
[filename]: path_1.default.join(dir, `${name.replace(metafileExtensionPrefix, '')}-${Date.now()}${project_parsing_lib_1.metafileExtension}`),
|
|
39
|
+
};
|
|
40
|
+
}, {});
|
|
41
|
+
// Update the metafiles that might contain references to the old filenames
|
|
42
|
+
hsMetaFiles.forEach(file => {
|
|
43
|
+
updateMetaFile({
|
|
44
|
+
dest,
|
|
45
|
+
src,
|
|
46
|
+
file,
|
|
47
|
+
sourceFilenameMapping,
|
|
48
|
+
metaFilenameMapping,
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
// Copy the renamed files into their new destination location
|
|
52
|
+
Object.entries(sourceFilenameMapping).forEach(([key, value]) => {
|
|
53
|
+
fs_1.default.copyFileSync(path_1.default.join(src, key), path_1.default.join(dest, value));
|
|
54
|
+
});
|
|
55
|
+
if (packageJsonFiles.length) {
|
|
56
|
+
handlePackageJsonCollisions(dest, src, packageJsonFiles);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function updateMetaFile({ dest, src, file, sourceFilenameMapping, metaFilenameMapping, }) {
|
|
60
|
+
let text = fs_1.default.readFileSync(path_1.default.join(src, file), 'utf-8');
|
|
61
|
+
Object.entries(sourceFilenameMapping).forEach(([key, value]) => {
|
|
62
|
+
const { base: oldFileName } = path_1.default.parse(key);
|
|
63
|
+
const { base: newFileName } = path_1.default.parse(value);
|
|
64
|
+
text = text.replace(oldFileName, newFileName);
|
|
65
|
+
});
|
|
66
|
+
fs_1.default.writeFileSync(path_1.default.join(dest, metaFilenameMapping[file]), text);
|
|
67
|
+
}
|
|
68
|
+
function handlePackageJsonCollisions(dest, src, packageJsonFiles) {
|
|
69
|
+
packageJsonFiles.forEach(file => {
|
|
70
|
+
const existingPackageJsonContents = JSON.parse(fs_1.default.readFileSync(path_1.default.join(dest, file), 'utf-8'));
|
|
71
|
+
const newPackageJsonContents = JSON.parse(fs_1.default.readFileSync(path_1.default.join(src, file), 'utf-8'));
|
|
72
|
+
existingPackageJsonContents.dependencies = {
|
|
73
|
+
...newPackageJsonContents.dependencies,
|
|
74
|
+
...existingPackageJsonContents.dependencies,
|
|
75
|
+
};
|
|
76
|
+
existingPackageJsonContents.devDependencies = {
|
|
77
|
+
...newPackageJsonContents.devDependencies,
|
|
78
|
+
...existingPackageJsonContents.devDependencies,
|
|
79
|
+
};
|
|
80
|
+
fs_1.default.writeFileSync(path_1.default.join(dest, file), JSON.stringify(existingPackageJsonContents, null, 2));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ArgumentsCamelCase } from 'yargs';
|
|
2
|
+
import { ProjectTemplateRepoConfig } from '../../../types/Projects';
|
|
3
|
+
import { CreateProjectPromptResponse } from '../../prompts/createProjectPrompt';
|
|
4
|
+
import { AccountArgs, CommonArgs, ConfigArgs, EnvironmentArgs } from '../../../types/Yargs';
|
|
5
|
+
import { RepoPath } from '@hubspot/local-dev-lib/types/Github';
|
|
6
|
+
export type ProjectCreateArgs = CommonArgs & ConfigArgs & AccountArgs & EnvironmentArgs & {
|
|
7
|
+
name?: string;
|
|
8
|
+
dest?: string;
|
|
9
|
+
templateSource?: RepoPath;
|
|
10
|
+
template?: string;
|
|
11
|
+
features?: string[];
|
|
12
|
+
platformVersion: string;
|
|
13
|
+
projectBase?: string;
|
|
14
|
+
auth?: string;
|
|
15
|
+
distribution?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function handleProjectCreationFlow(args: ArgumentsCamelCase<ProjectCreateArgs>): Promise<{
|
|
18
|
+
authType?: string;
|
|
19
|
+
distribution?: string;
|
|
20
|
+
repoConfig?: ProjectTemplateRepoConfig;
|
|
21
|
+
projectContents?: string;
|
|
22
|
+
createProjectPromptResponse: CreateProjectPromptResponse;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleProjectCreationFlow = handleProjectCreationFlow;
|
|
4
|
+
const createProjectPrompt_1 = require("../../prompts/createProjectPrompt");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const buildAndDeploy_1 = require("../buildAndDeploy");
|
|
7
|
+
const v3_1 = require("./v3");
|
|
8
|
+
const legacy_1 = require("./legacy");
|
|
9
|
+
const logger_1 = require("../../ui/logger");
|
|
10
|
+
const en_1 = require("../../../lang/en");
|
|
11
|
+
const exitCodes_1 = require("../../enums/exitCodes");
|
|
12
|
+
async function handleProjectCreationFlow(args) {
|
|
13
|
+
const { platformVersion, templateSource, projectBase, auth: providedAuth, distribution: providedDistribution, } = args;
|
|
14
|
+
const repo = templateSource || constants_1.HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH;
|
|
15
|
+
if ((0, buildAndDeploy_1.useV3Api)(platformVersion)) {
|
|
16
|
+
const { componentTemplateChoices, authType, distribution, repoConfig, projectContents, } = await (0, v3_1.v3ComponentFlow)(platformVersion, projectBase, providedAuth, providedDistribution);
|
|
17
|
+
const createProjectPromptResponse = await (0, createProjectPrompt_1.createProjectPrompt)(args, undefined, projectContents !== v3_1.EMPTY_PROJECT ? componentTemplateChoices : undefined);
|
|
18
|
+
return {
|
|
19
|
+
authType,
|
|
20
|
+
distribution,
|
|
21
|
+
repoConfig,
|
|
22
|
+
projectContents,
|
|
23
|
+
createProjectPromptResponse,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const projectTemplates = await (0, legacy_1.getProjectTemplateListFromRepo)(repo, 'main');
|
|
27
|
+
if (!projectTemplates.length) {
|
|
28
|
+
logger_1.uiLogger.error(en_1.commands.project.create.errors.failedToFetchProjectList);
|
|
29
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
30
|
+
}
|
|
31
|
+
const createProjectPromptResponse = await (0, createProjectPrompt_1.createProjectPrompt)(args, projectTemplates);
|
|
32
|
+
return { createProjectPromptResponse };
|
|
33
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RepoPath } from '@hubspot/local-dev-lib/types/Github';
|
|
2
|
+
import { ProjectTemplate, ComponentTemplate, ProjectTemplateRepoConfig } from '../../../types/Projects';
|
|
3
|
+
export declare const EMPTY_PROJECT_TEMPLATE_NAME = "no-template";
|
|
4
|
+
export declare function getConfigForPlatformVersion(platformVersion: string): Promise<ProjectTemplateRepoConfig> | never;
|
|
5
|
+
export declare function getProjectComponentListFromRepo(platformVersion: string): Promise<ComponentTemplate[]>;
|
|
6
|
+
export declare function getProjectTemplateListFromRepo(templateSource: RepoPath, githubRef: string): Promise<ProjectTemplate[]>;
|
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EMPTY_PROJECT_TEMPLATE_NAME = void 0;
|
|
4
|
+
exports.getConfigForPlatformVersion = getConfigForPlatformVersion;
|
|
4
5
|
exports.getProjectComponentListFromRepo = getProjectComponentListFromRepo;
|
|
5
6
|
exports.getProjectTemplateListFromRepo = getProjectTemplateListFromRepo;
|
|
6
7
|
const github_1 = require("@hubspot/local-dev-lib/api/github");
|
|
7
|
-
const constants_1 = require("
|
|
8
|
-
const exitCodes_1 = require("
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
8
|
+
const constants_1 = require("../../constants");
|
|
9
|
+
const exitCodes_1 = require("../../enums/exitCodes");
|
|
10
|
+
const errorHandlers_1 = require("../../errorHandlers");
|
|
11
|
+
const logger_1 = require("../../ui/logger");
|
|
12
|
+
const buildAndDeploy_1 = require("../buildAndDeploy");
|
|
13
|
+
const en_1 = require("../../../lang/en");
|
|
14
|
+
const PROJECT_TEMPLATE_PROPERTIES = ['name', 'label', 'path'];
|
|
12
15
|
exports.EMPTY_PROJECT_TEMPLATE_NAME = 'no-template';
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
async function getConfigForPlatformVersion(platformVersion) {
|
|
17
|
+
let path = '';
|
|
18
|
+
if ((0, buildAndDeploy_1.useV3Api)(platformVersion)) {
|
|
19
|
+
path = `${platformVersion}/`;
|
|
20
|
+
}
|
|
21
|
+
const { data } = await (0, github_1.fetchRepoFile)(constants_1.HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, `${path}config.json`, 'main');
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
async function getProjectComponentListFromRepo(platformVersion) {
|
|
15
25
|
let config;
|
|
16
26
|
try {
|
|
17
|
-
|
|
18
|
-
config = data;
|
|
27
|
+
config = await getConfigForPlatformVersion(platformVersion);
|
|
19
28
|
}
|
|
20
29
|
catch (err) {
|
|
21
|
-
(0,
|
|
30
|
+
(0, errorHandlers_1.debugError)(err);
|
|
22
31
|
}
|
|
23
32
|
if (config) {
|
|
24
33
|
return config[constants_1.PROJECT_COMPONENT_TYPES.COMPONENTS] || [];
|
|
@@ -32,7 +41,7 @@ async function getProjectTemplateListFromRepo(templateSource, githubRef) {
|
|
|
32
41
|
config = data;
|
|
33
42
|
}
|
|
34
43
|
catch (e) {
|
|
35
|
-
(0,
|
|
44
|
+
(0, errorHandlers_1.debugError)(e);
|
|
36
45
|
logger_1.uiLogger.error(en_1.lib.projects.create.errors.missingConfigFileTemplateSource);
|
|
37
46
|
return process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
38
47
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ComponentTemplate, ComponentTemplateChoice, ProjectTemplateRepoConfig } from '../../../types/Projects';
|
|
2
|
+
import { ProjectMetadata } from '@hubspot/project-parsing-lib/src/lib/project';
|
|
3
|
+
import { CreateProjectPromptResponse } from '../../prompts/createProjectPrompt';
|
|
4
|
+
export declare const EMPTY_PROJECT = "empty";
|
|
5
|
+
export declare const PROJECT_WITH_APP = "app";
|
|
6
|
+
export declare function createV3App(providedAuth: string | undefined, providedDistribution: string | undefined): Promise<{
|
|
7
|
+
authType: string;
|
|
8
|
+
distribution: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function calculateComponentTemplateChoices(components: ComponentTemplate[], authType: string | undefined, distribution: string | undefined, projectMetadata?: ProjectMetadata): ComponentTemplateChoice[];
|
|
11
|
+
type V3ComponentInfo = {
|
|
12
|
+
authType?: string;
|
|
13
|
+
distribution?: string;
|
|
14
|
+
repoConfig?: ProjectTemplateRepoConfig;
|
|
15
|
+
projectContents?: string;
|
|
16
|
+
componentTemplateChoices?: ComponentTemplateChoice[];
|
|
17
|
+
};
|
|
18
|
+
export declare function v3ComponentFlow(platformVersion: string, projectBase: string | undefined, providedAuth: string | undefined, providedDistribution: string | undefined): Promise<V3ComponentInfo>;
|
|
19
|
+
export declare function generateComponentPaths({ createProjectPromptResponse, platformVersion, repoConfig, projectContents, authType, distribution, }: {
|
|
20
|
+
createProjectPromptResponse: CreateProjectPromptResponse;
|
|
21
|
+
platformVersion: string;
|
|
22
|
+
repoConfig?: ProjectTemplateRepoConfig;
|
|
23
|
+
projectContents?: string;
|
|
24
|
+
authType?: string;
|
|
25
|
+
distribution?: string;
|
|
26
|
+
}): string[];
|
|
27
|
+
export {};
|