Permalink
Browse files

Add the Closure Compiler/Library/Templates dependencies

This CL does a few things:
- Adds the template Soy-to-JS compilation (note: this requires the extra
  soyutils_usegoog.js file separately so that the compiled *.soy.js files work
- Adds the Closure Compiler to compile and check our JS
- Adds an NPM task to allow us to download dependencies
- Adds the Closure library as an NPM package

Note: this probably won't compile until we fix the test JS files

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=233059414
  • Loading branch information...
gbrodman committed Feb 8, 2019
1 parent 71d65ed commit a995fc09cb56757ab0b82f68d11a25b825769a0e
Showing with 2,583 additions and 15 deletions.
  1. +27 −0 gradle/build.gradle
  2. +76 −15 gradle/core/build.gradle
  3. +1 −0 gradle/dependencies.gradle
  4. +2,457 −0 gradle/node_modules/soyutils_usegoog.js
  5. +22 −0 gradle/package.json
@@ -26,6 +26,7 @@ plugins {
id 'com.bmuschko.docker-java-application' version '4.0.4' apply false
id 'net.ltgt.errorprone' version '0.6.1'
id 'checkstyle'
id "com.moowork.node" version "1.2.0"
}

apply from: 'dependencies.gradle'
@@ -211,6 +212,32 @@ subprojects {
}
}

if (project.path.contains("default")) {
def coreResourcesDir = "${rootDir}/core/build/resources/main"
war {
from("${coreResourcesDir}/google/registry/ui") {
include "registrar_bin*"
into("assets/js")
rename { String filename -> filename.replace("bin", "dbg")}
}
from("${coreResourcesDir}/google/registry/ui") {
include "registrar_bin*"
into("assets/js")
}
from("${coreResourcesDir}/google/registry/ui/css") {
include "registrar*"
into("assets/css")
}
from("${coreResourcesDir}/google/registry/ui/assets/images") {
include "**/*"
into("assets/images")
}
from("${coreResourcesDir}/google/registry/ui/html") {
include "*.html"
}
}
}

