Skip to content

Commit

Permalink
JS: Add build.xml to compile and lint the code. Updated README with i…
Browse files Browse the repository at this point in the history
…nstructions how to compile and use the library. Use demo.js and demo-compiled.js as example. Checking in demo-compiled.html and js to be linked from the project home page.

Review URL: https://codereview.appspot.com/8889044
  • Loading branch information
tronikos authored and mihaelacr-google committed Dec 3, 2014
1 parent b86c00f commit ae0818a
Show file tree
Hide file tree
Showing 7 changed files with 899 additions and 230 deletions.
44 changes: 39 additions & 5 deletions javascript/README
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ international phone numbers.

How to setup:
=============
1. Checkout closure-library next to libphonenumber:
1. Checkout closure-library, closure-compiler, closure-linter and python-gflags
next to libphonenumber:

e.g.
svn checkout http://libphonenumber.googlecode.com/svn/trunk/ ~/src/libphonenumber
svn checkout http://closure-library.googlecode.com/svn/trunk/ ~/src/closure-library
svn checkout http://closure-compiler.googlecode.com/svn/trunk/ ~/src/closure-compiler
svn checkout http://closure-linter.googlecode.com/svn/trunk/ ~/src/closure-linter
svn checkout http://python-gflags.googlecode.com/svn/trunk/ ~/src/python-gflags

(Or change the path of the <script src=""> in the html pages to point to
wherever base.js is located.)
(If you don't checkout the dependencies next to libphonenumber:
a. change the path of the <script src=""> in the html pages to point to wherever
base.js is located
b. update javascript/build.xml with the correct paths)

2. Run the unit tests to make sure everything is working. Open the following
pages with your web browser:
Expand All @@ -23,6 +29,29 @@ pages with your web browser:
3. Run the demo: javascript/i18n/phonenumbers/demo.html


How to compile:
===============
1. Build Closure's compiler.jar:

e.g.
ant -f ~/src/closure-compiler/build.xml

2. Compile the demo.js and all its dependencies to one file: demo-compiled.js:

ant -f javascript/build.xml compile-demo

3. Run the compiled demo: javascript/i18n/phonenumbers/demo-compiled.html


How to use:
===========
To use and compile the library in your own project, use the
javascript/i18n/phonenumbers/demo.js as an example. You will need to
goog.exportSymbol all the methods you use in your html so that the compiler
won't rename them. You can then invoke the compiler similarly to how the
compile-demo ant target in javascript/build.xml invokes it.


How to update:
==============
The JavaScript library is ported from the Java implementation (revision 536).
Expand Down Expand Up @@ -51,9 +80,14 @@ project:
PhoneNumberUtilTest.java => phonenumberutil_test.js
AsYouTypeFormatterTest.java => asyoutypeformatter_test.js

4. Run the Closure Compiler to get your changes syntax checked:
4. Run the Closure Compiler to get your changes syntax and type checked.
This will also generate demo-compiled.js used by demo-compiler.html:

ant -f javascript/build.xml compile

5. Run the Closure Linter to lint the JavaScript files:

./compile.sh
ant -f javascript/build.xml lint


TODO:
Expand Down
137 changes: 137 additions & 0 deletions javascript/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?xml version="1.0" ?>

<project name="libphonenumber-javascript" default="compile">
<property name="closure-compiler.dir"
value="${basedir}/../../closure-compiler" />
<property name="closure-compiler.jar"
value="${closure-compiler.dir}/build/compiler.jar" />
<property name="closure-library.dir"
value="${basedir}/../../closure-library" />
<property name="closure-linter.dir"
value="${basedir}/../../closure-linter" />
<property name="python-gflags.dir"
value="${basedir}/../../python-gflags" />

<macrodef name="closure-compile">
<attribute name="inputfile" />
<attribute name="outputfile" />
<attribute name="compilationlevel" default="ADVANCED_OPTIMIZATIONS" />
<attribute name="outputmode" default="compiled" />
<attribute name="outputwrapper" default="(function(){%output%})();" />
<element name="extraflags" optional="yes" />
<sequential>
<exec executable="python" failonerror="true" logError="true">
<arg value="${closure-library.dir}/closure/bin/calcdeps.py" />
<arg line='-i "@{inputfile}"' />
<arg line='--output_file "@{outputfile}"' />
<arg line='-p "${closure-library.dir}"' />
<arg line="-o @{outputmode}" />
<arg line='-c "${closure-compiler.jar}"' />
<arg line='-f "--output_wrapper=@{outputwrapper}"' />
<arg line='-f "--compilation_level=@{compilationlevel}"' />
<arg line='-f "--warning_level=VERBOSE"' />
<arg line='-f "--jscomp_error=accessControls"' />
<arg line='-f "--jscomp_error=ambiguousFunctionDecl"' />
<arg line='-f "--jscomp_error=checkDebuggerStatement"' />
<arg line='-f "--jscomp_error=checkRegExp"' />
<arg line='-f "--jscomp_error=checkTypes"' />
<arg line='-f "--jscomp_error=checkVars"' />
<arg line='-f "--jscomp_error=const"' />
<arg line='-f "--jscomp_error=constantProperty"' />
<arg line='-f "--jscomp_error=deprecated"' />
<arg line='-f "--jscomp_error=duplicate"' />
<arg line='-f "--jscomp_error=duplicateMessage"' />
<arg line='-f "--jscomp_error=es5Strict"' />
<arg line='-f "--jscomp_error=externsValidation"' />
<arg line='-f "--jscomp_error=fileoverviewTags"' />
<arg line='-f "--jscomp_error=globalThis"' />
<arg line='-f "--jscomp_error=internetExplorerChecks"' />
<arg line='-f "--jscomp_error=invalidCasts"' />
<arg line='-f "--jscomp_error=misplacedTypeAnnotation"' />
<arg line='-f "--jscomp_error=missingProperties"' />
<arg line='-f "--jscomp_error=nonStandardJsDocs"' />
<arg line='-f "--jscomp_error=strictModuleDepCheck"' />
<arg line='-f "--jscomp_error=suspiciousCode"' />
<arg line='-f "--jscomp_error=typeInvalidation"' />
<arg line='-f "--jscomp_error=undefinedNames"' />
<arg line='-f "--jscomp_error=undefinedVars"' />
<arg line='-f "--jscomp_error=unknownDefines"' />
<arg line='-f "--jscomp_error=uselessCode"' />
<arg line='-f "--jscomp_error=visibility"' />
<extraflags />
</exec>
</sequential>
</macrodef>

