Skip to content

Commit

Permalink
Add validateProjectConfig to project dev command
Browse files Browse the repository at this point in the history
Also reworks the error message for srcOutsideProjectDir to be more informative and actionable
  • Loading branch information
mendel-at-hubspot committed Nov 6, 2023
1 parent 0ecf9f5 commit 7dc3b30
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/cli/commands/project/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
handleProjectUpload,
pollProjectBuildAndDeploy,
showPlatformVersionWarning,
validateProjectConfig,
} = require('../../lib/projects');
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
const {
Expand Down Expand Up @@ -87,6 +88,8 @@ exports.handler = async options => {
process.exit(EXIT_CODES.ERROR);
}

validateProjectConfig(projectConfig, projectDir);

const accounts = getConfigAccounts();
let targetAccountId = options.account ? accountId : null;
let createNewSandbox = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ en:
fileChangeError: "Failed to notify local dev server of file change: {{ message }}"
projects:
config:
srcOutsideProjectDir: "Project source directory '{{ srcDir }}' should be contained within '{{ projectDir }}'"
srcOutsideProjectDir: "Invalid line in {{ projectConfig}}: {{#bold}}srcDir: \"{{ srcDir }}\"{{/bold}}\n\t`srcDir` should be a relative path to a directory within {{ projectDir }}, such as \".\" or \"./src\""
uploadProjectFiles:
add: "Uploading {{#bold}}{{ projectName }}{{/bold}} project files to {{ accountIdentifier }}"
fail: "Failed to upload {{#bold}}{{ projectName }}{{/bold}} project files to {{ accountIdentifier }}"
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/lib/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,15 @@ const validateProjectConfig = (projectConfig, projectDir) => {

const resolvedPath = path.resolve(projectDir, projectConfig.srcDir);
if (!resolvedPath.startsWith(projectDir)) {
const projectConfigFile = path.relative(
'.',
path.join(projectDir, PROJECT_CONFIG_FILE)
);
logger.error(
i18n(`${i18nKey}.config.srcOutsideProjectDir`, {
srcDir: projectConfig.srcDir,
projectDir,
projectConfig: projectConfigFile,
})
);
return process.exit(EXIT_CODES.ERROR);
Expand Down

0 comments on commit 7dc3b30

Please sign in to comment.