@@ -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() {
245244function 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 */
744743function 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 */
784783function 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