199 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
Highlights of MWLUG 2017
Thu, Aug 17th 2017 109
Phora Group Announces iPhora® integration with DocuSign
Wed, Aug 9th 2017 23
Phora Group Announces iPhora® Async
Mon, Aug 7th 2017 20
MWLUG 2017 - Announcing MWLUG Community Outreach Program Beneficiary
Mon, Aug 7th 2017 22
MWLUG 2017 Transportation from Airport and Parking
Mon, Aug 7th 2017 17
When your Tool is a Hammer, Everything is a Nail, App Modernization - Part 1
Sun, Jul 30th 2017 6
MWLUG 2017 - Domino Application Development Roundtable
Thu, Jul 20th 2017 10
Top 10
Highlights of MWLUG 2017
Thu, Aug 17th 2017 109
Phora Group Announces iPhora® integration with DocuSign
Wed, Aug 9th 2017 23
MWLUG 2017 - Announcing MWLUG Community Outreach Program Beneficiary
Mon, Aug 7th 2017 22
Phora Group Announces iPhora® Async
Mon, Aug 7th 2017 20
MWLUG 2017 Transportation from Airport and Parking
Mon, Aug 7th 2017 17
MWLUG 2017 - Domino Application Development Roundtable
Thu, Jul 20th 2017 10
MWLUG 2016 Abstract Submission is Closing Soon
Wed, Jun 1st 2016 8
MWLUG 2016 Session Schedule is Now Available
Mon, Jul 25th 2016 7
Announcing the MWLUG 2016 OGS IBM Speaker
Tue, Jul 19th 2016 6
When your Tool is a Hammer, Everything is a Nail, App Modernization - Part 1
Sun, Jul 30th 2017 6


Creating Beauty with UglifyJS
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
   

For the past five years, we have been using a Notes-client base tool called iPhora Application Designer, that we created to build our iPhora applications written for our Dojo-based iPhora-MVC platform. This tool is written entirely in LotusScript and @Formula language.

With this tool we compile the  XML/JS view code into pure JavaScript onto a targeted application server all without opening Domino Designer.  Rarely do we venture into using Domino Designer. We only use Domino Designer to enhance our tool or fix a bug. Since this tool is Notes-client based, a key advantage of this tool is the ability to replicate every day our code to a backup server and when we are at home we can replicate to our computer at home.

Currently, our JavaScript MVC platform has over a 1,000,000 lines of Dojo/Javascript code and it grows every day as we add new widgets and modules. Majority of the code is automatically generated by our iPhora Application Designer. Can not imagine generating the code manually.

As part of the compilation process, we created a code HTML/JS minimifier in LotusScript to compress the code.  However, it never really worked the way that we wanted it to and it could not obfuscate the code. So we decide to look elsewhere for help.

There are many JS minimifier out there, but we wanted the ability to integrate it with our development process and also our iPhora Application Designer.  So we looked into integrating tools that we can run using the LotusScript Shell command to process the JavaScript.

After researching different alternatives, we decided to tried a node-based solution called UglifyJS which has a command line interface which we can invoke using the LotusScript Shell command.

First, you need to download and install the latest version of Node.  Make sure that you include the NPM manager during the installation process.

https://nodejs.org/en/download/

After installing node and npm, open a command line window and install uglifyJS from the NPM depository using the following command line.


npm install uglify-js -g

Now that you have installed UglifyJS, you need to confirm that it is working correctly. Create a simple JavaScript file called test.js and run UglifyJS using the following command.

uglifyjs test.js -c -m -o test.min.js

-c : compress the code
-m : mangle the code
-o : declare that there is output file with the following name

If the resulting test.min.js is a compressed mangled version of test.js then it is working.  

We could manually create files and then uglify them one at a time and then uploaded them to the server, but that is time consuming and laborious. Automation is key to reducing the time that you need to spend coding. So we needed to figure out a way to automate the process.

Our XML/JS code are stored in Notes Rich-text fields. When the code is compiled, the generated compiled code is pushed into the targeted Domino server using good old DXL. 

In order to minimify the code using UglifyJS we needed to change our process. Rather than compressing the code using the LotusScript and then pushing it up to the server, we needed a way to get it into the format that the Node-based uglifyJS can use, compress and mangle the code, read the code and push it into the server all in one single operation.  Show below is the process and code that we created to achieve our goal.

Read JavaScript Code from Rich Text

To get the code from the rich-text field using "GetUnformattedText()" Lotusscript rich text item method.

Set ritem = doc.GetFirstItem(fieldName)
If Not(ritem Is Nothing) Then
code = ritem.GetUnformattedText()
else 
code = ""
end if
fileName = tempGetNotesDirectory() & || & |input.js|
Dim fn%
fn = FreeFile
Open fileName For Output As fn
Print #fn,code
Close fn

Create Batch File to Process the JavaScript

cmdLine = |uglifyjs input.js -c -m -o output.js|

Create a batch file that has the command to run UglifyJS, UglifyJS.bat


cmdLine = |uglifyjs input.js -c -m -o output.js|

fileName = tempGetNotesDirectory() & || & |UglifyJS.bat|

Dim fn%

fn = FreeFile
Open fileName For Output As fn
Print #fn,cmdLine
Close fn

Run the batch using the LotusScript Shell command to create the file "output.js"

batchInstance = Shell("UglifyJS.bat",0);

The problem that you have running a batch file using Shell is that there is no way to know if the process has been completed using LotusScript. However, an easy way to check if the process is done is determine if the file output.js has been created.  If not, wait and check again. The following code allows you to query the file system for completion. The uglifying process is very fast, but a large JavaScript file may take longer. The code waits for 1 second and checks the file system. It tried this 10 times and if it can't find it the entire process is killed off.

Function runBatch() as Boolean
Dim tempdir As String
Dim i As Integer
i = 0
On Error GoTo ProcessError
batchInstance = Shell(tempdir &"node_batch.bat", 6)
Do While i < 10
Sleep(1)
If Dir$("output.js",0) <> "" Then
Exit Do
End If
i = i + 1
Loop
If i > 10 Then
runBatch = false ' process timeout
Else
runBatch = true  ' process ran successful
End if

End Function

After the process completes we need to read the output.js file so that we can push it up to the Domino server.

Function readJSFile() As String
Dim tempdir As String
Dim fileName As String
Dim uglifiedCode As String
On Error GoTo ProcessError
tempdir = tempGetNotesDirectory()
fileName = tempdir & |output.js|
Dim fn%
fn = FreeFile
Open fileName For Input As fn
uglifiedCode = Input(LOF(fn), fn)
Close fn
readJSFile = uglifiedCode
End Function

Using our DXL-based methods we stream the compressed and mangled file up to the Domino server.

There is one more step that is required. We need to delete all the files that we created in the temporary directory so that we can process another file. If not, the process can not be repeated since there will always be a output.js file.

Function removeTempFiles() as Boolean
tempdir = tempGetNotesDirectory()
kill tempdir & |uglifyjs.bat|
kill tempdir & |input.js|
kill tempdir & |output.js|
End Function

tempGetNotesDirectory(), function to find the Notes temporary directory

The inclusion of UglifyJS to our iPhora Application Designer has been so successful that we have added other Node-based developer tools to it using the same method to connect our Notes-based tool to new and modern development tools. So far we have added CSSLint and Minifier to cleanup and compress our CSS file. We are looking for other Node modules that we can include to help us automatic the development and testing process. There are thousands of npm modules that run on Node. There are many to choose from.

If you are using the Domino Designer, you should look at this Node-based tools to add new capabilities in your developer's toolbox. How that can be done is beyond my skills.






---------------------
http://dominointerface.blogspot.com/2017/01/creating-beauty-with-uglifyjs.html
Jan 26, 2017
5 hits



