@@ -14,7 +14,7 @@ printf!("==== LuaWebGen v"..getReleaseVersion().." ====")
1414
1515
1616
17- -- done = setup( )
17+ -- readyToExit = setup( )
1818local function setup()
1919
2020 -- Parse arguments.
@@ -317,13 +317,16 @@ local function setup()
317317 elseif arg == "--verbose" then
318318 _G.verbosePrint = true
319319
320- elseif arg == "--meta" then
320+ elseif arg == "--meta" then -- @Doc?
321321 _G.outputMetaprograms = true
322322
323- elseif arg == "--nogc" then
323+ elseif arg == "--nogc" then -- @Doc?
324324 _G.enableGc = false
325325 collectgarbage("stop")
326326
327+ elseif arg == "--fullpaths" then -- @Doc?
328+ _G.useFullPaths = true
329+
327330 elseif arg:find"^%-" then
328331 errorNoPos("[Arguments] Unknown option '%s'.", argRaw)
329332 else
@@ -372,7 +375,7 @@ local function setup()
372375 _G.logPath = basePath .. "_" .. i .. ".log"
373376 end
374377
375- _G.logFile = io.open(logPath, "w")
378+ _G.logFile = io.open(logPath, "w") -- We don't sweat it if this fails.
376379 end
377380
378381
@@ -1073,12 +1076,12 @@ local function setup()
10731076 local path = F("%s/%s.html", DIR_LAYOUTS, htmlFileBasename)
10741077 local template, err = getFileContentsText(path)
10751078 if not template then
1076- errorf(2, "Could not read file '%s': %s", path, err)
1079+ errorf(2, "Could not read file '%s': %s", maybeFullPath( path) , err)
10771080 end
10781081
1079- -- timestampPrintVerbose("--> Processing(start): %s", path)
1082+ -- timestampPrintVerbose("--> Processing(start): %s", maybeFullPath( path) )
10801083 local html = parseAndRunTemplate(getContext().page, path, template, "html", true, nil)
1081- -- timestampPrintVerbose("--> Processing(finish): %s", path)
1084+ -- timestampPrintVerbose("--> Processing(finish): %s", maybeFullPath( path) )
10821085 return html
10831086 end,
10841087
@@ -1119,7 +1122,7 @@ local function setup()
11191122 local path = DIR_OUTPUT.."/"..pathOutputRel
11201123
11211124 if not isFile(path) then
1122- errorf(2, "File does not exist. (%s)", path)
1125+ errorf(2, "File does not exist. (%s)", maybeFullPath( path) )
11231126 end
11241127
11251128 preserveExistingOutputFile("raw", pathRel, sitePathRel, "")
@@ -1348,16 +1351,14 @@ local function buildWebsite()
13481351 end
13491352
13501353 if not isFile"config.lua" then
1351- errorNoPos("Missing config.lua in site folder.")
1354+ errorNoPos("Missing %s in site folder.", maybeFullPath"config.lua ")
13521355 end
13531356
1354- local chunk, err = loadfile"config.lua"
1355- if not chunk then errorNoPos(err) end
1356-
1357- setfenv(chunk, scriptEnvironment)
1357+ local main_chunk, err = loadLuaFile("config.lua", scriptEnvironment)
1358+ if not main_chunk then errorNoPos(err) end
13581359
1359- local config = chunk ()
1360- lineAssertTable(config, nil, nil, "config.lua : The file must return a table.")
1360+ local config = main_chunk ()
1361+ lineAssertTable(config, nil, nil, "%s : The file must return a table.", maybeFullPath"config.lua ")
13611362
13621363 local function get(kPath, default, assertFunc, ...)
13631364 local v = config
@@ -1383,22 +1384,22 @@ local function buildWebsite()
13831384 local function getV(kPath, default, vType) -- Value.
13841385 return get(
13851386 kPath, default, lineAssertType, vType,
1386- "config.lua : config.%s must be a %s.",
1387- kPath, vType
1387+ "%s : config.%s must be a %s.",
1388+ maybeFullPath"config.lua", kPath, vType
13881389 )
13891390 end
13901391 local function getT(kPath, default, kType, vType) -- Table
13911392 return get(
13921393 kPath, default, lineAssertTable, kType, vType,
1393- "config.lua : config.%s must be a table of [%s]=%s.",
1394- kPath, (kType or "value"), (vType or "value")
1394+ "%s : config.%s must be a table of [%s]=%s.",
1395+ maybeFullPath"config.lua", kPath, (kType or "value"), (vType or "value")
13951396 )
13961397 end
13971398 local function getA(kPath, default, vType) -- Array.
13981399 return get(
13991400 kPath, default, lineAssertTable, "number", vType,
1400- "config.lua : config.%s must be an array of %s.",
1401- kPath, vType
1401+ "%s : config.%s must be an array of %s.",
1402+ maybeFullPath"config.lua", kPath, vType
14021403 )
14031404 end
14041405
@@ -1448,46 +1449,46 @@ local function buildWebsite()
14481449 end
14491450
14501451 if not isAny(type(site._outputPathFormat), "string","function") then
1451- errorNoPos("config.lua : config.rewriteOutputPath must be a string or a function.")
1452+ errorNoPos("%s : config.rewriteOutputPath must be a string or a function.", maybeFullPath"config.lua ")
14521453 end
14531454
14541455 -- Validate config.types
14551456 for ext, fileType in pairs(site._fileTypes) do
14561457 if ext ~= ext:lower() then
1457- errorNoPos("config.lua : File extensions must be lower case: config.types[\"%s\"]", ext)
1458+ errorNoPos("%s : File extensions must be lower case: config.types[\"%s\"]", maybeFullPath"config.lua ", ext)
14581459 elseif not FILE_TYPE_SET[fileType] then
1459- errorNoPos("config.lua : Invalid generator file type '%s'.", fileType)
1460+ errorNoPos("%s : Invalid generator file type '%s'.", maybeFullPath"config.lua ", fileType)
14601461 end
14611462 end
14621463
14631464 -- Validate config.processors
14641465 for ext in pairs(site._fileProcessors) do
14651466 if ext ~= ext:lower() then
1466- errorNoPos("config.lua : File extensions must be lower case: config.processors[\"%s\"]", ext)
1467+ errorNoPos("%s : File extensions must be lower case: config.processors[\"%s\"]", maybeFullPath"config.lua ", ext)
14671468 end
14681469 end
14691470
14701471 -- Validate config.baseUrl
14711472 local parsedUrl = require"url".parse(site.baseUrl.v)
14721473
14731474 if site.baseUrl.v == "" then
1474- errorNoPos("config.lua : config.baseUrl is missing or empty.", site.baseUrl.v)
1475+ errorNoPos("%s : config.baseUrl is missing or empty.", maybeFullPath"config.lua ", site.baseUrl.v)
14751476
14761477 elseif not parsedUrl.host then
1477- errorNoPos("config.lua : Missing host in config.baseUrl (%s)", site.baseUrl.v)
1478+ errorNoPos("%s : Missing host in config.baseUrl (%s)", maybeFullPath"config.lua ", site.baseUrl.v)
14781479
14791480 elseif not parsedUrl.scheme then
1480- errorNoPos("config.lua : Missing scheme in config.baseUrl (%s)", site.baseUrl.v)
1481+ errorNoPos("%s : Missing scheme in config.baseUrl (%s)", maybeFullPath"config.lua ", site.baseUrl.v)
14811482 elseif not isAny(parsedUrl.scheme, "http","https") then
1482- errorNoPos("config.lua : Invalid scheme in config.baseUrl (Expected http or https, got '%s')", parsedUrl.scheme)
1483+ errorNoPos("%s : Invalid scheme in config.baseUrl (Expected http or https, got '%s')", maybeFullPath"config.lua ", parsedUrl.scheme)
14831484
14841485 elseif not (parsedUrl.path or ""):find"/$" then
1485- errorNoPos("config.lua : config.baseUrl must end with '/'. (%s)", site.baseUrl.v)
1486+ errorNoPos("%s : config.baseUrl must end with '/'. (%s)", maybeFullPath"config.lua ", site.baseUrl.v)
14861487
14871488 elseif parsedUrl.query then
1488- errorNoPos("config.lua : config.baseUrl Cannot contain a query. (%s)", site.baseUrl.v)
1489+ errorNoPos("%s : config.baseUrl Cannot contain a query. (%s)", maybeFullPath"config.lua ", site.baseUrl.v)
14891490 elseif parsedUrl.fragment then
1490- errorNoPos("config.lua : config.baseUrl Cannot contain a fragment. (%s)", site.baseUrl.v)
1491+ errorNoPos("%s : config.baseUrl Cannot contain a fragment. (%s)", maybeFullPath"config.lua ", site.baseUrl.v)
14911492 end
14921493
14931494 -- Final config handling.
@@ -1498,7 +1499,7 @@ local function buildWebsite()
14981499 dataParserIsBinary[ext] = false
14991500
15001501 if customDataBinaryParsers[ext] then
1501- errorNoPos("config.lua : Both config.dataTextParsers.%s and config.dataBinaryParsers.%s are defined.", ext, ext)
1502+ errorNoPos("%s : Both config.dataTextParsers.%s and config.dataBinaryParsers.%s are defined.", maybeFullPath"config.lua ", ext, ext)
15021503 end
15031504 end
15041505
@@ -1509,7 +1510,7 @@ local function buildWebsite()
15091510 dataParserIsBinary[ext] = true
15101511
15111512 if customDataTextParsers[ext] then
1512- errorNoPos("config.lua : Both config.dataTextParsers.%s and config.dataBinaryParsers.%s are defined.", ext, ext)
1513+ errorNoPos("%s : Both config.dataTextParsers.%s and config.dataBinaryParsers.%s are defined.", maybeFullPath"config.lua ", ext, ext)
15131514 end
15141515 end
15151516
@@ -1863,7 +1864,7 @@ local function buildWebsite()
18631864 --
18641865 traverseFiles(DIR_OUTPUT, nil, function(path, pathOutputRel, filename, extLower)
18651866 if not site._writtenOutputFiles[pathOutputRel] then
1866- timestampPrintVerbose("Removing: %s", path)
1867+ timestampPrintVerbose("Removing: %s", maybeFullPath( path) )
18671868 assert(os.remove(path))
18681869 end
18691870 end)
@@ -1915,7 +1916,7 @@ if autobuild then
19151916
19161917 if lastDirTree and lastDirTree[path] and dirTree[path] > lastDirTree[path] then
19171918 if not silent then
1918- printf("Detected file change: %s", path)
1919+ printf("Detected file change: %s", maybeFullPath( path) )
19191920 end
19201921 somethingChanged = true
19211922 end
@@ -1935,7 +1936,7 @@ if autobuild then
19351936 if lastDirTree and not lastDirTree[path] then
19361937 somethingChanged = true
19371938 if not silent then
1938- printf("Detected addition: %s", path)
1939+ printf("Detected addition: %s", maybeFullPath( path) )
19391940 end
19401941 end
19411942 end)
@@ -1954,7 +1955,7 @@ if autobuild then
19541955 for path in pairs(lastDirTree) do
19551956 if not dirTree[path] then
19561957 somethingChanged = true
1957- printf("Detected removal: %s", path)
1958+ printf("Detected removal: %s", maybeFullPath( path) )
19581959 break
19591960 end
19601961 end
@@ -1993,8 +1994,10 @@ if not enableGc then
19931994 printf("Memory usage: %s", formatBytes(collectgarbage"count"*1024))
19941995end
19951996
1996- printfNoLog("Check log for details: %s", logPath)
1997- logFile:close()
1998- _G.logFile = nil
1997+ printfNoLog("Check log for details: %s", maybeFullPath(logPath))
1998+ if logFile then
1999+ logFile:close()
2000+ _G.logFile = nil
2001+ end
19992002
20002003return appOk
0 commit comments