Skip to content

Commit 6c4a8fa

Browse files
committed
CDS extractor constant for model.cds.json filename
This commit replaces many separate string literals for `model.cds.json` with an exported constant of the same string in an effort to improve the readability and maintainability of CDS extractor code.
1 parent 3058ac2 commit 6c4a8fa

File tree

6 files changed

+33
-22
lines changed

6 files changed

+33
-22
lines changed

extractors/cds/tools/dist/cds-extractor.bundle.js

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extractors/cds/tools/dist/cds-extractor.bundle.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extractors/cds/tools/src/cds/compiler/compile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { resolve, join, delimiter, relative, dirname, basename } from 'path';
33

44
import { CdsCompilationResult } from './types';
55
import { getCdsVersion } from './version';
6+
import { modelCdsJsonFile } from '../../constants';
67
import { fileExists, dirExists, recursivelyRenameJsonFiles } from '../../filesystem';
78
import { cdsExtractorLog } from '../../logging';
89
import { BasicCdsProject } from '../parser/types';
@@ -60,7 +61,7 @@ function determineCompilationTargets(project: BasicCdsProject, sourceRoot: strin
6061
* Compiles a CDS project to JSON using project-level compilation only.
6162
* This function has been simplified to only use project-level compilation,
6263
* eliminating all individual file compilation logic and standardizing output
63-
* to a single model.cds.json file per project.
64+
* to a single {@link modelCdsJsonFile} file per project.
6465
*
6566
*
6667
* @param cdsFilePath The path to the CDS file to compile, relative to the `sourceRoot`.
@@ -146,16 +147,15 @@ function compileProject(
146147
);
147148
}
148149

149-
// Generate output path for the compiled model - always model.cds.json in project base directory
150-
const projectJsonOutPath = join(sourceRoot, projectDir, 'model.cds.json');
150+
const projectJsonOutPath = join(sourceRoot, projectDir, modelCdsJsonFile);
151151

152152
const compileArgs = [
153153
'compile',
154154
...compilationTargets,
155155
'--to',
156156
'json',
157157
'--dest',
158-
'model.cds.json',
158+
modelCdsJsonFile,
159159
'--locations',
160160
'--log-level',
161161
'warn',

extractors/cds/tools/src/cds/parser/functions.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { basename, dirname, join, relative, sep } from 'path';
44
import { sync } from 'glob';
55

66
import { CdsFilesToCompile, CdsImport, PackageJson } from './types';
7+
import { modelCdsJsonFile } from '../../constants';
78
import { cdsExtractorLog } from '../../logging';
89

910
/**
@@ -415,7 +416,7 @@ export function determineCdsFilesToCompile(
415416
if (!project.cdsFiles || project.cdsFiles.length === 0) {
416417
return {
417418
compilationTargets: [],
418-
expectedOutputFile: join(project.projectDir, 'model.cds.json'),
419+
expectedOutputFile: join(project.projectDir, modelCdsJsonFile),
419420
};
420421
}
421422

@@ -429,7 +430,7 @@ export function determineCdsFilesToCompile(
429430
// Use standard CAP directories
430431
return {
431432
compilationTargets: existingCapDirs,
432-
expectedOutputFile: join(project.projectDir, 'model.cds.json'),
433+
expectedOutputFile: join(project.projectDir, modelCdsJsonFile),
433434
};
434435
}
435436

@@ -442,7 +443,7 @@ export function determineCdsFilesToCompile(
442443
// Use root-level files
443444
return {
444445
compilationTargets: rootCdsFiles,
445-
expectedOutputFile: join(project.projectDir, 'model.cds.json'),
446+
expectedOutputFile: join(project.projectDir, modelCdsJsonFile),
446447
};
447448
}
448449

@@ -453,7 +454,7 @@ export function determineCdsFilesToCompile(
453454

454455
return {
455456
compilationTargets,
456-
expectedOutputFile: join(project.projectDir, 'model.cds.json'),
457+
expectedOutputFile: join(project.projectDir, modelCdsJsonFile),
457458
};
458459
}
459460

extractors/cds/tools/src/cds/parser/graph.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
readPackageJsonFile,
99
} from './functions';
1010
import { CdsDependencyGraph, CdsImport, CdsProject, BasicCdsProject } from './types';
11+
import { modelCdsJsonFile } from '../../constants';
1112
import { cdsExtractorLog } from '../../logging';
1213

1314
/**
@@ -44,7 +45,7 @@ function buildBasicCdsProjectDependencyGraph(sourceRootDir: string): Map<string,
4445
projectDir,
4546
cdsFiles,
4647
compilationTargets: [], // Will be populated in the third pass
47-
expectedOutputFile: join(projectDir, 'model.cds.json'), // Always model.cds.json, relative to source root
48+
expectedOutputFile: join(projectDir, modelCdsJsonFile),
4849
packageJson,
4950
dependencies: [],
5051
imports: new Map<string, CdsImport[]>(),
@@ -170,7 +171,7 @@ function buildBasicCdsProjectDependencyGraph(sourceRootDir: string): Map<string,
170171
);
171172
// Fall back to default project compilation on error
172173
project.compilationTargets = project.cdsFiles.map(file => basename(file));
173-
project.expectedOutputFile = join(project.projectDir, 'model.cds.json');
174+
project.expectedOutputFile = join(project.projectDir, modelCdsJsonFile);
174175
}
175176
}
176177

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** Common constants used throughout the CDS extractor. */
2+
3+
/**
4+
* Common, expected name of the JSON file created by CDS compilation
5+
* tasks performed by, or on behalf of, the CDS extractor.
6+
*/
7+
export const modelCdsJsonFile = 'model.cds.json';

0 commit comments

Comments
 (0)