Skip to content

Commit 51ded8b

Browse files
committed
package can now differ from output directory
1 parent 482c689 commit 51ded8b

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ to [BO4E-Java](https://github.com/TimoMolls/BO4E-Java).
1515
| name | alias | type | description |
1616
|----------|-------|-----------|---------------------------------------------------------------------------------|
1717
| input | i | string | The input directory that holds the json-schemas and defines the file structure. |
18-
| output | o | string | The output directory (will be included in package signature). |
19-
| package | p | string... | Additional packages to add to the classes package signature. |
18+
| output | o | string | The output directory. |
19+
| package | p | string... | The package to put in the classes package signature (default: same as output). |
2020
| keep | k | boolean | Prevent overwriting of existing files. |
2121
| remove | r | boolean | Delete all existing files in output directory. |
2222
| create | c | boolean | Create output directory if it does not exist. |
@@ -34,5 +34,5 @@ to [BO4E-Java](https://github.com/TimoMolls/BO4E-Java).
3434
- all classes in *com* extend **COM**
3535
- **Geschaeftsobjekt** and **COM** are added, even if not included in the *schemas*
3636
- *version* was renamed to **boVersion** since there already is a version field in **Lastgang**
37-
- every class has a *no-args-constructor* and a **Builder** but currently no *all-args-constructor*
37+
- every class has a *no-args-constructor* and a **Builder** but no *all-args-constructor*
3838
- Comments are copied from the schemas, their correctness is not validated

quicktype.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,17 @@ const optionDefinitions = [
105105
},
106106
{
107107
name: 'output',
108-
description: 'Path to the output directory (will be included in package signature).',
108+
description: 'Path to the output directory.',
109109
alias: 'o',
110110
type: String,
111111
typeLabel: '{underline path}'
112112
},
113113
{
114114
name: 'package',
115-
description: 'Additional packages to add to the package signature.',
115+
description: 'The package to put in the classes package signature (default: same as output).',
116116
alias: 'p',
117117
type: String,
118-
multiple: true,
119-
typeLabel: '{underline package} ...'
118+
typeLabel: '{underline package}'
120119
},
121120
{
122121
name: 'keep',
@@ -186,8 +185,8 @@ const sections = [
186185
example: 'node quicktype.js -o bo4e/api data/bo4e_schemas'
187186
},
188187
{
189-
desc: '2. Outputs to "bo4e/api", package will be "example.test.bo4e.api"',
190-
example: 'node quicktype.js -o bo4e/api bo4e_schemas -p example test'
188+
desc: '2. Outputs to "bo4e/api", package will be "bo4e.example.api"',
189+
example: 'node quicktype.js -o bo4e/api bo4e_schemas -p bo4e.example.api'
191190
},
192191
{
193192
desc: '3. Use annotations and enable debug output',
@@ -233,7 +232,7 @@ async function processCommandLineArguments() {
233232
TARGET_DIR_PATH = options['output'];
234233
}
235234
SOURCE_DIR_PATH = options['input'];
236-
PACKAGE_NAME = options['package'] && options['package'].length > 0 ? options['package'].join('.') + '.' : '';
235+
PACKAGE_NAME = (options['package'] && options['package'].length > 0) ? options['package'].join('.') : TARGET_DIR_PATH.replaceAll('/', '.');
237236
USE_ANNOTATIONS = !!options['annotate'];
238237
VERBOSE = !!options['verbose'];
239238
QUIET = !!options['quiet'];
@@ -245,7 +244,7 @@ async function processCommandLineArguments() {
245244
function logSettings() {
246245
log(`Using source directory: ${SOURCE_DIR_PATH}`);
247246
log(`Using target directory: ${TARGET_DIR_PATH}`);
248-
log(`Using package: ${(PACKAGE_NAME ? PACKAGE_NAME + TARGET_DIR_PATH : TARGET_DIR_PATH).replaceAll('/', '.')}`);
247+
log(`Using package: ${PACKAGE_NAME}`);
249248
log(`Prevent overwriting existing files: ${KEEP}`);
250249
log(`Delete files in output: ${REMOVE}`);
251250
log(`Create output directory: ${CREATE}`);
@@ -586,7 +585,7 @@ function addImports(fieldType, fileMap, importList, classDirPath) {
586585
}
587586
const importData = fileMap.get(fieldType.toLowerCase());
588587
if (importData !== undefined && importData.javaFilePath !== classDirPath) {
589-
const importPackage = PACKAGE_NAME + importData.javaFilePath.replaceAll('/', '.');
588+
const importPackage = importData.javaFilePath.replace(TARGET_DIR_PATH, PACKAGE_NAME).replaceAll('/', '.');
590589
const importString = `import ${importPackage}.${importData.javaFileName};`;
591590
if (!importList.includes(importString)) {
592591
importList.push(importString);
@@ -743,7 +742,7 @@ function addIndentation(classString) {
743742
*/
744743
function completeJavaFile(contentList, fileData, fileMap) {
745744
const classFoot = '}';
746-
const newPackageName = PACKAGE_NAME + fileData.javaFilePath.replaceAll('/', '.');
745+
const newPackageName = fileData.javaFilePath.replace(TARGET_DIR_PATH, PACKAGE_NAME).replaceAll('/', '.');
747746
const newPackage = contentList[0].replace('placeholder', newPackageName);
748747
const classIndex = contentList.findIndex(value => value.startsWith('public class'));
749748
if (classIndex < 0) {
@@ -782,12 +781,12 @@ function completeJavaFile(contentList, fileData, fileMap) {
782781
* @param fileMap {Map<string,{jsonFileName: string, jsonFilePath: string, javaFileName: string, javaFilePath: string}>} maps lowercase fileName to fileData
783782
*/
784783
function restoreMissingFiles(fileMap) {
785-
const zaImport = PACKAGE_NAME + fileMap.get('zusatzattribut').javaFilePath.replaceAll('/', '.');
786-
const typImport = PACKAGE_NAME + fileMap.get('typ').javaFilePath.replaceAll('/', '.');
784+
const zaImport = fileMap.get('zusatzattribut').javaFilePath.replace(TARGET_DIR_PATH, PACKAGE_NAME).replaceAll('/', '.');
785+
const typImport = fileMap.get('typ').javaFilePath.replace(TARGET_DIR_PATH, PACKAGE_NAME).replaceAll('/', '.');
787786
MISSING_PARENT_CLASSES.forEach(({fileName, pathToFile}) => {
788787
if (!fileMap.has(fileName.toLowerCase())) {
789788
const javaFileName = fileName + '.java';
790-
const classPackage = PACKAGE_NAME + TARGET_DIR_PATH + '.' + pathToFile.substring(0, pathToFile.length - 1).replace('/', '.');
789+
const classPackage = PACKAGE_NAME + '.' + pathToFile.substring(0, pathToFile.length - 1).replace('/', '.');
791790
let fileContent = fs.readFileSync('resource_schemas/' + javaFileName, 'utf-8');
792791
if (USE_ANNOTATIONS) {
793792
fileContent = fileContent

0 commit comments

Comments
 (0)