<macrodef name="gjslint">
<attribute name="inputfile" />
<sequential>
<exec executable="python" failonerror="false" logError="true">
<env key="PYTHONPATH"
value="${closure-linter.dir}:${python-gflags.dir}"/>
<arg value="${closure-linter.dir}/closure_linter/gjslint.py" />
<arg line='--strict' />
<arg line='"@{inputfile}"' />
</exec>
</sequential>
</macrodef>

<condition property="os.iswindows">
<os family="windows" />
</condition>
<condition property="os.isunix">
<os family="unix" />
</condition>
<target name="nul" if="os.iswindows">
<property name="null.device" value="NUL" />
</target>
<target name="devnull" if="os.isunix">
<property name="null.device" value="/dev/null" />
</target>
<target name="setnulldevice" depends="nul,devnull" />

<target name="clean" description="deletes all generated files">
<delete file="i18n/phonenumbers/demo-compiled.js" />
</target>

<target name="compile-demo"
description="generates demo-compiled.js">
<closure-compile inputfile="i18n/phonenumbers/demo.js"
outputfile="i18n/phonenumbers/demo-compiled.js">
<extraflags>
<arg line='-p "i18n/phonenumbers"' />
<arg line='-e "i18n/phonenumbers/metadatafortesting.js"' />
<arg line='-e "i18n/phonenumbers/metadatalite.js"' />
<arg line='-e "i18n/phonenumbers/regioncodefortesting.js"' />
</extraflags>
</closure-compile>
</target>

<target name="compile-tests" depends="setnulldevice">
<closure-compile inputfile="i18n/phonenumbers/asyoutypeformatter_test.js"
outputfile="${null.device}">
<extraflags>
<arg line='-p "i18n/phonenumbers"' />
<arg line='-e "i18n/phonenumbers/metadata.js"' />
<arg line='-e "i18n/phonenumbers/metadatalite.js"' />
</extraflags>
</closure-compile>
<closure-compile inputfile="i18n/phonenumbers/phonenumberutil_test.js"
outputfile="${null.device}">
<extraflags>
<arg line='-p "i18n/phonenumbers"' />
<arg line='-e "i18n/phonenumbers/metadata.js"' />
<arg line='-e "i18n/phonenumbers/metadatalite.js"' />
</extraflags>
</closure-compile>
</target>

<target name="compile" depends="compile-demo,compile-tests" />

<target name="lint" description="lints all javascript files">
<gjslint inputfile="i18n/phonenumbers/asyoutypeformatter*.js" />
<gjslint inputfile="i18n/phonenumbers/demo.js" />
<gjslint inputfile="i18n/phonenumbers/phonenumberutil*.js" />
</target>

</project>
93 changes: 0 additions & 93 deletions javascript/compile.sh

This file was deleted.

53 changes: 53 additions & 0 deletions javascript/i18n/phonenumbers/demo-compiled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<!--
@license
Copyright (C) 2010 The Libphonenumber Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
Author: Nikolaos Trogkanis
-->
<head>
<title>Phone Number Parser Demo</title>
<script src="demo-compiled.js"></script>
</head>
<body>

<h2>Phone Number Parser Demo</h2>

<form>
<p>
Specify a Phone Number:
<input type="text" name="phoneNumber" id="phoneNumber" size="25" />
</p>
<p>
Specify a Default Country:
<input type="text" name="defaultCountry" id="defaultCountry" size="2" />
(ISO 3166-1 two-letter country code)
</p>
<p>
Specify a Carrier Code:
<input type="text" name="carrierCode" id="carrierCode" size="2" />
(optional, only valid for some countries)
</p>
<input type="submit" value="Submit" onclick="return phoneNumberParser();" />
<input type="reset" value="Reset" />
<p>
<textarea id="output" rows="30" cols="80"></textarea>
</p>
</form>

</body>
</html>
Loading

0 comments on commit ae0818a

Please sign in to comment.