diff --git a/src/main/java/org/jsweet/JSweetCommandLineLauncher.java b/src/main/java/org/jsweet/JSweetCommandLineLauncher.java index 37c3f17d..c1b06428 100644 --- a/src/main/java/org/jsweet/JSweetCommandLineLauncher.java +++ b/src/main/java/org/jsweet/JSweetCommandLineLauncher.java @@ -81,8 +81,9 @@ public class JSweetCommandLineLauncher { Util.addFiles(".java", inputDir, files); JSweetTranspiler transpiler = new JSweetTranspiler(tsOutputDir, jsOutputDir, classPath); - transpiler.setBundle(jsapArgs.getBoolean("bundle")); + transpiler.setBundle(jsapArgs.getBoolean("bundle")); + transpiler.setNoRootDirectories(jsapArgs.getBoolean("noRootDirectories")); File bundlesDirectory = null; if (jsapArgs.getFile("bundlesDirectory") != null) { bundlesDirectory = jsapArgs.getFile("bundlesDirectory"); @@ -90,25 +91,13 @@ public class JSweetCommandLineLauncher { } logger.info("bundles directory: " + bundlesDirectory); transpiler.setBundlesDirectory(bundlesDirectory); - transpiler.setPreserveSourceLineNumbers(jsapArgs.getBoolean("debug")); - if (args.length > 4) { - File f = new File(args[4]); - if (f.exists()) { - transpiler.setTsDefDirs(f); - logger.info("tsdef dir: " + args[4]); - } else { - OUTPUT_LOGGER.warn("tsdef dir does not exist - " + args[4]); - } - } - transpiler.setModuleKind(ModuleKind.valueOf(jsapArgs.getString("module"))); + transpiler.setEncoding(jsapArgs.getString("encoding")); ErrorCountTranspilationHandler transpilationHandler = new ErrorCountTranspilationHandler(new ConsoleTranspilationHandler()); errorCount = transpilationHandler.getErrorCount(); - transpiler.setEncoding(jsapArgs.getString("encoding")); - transpiler.transpile(transpilationHandler, SourceFile.toSourceFiles(files)); errorCount = transpilationHandler.getErrorCount(); @@ -159,6 +148,14 @@ public class JSweetCommandLineLauncher { optionArg.setHelp("An input dir containing Java files to be transpiled."); jsap.registerParameter(optionArg); + // Skip empty root dirs + switchArg = new Switch("noRootDirectories"); + switchArg.setLongFlag("noRootDirectories"); + switchArg.setHelp( + "Skip the root directories (i.e. packages annotated with @jsweet.lang.Root) so that the generated file hierarchy starts at the root directories rather than including the entire directory structure."); + switchArg.setDefault("false"); + jsap.registerParameter(switchArg); + // TypeScript output directory optionArg = new FlaggedOption("tsout"); optionArg.setLongFlag("tsout"); diff --git a/src/main/java/org/jsweet/transpiler/JSweetTranspiler.java b/src/main/java/org/jsweet/transpiler/JSweetTranspiler.java index bb3a98c4..c56cfa64 100644 --- a/src/main/java/org/jsweet/transpiler/JSweetTranspiler.java +++ b/src/main/java/org/jsweet/transpiler/JSweetTranspiler.java @@ -132,6 +132,7 @@ public class JSweetTranspiler { private boolean bundle = false; private File bundlesDirectory; private String encoding = null; + private boolean noRootDirectories = false; /** * Creates a JSweet transpiler, with the default values. @@ -773,7 +774,8 @@ public class JSweetTranspiler { String cuName = s[s.length - 1]; s = cuName.split("\\."); cuName = s[0]; - String outputFileRelativePathNoExt = cu.packge.fullname.toString().replace(".", File.separator) + File.separator + cuName; + String packageName = isNoRootDirectories() ? Util.getRootRelativeJavaName(cu.packge) : cu.packge.getQualifiedName().toString(); + String outputFileRelativePathNoExt = packageName.replace(".", File.separator) + File.separator + cuName; String outputFileRelativePath = outputFileRelativePathNoExt + printer.getTargetFilesExtension(); logger.info("output file: " + outputFileRelativePath); File outputFile = new File(tsOutputDir, outputFileRelativePath); @@ -1236,4 +1238,24 @@ public class JSweetTranspiler { public void setEncoding(String encoding) { this.encoding = encoding; } + + /** + * Tells if this transpiler skips the root directories (packages annotated + * with @jsweet.lang.Root) so that the generated file hierarchy starts at + * the root directories rather than including the entire directory + * structure. + */ + public boolean isNoRootDirectories() { + return noRootDirectories; + } + + /** + * Sets this transpiler to skip the root directories (packages annotated + * with @jsweet.lang.Root) so that the generated file hierarchy starts at + * the root directories rather than including the entire directory + * structure. + */ + public void setNoRootDirectories(boolean noRootDirectories) { + this.noRootDirectories = noRootDirectories; + } }