diff --git a/gradle-spaghetti-plugin/src/main/java/com/prezi/spaghetti/gradle/PackageApplication.java b/gradle-spaghetti-plugin/src/main/java/com/prezi/spaghetti/gradle/PackageApplication.java index 6de9076a3..d213a6256 100644 --- a/gradle-spaghetti-plugin/src/main/java/com/prezi/spaghetti/gradle/PackageApplication.java +++ b/gradle-spaghetti-plugin/src/main/java/com/prezi/spaghetti/gradle/PackageApplication.java @@ -1,5 +1,6 @@ package com.prezi.spaghetti.gradle; +import com.google.common.collect.Maps; import com.prezi.spaghetti.gradle.internal.AbstractSpaghettiTask; import com.prezi.spaghetti.gradle.internal.ModuleBundleLookupResult; import com.prezi.spaghetti.packaging.ApplicationPackageParameters; @@ -13,6 +14,7 @@ import java.io.File; import java.io.IOException; +import java.util.Map; import java.util.concurrent.Callable; import static com.prezi.spaghetti.gradle.internal.TextFileUtils.getText; @@ -25,6 +27,36 @@ public class PackageApplication extends AbstractSpaghettiTask { private ApplicationType type = ApplicationType.COMMON_JS; private Boolean execute = null; private File outputDirectory; + private Map parameters = Maps.newLinkedHashMap(); + + public PackageApplication() { + this.getConventionMapping().map("outputDirectory", new Callable() { + @Override + public File call() throws Exception { + return new File(getProject().getBuildDir(), "spaghetti/application"); + } + + }); + if ((execute == Boolean.TRUE) && (mainModule == null)) { + throw new IllegalArgumentException("You need to set mainModule as well when execute is true"); + } + } + + @TaskAction + @SuppressWarnings("UnusedDeclaration") + public void makeBundle() throws IOException { + ModuleBundleLookupResult bundles = lookupBundles(); + getLogger().info("Creating {} application in {}", getType().getDescription(), getOutputDirectory()); + getType().getPackager().packageApplicationDirectory(getOutputDirectory(), new ApplicationPackageParameters( + bundles.getAllBundles(), + getApplicationName(), + getMainModule(), + getExecute(), + getParameters(), + getText(getPrefixes()), + getText(getSuffixes()) + )); + } @Input @Optional @@ -128,31 +160,14 @@ public File getApplicationFile() { return new File(getOutputDirectory(), getApplicationName()); } - public PackageApplication() { - this.getConventionMapping().map("outputDirectory", new Callable() { - @Override - public File call() throws Exception { - return new File(getProject().getBuildDir(), "spaghetti/application"); - } - - }); - if ((execute == Boolean.TRUE) && (mainModule == null)) { - throw new IllegalArgumentException("You need to set mainModule as well when execute is true"); - } + @Input + public Map getParameters() { + return parameters; } - @TaskAction - @SuppressWarnings("UnusedDeclaration") - public void makeBundle() throws IOException { - ModuleBundleLookupResult bundles = lookupBundles(); - getLogger().info("Creating {} application in {}", getType().getDescription(), getOutputDirectory()); - getType().getPackager().packageApplicationDirectory(getOutputDirectory(), new ApplicationPackageParameters( - bundles.getAllBundles(), - getApplicationName(), - getMainModule(), - getExecute(), - getText(getPrefixes()), - getText(getSuffixes()) - )); + public void parameters(Map parameters) { + for (Map.Entry entry : parameters.entrySet()) { + this.parameters.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())); + } } } diff --git a/spaghetti-core/src/main/java/com/prezi/spaghetti/ast/internal/parser/ModuleParser.java b/spaghetti-core/src/main/java/com/prezi/spaghetti/ast/internal/parser/ModuleParser.java index 3803b9f6f..cbd17d4aa 100644 --- a/spaghetti-core/src/main/java/com/prezi/spaghetti/ast/internal/parser/ModuleParser.java +++ b/spaghetti-core/src/main/java/com/prezi/spaghetti/ast/internal/parser/ModuleParser.java @@ -1,8 +1,11 @@ package com.prezi.spaghetti.ast.internal.parser; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.prezi.spaghetti.ast.FQName; import com.prezi.spaghetti.ast.ModuleNode; +import com.prezi.spaghetti.ast.QualifiedTypeNode; +import com.prezi.spaghetti.ast.internal.DefaultExternInterfaceNode; import com.prezi.spaghetti.ast.internal.DefaultImportNode; import com.prezi.spaghetti.ast.internal.DefaultMethodNode; import com.prezi.spaghetti.ast.internal.DefaultModuleNode; @@ -13,8 +16,13 @@ import java.util.Arrays; import java.util.List; +import java.util.Set; public class ModuleParser { + private static final Set DEFAULT_EXTERNS = ImmutableSet. builder() + .add(new DefaultExternInterfaceNode(FQName.fromString("SpaghettiParameters"))) + .build(); + private final List typeParsers; private final List moduleMethodsToParse; private final DefaultModuleNode module; @@ -43,6 +51,9 @@ protected ModuleParser(ModuleDefinitionSource source, com.prezi.spaghetti.intern moduleAlias = StringUtils.capitalize(nameParts.get(nameParts.size() - 1)) + "Module"; } this.module = new DefaultModuleNode(moduleName, moduleAlias, source); + //noinspection deprecation + module.getExternTypes().addAll(DEFAULT_EXTERNS); + AnnotationsParser.parseAnnotations(moduleCtx.annotations(), module); DocumentationParser.parseDocumentation(moduleCtx.documentation, module); diff --git a/spaghetti-core/src/main/java/com/prezi/spaghetti/generator/ReservedWords.java b/spaghetti-core/src/main/java/com/prezi/spaghetti/generator/ReservedWords.java index 6ba1114fc..ce4057104 100644 --- a/spaghetti-core/src/main/java/com/prezi/spaghetti/generator/ReservedWords.java +++ b/spaghetti-core/src/main/java/com/prezi/spaghetti/generator/ReservedWords.java @@ -12,6 +12,7 @@ public class ReservedWords { public static final String MODULE_WRAPPER_FUNCTION = "module"; public static final String SPAGHETTI_CLASS = "Spaghetti"; + public static final String SPAGHETTI_PARAMETERS_CLASS = "SpaghettiParameters"; @ProtectedWord public static final String GET_MODULE_VERSION = "getModuleVersion"; @@ -25,6 +26,9 @@ public class ReservedWords { @ProtectedWord public static final String GET_MODULE_NAME = "getModuleName"; + @ProtectedWord + public static final String GET_PARAMETER = "getParameter"; + public static final String MODULE = "module"; public static final String DEPENDENCIES = "dependencies"; diff --git a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/ApplicationPackageParameters.java b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/ApplicationPackageParameters.java index f9dc28612..d0139edee 100644 --- a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/ApplicationPackageParameters.java +++ b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/ApplicationPackageParameters.java @@ -2,6 +2,7 @@ import com.prezi.spaghetti.bundle.ModuleBundle; +import java.util.Map; import java.util.Set; public class ApplicationPackageParameters { @@ -11,14 +12,16 @@ public class ApplicationPackageParameters { public final String applicationName; public final String mainModule; public final boolean execute; + public final Map parameters; public final Iterable prefixes; public final Iterable suffixes; - public ApplicationPackageParameters(Set bundles, String applicationName, String mainModule, boolean execute, Iterable prefixes, Iterable suffixes) { + public ApplicationPackageParameters(Set bundles, String applicationName, String mainModule, boolean execute, Map parameters, Iterable prefixes, Iterable suffixes) { this.bundles = bundles; this.applicationName = applicationName; this.mainModule = mainModule; this.execute = execute; + this.parameters = parameters; this.prefixes = prefixes; this.suffixes = suffixes; } diff --git a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/ModuleWrapper.java b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/ModuleWrapper.java index d59b8f320..72d4767ef 100644 --- a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/ModuleWrapper.java +++ b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/ModuleWrapper.java @@ -6,6 +6,5 @@ public interface ModuleWrapper { String wrap(ModuleWrapperParameters params) throws IOException; - - String makeApplication(Map> dependencyTree, String mainModule, boolean execute); + String makeApplication(Map> dependencyTree, String mainModule, boolean execute, Map parameters); } diff --git a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AbstractModuleWrapper.java b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AbstractModuleWrapper.java index 6d07fa60b..041dd8060 100644 --- a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AbstractModuleWrapper.java +++ b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AbstractModuleWrapper.java @@ -3,18 +3,21 @@ import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; import com.prezi.spaghetti.internal.Version; import com.prezi.spaghetti.packaging.ModuleWrapper; import com.prezi.spaghetti.packaging.ModuleWrapperParameters; +import org.apache.commons.lang.StringEscapeUtils; import java.io.IOException; +import java.util.List; import java.util.Map; import static com.prezi.spaghetti.generator.ReservedWords.DEPENDENCIES; import static com.prezi.spaghetti.generator.ReservedWords.GET_MODULE_NAME; +import static com.prezi.spaghetti.generator.ReservedWords.GET_MODULE_VERSION; import static com.prezi.spaghetti.generator.ReservedWords.GET_RESOURCE_URL; import static com.prezi.spaghetti.generator.ReservedWords.GET_SPAGHETTI_VERSION; -import static com.prezi.spaghetti.generator.ReservedWords.GET_MODULE_VERSION; import static com.prezi.spaghetti.packaging.internal.CommentUtils.appendAfterInitialComment; public abstract class AbstractModuleWrapper implements ModuleWrapper { @@ -60,4 +63,18 @@ public String apply(Map.Entry entry) { builder.append("\"spaghettiVersion\":\"").append(Version.SPAGHETTI_VERSION).append("\""); builder.append("};"); } + + protected static void makeParameters(StringBuilder builder, Map parameters) { + List entries = Lists.newArrayList(); + for (Map.Entry entry : parameters.entrySet()) { + entries.add("\"" + StringEscapeUtils.escapeJavaScript(entry.getKey()) + "\":\"" + StringEscapeUtils.escapeJavaScript(entry.getValue()) + "\""); + } + builder.append("{"); + builder.append("\"getParameter\":function(name){"); + builder.append("return({"); + builder.append(Joiner.on(",").join(entries)); + builder.append("})[name];"); + builder.append("}"); + builder.append("}"); + } } diff --git a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AbstractStructuredApplicationPackager.java b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AbstractStructuredApplicationPackager.java index 9e8e467f7..8046872f7 100644 --- a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AbstractStructuredApplicationPackager.java +++ b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AbstractStructuredApplicationPackager.java @@ -53,7 +53,7 @@ public void execute(OutputStream out) throws IOException { IOUtils.write(prefix, out, Charsets.UTF_8); } - String wrappedApplication = wrapper.makeApplication(dependencyTree, params.mainModule, params.execute); + String wrappedApplication = wrapper.makeApplication(dependencyTree, params.mainModule, params.execute, params.parameters); IOUtils.write(wrappedApplication, out, Charsets.UTF_8); for (String suffix : params.suffixes) { diff --git a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AmdModuleWrapper.java b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AmdModuleWrapper.java index e21fec830..47b6e628d 100644 --- a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AmdModuleWrapper.java +++ b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/AmdModuleWrapper.java @@ -38,13 +38,15 @@ public String wrap(ModuleWrapperParameters params) throws IOException { } @Override - public String makeApplication(Map> dependencyTree, final String mainModule, boolean execute) { + public String makeApplication(Map> dependencyTree, String mainModule, boolean execute, Map parameters) { StringBuilder result = new StringBuilder(); result.append(makeConfig(getModulesDirectory(), Sets.newTreeSet(dependencyTree.keySet()))); if (mainModule != null) { result.append("require([\"").append(mainModule).append("\"],function(__mainModule){"); if (execute) { - result.append("__mainModule[\"").append(MODULE).append("\"][\"main\"]();"); + result.append("__mainModule[\"").append(MODULE).append("\"][\"main\"]("); + makeParameters(result, parameters); + result.append(");"); } result.append("});\n"); diff --git a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/CommonJsModuleWrapper.java b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/CommonJsModuleWrapper.java index bad588289..00af1f8c9 100644 --- a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/CommonJsModuleWrapper.java +++ b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/CommonJsModuleWrapper.java @@ -27,12 +27,14 @@ public String wrap(ModuleWrapperParameters params) throws IOException { } @Override - public String makeApplication(Map> dependencyTree, final String mainModule, boolean execute) { + public String makeApplication(Map> dependencyTree, final String mainModule, boolean execute, Map parameters) { StringBuilder result = new StringBuilder(); if (mainModule != null) { result.append("var mainModule=require(\"").append(mainModule).append("\")[\"").append(MODULE).append("\"];"); if (execute) { - result.append("mainModule[\"main\"]();\n"); + result.append("mainModule[\"main\"]("); + makeParameters(result, parameters); + result.append(");\n"); } } diff --git a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/SingleFileApplicationPackager.java b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/SingleFileApplicationPackager.java index 3b2428962..bda824ef2 100644 --- a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/SingleFileApplicationPackager.java +++ b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/SingleFileApplicationPackager.java @@ -82,7 +82,7 @@ public String apply(String it) { IOUtils.write(Joiner.on('\n').join(dependencyInitializers), out, Charsets.UTF_8); IOUtils.write("\n", out); - String wrappedApplication = wrapper.makeApplication(dependencyTree, params.mainModule, params.execute); + String wrappedApplication = wrapper.makeApplication(dependencyTree, params.mainModule, params.execute, params.parameters); IOUtils.write(wrappedApplication, out, Charsets.UTF_8); for (String suffix : params.suffixes) { diff --git a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/SingleFileModuleWrapper.java b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/SingleFileModuleWrapper.java index 8b33563d4..4e715cf2d 100644 --- a/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/SingleFileModuleWrapper.java +++ b/spaghetti-core/src/main/java/com/prezi/spaghetti/packaging/internal/SingleFileModuleWrapper.java @@ -29,12 +29,14 @@ public String wrap(ModuleWrapperParameters params) throws IOException { } @Override - public String makeApplication(Map> dependencyTree, final String mainModule, boolean execute) { + public String makeApplication(Map> dependencyTree, final String mainModule, boolean execute, Map parameters) { StringBuilder result = new StringBuilder(); if (!Strings.isNullOrEmpty(mainModule)) { result.append("var mainModule=modules[\"").append(mainModule).append("\"][\"").append(MODULE).append("\"];"); if (execute) { - result.append("mainModule[\"main\"]();"); + result.append("mainModule[\"main\"]("); + makeParameters(result, parameters); + result.append(");"); } } diff --git a/spaghetti-core/src/test/groovy/com/prezi/spaghetti/ast/internal/parser/ModuleParserTest.groovy b/spaghetti-core/src/test/groovy/com/prezi/spaghetti/ast/internal/parser/ModuleParserTest.groovy index 83549514e..7fea78f90 100644 --- a/spaghetti-core/src/test/groovy/com/prezi/spaghetti/ast/internal/parser/ModuleParserTest.groovy +++ b/spaghetti-core/src/test/groovy/com/prezi/spaghetti/ast/internal/parser/ModuleParserTest.groovy @@ -23,6 +23,8 @@ struct MyStruct { interface Lajos extends Iterable { } + +void main(SpaghettiParameters params) """ def parser = ModuleParser.create(ModuleDefinitionSource.fromString("test", definition)) @@ -39,11 +41,15 @@ interface Lajos extends Iterable { "com.example.test.MyStruct", "com.example.test.Lajos", ] - module.externTypes*.qualifiedName*.toString().asList() == [ + module.externTypes*.qualifiedName*.toString().asList().sort() == [ "JSON", - "Iterable" - ] + "Iterable", + "SpaghettiParameters" + ].sort() 0 * _ + module.methods*.name == [ + "main" + ] } def "parse import"() { diff --git a/spaghetti-core/src/test/groovy/com/prezi/spaghetti/generator/ReservedWordsTest.groovy b/spaghetti-core/src/test/groovy/com/prezi/spaghetti/generator/ReservedWordsTest.groovy index 972d5983c..8ce0f7540 100644 --- a/spaghetti-core/src/test/groovy/com/prezi/spaghetti/generator/ReservedWordsTest.groovy +++ b/spaghetti-core/src/test/groovy/com/prezi/spaghetti/generator/ReservedWordsTest.groovy @@ -6,7 +6,7 @@ class ReservedWordsTest extends Specification { def "protected words"() { expect: ReservedWords.PROTECTED_WORDS.asList() == [ - "getModuleName", "getModuleVersion", "getSpaghettiVersion", "getResourceUrl" + "getModuleName", "getModuleVersion", "getSpaghettiVersion", "getResourceUrl", "getParameter" ].sort() } } diff --git a/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/AmdModuleWrapperTest.groovy b/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/AmdModuleWrapperTest.groovy index 0877905f3..39c69c265 100644 --- a/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/AmdModuleWrapperTest.groovy +++ b/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/AmdModuleWrapperTest.groovy @@ -53,7 +53,7 @@ class AmdModuleWrapperTest extends WrapperTestBase { "com.example.alma": ["com.example.bela"].toSet(), "com.example.bela": [].toSet() ] - def result = new AmdModuleWrapper().makeApplication(dependencyTree, "com.example.test", true) + def result = new AmdModuleWrapper().makeApplication(dependencyTree, "com.example.test", true, [alma: "bela"]) expect: result == [ @@ -66,7 +66,13 @@ class AmdModuleWrapperTest extends WrapperTestBase { '}', '});', 'require(["com.example.test"],function(__mainModule){', - '__mainModule["module"]["main"]();', + '__mainModule["module"]["main"]({', + '"getParameter":function(name){', + 'return({', + '"alma":"bela"', + '})[name];', + '}', + '});', '});', '\n' ].join("") diff --git a/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/CommonJsModuleWrapperTest.groovy b/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/CommonJsModuleWrapperTest.groovy index 9abc2432e..26b7a674f 100644 --- a/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/CommonJsModuleWrapperTest.groovy +++ b/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/CommonJsModuleWrapperTest.groovy @@ -51,12 +51,18 @@ class CommonJsModuleWrapperTest extends WrapperTestBase { "com.example.alma": ["com.example.bela"].toSet(), "com.example.bela": [].toSet() ] - def result = new CommonJsModuleWrapper().makeApplication(dependencyTree, "com.example.test", true) + def result = new CommonJsModuleWrapper().makeApplication(dependencyTree, "com.example.test", true, [alma: "bela"]) expect: result == [ 'var mainModule=require("com.example.test")["module"];', - 'mainModule["main"]();\n', + 'mainModule["main"]({', + '"getParameter":function(name){', + 'return({', + '"alma":"bela"', + '})[name];', + '}', + '});\n', ].join("") } } diff --git a/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/SingleFileModuleWrapperTest.groovy b/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/SingleFileModuleWrapperTest.groovy index bcf0dbbd9..15775880a 100644 --- a/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/SingleFileModuleWrapperTest.groovy +++ b/spaghetti-core/src/test/groovy/com/prezi/spaghetti/packaging/SingleFileModuleWrapperTest.groovy @@ -51,12 +51,18 @@ class SingleFileModuleWrapperTest extends WrapperTestBase { "com.example.alma": ["com.example.bela"].toSet(), "com.example.bela": [].toSet() ] - def result = new SingleFileModuleWrapper().makeApplication(dependencyTree, "com.example.test", true) + def result = new SingleFileModuleWrapper().makeApplication(dependencyTree, "com.example.test", true, [alma: "bela"]) expect: result == [ 'var mainModule=modules["com.example.test"]["module"];', - 'mainModule["main"]();' + 'mainModule["main"]({', + '"getParameter":function(name){', + 'return({', + '"alma":"bela"', + '})[name];', + '}', + '});', ].join("") } } diff --git a/spaghetti-gradle-example/app/build.gradle b/spaghetti-gradle-example/app/build.gradle index dc0bd91b3..8ca1d55e3 100644 --- a/spaghetti-gradle-example/app/build.gradle +++ b/spaghetti-gradle-example/app/build.gradle @@ -39,36 +39,28 @@ def bundleTask = hasProperty("obfuscated") ? obfuscateJsModule : bundleJsModule def config = hasProperty("obfuscated") ? configurations.modulesObf : configurations.modules task packageAmdApplication(type: com.prezi.spaghetti.gradle.PackageApplication) { - dependsOn bundleTask - dependentModules config - additionalDirectDependentModule bundleTask.outputDirectory - mainModule "prezi.test.client" outputDirectory "${buildDir}/applications/web" - prefix "src/main/spaghetti/prefix.js" - suffix "src/main/spaghetti/suffix.js" type "requirejs" } task packageNodeApplication(type: com.prezi.spaghetti.gradle.PackageApplication) { - dependsOn bundleTask - dependentModules config - additionalDirectDependentModule bundleTask.outputDirectory - mainModule "prezi.test.client" outputDirectory "${buildDir}/applications/node" - prefix "src/main/spaghetti/prefix.js" - suffix "src/main/spaghetti/suffix.js" type "node" } task packageSingleFileApplication(type: com.prezi.spaghetti.gradle.PackageApplication) { + outputDirectory "${buildDir}/applications/single" + type "single" +} + +tasks.withType(com.prezi.spaghetti.gradle.PackageApplication) { dependsOn bundleTask dependentModules config additionalDirectDependentModule bundleTask.outputDirectory - mainModule "prezi.test.client" - outputDirectory "${buildDir}/applications/single" + parameters version: project.version + "-app" prefix "src/main/spaghetti/prefix.js" suffix "src/main/spaghetti/suffix.js" - type "single" + mainModule "prezi.test.client" } def testWebappDir = file("${buildDir}/webapp") diff --git a/spaghetti-gradle-example/app/src/main/haxe/prezi/test/client/Client.hx b/spaghetti-gradle-example/app/src/main/haxe/prezi/test/client/Client.hx index 19c58919c..002ef608d 100644 --- a/spaghetti-gradle-example/app/src/main/haxe/prezi/test/client/Client.hx +++ b/spaghetti-gradle-example/app/src/main/haxe/prezi/test/client/Client.hx @@ -7,9 +7,10 @@ import prezi.graphics.text.Values; import prezi.graphics.text.render.RenderModule; class Client { - public static function main() { + public static function main(params:SpaghettiParameters) { trace("App name: " + Spaghetti.getModuleName()); - trace("App version: " + Spaghetti.getModuleVersion()); + trace("App module version: " + Spaghetti.getModuleVersion()); + trace("App version: " + params.getParameter("version")); trace("App built by Spaghetti version " + Spaghetti.getSpaghettiVersion()); var text = prezi.graphics.text.Layout.createText(); var style:prezi.graphics.text.CharacterStyle = { type: CharacterStyleType.FONT_WEIGHT, value: "bold" }; diff --git a/spaghetti-gradle-example/app/src/main/spaghetti/App.module b/spaghetti-gradle-example/app/src/main/spaghetti/App.module index 14ea37e7b..33534899a 100644 --- a/spaghetti-gradle-example/app/src/main/spaghetti/App.module +++ b/spaghetti-gradle-example/app/src/main/spaghetti/App.module @@ -1,3 +1,3 @@ module prezi.test.client as Client -void main() +void main(SpaghettiParameters params) diff --git a/spaghetti-haxe-support/src/main/groovy/com/prezi/spaghetti/haxe/HaxeGenerator.groovy b/spaghetti-haxe-support/src/main/groovy/com/prezi/spaghetti/haxe/HaxeGenerator.groovy index 564958517..ae6b7ab82 100644 --- a/spaghetti-haxe-support/src/main/groovy/com/prezi/spaghetti/haxe/HaxeGenerator.groovy +++ b/spaghetti-haxe-support/src/main/groovy/com/prezi/spaghetti/haxe/HaxeGenerator.groovy @@ -11,6 +11,7 @@ import com.prezi.spaghetti.haxe.impl.HaxeModuleProxyGeneratorVisitor import com.prezi.spaghetti.haxe.stub.HaxeInterfaceStubGeneratorVisitor import static com.prezi.spaghetti.generator.ReservedWords.SPAGHETTI_CLASS +import static com.prezi.spaghetti.generator.ReservedWords.SPAGHETTI_PARAMETERS_CLASS class HaxeGenerator extends AbstractGenerator { @@ -68,6 +69,7 @@ return ${HAXE_MODULE_VAR}; */ private static void copySpaghettiClass(File outputDirectory) { new File(outputDirectory, "${SPAGHETTI_CLASS}.hx") << HaxeGenerator.class.getResourceAsStream("/${SPAGHETTI_CLASS}.hx") + new File(outputDirectory, "${SPAGHETTI_PARAMETERS_CLASS}.hx") << HaxeGenerator.class.getResourceAsStream("/${SPAGHETTI_PARAMETERS_CLASS}.hx") } /** diff --git a/spaghetti-haxe-support/src/main/resources/SpaghettiParameters.hx b/spaghetti-haxe-support/src/main/resources/SpaghettiParameters.hx new file mode 100644 index 000000000..377967657 --- /dev/null +++ b/spaghetti-haxe-support/src/main/resources/SpaghettiParameters.hx @@ -0,0 +1,6 @@ +interface SpaghettiParameters { + /** + * Returns the value of a parameter. + */ + public function getParameter(name:String):Dynamic; +} diff --git a/spaghetti-typescript-support/src/main/groovy/com/prezi/spaghetti/typescript/TypeScriptGenerator.groovy b/spaghetti-typescript-support/src/main/groovy/com/prezi/spaghetti/typescript/TypeScriptGenerator.groovy index bef05d541..a9fe81cf5 100644 --- a/spaghetti-typescript-support/src/main/groovy/com/prezi/spaghetti/typescript/TypeScriptGenerator.groovy +++ b/spaghetti-typescript-support/src/main/groovy/com/prezi/spaghetti/typescript/TypeScriptGenerator.groovy @@ -11,6 +11,7 @@ import com.prezi.spaghetti.typescript.impl.TypeScriptModuleProxyGeneratorVisitor import com.prezi.spaghetti.typescript.stub.TypeScriptInterfaceStubGeneratorVisitor import static com.prezi.spaghetti.generator.ReservedWords.SPAGHETTI_CLASS +import static com.prezi.spaghetti.generator.ReservedWords.SPAGHETTI_PARAMETERS_CLASS class TypeScriptGenerator extends AbstractGenerator { @@ -63,6 +64,7 @@ return ${module.name}.${CREATE_MODULE_FUNCTION}(${SPAGHETTI_CLASS}); */ private static void copySpaghettiClass(File outputDirectory) { new File(outputDirectory, "${SPAGHETTI_CLASS}.ts") << TypeScriptGenerator.class.getResourceAsStream("/${SPAGHETTI_CLASS}.ts") + new File(outputDirectory, "${SPAGHETTI_PARAMETERS_CLASS}.ts") << TypeScriptGenerator.class.getResourceAsStream("/${SPAGHETTI_PARAMETERS_CLASS}.ts") } /** diff --git a/spaghetti-typescript-support/src/main/resources/SpaghettiParameters.ts b/spaghetti-typescript-support/src/main/resources/SpaghettiParameters.ts new file mode 100644 index 000000000..9314ad079 --- /dev/null +++ b/spaghetti-typescript-support/src/main/resources/SpaghettiParameters.ts @@ -0,0 +1,6 @@ +interface SpaghettiParameters { + /** + * Returns the value of a parameter. + */ + getParameter(name:string):any; +} diff --git a/spaghetti/src/main/java/com/prezi/spaghetti/cli/commands/PackageApplicationCommand.java b/spaghetti/src/main/java/com/prezi/spaghetti/cli/commands/PackageApplicationCommand.java index 5319cdac0..d312c2d83 100644 --- a/spaghetti/src/main/java/com/prezi/spaghetti/cli/commands/PackageApplicationCommand.java +++ b/spaghetti/src/main/java/com/prezi/spaghetti/cli/commands/PackageApplicationCommand.java @@ -51,6 +51,7 @@ public Integer call() throws Exception { name != null ? name + ".js" : "application.js", mainModule, execute != null ? execute : mainModule != null, + Collections. emptyMap(), Collections. emptySet(), Collections. emptySet() );