File html = new File(outputDir, "index.html");
InstanceService instanceService = Aura.getInstanceService();
RenderingService renderingService = Aura.getRenderingService();
ContextService contextService = Aura.getContextService();
AuraContext context = contextService.getCurrentContext();
Writer htmlWriter = new FileWriter(html);
try {
String uid = context.getDefRegistry().getUid(null, def.getDescriptor());
Set<DefDescriptor<?>> dependencies = context.getDefRegistry().getDependencies(uid);
ComponentDef templateDef = def.getTemplateDef();
Map<String, Object> attributes = Maps.newHashMap();
StringBuilder sb = new StringBuilder();
// Get the preload css
List<String> styles = Lists.newArrayList(String.format("%s.css", appName));
this.writeHtmlStyles(styles, sb);
File css = new File(outputDir, String.format("%s.css", appName));
FileWriter cssWriter = new FileWriter(css);
try {
Aura.getServerService().writeAppCss(dependencies, cssWriter);
} finally {
cssWriter.close();
}
attributes.put("auraStyleTags", sb.toString());
// Clear sb out
sb.setLength(0);
List<String> scripts = Lists.newArrayList("aura.js", String.format("%s.js", appName));
writeHtmlScripts(scripts, sb);
// Get the framework js
File auraJs = new File(outputDir, "aura.js");
FileWriter auraJsWriter = new FileWriter(auraJs);
InputStream in = Aura.getConfigAdapter().getResourceLoader()
.getResourceAsStream("aura/javascript/aura_dev.js");
InputStreamReader reader = new InputStreamReader(in);
try {
Aura.getConfigAdapter().regenerateAuraJS();
IOUtil.copyStream(reader, auraJsWriter);
} finally {
try {
auraJsWriter.close();
} finally {
reader.close();
}
}
Application instance = instanceService.getInstance(def, null);
// Get the preload js
File js = new File(outputDir, String.format("%s.js", appName));
FileWriter jsWriter = new FileWriter(js);
try {
Aura.getServerService().writeDefinitions(dependencies, jsWriter);
// Write the app at the bottom of the same file
Map<String, Object> auraInit = Maps.newHashMap();
auraInit.put("instance", instance);
auraInit.put("token", AuraServlet.getToken());
auraInit.put("host", context.getContextPath());
contextService.startContext(Mode.PROD, Format.HTML, Authentication.AUTHENTICATED, def.getDescriptor());
auraInit.put("context", contextService.getCurrentContext());
jsWriter.append("\n$A.initConfig($A.util.json.resolveRefs(");
Json.serialize(auraInit, jsWriter, context.getJsonSerializationContext());
jsWriter.append("));\n");
} finally {
jsWriter.close();