Files
cappuccino/Tests/Manual/CSVImportTest/Jakefile
T
David Richardson 416718a8d3 Tests: Configure manual test applications with explicit themes and theme tasks
* Tests/Manual/*/Info.plist: Set CPDefaultTheme to Aristo3 across all manual test applications, including those previously overriding to Aristo2.

* Tests/Manual/*/Jakefile: Add an orchestration task to update CPDefaultTheme (e.g., npx jake theme "Aristo3 Dark"). For testing convenience.

* Tests/Manual/*/Jakefile (Narwhal format): Migrate module imports and execution calls to Node equivalents from the capp application template, and remove syntax artifacts.
2026-11-03 21:26:03 -06:00

146 lines
5.0 KiB
JavaScript

/*
* Jakefile
* CSVImportTest
*
* Created by David Richardson on 2026-11-02.
* Copyright David Richardson 2026.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
const cp = require("child_process");
const path = require("path");
var ENV = process.env,
task = JAKE.task,
FileList = JAKE.FileList,
app = CAPPUCCINO.Jake.applicationtask.app,
configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug",
projectName = "CSVImportTest";
var buildDir = path.resolve(ENV["BUILD_PATH"] || ENV["CAPP_BUILD"] || "Build");
app (projectName, function(task)
{
ENV["OBJJ_INCLUDE_PATHS"] = "Frameworks";
if (configuration === "Debug")
ENV["OBJJ_INCLUDE_PATHS"] = path.join(ENV["OBJJ_INCLUDE_PATHS"], configuration);
task.setBuildIntermediatesPath(path.join(buildDir, projectName + ".build", configuration));
task.setBuildPath(path.join(buildDir, configuration));
task.setProductName(projectName);
task.setIdentifier("dev.cappuccino." + projectName);
task.setVersion("1.0");
task.setAuthor("David Richardson");
task.setSummary(projectName);
task.setSources(new FileList("**/*.j").exclude(path.join("Build", "**")).exclude(path.join("Frameworks", "**")));
task.setResources(new FileList("Resources/**"));
task.setIndexFilePath("index.html");
task.setInfoPlistPath("Info.plist");
if (configuration === "Debug")
task.setCompilerFlags("-DDEBUG -g -S --inline-msg-send");
else
task.setCompilerFlags("-O2");
});
task ("default", [projectName], function()
{
printResults(configuration);
});
task ("build", ["default"]);
task ("debug", function()
{
configuration = ENV["CONFIGURATION"] = "Debug";
JAKE.subjake(["."], "build", ENV);
});
task ("release", function()
{
configuration = ENV["CONFIGURATION"] = "Release";
JAKE.subjake(["."], "build", ENV);
});
task ("run", ["debug"], function()
{
cp.execFileSync("open", [path.join(buildDir, "Debug", projectName, "index.html")], { stdio: "inherit" });
});
task ("run-release", ["release"], function()
{
cp.execFileSync("open", [path.join(buildDir, "Release", projectName, "index.html")], { stdio: "inherit" });
});
function printResults(configuration)
{
console.log("----------------------------");
console.log(configuration + " app built at path: " + path.join(buildDir, configuration, projectName));
console.log("----------------------------");
}
/*
Sets the theme this application uses, for example:
npx jake theme Aristo2
npx jake theme "Aristo3 Dark"
The name is written to CPDefaultTheme in Info.plist as given, with its case
kept and &, < and > escaped. Empty the browser cache afterwards, because the
browser keeps the old Info.plist.
Jake runs each word on the command line as a task, in order, and looks a task
up only when it reaches it. So this task declares the theme name as an empty
task, which Jake then runs without effect. A name that is already a task is
refused, because Jake would run that task after this one. So is a name that
starts with ^ or jake:, which Jake reads as a task scope.
*/
JAKE.task ("theme", function()
{
var fs = require("fs"),
path = require("path"),
themeName = process.argv[process.argv.indexOf("theme") + 1],
plistPath = path.join(__dirname, "Info.plist"),
themeKey = /(<key>CPDefaultTheme<\/key>\s*<string>)[^<]*(<\/string>)/;
if (!themeName || !themeName.trim())
throw new Error("Give a theme name, for example: npx jake theme \"Aristo3 Dark\"");
if (/^(\^|jake:)/.test(themeName))
throw new Error("A theme name cannot start with ^ or jake:, which Jake reads as a task scope");
if (JAKE.application().lookup(themeName))
throw new Error(themeName + " is a task in this Jakefile, not a theme name");
var plist = fs.readFileSync(plistPath, "utf8"),
plistValue = themeName.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
if (!themeKey.test(plist))
throw new Error("No CPDefaultTheme key in " + plistPath);
plist = plist.replace(themeKey, function(match, head, tail)
{
return head + plistValue + tail;
});
fs.writeFileSync(plistPath, plist);
JAKE.task(themeName);
console.log("Theme set to " + themeName + " in " + plistPath);
});