//WriteDump(attributes);
// === parameter options === //
if ( !structKeyExists(attributes, "updateExisting") OR !IsBoolean(attributes.updateExisting) )
attributes.updateExisting = 0;
if ( !structKeyExists(attributes, "scriptsPackage") )
attributes.scriptsPackage = ""; // Options: full or min
// ==== new parameters (ADF v2.6) ==== //
if ( !structKeyExists(attributes, "useExternal") OR !IsBoolean(attributes.useExternal) )
attributes.useExternal = false; // Default: false
if ( !structKeyExists(attributes, "scriptsSource") OR attributes.scriptsSource NEQ "external" )
attributes.scriptsSource = "local"; // Options: local (adf) or external (cdn)
// useExternal - overrides 'scriptsSource'
if ( attributes.useExternal )
attributes.scriptsSource = "external";
if ( !structKeyExists(attributes, "preserveAliases") OR !IsBoolean(attributes.preserveAliases) )
attributes.preserveAliases = true; // Default: True
// Group List Filter (one or more items)
if ( !structKeyExists(attributes, "groupList") )
attributes.groupList = ""; // Options: full,min,jquery,jqueryui,fontawesome
// Alias List Filter (one or more items)
if ( !structKeyExists(attributes, "aliasList") )
attributes.aliasList = ""; // Options: [any available resource alias]
// loadingType=early to load all js resource early
if ( !structKeyExists(attributes, "loadingType") OR attributes.loadingType NEQ "early" )
attributes.loadingType = "late"; // Options: early or late - Default: late
// 'useLegacyEarlyJs=true' overrides 'loadingType=late'
if ( !structKeyExists(attributes, "useLegacyEarlyJs") OR !IsBoolean(attributes.useLegacyEarlyJs) )
attributes.useLegacyEarlyJs = false; // Options: true or false
// if scriptsPackage is used (and not "full"), add them to the groupList filter
if ( LEN(TRIM(attributes.scriptsPackage)) AND attributes.scriptsPackage NEQ "full" )
attributes.groupList = application.ADF.data.listAppendNoDuplicates(list=attributes.groupList,value=attributes.scriptsPackage);
// groupList that contains "full" overrides all other groups
if ( ListFindNoCase(attributes.groupList,"full") )
attributes.groupList = "";
if ( !structKeyExists(attributes, "outputInstallScripts") OR !IsBoolean(attributes.outputInstallScripts) )
attributes.outputInstallScripts = false;
if ( !structKeyExists(attributes, "doBackup") OR !IsBoolean(attributes.doBackup) )
attributes.doBackup = true;
if ( !structKeyExists(attributes, "verboseOutput") OR !IsBoolean(attributes.verboseOutput) )
attributes.verboseOutput = false;
ropsAbortMsg = "Note: This process can not run on a Read-Only server!";
// Make sure we only run on an Authoring or Stand-Alone CS Server (non-ROPS)
if (Request.Site.State EQ Request.Constants.SiteIsReadOnlyReplica) // replication ROPS
Server.CommonSpot.UDF.util.ThrowCSException("Abort",ropsAbortMsg);
else if (Request.CP.IsMaster EQ 0) // cluster ROPS
Server.CommonSpot.UDF.util.ThrowCSException("Abort",ropsAbortMsg);
// Output Options
WriteOutput("Update Existing: " & UCASE(YesNoFormat(attributes.updateExisting)) & "
");
WriteOutput("Scripts Source: " & UCASE(attributes.scriptsSource) & "
");
WriteOutput("Preserve Aliases: " & UCASE(YesNoFormat(attributes.preserveAliases)) & "
");
WriteOutput("Resource Loading Type: " & UCASE(attributes.loadingType) & "
");
if ( attributes.useLegacyEarlyJs )
WriteOutput("Using Legacy Early JS: " & UCASE(YesNoFormat(attributes.useLegacyEarlyJs)) & "
");
if ( LEN(TRIM(attributes.aliasList)) )
WriteOutput("Alias List: " & UCASE(attributes.aliasList) & "
");
if ( LEN(TRIM(attributes.groupList)) )
WriteOutput("Group List: " & UCASE(attributes.groupList) & "
");
if ( attributes.outputInstallScripts )
WriteOutput('Outputting Installation Scripts Only...
');
WriteOutput("
");
// === START: backup current set of registered resources === //
// backup files found in the /_cs_apps/resources/backups
if ( attributes.doBackup )
application.ADF.resourceService.backupRegisteredResources();
// === START: get update data === //
if ( LEN(TRIM(attributes.aliasList)) )
{
// Get the Scripts By AliasList
scriptsArr = application.ADF.resourceService.getScriptsByAliasList(aliasList=attributes.aliasList,source=attributes.scriptsSource);
}
else if ( LEN(TRIM(attributes.groupList)) )
{
// Get the Scripts By GroupList
scriptsArr = application.ADF.resourceService.getScriptsByGroupList(groupList=attributes.groupList,source=attributes.scriptsSource);
}
else
{
// Get the All Scripts Data
scriptsArr = application.ADF.resourceService.getAllScripts(source=attributes.scriptsSource);
}
//WriteDump(var=attributes,label="attributes",expand=false);
//WriteDump(var=attributes.groupList,expand=false);
//WriteDump(var=scriptsArr,expand=false);
if ( attributes.outputInstallScripts )
WriteOutput("");
for ( i=1; i <= ArrayLen(scriptsArr); i++ ) {
regData = scriptsArr[i];
legacyLoadJSEarlyDefault = 0;
cssProps = [];
jsProps = [];
// Get the Default values from the resource data
if ( StructKeyExists(regData,"legacyLoadJsEarly") )
legacyLoadJSEarlyDefault = regData.legacyLoadJsEarly;
if ( StructKeyExists(regData,"cssSourceArray") )
cssProps = regData.cssSourceArray;
if ( StructKeyExists(regData,"jsSourceArray") )
jsProps = regData.jsSourceArray;
// If enabled, use the legacyLoadJSEarlyDefault
jsLoadEarly = attributes.useLegacyEarlyJs ? legacyLoadJSEarlyDefault : 0;
// Set the Early and Late Properties
propsEarly = [];
propsLate = [];
if ( ArrayLen(cssProps) )
propsEarly = cssProps;
if ( ArrayLen(jsProps) ) {
if ( jsLoadEarly OR attributes.loadingType EQ "early" )
ArrayAppend(propsEarly,jsProps,true);
else
propsLate = jsProps;
}
/*
required string name,
required string category,
required array earlyLoadSourceArray,
required array lateLoadSourceArray,
required string description,
required string installInstructions,
string aliasList="",
boolean redistributable=0,
boolean updateExisting=0,
boolean silent=0
boolan preserveAliases=1
*/
if ( attributes.outputInstallScripts ) {
WriteOutput(
'application.ADF.scriptsService.registerResource(
name = "#regData.name#",
category = "#regData.category#",
earlyLoadSourceArray = #SerializeJSON(propsEarly)#,
lateLoadSourceArray = #SerializeJSON(propsLate)#,
description = "#regData.description#",
installInstructions = "#regData.installInstructions#",
aliasList = "#regData.aliasList#",
redistributable = #regData.redistributable#,
updateExisting = #attributes.updateExisting#,
silent = #regData.silent#,
preserveAliases = #attributes.preserveAliases#
);'
);
WriteOutput("
");
}
else {
try {
application.ADF.scriptsService.registerResource(
"#regData.name#", "#regData.category#",
propsEarly,
propsLate,
"#regData.description#", "#regData.installInstructions#", "#regData.aliasList#"
,regData.redistributable, attributes.updateExisting, regData.silent
,attributes.preserveAliases
);
}
catch (any ex) {
logMsg = "An error occurred when attempting to register: " & regData.name & " (" & regData.aliaslist & ")";
msg = " -- WARNING: " & logMsg;
if ( StructKeyExists(ex,"Message") ) {
msg = msg & "
-- " & ex.Message;
logMsg = logMsg & " - " & ex.Message;
}
writeOutput(msg & "
");
application.ADF.log.addLogEntry(message=logMsg,CFCatch=ex,forceStackTrace=false,useDatePrefix=true);
if ( attributes.verboseOutput )
WriteDump(ex);
}
}
}
if ( attributes.outputInstallScripts )
WriteOutput("");