Recent Blog Posts
109
Highlights of MWLUG 2017
Thu, Aug 17th 2017 5:11a   Richard Moy
This year the MWLUG conference was held at the Hilton Mark Center in Alexandria, VA. The theme for MWLUG 2017 was "Moving Collaboration Forward." There are numerous changes to the IBM Collaboration landscape and we wanted to cover these changes, but at the same time augment our normal ICS specific sessions with sessions focused on the greater landscape of collaboration. We had sessions on non-ICS specific topics like MongoDB, IoT, and Sharepoint. MWLUG 2017 this year comprised of 60 sessions
23
Phora Group Announces iPhora® integration with DocuSign
Wed, Aug 9th 2017 11:42a   Richard Moy
Posted August 9, 2017 - By Louise Burton - Communication Phora Group, a DocuSign Partner is pleased to announce that its iPhora application platform now integrates directly with DocuSign, the leading cloud-based provider of electronic signature services with over 200 million users in 188 countries. With the integration of DocuSign, complex document workflows and business processes requiring electronic signatures can be instantly signed, anywhere in the world, using a process that is secure and
20
Phora Group Announces iPhora® Async
Mon, Aug 7th 2017 3:28a   Richard Moy
Posted August 4, 2017 - By Louise Burton - Communication Phora Group is pleased to announce iPhora Async, a secure, asynchronous, event-driven add-on to iPhora Foundation, Phora Group's primary application platform for collaboration and business process management (BPM). iPhora Async allows organizations to integrate external cloud-based services into their core business processes in a secure and controlled environment. iPhora Async extends Phora Group's commitment to providing highly secure
22
MWLUG 2017 - Announcing MWLUG Community Outreach Program Beneficiary
Mon, Aug 7th 2017 3:18a   Richard Moy
As members of the IT community, we are also an important part of our local community. Through the MWLUG 2017 Community Outreach Program, we are raising money for organizations that help the local community. Each year we identify an organization in which our contribution would have the greatest impact on the local community of the host city. Thanks to the generosity of the Hilton Mark Center, we will be raffling off a weekend stay at the Hilton Mark Center as the grand prize. Please take the opp
17
MWLUG 2017 Transportation from Airport and Parking
Mon, Aug 7th 2017 3:15a   Richard Moy
If you are traveling to the Reagan International Airport to the Hilton Mark Center remember there is a free shuttle. Here is the shuttle schedule:National Airport/Pentagon City Mall & MetroThe Hilton Alexandria Mark Center offers a complimentary shuttle service 7 days a week from 6:00 am. to 10:30 pm. The vans depart from the front of the Hotel on the hour and half hour, arrive at Pentagon City Mall/Metro (blue and yellow line) at approximately 10 minutes and 40 minutes after the hourand c
6
When your Tool is a Hammer, Everything is a Nail, App Modernization - Part 1
Sun, Jul 30th 2017 8:12p   Richard Moy
I wrote this blog post about 9 months ago and never got around to finishing it. I felt this would be a good time to post this since MWLUG 2017 is coming up and with the Domino Application Development Roundtables at MWLUG 2017 both customers and partners have the opportunity to voice their desires on how they want IBM to move forward with IBM Domino. As an long time IBM Business Partner and ISV focused on the IBM Domino platform, we have been quite disappointed with the progress and improvements
10
MWLUG 2017 - Domino Application Development Roundtable
Thu, Jul 20th 2017 5:16p   Richard Moy
IBM Domino is nearing its 30th anniversary and yet it is still one of the most innovative software products on the market with features still not found in other solutions. Want to discuss with IBM your thoughts on how we can continue to make Domino one of the most relevant product for the next 30 years? We are please to announce that MWLUG 2017 will be hosting two Domino Application Development Roundtables on Wednesday August 9, 2017. Each roundtable session will be 45 minutes. There is one fo
3
MWLUG 2017 Agenda and the Future
Thu, Jul 13th 2017 8:33p   Richard Moy
The agenda for MWLUG 2017 is now available online, http://mwlug.com/mwlug/mwlug2017.nsf/schedule.xsp. MWLUG 2017 includes 59 technical and business sessions, workshops, and roundtable discussions presented by some of the best speakers in the ICS community including more than 20 IBM Champions. This is the most comprehensive conference we have ever had. MWLUG 2017 covers a variety of important topics including: Big Data and Graphic DatabasesConnections PinkData Management and SecurityIBM Colla
1
MWLUG 2017 Sessions and More
Thu, Jun 29th 2017 5:42p   Richard Moy
MWLUG 2017 sessions are now available on the MWLUG 2017 web site, http://mwlug.com/mwlug/mwlug2017.nsf/sessions.xsp This year we have a great line up of both new and previous speakers with sessions covering gambit of the IBM solutions including IBM Domino, IBM Notes, IBM Verse/VOP, IBM Connections, IBM Cloud, and Watson Workspace along with IBM Pink. In tuned with our theme, "Moving Collaboration Forward" we have many sessions covering some of the latest technologies and how to use those tec
4
IBM Domino Application Transformation Jumpstart Workshop at MWLUG 2017 on Tuesday, August 8, 2017
Thu, Jun 8th 2017 4:17p   Richard Moy
Announcing one of two workshops at MWLUG 2017. Our Platinum Sponsor, panagenda is having a workshop on Tuesday morning on August 8, 2017 from 9:30 AM to 1:30 PM, "IBM Domino Application Transformation Jumpstart". This free workshop covers a number of important topics including ApplicationInsights which is now shipped with Domino. To register for this workshop go to: https://www.panagenda.com/news-events/events/ibm-domino-application-transformation-jumpstart/ Domino Interface




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition