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
This commit is contained in:
gbrodman 2019-02-08 07:50:29 -08:00 committed by Gus Brodman
parent 71d65ed73a
commit a995fc09cb
5 changed files with 2583 additions and 15 deletions

View file

@ -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.

View file

@ -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,21 +454,38 @@ 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
@ -440,6 +495,12 @@ compileJava.dependsOn soyToJava
// 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.

View file

@ -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',

2457
gradle/node_modules/soyutils_usegoog.js generated vendored Normal file

File diff suppressed because it is too large Load diff

22
gradle/package.json Normal file
View file

@ -0,0 +1,22 @@
{
"name": "nomulus",
"version": "1.0.0",
"description": "Top-level domain name registry service on Google App Engine https://registry.google",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/google/nomulus.git"
},
"author": "",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/google/nomulus/issues"
},
"homepage": "https://github.com/google/nomulus#readme",
"dependencies": {
"google-closure-library": "20190121.0.0"
}
}