appengine {
deploy {
// TODO: change this to a variable.
@@ -5,6 +5,7 @@ plugins {
// Path to code generated by ad hoc tasks in this project. A separate path is
// used for easy inspection.
def generatedDir = "${project.buildDir}/generated/source/custom/main"
def resourcesDir = "${project.buildDir}/resources/main"

// Tests that conflict with (mostly unidentified) members of the main test
// suite. It is unclear if they are offenders (i.e., those that pollute global
@@ -59,6 +60,7 @@ configurations {
// either compile or testRuntime. However, they may be needed at runtime.
// TODO(weiminyu): identify runtime dependencies and remove the rest.
maybeRuntime
closureCompiler
}

// Known issues:
@@ -269,6 +271,8 @@ dependencies {

// Tool dependencies. used for doc generation.
compile files("${System.properties['java.home']}/../lib/tools.jar")

closureCompiler deps['com.google.javascript:closure-compiler']
}

task jaxbToJava {
@@ -384,9 +388,43 @@ task soyToJava {
}
}

task soyToJS {
ext.soyToJS = { outputDirectory, soyFiles , deps->
javaexec {
main = "com.google.template.soy.SoyToJsSrcCompiler"
classpath configurations.soy

args "--outputPathFormat", "${outputDirectory}/{INPUT_FILE_NAME}.js",
"--allowExternalCalls", "false",
"--srcs", "${soyFiles.join(',')}",
"--shouldProvideRequireSoyNamespaces", "true",
"--compileTimeGlobalsFile", "${javaDir}/google/registry/ui/globals.txt",
"--deps", "${deps.join(',')}"
}
}

doLast {
def rootSoyFiles =
fileTree(
dir: "${javaDir}/google/registry/ui/soy",
include: ['*.soy'])

soyToJS("${generatedDir}/google/registry/ui/soy", rootSoyFiles, "")
soyToJS("${generatedDir}/google/registry/ui/soy/registrar",
files {
file("${javaDir}/google/registry/ui/soy/registrar").listFiles()
}.filter {
it.name.endsWith(".soy")
}.filter{
// TODO(b/123653579): add this back in when it compiles
!it.name.equals("OteSetupConsole.soy")
}, rootSoyFiles)
}
}

task stylesheetsToJavascript {
def cssSourceDir = "${javaDir}/google/registry/ui/css"
def outputDir = "${project.buildDir}/resources/main/google/registry/ui/css"
def outputDir = "${resourcesDir}/google/registry/ui/css"
inputs.dir cssSourceDir
outputs.dir outputDir

@@ -416,30 +454,53 @@ task stylesheetsToJavascript {

doLast {
file("${outputDir}").mkdirs()
def srcFiles = [
"${cssSourceDir}/console.css",
"${cssSourceDir}/contact-settings.css",
"${cssSourceDir}/contact-us.css",
"${cssSourceDir}/dashboard.css",
"${cssSourceDir}/epp.css",
"${cssSourceDir}/forms.css",
"${cssSourceDir}/kd_components.css",
"${cssSourceDir}/registry.css",
"${cssSourceDir}/resources.css",
"${cssSourceDir}/security-settings.css"
]
cssCompile("${outputDir}/registrar_bin", false, srcFiles)
cssCompile("${outputDir}/registrar_dbg", true, srcFiles)
def ignoredFiles = ["demo_css.css", "registrar_imports_raw.css"]
def sourceFiles = []
// include all CSS files that we find except for the ones explicitly ignored
fileTree(cssSourceDir).each {
if (it.name.endsWith(".css") && !ignoredFiles.contains(it.name)) {
sourceFiles << (cssSourceDir + "/" + it.name)
}
}
cssCompile("${outputDir}/registrar_bin", false, sourceFiles)
cssCompile("${outputDir}/registrar_dbg", true, sourceFiles)
}
}

task compileProdJS(type: JavaExec) {
// TODO(b/123647609) clean this up in general
// - have two separate tasks for dev/prod
// - the prod task uses the ADVANCED_OPTIMIZATION flag.
// - have this be a configurable task so we can change the inputs/outputs
classpath configurations.closureCompiler
main = 'com.google.javascript.jscomp.CommandLineRunner'

def closureArgs = []
closureArgs << "--compilation_level=SIMPLE_OPTIMIZATIONS"
closureArgs << "--js_output_file=${resourcesDir}/google/registry/ui/registrar_bin.js"
closureArgs << "--js=${rootDir}/node_modules/google-closure-library/**.js"
closureArgs << "--js=${rootDir}/node_modules/soyutils_usegoog.js"
closureArgs << "--entry_point=goog:registry.registrar.main"
closureArgs << "--externs=${javaDir}/google/registry/ui/externs/json.js"
closureArgs << "--js=${resourcesDir}/google/registry/ui/css/registrar_bin.css.js"
closureArgs << "--js=${javaDir}/google/registry/ui/js/**.js"
closureArgs << "--js=${generatedDir}/google/registry/ui/soy/**.js"
args closureArgs
}

compileJava.dependsOn jaxbToJava
compileJava.dependsOn soyToJava

// stylesheetsToJavascript must happen after processResources, which wipes the
// resources folder before copying data into it.
stylesheetsToJavascript.dependsOn processResources
classes.dependsOn stylesheetsToJavascript
compileProdJS.dependsOn stylesheetsToJavascript
compileProdJS.dependsOn rootProject.npmInstall
compileProdJS.dependsOn processResources
compileProdJS.dependsOn processTestResources
compileProdJS.dependsOn soyToJS
assemble.dependsOn compileProdJS

// Make testing artifacts available to be depended up on by other projects.
// TODO: factor out google.registry.testing to be a separate project.
@@ -57,6 +57,7 @@ ext {
'com.google.http-client:google-http-client:1.28.0',
'com.google.http-client:google-http-client-appengine:1.22.0',
'com.google.http-client:google-http-client-jackson2:1.25.0',
'com.google.javascript:closure-compiler:v20190121',
'com.google.monitoring-client:contrib:1.0.4',
'com.google.monitoring-client:metrics:1.0.4',
'com.google.monitoring-client:stackdriver:1.0.4',
Oops, something went wrong.

0 comments on commit a995fc0

Please sign in to comment.