Commit c25790e4 authored by Bas Lijnse's avatar Bas Lijnse

Updated web resource collector to aggrate CSS from different clean modules

parent 29a56a37
Pipeline #22101 passed with stage
in 4 minutes and 46 seconds
<!DOCTYPE html>
<html style="width: 100%; height: 100%;">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="/css/itasks.css" type="text/css" >
<link rel="stylesheet" href="/BasicAPIExamples.css" type="text/css" >
<!-- Sapl dependencies -->
<script type="text/javascript" src="/js/sapl-utils.js"></script>
<script type="text/javascript" src="/js/sapl-builtin.js"></script>
<script type="text/javascript" src="/js/sapl-dynamic.js"></script>
<script type="text/javascript" src="/js/sapl-itasks.js"></script>
<script type="text/javascript" src="/js/sapl-rt.js"></script>
<script type="text/javascript" src="/js/sapl-support.js"></script>
<script type="text/javascript" src="/js/sapl-debug.js"></script>
<!-- iTasks framework -->
<script type="text/javascript" src="/js/itasks-core.js"></script>
<script type="text/javascript" src="/js/itasks-components-raw.js"></script>
<script type="text/javascript" src="/js/itasks-components-form.js"></script>
<script type="text/javascript" src="/js/itasks-components-display.js"></script>
<script type="text/javascript" src="/js/itasks-components-selection.js"></script>
<script type="text/javascript" src="/js/itasks-components-container.js"></script>
<script type="text/javascript" src="/js/itasks-js-interface.js"></script>
<!-- load iTasks viewport -->
<script type="text/javascript">
window.onload = function() {
itasks.viewport({syncTitle: true}, document.body);
};
</script>
</head>
<body style="width: 100%; height: 100%">
</body>
</html>
......@@ -5,6 +5,7 @@
<title></title>
<link rel="stylesheet" href="/css/itasks.css" type="text/css" >
<link rel="stylesheet" href="/css/itasks-modules.css" type="text/css" >
<!-- Sapl dependencies -->
<script type="text/javascript" src="/js/sapl-utils.js"></script>
......
module WebResourceCollector
/**
* This program collects all the necessary public web resources that an iTasks program
* This program collects and creates all the necessary public web resources that an iTasks program
* needs to run. These are for example, static javascript files, images and the html launch page.
*
* The way this collector works is straightforward. It looks in a project file which modules are
* To find bundled public resources it looks in a project file which modules are
* used by a program and then checks for each module if a directory called "<modulename>-webpublic" exists
* if it exists, the full contents of that directory are copied to the collection directory called "<applicationname>-webpublic"
*
* It also creates an aggregated css file with additional style rules that are needed by Clean modules.
* If for an imported Clean module a file exists with the same name, but a .css extension it is included in the aggregation.
* The total collected css is written to "<applicationname>-webpublic/css/itasks-modules.css"
*
* To always bundle the right versions of web resources, this program must be run after every build
* in the link phase.
* To always bundle the right versions of web resources, this program must be run after every build in the link phase.
*/
import StdEnv
......@@ -28,11 +31,21 @@ Start world
# content = fromOk content
# outDir = exePathToOutputDir (lookupExePath content)
# inDirs = objectPathsToInputDirs (lookupObjectPaths content)
//Create output dir
# cssParts = objectPathsToCSSFiles (lookupObjectPaths content)
# cssFile = outDir </> "css" </>"itasks-modules.css"
# world = print ("Output css file " +++ cssFile) world
//Create output dir and 'css' dir in it
# (mbErr,world) = createDirectory outDir world
| not (mbErr =: (Ok _) || mbErr =: (Error (17,_))) //Ignore 'File exists' errors
# (errorcode,errormsg) = fromError mbErr
= print errormsg world
# (mbErr,world) = createDirectory (outDir </> "css") world
| not (mbErr =: (Ok _) || mbErr =: (Error (17,_))) //Ignore 'File exists' errors
# (errorcode,errormsg) = fromError mbErr
= print errormsg world
//Create the aggregated css file
# (mbErr,world) = writeFile cssFile "" world
# world = foldr (\f w -> aggregateCSS f cssFile w) world cssParts
//Copy the contents of the input dirs if they exist
# world = foldr (\d w -> copyWebResources d outDir w) world inDirs
= world
......@@ -59,7 +72,7 @@ lookupObjectPaths linkopts
exePathToOutputDir :: FilePath-> FilePath
exePathToOutputDir path = dropExtension path +++ "-www"
//Determine the potential input folders
//Determine the potential input folders and css fragments
objectPathsToInputDirs :: [FilePath] -> [FilePath]
objectPathsToInputDirs paths = flatten (map rewrite paths)
where
......@@ -68,6 +81,11 @@ where
,join {pathSeparator} ((filter ((<>) "Clean System Files") (split {pathSeparator} (takeDirectory path)))) </> "WebPublic"
]
objectPathsToCSSFiles :: [FilePath] -> [FilePath]
objectPathsToCSSFiles paths = map rewrite paths
where
rewrite path = addExtension (join {pathSeparator} ((filter ((<>) "Clean System Files") (split {pathSeparator} (dropExtension path))))) "css"
//Copy the web resources if the input directory exists
copyWebResources :: !FilePath !FilePath !*World -> *World
copyWebResources indir outdir world
......@@ -77,6 +95,14 @@ copyWebResources indir outdir world
= copyDirectoryContent indir outdir world
| otherwise = world
aggregateCSS :: !FilePath !FilePath !*World -> *World
aggregateCSS inFile outFile world
# (exists,world) = fileExists inFile world
| exists
# world = print ("Adding css file "+++inFile) world
= copyFile inFile outFile True world
| otherwise = world
//GENERAL UTIL, SHOULD BE PART OF PLATFORM
isDirectory :: !FilePath !*World -> (!Bool, !*World)
isDirectory path world = case getFileInfo path world of
......@@ -96,14 +122,14 @@ where
# (_,world) = createDirectory (outdir </> item) world
= copyDirectoryContent (indir </> item) (outdir </> item) world
| otherwise //Copy the file
= copyFile (indir </> item) (outdir </> item) world
= copyFile (indir </> item) (outdir </> item) False world
copyFile :: !FilePath !FilePath !*World -> *World
copyFile inf outf world
copyFile :: !FilePath !FilePath !Bool !*World -> *World
copyFile inf outf append world
# (ok,inh,world) = fopen inf FReadData world
| not ok
= world
# (ok,outh,world) = fopen outf FWriteData world
# (ok,outh,world) = fopen outf (if append FAppendData FWriteData) world
| not ok
= world
# (inh,outh) = copy inh outh
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment