starting to port the capp tool to node

This commit is contained in:
Alfred Wärnsäter
2021-07-30 14:09:11 +02:00
parent 87a1c6621c
commit e64c9d9cd4
6 changed files with 113 additions and 79 deletions
+8 -1
View File
@@ -453,7 +453,14 @@ BundleTask.prototype.defineResourceTask = function(aResourcePath, aDestinationPa
nib2cibFlags = nib2cibFlags.join(" ");
filedir(cibDestinationPath, [aResourcePath], function()
{
child_process.execSync("nib2cib " + aResourcePath + " " + cibDestinationPath + " " + nib2cibFlags);
try {
child_process.execSync("nib2cib " + aResourcePath + " " + cibDestinationPath + " " + nib2cibFlags);
} catch(error) {
console.log("hello?");
console.log(error);
console.log(error.output.toString());
}
});
this.enhance([cibDestinationPath]);
}};
+1 -1
View File
@@ -5,4 +5,4 @@ require("../common.jake");
//subtasks(["fontinfo", "imagesize"], ["clean", "clobber"]);
subtasks(["fontinfo", "imagesize", "nib2cib"], ["build", /*"clean", "clobber"*/]);
subtasks(["fontinfo", "imagesize", "nib2cib", "capp"], ["build", /*"clean", "clobber"*/]);
+15 -4
View File
@@ -4,9 +4,11 @@
@import <Foundation/CPObject.j>
@import <Foundation/CPSet.j>
var fs = require("fs");
var path = require("path");
var FILE = require("file"),
SYSTEM = require("system");
/* var FILE = require("file"),
SYSTEM = require("system"); */
var DefaultDictionary = nil,
DefaultConfiguration = nil,
@@ -51,7 +53,7 @@ var DefaultDictionary = nil,
+ (id)userConfiguration
{
if (!UserConfiguration)
UserConfiguration = [[self alloc] initWithPath:FILE.join(SYSTEM.env["HOME"], ".cappconfig")];
UserConfiguration = [[self alloc] initWithPath:FILE.join(process.env["HOME"], ".cappconfig")];
return UserConfiguration;
}
@@ -65,7 +67,16 @@ var DefaultDictionary = nil,
path = aPath;
temporaryDictionary = @{};
if (path && FILE.isReadable(path))
function isReadable(p) {
try {
fs.accessSync(p, constants.R_OK);
return true;
} catch (err) {
return false;
}
}
if (path && isReadable(path))
dictionary = CFPropertyList.readPropertyListFromFile(path);
// readPlist will return nil if the file is empty
+84 -68
View File
@@ -22,15 +22,25 @@
@import "Configuration.j"
var OS = require("os"),
/* var OS = require("os"),
SYSTEM = require("system"),
FILE = require("file"),
OBJJ = require("objective-j"),
FILE = require("file"); */
var OBJJ = require("objj-runtime"),
stream = require("objj-runtime").term.stream;
stream = require("narwhal/term").stream,
parser = new (require("narwhal/args").Parser)();
// parser = new (require("narwhal/args").Parser)();
parser.usage("DESTINATION_DIRECTORY");
// FIXME: lots of chaining using narwhals path wrapper, this file might still be broken
var fs = require("fs-extra");
var node_path = require("path");
var child_process = require("child_process");
var glob = require("glob");
// FIXME: removing command line options for now
/* parser.usage("DESTINATION_DIRECTORY");
parser.help("Generate a Cappuccino project or Frameworks directory");
@@ -85,21 +95,25 @@ parser.option("--list-frameworks", "listFrameworks")
.set(true)
.help("Lists available frameworks.");
parser.helpful();
parser.helpful(); */
// FIXME: better way to do this:
var CAPP_HOME = require("narwhal/packages").catalog["cappuccino"].directory,
templatesDirectory = FILE.join(CAPP_HOME, "lib", "capp", "Resources", "Templates");
/* var CAPP_HOME = require("narwhal/packages").catalog["cappuccino"].directory,
templatesDirectory = node_path.join(CAPP_HOME, "lib", "capp", "Resources", "Templates"); */
var templatesDirectory = "/Users/alfred/Developer/cappuccino/Tools/capp/Resources/Templates";
function gen(/*va_args*/)
{
var args = ["capp gen"].concat(Array.prototype.slice.call(arguments)),
options = parser.parse(args, null, null, true);
var args = ["capp gen"].concat(Array.prototype.slice.call(arguments));
var options = { args: args };
//options = parser.parse(args, null, null, true);
if (options.args.length > 1)
{
parser.printUsage(options);
OS.exit(1);
process.exit(1);
}
if (options.listTemplates)
@@ -124,29 +138,29 @@ function gen(/*va_args*/)
else
{
parser.printUsage(options);
OS.exit(1);
process.exit(1);
}
}
var sourceTemplate = null;
if (FILE.isAbsolute(options.template))
if (node_path.isAbsolute(options.template))
sourceTemplate = options.template;
else
sourceTemplate = FILE.join(templatesDirectory, options.template);
if (!FILE.isDirectory(sourceTemplate))
sourceTemplate = node_path.join(templatesDirectory, options.template);
if (!fs.lstatSync(sourceTemplate).isDirectory())
{
stream.print(colorize("Error: ", "red") + "The template " + logPath(sourceTemplate) + " cannot be found. Available templates are:");
listTemplates();
OS.exit(1);
process.exit(1);
}
var configFile = FILE.join(sourceTemplate, "template.config"),
var configFile = node_path.join(sourceTemplate, "template.config"),
config = {};
if (FILE.isFile(configFile))
config = JSON.parse(FILE.read(configFile, { charset:"UTF-8" }));
if (fs.lstatSync(configFile).isFile())
config = JSON.parse(fs.readFileSync(configFile, { encoding: "utf8" }));
//config = JSON.parse(FILE.read(configFile, { charset:"UTF-8" }));
var destinationProject = destination,
configuration = options.noconfig ? [Configuration defaultConfiguration] : [Configuration userConfiguration],
@@ -162,14 +176,14 @@ function gen(/*va_args*/)
createThemesInFile(themes, destinationProject, options.symlink, options.force);
}
else if (!FILE.exists(destinationProject))
else if (!fs.existsSync(destinationProject))
{
// FIXME???
FILE.copyTree(sourceTemplate, destinationProject);
fs.copySync(sourceTemplate, destinationProject, { recursive: true });
var files = FILE.glob(FILE.join(destinationProject, "**", "*")),
var files = glob.sync(node_path.join(destinationProject, "**", "*")),
count = files.length,
name = FILE.basename(destinationProject),
name = node_path.basename(destinationProject),
orgIdentifier = [configuration valueForKey:@"organization.identifier"] || "";
[configuration setTemporaryValue:name forKey:@"project.name"];
@@ -180,26 +194,28 @@ function gen(/*va_args*/)
{
var path = files[index];
if (FILE.isDirectory(path))
if (fs.lstatSync(path).isDirectory())
continue;
if (FILE.basename(path) === ".DS_Store")
if (node_path.basename(path) === ".DS_Store")
continue;
// Don't do this for images.
if ([".png", ".jpg", ".jpeg", ".gif", ".tif", ".tiff"].indexOf(FILE.extension(path).toLowerCase()) !== -1)
if ([".png", ".jpg", ".jpeg", ".gif", ".tif", ".tiff"].indexOf(node_path.extname(path).toLowerCase()) !== -1)
continue;
try
{
var contents = FILE.read(path, { charset : "UTF-8" }),
var contents = fs.readFileSync(path, { encoding: "utf8" }),
//var contents = FILE.read(path, { charset : "UTF-8" }),
key = null,
keyEnumerator = [configuration keyEnumerator];
while ((key = [keyEnumerator nextObject]) !== nil)
contents = contents.replace(new RegExp("__" + RegExp.escape(key) + "__", 'g'), [configuration valueForKey:key]);
FILE.write(path, contents, { charset: "UTF-8"});
fs.writeFileSync(path, contents, { encoding: "utf8" });
//FILE.write(path, contents, { charset: "UTF-8"});
}
catch (anException)
{
@@ -210,7 +226,7 @@ function gen(/*va_args*/)
var frameworkDestination = destinationProject;
if (config.FrameworksPath)
frameworkDestination = FILE.join(frameworkDestination, config.FrameworksPath);
frameworkDestination = node_path.join(frameworkDestination, config.FrameworksPath);
createFrameworksInFile(frameworks, frameworkDestination, options.symlink, options.useCappBuild);
@@ -222,7 +238,7 @@ function gen(/*va_args*/)
else
{
fail("The directory " + FILE.absolute(destinationProject) + " already exists.");
fail("The directory " + node_path.resolve(destinationProject) + " already exists.");
}
executePostInstallScript(destinationProject);
@@ -230,7 +246,7 @@ function gen(/*va_args*/)
function createFrameworksInFile(/*Array*/ frameworks, /*String*/ aFile, /*Boolean*/ symlink, /*Boolean*/ build, /*Boolean*/ force)
{
var destination = FILE.path(FILE.absolute(aFile));
var destination = node_path.path(node_path.resolve(aFile));
if (!destination.isDirectory())
fail("Cannot create Frameworks. The directory does not exist: " + destination);
@@ -245,12 +261,12 @@ function createFrameworksInFile(/*Array*/ frameworks, /*String*/ aFile, /*Boolea
if (build)
{
if (!(SYSTEM.env["CAPP_BUILD"]))
if (!(process.env["CAPP_BUILD"]))
fail("$CAPP_BUILD must be defined to use the --build or -l option.");
var builtFrameworks = FILE.path(SYSTEM.env["CAPP_BUILD"]),
sourceFrameworks = builtFrameworks.join("Release"),
sourceDebugFrameworks = builtFrameworks.join("Debug");
var builtFrameworks = process.env["CAPP_BUILD"],
sourceFrameworks = node_path.join(builtFrameworks, "Relesase"),
sourceDebugFrameworks = node_path.join(builtFrameworks, "Debug");
frameworks.forEach(function(framework)
{
@@ -267,9 +283,9 @@ function createFrameworksInFile(/*Array*/ frameworks, /*String*/ aFile, /*Boolea
if (framework === "Objective-J")
{
// Objective-J. Take from OBJJ_HOME.
var objjHome = FILE.path(OBJJ.OBJJ_HOME),
objjPath = objjHome.join("Frameworks", "Objective-J"),
objjDebugPath = objjHome.join("Frameworks", "Debug", "Objective-J");
var objjHome = OBJJ.OBJJ_HOME,
objjPath = node_path.join(objjHome, "Frameworks", "Objective-J"),
objjDebugPath = node_path.join(objjHome, "Frameworks", "Debug", "Objective-J");
installFramework(objjPath, destinationFrameworks.join("Objective-J"), force, symlink);
installFramework(objjDebugPath, destinationDebugFrameworks.join("Objective-J"), force, symlink);
@@ -281,9 +297,9 @@ function createFrameworksInFile(/*Array*/ frameworks, /*String*/ aFile, /*Boolea
for (var i = 0; i < OBJJ.objj_frameworks.length; i++)
{
var sourceFramework = FILE.path(OBJJ.objj_frameworks[i]).join(framework);
if (FILE.isDirectory(sourceFramework))
var sourceFramework = node_path.join(OBJJ.objj_frameworks[i], framework);
if (fs.lstatSync(sourceFramework).isDirectory())
{
installFramework(sourceFramework, destinationFrameworks.join(framework), force, symlink);
found = true;
@@ -296,9 +312,9 @@ function createFrameworksInFile(/*Array*/ frameworks, /*String*/ aFile, /*Boolea
for (var i = 0, found = false; i < OBJJ.objj_debug_frameworks.length; i++)
{
var sourceDebugFramework = FILE.path(OBJJ.objj_debug_frameworks[i]).join(framework);
if (FILE.isDirectory(sourceDebugFramework))
var sourceDebugFramework = node_path.join(OBJJ.objj_debug_frameworks[i], framework);
if (fs.lstatSync(sourceDebugFramework).isDirectory())
{
installFramework(sourceDebugFramework, destinationDebugFrameworks.join(framework), force, symlink);
found = true;
@@ -331,9 +347,9 @@ function installFramework(source, dest, force, symlink)
stream.print((symlink ? "Symlinking " : "Copying ") + logPath(source) + " ==> " + logPath(dest));
if (symlink)
FILE.symlink(source, dest);
fs.symlinkSync(source, dest);
else
FILE.copyTree(source, dest);
fs.copySync(source, dest, { recursive: true });
}
else
warn("Cannot find: " + logPath(source));
@@ -341,7 +357,7 @@ function installFramework(source, dest, force, symlink)
function createThemesInFile(/*Array*/ themes, /*String*/ aFile, /*Boolean*/ symlink, /*Boolean*/ force)
{
var destination = FILE.path(FILE.absolute(aFile));
var destination = node_path.resolve(aFile);
if (!destination.isDirectory())
fail("Cannot create Themes. The directory does not exist: " + destination);
@@ -350,26 +366,26 @@ function createThemesInFile(/*Array*/ themes, /*String*/ aFile, /*Boolean*/ syml
stream.print("Creating Themes in " + logPath(destinationThemes) + "...");
if (!(SYSTEM.env["CAPP_BUILD"]))
if (!(process.env["CAPP_BUILD"]))
fail("$CAPP_BUILD must be defined to use the --theme or -T option.");
var themesBuild = FILE.join(SYSTEM.env["CAPP_BUILD"], "Release"),
var themesBuild = node_path.join(process.env["CAPP_BUILD"], "Release"),
sources = [];
themes.forEach(function(theme)
{
var themeFolder = theme + ".blend",
path = FILE.join(themesBuild, themeFolder);
if (!FILE.isDirectory(path))
path = node_path.join(themesBuild, themeFolder);
if (!fs.lstatSync(path).isDirectory())
fail("Cannot find theme " + themeFolder + " in " + themesBuild);
sources.push([FILE.path(path), themeFolder])
sources.push([path, themeFolder])
});
sources.forEach(function(source)
{
installTheme(source[0], FILE.path(destinationThemes).join(source[1]), force, symlink);
installTheme(source[0], node_path.join(destinationThemes, source[1]), force, symlink);
});
}
@@ -392,9 +408,9 @@ function installTheme(source, dest, force, symlink)
stream.print((symlink ? "Symlinking " : "Copying ") + logPath(source) + " ==> " + logPath(dest));
if (symlink)
FILE.symlink(source, dest);
fs.symlinkSync(source, dest);
else
FILE.copyTree(source, dest);
fs.copySync(source, dest, { recursive: true });
}
else
warn("Cannot find: " + logPath(source));
@@ -430,7 +446,7 @@ function toIdentifier(/*String*/ aString)
function listTemplates()
{
FILE.list(templatesDirectory).forEach(function(templateName)
fs.readdirSync(templatesDirectory).forEach(function(templateName)
{
stream.print(templateName);
});
@@ -444,7 +460,7 @@ function listFrameworks()
{
stream.print(" " + frameworksDirectory);
FILE.list(frameworksDirectory).forEach(function(templateName)
fs.readdirSync(frameworksDirectory).forEach(function(templateName)
{
stream.print(" + " + templateName);
});
@@ -456,7 +472,7 @@ function listFrameworks()
{
stream.print(" " + frameworksDirectory);
FILE.list(frameworksDirectory).forEach(function(frameworkName)
fs.readdirSync(frameworksDirectory).forEach(function(frameworkName)
{
stream.print(" + " + frameworkName);
});
@@ -465,14 +481,14 @@ function listFrameworks()
function executePostInstallScript(/*String*/ destinationProject)
{
var path = FILE.join(destinationProject, "postinstall");
if (FILE.exists(path))
var path = node_path.join(destinationProject, "postinstall");
if (fs.existsSync(path))
{
stream.print(colorize("Executing postinstall script...", "cyan"));
OS.system(["/bin/sh", path, destinationProject]); // Use sh in case it isn't marked executable
FILE.remove(path);
child_process.execSync("/bin/sh" + " " + path + " " + destinationProject);
//OS.system(["/bin/sh", path, destinationProject]); // Use sh in case it isn't marked executable
fs.rmSync(path);
}
}
@@ -494,5 +510,5 @@ function warn(message)
function fail(message)
{
stream.print(colorize(message, "red"));
OS.exit(1);
process.exit(1);
}
+4 -5
View File
@@ -1,9 +1,8 @@
require ("../../common.jake");
var app = require("../../Foundation/objective-j/jake.js").app;
var BundleTask = require("../../Foundation/objective-j/jake.js").BundleTask;
var app = require("../../Jake/applicationtask.js").app;
var BundleTask = require("../../Jake/bundletask.js").BundleTask;
/* fileCreate = require("jake").fileCreate,
FILE = require("file"),
@@ -26,9 +25,9 @@ app ("capp", function(cappTask)
cappTask.setSources(new FileList("*.j"));
cappTask.setResources(new FileList("Resources/*"));
cappTask.setIncludesNibsAndXibs(true);
cappTask.setEnvironments(require("../../Foundation/objective-j/jake/environment.js").CommonJS);
cappTask.setEnvironments(require("../../Jake/environment.js").CommonJS);
cappTask.setFlattensSources(true);
cappTask.setSpritesResources(false);
cappTask.setSpritesResources(false);
if ($CONFIGURATION === "Release")
cappTask.setCompilerFlags("-O");
+1
View File
@@ -445,6 +445,7 @@ global.installCopy = function(sourcePath, useSudo)
global.spawnJake = function(/*String*/ aTaskName)
{
console.log("i spawnJake");
//if (systemSync(serializedENV() + " " + "npx --node-options='--inspect-brk' objj-jake" + " " + aTaskName))
if (systemSync(serializedENV() + " " + "npx objj-jake" + " " + aTaskName))
console.log("exited in spawnJake with code 1");
process.exit(1); //rake abort if ($? != 0)