202 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
When your Tool is a Hammer, Everything is a Nail, Transformation of Domino - Part 2
Mon, Nov 13th 2017 10
Domino X and Beyond, What Does this Mean?
Fri, Nov 3rd 2017 6
All Good Things Must Come to an End and the New Hope and Direction
Sat, Aug 19th 2017 6
Highlights of MWLUG 2017
Thu, Aug 17th 2017 6
Phora Group Announces iPhora® integration with DocuSign
Wed, Aug 9th 2017 6
Phora Group Announces iPhora® Async
Mon, Aug 7th 2017 7
MWLUG 2017 - Announcing MWLUG Community Outreach Program Beneficiary
Mon, Aug 7th 2017 7
Top 10
Creating Beauty with UglifyJS
Thu, Jan 26th 2017 11
When your Tool is a Hammer, Everything is a Nail, Transformation of Domino - Part 2
Mon, Nov 13th 2017 10
MWLUG 2016, Defining the Art Collaboration - Abstract Submission is Closing
Wed, May 25th 2016 9
MWLUG 2016 IBM Design Tour Registration is Now Open, Wednesday August 17, 2016
Thu, Jul 7th 2016 9
Announcing the MWLUG 2016 OGS IBM Speaker
Tue, Jul 19th 2016 9
Announcing MWLUG 2016 Opening General Session Guest Speaker
Wed, Jun 8th 2016 8
MWLUG 2016 Session Schedule is Now Available
Mon, Jul 25th 2016 8
Don't Get Disconnected with Connect
Mon, Mar 31st 2014 7
Phora Group Announces iPhora® Async
Mon, Aug 7th 2017 7
MWLUG 2017 - Announcing MWLUG Community Outreach Program Beneficiary
Mon, Aug 7th 2017 7


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
12 hits



Recent Blog Posts
10
When your Tool is a Hammer, Everything is a Nail, Transformation of Domino - Part 2
Mon, Nov 13th 2017 4:03p   Richard Moy
The recent announcement by IBM to continue the development and support for the IBM Domino platform indefinitely was great timing for part 2 of this series. This series is about the direction that we are taking Domino. This journey has taken more than five years with many different designs and experiments to get to where we are in our iPhora technology. You can find Part 1 of this series here. There are many tools and solutions out there from many vendors for "Modernizing" a Notes application
6
Domino X and Beyond, What Does this Mean?
Fri, Nov 3rd 2017 5:07p   Richard Moy
On October 25, 2017, IBM announced their strategic partnership with HCL with Domino, Sametime, Traveler, Verse and other products. As many have blogged and tweeted, IBM is turning over the development of these products for the forseeable future to HCL. Also, Ed Brill announced that IBM will be releasing Domino X in 2018 and #Domino2025 Jam to help determine the future of the Domino technology. I am not going to dwell on the details. You can find it yourself. I am going to discuss what this mean
6
All Good Things Must Come to an End and the New Hope and Direction
Sat, Aug 19th 2017 7:47p   Richard Moy
MWLUG 2017 was our most successful MWLUG conference we have ever had. With over 232 registered and a small number of cancellations, MWLUG 2017 was the most attended and largest conference. We had over 60 sessions, workshops and round tables with speakers from all over the United States and Europe. Over a third of the sessions were non-IBM specific and included sessions covering new topics like MongoDB and GDPR. In tuned with our theme this year, Moving Collaboration Forward, our goal was to expa
6
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
6
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
7
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
7
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
4
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
2
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
2
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




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