getting rid of "defer" on require.js + post processing Bash

This forum is for all Flare related Tips and Tricks.
Have a tip or trick you use while working in Flare? Share it here.
Post Reply
yonatanlehman
Propeller Head
Posts: 51
Joined: Mon Sep 18, 2017 6:14 am

getting rid of "defer" on require.js + post processing Bash

Post by yonatanlehman »

This tip solves shows
1) How I solved Madcap crashing because of a clash with the googletagmanager that was caused because Flare uses "defer" when loading the require.min.js script
For details see here viewtopic.php?f=12&t=33034&p=142038#p142038
2) How I run post-processing using WSL/Linux style scripts

I grew up using Unix so I find Poweshell uncomprehensible - so when I had to write a post-process to work around a Flare crashing bug (nudge, nudge, hint, hint, say no more) I wanted to do it using Bash, find and sed. It was quite a challenge for various reasons:
1) I wanted to pass the output folder and needed to change the '\' to '/'
2) When you run bash from a CMD tool it uses a different version of the Unix tools to what runs from my Git installed Bash script

So here is my solution for whats it worth - you can adapt it as necessary - you need to have WSL or some other Linux type environment installed.

The post build command set in the the Project Build Event" tab is as follows:

Code: Select all

cd $(ProjectDirectory)Content\processing
$(ProjectDirectory)Content\processing\postprocessing  $(OutputDirectory)
It changes the wording directory to the folder Content\processing and runs the script postprocessing.bat
The postprocessing.bat files contains as follows:

Code: Select all

set output1=%1
set output2=%output1:\=/%
echo -%output1%-%output2%- >debug2.txt
bash.exe  ./postprocessing.sh %output2%
This converts the path to use linux style forward slashes instead of back slashes and then starts the Bash script postprocessing.sh which has the following content:

Code: Select all

echo $1 | sed 's/[cC]:/\/mnt\/c/'` 
echo "dir is " `pwd` >debug1.txt
echo "output is $output" >> debug1.txt
find $output -name '*.html' -print  >>debug1.txt
find $output -name '*.html' -print0  | xargs -0 sed -i 's/\(require\.min\.js" .*\)defer="defer"/\1/g'
This
1) converts the C: to /mnt/c (you might need to change it it /c on your system)
2) Writes some debug output (left it here just in case you need to debug it)
3) searches for all the .html files in the output and then removes the defer="defer" from the line that contains require.min.js
It could be improved by making sure that the require.min.js is in a <script> but I'm scared Madcap will change the format to multiple lines or do something else that will make the search fail.

Enjoy !
jmehaffey
Jr. Propeller Head
Posts: 7
Joined: Thu Aug 23, 2018 2:45 am

Re: getting rid of "defer" on require.js + post processing B

Post by jmehaffey »

You are the only person I have seen solve this!

I am not familiar with WSL, but I installed the Ubuntu shell to try and run these scripts. How would I set up a project to work like this with the WSL Ubuntu shell?

I keep all of my projects in C:\, but where should the Ubuntu or bash executable live? Thanks if you answer this 5 year old thread!
Post Reply