Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: compile in AMD and CJS #388

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,59 @@ rm -rf dist/* \
--js=src/shortnumberinfo.js \
--js=src/shortnumbermetadata.js \
--js=src/asyoutypeformatter.js \
--js_output_file=dist/libphonenumber.original.js \
&& ./node_modules/.bin/browserify dist/libphonenumber.original.js --standalone libphonenumber --no-browser-field --outfile dist/libphonenumber.js \
&& rm dist/libphonenumber.original.js \
--process_common_js_modules \
--module_resolution=NODE \
--common_js_entry_module=src/index.js \
--module_output_path_prefix=dist/ \
--create_source_map=%outname%.map \
--js_output_file=dist/libphonenumber.cjs.js \
&& ./node_modules/.bin/google-closure-compiler \
--compilation_level=SIMPLE \
--js=node_modules/google-closure-library/closure/goog/array/array.js \
--js=node_modules/google-closure-library/closure/goog/asserts/asserts.js \
--js=node_modules/google-closure-library/closure/goog/base.js \
--js=node_modules/google-closure-library/closure/goog/debug/error.js \
--js=node_modules/google-closure-library/closure/goog/dom/asserts.js \
--js=node_modules/google-closure-library/closure/goog/dom/htmlelement.js \
--js=node_modules/google-closure-library/closure/goog/dom/nodetype.js \
--js=node_modules/google-closure-library/closure/goog/dom/safe.js \
--js=node_modules/google-closure-library/closure/goog/dom/tagname.js \
--js=node_modules/google-closure-library/closure/goog/dom/tags.js \
--js=node_modules/google-closure-library/closure/goog/fs/blob.js \
--js=node_modules/google-closure-library/closure/goog/fs/url.js \
--js=node_modules/google-closure-library/closure/goog/functions/functions.js \
--js=node_modules/google-closure-library/closure/goog/html/safehtml.js \
--js=node_modules/google-closure-library/closure/goog/html/safescript.js \
--js=node_modules/google-closure-library/closure/goog/html/safestyle.js \
--js=node_modules/google-closure-library/closure/goog/html/safestylesheet.js \
--js=node_modules/google-closure-library/closure/goog/html/safeurl.js \
--js=node_modules/google-closure-library/closure/goog/html/trustedresourceurl.js \
--js=node_modules/google-closure-library/closure/goog/html/trustedtypes.js \
--js=node_modules/google-closure-library/closure/goog/html/uncheckedconversions.js \
--js=node_modules/google-closure-library/closure/goog/i18n/bidi.js \
--js=node_modules/google-closure-library/closure/goog/labs/useragent/browser.js \
--js=node_modules/google-closure-library/closure/goog/labs/useragent/util.js \
--js=node_modules/google-closure-library/closure/goog/object/object.js \
--js=node_modules/google-closure-library/closure/goog/proto2/descriptor.js \
--js=node_modules/google-closure-library/closure/goog/proto2/fielddescriptor.js \
--js=node_modules/google-closure-library/closure/goog/proto2/lazydeserializer.js \
--js=node_modules/google-closure-library/closure/goog/proto2/message.js \
--js=node_modules/google-closure-library/closure/goog/proto2/pbliteserializer.js \
--js=node_modules/google-closure-library/closure/goog/proto2/serializer.js \
--js=node_modules/google-closure-library/closure/goog/string/const.js \
--js=node_modules/google-closure-library/closure/goog/string/internal.js \
--js=node_modules/google-closure-library/closure/goog/string/string.js \
--js=node_modules/google-closure-library/closure/goog/string/stringbuffer.js \
--js=node_modules/google-closure-library/closure/goog/string/typedstring.js \
--js=src/index.js \
--js=src/metadata.js \
--js=src/phonemetadata.pb.js \
--js=src/phonenumber.pb.js \
--js=src/phonenumberutil.js \
--js=src/shortnumberinfo.js \
--js=src/shortnumbermetadata.js \
--js=src/asyoutypeformatter.js \
--create_source_map=%outname%.map \
--js_output_file=dist/libphonenumber.amd.js \
--output_wrapper='define(function(){%output%});' \
&& echo "Build completed!"



31 changes: 28 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,45 @@
<arg line='-f "--jscomp_error=unknownDefines"' />
<arg line='-f "--jscomp_error=uselessCode"' />
<arg line='-f "--jscomp_error=visibility"' />
<arg line='-f "--language_in=ECMASCRIPT5_STRICT"' />
<arg line='-f "--language_out=ECMASCRIPT5_STRICT"' />
<arg line='-f "--process_common_js_modules"' />
<arg line='-f "--module_resolution=NODE"' />
<arg line='-f "--common_js_entry_module=src/index.js"' />
<arg line='-f "--module_output_path_prefix=dist/"' />
<extraflags />
</exec>
</sequential>
</macrodef>

<target name="build"
description="generates libphonenumber.js">
<target name="build" description="generates libphonenumber.js">
<!-- CommonJS build -->
<closure-compile inputfile="src/index.js"
outputfile="dist/libphonenumber.js">
outputfile="dist/libphonenumber.cjs.js"
outputwrapper="module.exports = (function() {%output%})();">
<extraflags>
<arg line='-p "src"' />
<arg line='-e "src/metadatafortesting.js"' />
<arg line='-e "src/metadatalite.js"' />
<arg line='-e "src/regioncodefortesting.js"' />
<arg line='-f "--process_common_js_modules"' />
<arg line='-f "--module_resolution=NODE"' />
<arg line='-f "--common_js_entry_module=src/index.js"' />
<arg line='-f "--module_output_path_prefix=dist/"' />
<arg line='-f "--create_source_map=%outname%.map"' />
</extraflags>
</closure-compile>

<!-- AMD build -->
<closure-compile inputfile="src/index.js"
outputfile="dist/libphonenumber.amd.js"
outputwrapper="define(function() {%output%});">
<extraflags>
<arg line='-p "src"' />
<arg line='-e "src/metadatafortesting.js"' />
<arg line='-e "src/metadatalite.js"' />
<arg line='-e "src/regioncodefortesting.js"' />
<arg line='-f "--create_source_map=%outname%.map"' />
</extraflags>
</closure-compile>
</target>
Expand Down
Loading