Skip to content

Commit

Permalink
modifications to support minification of CSS file in js-release solve…
Browse files Browse the repository at this point in the history
…s in part #39

Now needs more work of final minify process
  • Loading branch information
carlosrovira committed Apr 8, 2018
1 parent 730c5a9 commit 966a63e
Showing 1 changed file with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,11 @@ public boolean publish(ProblemQuery problems) throws IOException
project.needCSS = gdw.needCSS;
if (project.needCSS || googConfiguration.getSkipTranspile()) {
if (!googConfiguration.getSkipTranspile()) {
writeCSS(projectName, intermediateDir);
writeCSS(projectName, intermediateDir, false);
}
if (project.needCSS && configuration.release()) {
FileUtils.copyFile(new File(intermediateDir, projectName + ".css"),
new File(releaseDir, projectName + ".css"));
// if release version minify css string
writeCSS(projectName, releaseDir, true);
}
}

Expand Down Expand Up @@ -651,7 +651,13 @@ protected void writeTemplate(File template, String type, String projectName, Str
bgcolor = ta.getBackgroundColor();
pageTitle = ta.getPageTitle();
}
String result = input.replaceAll("\\$\\{application\\}", mainClassQName);

String result = null;
if (type.equals("release")) {
result = input.replaceAll("\\$\\{application\\}", mainClassQName + ".min");
} else {
result = input.replaceAll("\\$\\{application\\}", mainClassQName);
}
if (bgcolor != null)
result = result.replaceAll("\\$\\{bgcolor\\}", bgcolor);
//result = result.replaceAll("\\$\\{expressInstallSwf\\}", expressInstallSwf);
Expand Down Expand Up @@ -730,7 +736,13 @@ protected void writeHTML(String type, String projectName, String mainClassQName,
htmlFile.append("<head>\n");
htmlFile.append("\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n");
htmlFile.append("\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
htmlFile.append("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"").append(projectName).append(".css\">\n");

// if release version want to call minified css file, while in debug the non minified one
if (type.equals("release")) {
htmlFile.append("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"").append(projectName).append(".min.css\">\n");
} else {
htmlFile.append("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"").append(projectName).append(".css\">\n");
}

htmlFile.append(getTemplateAdditionalHTML(additionalHTML));
htmlFile.append(getTemplateDependencies(type, projectName, mainClassQName, deps));
Expand All @@ -746,10 +758,20 @@ protected void writeHTML(String type, String projectName, String mainClassQName,
writeFile(new File(targetDir, googConfiguration.getHtmlOutputFileName()), htmlFile.toString(), false);
}

private void writeCSS(String projectName, File targetDir) throws IOException
private void writeCSS(String projectName, File targetDir, Boolean minify) throws IOException
{
JSCSSCompilationSession cssSession = (JSCSSCompilationSession) project.getCSSCompilationSession();
writeFile(new File(targetDir, projectName + ".css"), cssSession.emitCSS(), false);
String cssString = cssSession.emitCSS();

if (minify)
{
//remove \r\n, \n for now this needs more work at this point
cssString = cssString.replaceAll("\\r\\n|\\n", "");
writeFile(new File(targetDir, projectName + ".min.css"), cssString, false);
} else {
writeFile(new File(targetDir, projectName + ".css"), cssString, false);
}

for (CSSFontFace fontFace : cssSession.fontFaces)
{
// check frameworks/fonts folder
Expand Down

0 comments on commit 966a63e

Please sign in to comment.