File tree Expand file tree Collapse file tree 4 files changed +24
-1
lines changed
typescript-generator-core/src/main/java/cz/habarta/typescript/generator
typescript-generator-gradle-plugin/src/main/java/cz/habarta/typescript/generator/gradle
typescript-generator-maven-plugin/src/main/java/cz/habarta/typescript/generator/maven Expand file tree Collapse file tree 4 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ public class Settings {
8080 public String npmVersion = null ;
8181 public Map <String , String > npmPackageDependencies = new LinkedHashMap <>();
8282 public String typescriptVersion = "^2.4" ;
83+ public String npmBuildScript = null ;
8384 @ Deprecated public boolean displaySerializerWarning ;
8485 @ Deprecated public boolean debug ;
8586 @ Deprecated public boolean disableJackson2ModuleDiscovery = false ;
@@ -279,6 +280,12 @@ public void validate() {
279280 if (npmName != null || npmVersion != null ) {
280281 throw new RuntimeException ("'npmName' and 'npmVersion' is only applicable when generating NPM 'package.json'." );
281282 }
283+ if (npmBuildScript != null ) {
284+ throw new RuntimeException ("'npmBuildScript' is only applicable when generating NPM 'package.json'." );
285+ }
286+ }
287+ if (npmBuildScript != null && outputFileType != TypeScriptFileType .implementationFile ) {
288+ throw new RuntimeException ("'npmBuildScript' can only be used when generating implementation file ('outputFileType' parameter is 'implementationFile')." );
282289 }
283290 getModuleDependencies ();
284291
Original file line number Diff line number Diff line change 77import cz .habarta .typescript .generator .util .Utils ;
88import java .io .*;
99import java .util .*;
10+ import java .util .regex .Pattern ;
1011
1112
1213public class TypeScriptGenerator {
@@ -103,7 +104,11 @@ private void generateNpmPackageJson(Output output) {
103104 npmPackageJson .main = Utils .replaceExtension (outputFile , ".js" ).getName ();
104105 npmPackageJson .dependencies .putAll (settings .npmPackageDependencies );
105106 npmPackageJson .devDependencies = Collections .singletonMap ("typescript" , settings .typescriptVersion );
106- npmPackageJson .scripts = Collections .singletonMap ("build" , "tsc --module umd --moduleResolution node --target es5 --lib es6 --declaration --sourceMap " + outputFile .getName ());
107+ final String npmBuildScript = settings .npmBuildScript != null
108+ ? settings .npmBuildScript
109+ : "tsc --module umd --moduleResolution node --target es5 --lib es6 --declaration --sourceMap $outputFile" ;
110+ final String build = npmBuildScript .replaceAll (Pattern .quote ("$outputFile" ), outputFile .getName ());
111+ npmPackageJson .scripts = Collections .singletonMap ("build" , build );
107112 }
108113 if (npmPackageJson .dependencies .isEmpty ()) {
109114 npmPackageJson .dependencies = null ;
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ public class GenerateTask extends DefaultTask {
7272 public boolean generateNpmPackageJson ;
7373 public String npmName ;
7474 public String npmVersion ;
75+ public String npmBuildScript ;
7576 public StringQuotes stringQuotes ;
7677 public String indentString ;
7778 @ Deprecated public boolean displaySerializerWarning ;
@@ -164,6 +165,7 @@ public void generate() throws Exception {
164165 settings .generateNpmPackageJson = generateNpmPackageJson ;
165166 settings .npmName = npmName == null && generateNpmPackageJson ? getProject ().getName () : npmName ;
166167 settings .npmVersion = npmVersion == null && generateNpmPackageJson ? settings .getDefaultNpmVersion () : npmVersion ;
168+ settings .npmBuildScript = npmBuildScript ;
167169 settings .setStringQuotes (stringQuotes );
168170 settings .setIndentString (indentString );
169171 settings .displaySerializerWarning = displaySerializerWarning ;
Original file line number Diff line number Diff line change @@ -534,6 +534,14 @@ public class GenerateMojo extends AbstractMojo {
534534 @ Parameter
535535 private String npmVersion ;
536536
537+ /**
538+ * Specifies NPM "build" script.<br>
539+ * Only applicable when {@link #generateNpmPackageJson} parameter is <code>true</code> and generating implementation file (.ts).<br>
540+ * Default value is <code>tsc --module umd --moduleResolution node --target es5 --lib es6 --declaration --sourceMap $outputFile</code>.
541+ */
542+ @ Parameter
543+ private String npmBuildScript ;
544+
537545 /**
538546 * Specifies how strings will be quoted.
539547 * Supported values are:
@@ -673,6 +681,7 @@ public void execute() {
673681 settings .generateNpmPackageJson = generateNpmPackageJson ;
674682 settings .npmName = npmName == null && generateNpmPackageJson ? project .getArtifactId () : npmName ;
675683 settings .npmVersion = npmVersion == null && generateNpmPackageJson ? settings .getDefaultNpmVersion () : npmVersion ;
684+ settings .npmBuildScript = npmBuildScript ;
676685 settings .setStringQuotes (stringQuotes );
677686 settings .setIndentString (indentString );
678687 settings .displaySerializerWarning = displaySerializerWarning ;
You can’t perform that action at this time.
0 commit comments