From b7c04d7d16c76e5104f02b788d4c385396bdd313 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Wed, 15 Sep 2021 17:32:31 +0200 Subject: [PATCH] Fixed: Converted the tool 'objj2objcskeleton' for Node --- Tools/Jakefile | 2 +- Tools/objj2objcskeleton/Jakefile | 19 ++++++++----- Tools/objj2objcskeleton/objj2objcskeleton | 33 ++++++++++++----------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Tools/Jakefile b/Tools/Jakefile index 761913173..a89b39d85 100644 --- a/Tools/Jakefile +++ b/Tools/Jakefile @@ -5,4 +5,4 @@ require("../common.jake"); //subtasks(["fontinfo", "imagesize"], ["clean", "clobber"]); -subtasks(["fontinfo", "imagesize", "nib2cib", "capp"], ["build", /*"clean", "clobber"*/]); +subtasks(["fontinfo", "imagesize", "nib2cib", "objj2objcskeleton", "capp"], ["build", /*"clean", "clobber"*/]); diff --git a/Tools/objj2objcskeleton/Jakefile b/Tools/objj2objcskeleton/Jakefile index f696e90a0..155d170c1 100644 --- a/Tools/objj2objcskeleton/Jakefile +++ b/Tools/objj2objcskeleton/Jakefile @@ -1,12 +1,19 @@ require ("../../common.jake"); -var FILE = require("file"), - SYSTEM = require("system"); - const path = require("path"); +const fs = require("fs"); +const utilsFile = ObjectiveJ.utils.file; -var p = FILE.Path(path.join(SYSTEM.prefix, "bin", "objj2objcskeleton")); +const $BUILD_BIN_FILE = path.join($BUILD_CJS_CAPPUCCINO_BIN, 'objj2objcskeleton'); + +const $OBJJ_2_OBJC_SKELETON_FILES = new FileList("objj2objcskeleton"); + +filedir($BUILD_BIN_FILE, $OBJJ_2_OBJC_SKELETON_FILES, function(aTask) +{ + utilsFile.cp("objj2objcskeleton", $BUILD_BIN_FILE); + fs.chmodSync($BUILD_BIN_FILE, 0o755); +}); + +task("build", $BUILD_BIN_FILE); -sudo(["cp", "-f", "objj2objcskeleton", p]); -sudo(["chmod", "755", p]); diff --git a/Tools/objj2objcskeleton/objj2objcskeleton b/Tools/objj2objcskeleton/objj2objcskeleton index 83a8ffe75..b7972dbb3 100644 --- a/Tools/objj2objcskeleton/objj2objcskeleton +++ b/Tools/objj2objcskeleton/objj2objcskeleton @@ -2,12 +2,16 @@ @import -var FILE = require("file"), - OS = require("os"), - stream = require("narwhal/term").stream; +var fs = require("fs"), + acorn = require("objj-parser"), + walk = require("objj-parser/util/walk"), + stream = ObjectiveJ.term; + + debugger; function main(args) { + debugger; args.shift(); if (args.length < 1) @@ -18,14 +22,14 @@ function main(args) function printUsage() { - print("objj2objskeleton [FILE] [DESTINATION]"); - print("Convert a objective-j file to an objective-c files skeleton (.h and .m)") + console.log("objj2objskeleton [FILE] [DESTINATION]"); + console.log("Convert a objective-j file to an objective-c files skeleton (.h and .m)") } // Debug function to print some JS objects function dump(obj) { - print(JSON.stringify(obj)); + console.log(JSON.stringify(obj)); } function raise(pos, message) @@ -37,7 +41,7 @@ function raise(pos, message) } var errors = [], - xcc = ObjectiveJ.acorn.walk.make( + xcc = walk.make( { ClassDeclarationStatement: function(node, st, c) { @@ -83,7 +87,7 @@ var errors = [], { var selectors = node.selectors, arguments = node.arguments, - methodReturnType = [node.returntype ? node.returntype.name : "id"], + //methodReturnType = [node.returntype ? node.returntype.name : "id"], methodHasAction = node.action ? "IBAction" : null, selector = selectors[0].name, actionInfo = {"name": selector, "arguments":[]}; @@ -149,9 +153,8 @@ function parser(args) baseFilenameWithNoExtension = args.shift() == "-n" ? args.shift() : baseFilename.substring(0, baseFilename.length - 2), outputHeaderURL = new CFURL([outputDirectory stringByAppendingPathComponent:baseFilenameWithNoExtension + ".h"]), outputImplementationURL = new CFURL([outputDirectory stringByAppendingPathComponent:baseFilenameWithNoExtension + ".m"]), - source = FILE.read(sourcePath, { charset: "UTF-8" }), - flags = ObjectiveJ.Preprocessor.Flags.IncludeDebugSymbols | ObjectiveJ.Preprocessor.Flags.IncludeTypeSignatures, - tokens = ObjectiveJ.acorn.parse(source, { locations:true, sourceFile:sourcePath }), + source = fs.readFileSync(sourcePath, { encoding: "utf8" }), + tokens = acorn.parse(source, { locations:true, sourceFile:sourcePath }), classesInformation = [], ObjectiveCSource = "", ObjectiveCHeader = "", @@ -186,7 +189,7 @@ function parser(args) }); if (aClass.actions.length > 0) - ObjectiveCHeader += "\n"; + ObjectiveCHeader += "\n"; // add each action in header aClass.actions.forEach(function(anAction) @@ -204,10 +207,10 @@ function parser(args) }); if (ObjectiveCSource.length) - FILE.write(outputImplementationURL, ObjectiveCSource, { charset:"UTF-8" }); + fs.writeFileSync(outputImplementationURL.absoluteString(), ObjectiveCSource, 'utf8'); if (ObjectiveCHeader.length) - FILE.write(outputHeaderURL, ObjectiveCHeader, { charset:"UTF-8" }); + fs.writeFileSync(outputHeaderURL.absoluteString(), ObjectiveCHeader, 'utf8'); } catch (e) { @@ -227,7 +230,7 @@ function parser(args) stream.printError([plist rawString]); // If there were category warnings, hasErrors is NO, so return a warning status - OS.exit(hasErrors ? 1 : 2); + process.exit(hasErrors ? 1 : 2); } }