Fixed: Moved common function used in Jakefiles that was declared all over the place to a file.js in @objj/utils. Also some general cleanup.

This commit is contained in:
Martin Carlberg
2021-08-25 09:32:58 +02:00
parent 52b7a82b4d
commit 55bcfacf3b
12 changed files with 53 additions and 146 deletions
+6 -5
View File
@@ -5,6 +5,7 @@ var framework = require("../Jake/frameworktask.js").framework,
BundleTask = require("../Jake/bundletask.js").BundleTask;
const path = require("path");
const utilsFile = ObjectiveJ.utils.file;
$BUILD_PATH = path.join($BUILD_DIR, $CONFIGURATION, 'AppKit');
@@ -46,7 +47,7 @@ $BUILD_CJS_CAPPUCCINO_APPKIT = path.join($BUILD_CJS_CAPPUCCINO_FRAMEWORKS, "AppK
filedir ($BUILD_CJS_CAPPUCCINO_APPKIT, ["AppKit"], function()
{
cp_r(appKitTask.buildProductPath(), $BUILD_CJS_CAPPUCCINO_APPKIT);
utilsFile.cp_r(appKitTask.buildProductPath(), $BUILD_CJS_CAPPUCCINO_APPKIT);
});
subtasks (["Themes"], ["clean", "clobber"]);
@@ -55,11 +56,11 @@ task ("Theme", [$BUILD_CJS_CAPPUCCINO_APPKIT], function()
{
subjake(["Themes"], "build");
cp_r(path.join($BUILD_DIR, $CONFIGURATION, 'Aristo.blend'), path.join($BUILD_PATH, 'Resources', 'Aristo.blend'));
cp_r(path.join($BUILD_DIR, $CONFIGURATION, 'Aristo.blend'), path.join($BUILD_CJS_CAPPUCCINO_APPKIT, "Resources", "Aristo.blend"));
utilsFile.cp_r(path.join($BUILD_DIR, $CONFIGURATION, 'Aristo.blend'), path.join($BUILD_PATH, 'Resources', 'Aristo.blend'));
utilsFile.cp_r(path.join($BUILD_DIR, $CONFIGURATION, 'Aristo.blend'), path.join($BUILD_CJS_CAPPUCCINO_APPKIT, "Resources", "Aristo.blend"));
cp_r(path.join($BUILD_DIR, $CONFIGURATION, 'Aristo2.blend'), path.join($BUILD_PATH, 'Resources', 'Aristo2.blend'));
cp_r(path.join($BUILD_DIR, $CONFIGURATION, 'Aristo2.blend'), path.join($BUILD_CJS_CAPPUCCINO_APPKIT, "Resources", "Aristo2.blend"));
utilsFile.cp_r(path.join($BUILD_DIR, $CONFIGURATION, 'Aristo2.blend'), path.join($BUILD_PATH, 'Resources', 'Aristo2.blend'));
utilsFile.cp_r(path.join($BUILD_DIR, $CONFIGURATION, 'Aristo2.blend'), path.join($BUILD_CJS_CAPPUCCINO_APPKIT, "Resources", "Aristo2.blend"));
});
task ("build", ["AppKit", $BUILD_CJS_CAPPUCCINO_APPKIT, "Theme"]);
+2 -1
View File
@@ -2,6 +2,7 @@
require("../../../common.jake");
const path = require("path");
const utilsFile = ObjectiveJ.utils.file;
var framework = require("../../../Jake/frameworktask.js").framework;
var BundleTask = require("../../../Jake/bundletask.js").BundleTask;
@@ -31,7 +32,7 @@ $BUILD_CJS_PRODUCT_BLENDKIT = path.join($BUILD_CJS_CAPPUCCINO_FRAMEWORKS, "Blend
filedir ($BUILD_CJS_PRODUCT_BLENDKIT, ["BlendKit"], function()
{
cp_r(blendKitTask.buildProductPath(), $BUILD_CJS_PRODUCT_BLENDKIT);
utilsFile.cp_r(blendKitTask.buildProductPath(), $BUILD_CJS_PRODUCT_BLENDKIT);
});
task ("build", ["BlendKit", $BUILD_CJS_PRODUCT_BLENDKIT]);
+2 -1
View File
@@ -2,13 +2,14 @@
require("../../../common.jake");
var path = require("path");
const utilsFile = ObjectiveJ.utils.file;
$BLENDTASK = "blendtask.j";
$BUILD_CJS_BLENDTASK = path.join($BUILD_CJS_CAPPUCCINO, "lib", "cappuccino", "jake", "blendtask.j");
filedir($BUILD_CJS_BLENDTASK, [$BLENDTASK], function()
{
cp_r($BLENDTASK, $BUILD_CJS_BLENDTASK);
utilsFile.cp_r($BLENDTASK, $BUILD_CJS_BLENDTASK);
});
task("build", [$BUILD_CJS_BLENDTASK]);
+4 -4
View File
@@ -1,8 +1,8 @@
require("../common.jake");
// var FILE = require("file");
var fs = require("fs");
var path = require("path");
const fs = require("fs");
const path = require("path");
const utilsFile = ObjectiveJ.utils.file;
var tmp_list = new FileList();
tmp_list.include("**/*");
@@ -17,7 +17,7 @@ tmp_list.forEach(function(aFilename)
filedir (buildFilename, [aFilename], function ()
{
cp(aFilename, buildFilename);
utilsFile.cp(aFilename, buildFilename);
});
// HACK: narwhal should copy permissions
+2 -1
View File
@@ -26,6 +26,7 @@ var framework = require("../Jake/frameworktask.js").framework;
var BundleTask = require("../Jake/bundletask.js").BundleTask;
const path = require("path");
const utilsFile = ObjectiveJ.utils.file;
foundationTask = framework ("Foundation", function(foundationTask)
{
@@ -64,7 +65,7 @@ $BUILD_CJS_FOUNDATION = path.join($BUILD_CJS_CAPPUCCINO_FRAMEWORKS, "Foundation"
filedir ($BUILD_CJS_FOUNDATION, ["Foundation"], function()
{
cp_r(foundationTask.buildProductPath(), $BUILD_CJS_FOUNDATION);
utilsFile.cp_r(foundationTask.buildProductPath(), $BUILD_CJS_FOUNDATION);
});
+2 -14
View File
@@ -28,19 +28,7 @@ var /* FILE = require("file"), */
var fs = require("fs");
var path = require("path");
var copyRecursiveSync = function (src, dest) {
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
var isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest, { recursive: true });
fs.readdirSync(src).forEach(function(childItemName) {
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
});
} else {
fs.copyFileSync(src, dest);
}
};
const utilsFile = ObjectiveJ.utils.file;
function ApplicationTask(aName)
{
@@ -113,7 +101,7 @@ ApplicationTask.prototype.defineFrameworksTask = function()
tempPath = path.join(process.cwd(), ".__capp_Frameworks_Source__");
if (hasSource)
fs.moveSync(sourcePath, tempPath);
copyRecursiveSync(thisTask._frameworksPath, newFrameworks);
utilsFile.copyRecursiveSync(thisTask._frameworksPath, newFrameworks);
if (hasSource)
fs.moveSync(tempPath, sourcePath);
} });
+2 -26
View File
@@ -26,35 +26,11 @@ const path = require("path");
// NPM modules
const fs = require("fs");
//const ObjectiveJ = require("@objj/runtime");
const term = ObjectiveJ.term;
const utilsFile = ObjectiveJ.utils.file;
// Internal modules
const environment = require("./environment");
//const JAKE = require("@objj/jake");
/* Old imports
FILE = require("file")
OS = require("os")
UTIL = require("narwhal/util")
TERM = require("narwhal/term")
base64 = require("base64")
JAKE = require("jake")
*/
var copyRecursiveSync = function (src, dest) {
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
var isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest, { recursive: true });
fs.readdirSync(src).forEach(function(childItemName) {
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
});
} else {
fs.copyFileSync(src, dest);
}
};
var task = JAKE.task;
var Task = JAKE.Task;
@@ -455,7 +431,7 @@ BundleTask.prototype.defineResourceTask = function(aResourcePath, aDestinationPa
catch(anException) {
}
if (fs.lstatSync(aResourcePath).isDirectory())
copyRecursiveSync(aResourcePath, aDestinationPath);
utilsFile.copyRecursiveSync(aResourcePath, aDestinationPath);
else
fs.copyFileSync(aResourcePath, aDestinationPath);
});
+22 -21
View File
@@ -5,6 +5,7 @@ var path = require('path');
var child_process = require("child_process");
const term = ObjectiveJ.term;
const utilsFile = ObjectiveJ.utils.file;
var subprojects = ["Objective-J", "CommonJS", "Foundation", "AppKit", "Tools"];
@@ -27,7 +28,7 @@ filedir ($BUILD_CJS_OBJECTIVE_J_DEBUG_FRAMEWORKS, ["debug", "release"], function
{
fs.mkdirSync($BUILD_CJS_OBJECTIVE_J_DEBUG_FRAMEWORKS, { recursive: true });
cp_r(path.join($BUILD_DIR, "Debug", "Objective-J"), path.join($BUILD_CJS_OBJECTIVE_J_DEBUG_FRAMEWORKS, "Objective-J"));
utilsFile.cp_r(path.join($BUILD_DIR, "Debug", "Objective-J"), path.join($BUILD_CJS_OBJECTIVE_J_DEBUG_FRAMEWORKS, "Objective-J"));
});
$BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS = path.join($BUILD_CJS_CAPPUCCINO, "Frameworks", "Debug");
@@ -36,9 +37,9 @@ filedir ($BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS, ["debug", "release"], function(
{
fs.mkdirSync($BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS, { recursive: true });
cp_r(path.join($BUILD_DIR, "Debug", "Foundation"), path.join($BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS, "Foundation"));
cp_r(path.join($BUILD_DIR, "Debug", "AppKit"), path.join($BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS, "AppKit"));
cp_r(path.join($BUILD_DIR, "Debug", "BlendKit"), path.join($BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS, "BlendKit"));
utilsFile.cp_r(path.join($BUILD_DIR, "Debug", "Foundation"), path.join($BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS, "Foundation"));
utilsFile.cp_r(path.join($BUILD_DIR, "Debug", "AppKit"), path.join($BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS, "AppKit"));
utilsFile.cp_r(path.join($BUILD_DIR, "Debug", "BlendKit"), path.join($BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS, "BlendKit"));
});
task ("CommonJS", [$BUILD_CJS_OBJECTIVE_J_DEBUG_FRAMEWORKS, $BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS, "debug", "release"], function() {
@@ -92,7 +93,7 @@ task ("clobber-theme", function()
paths.forEach(function(path)
{
rm_rf(path);
utilsFile.rm_rf(path);
});
});
@@ -173,13 +174,13 @@ function generateDocs(/* boolean */ noFrame)
return;
}
else if (FILE.exists(path.join(documentationDir, "Cappuccino.doxygen.bak")))
mv(path.join(documentationDir, "Cappuccino.doxygen.bak"), path.join(documentationDir, "Cappuccino.doxygen"));
utilsFile.mv(path.join(documentationDir, "Cappuccino.doxygen.bak"), path.join(documentationDir, "Cappuccino.doxygen"));
var doxygenDidSucceed = !OS.system([doxygen, path.join(documentationDir, "Cappuccino.doxygen")]);
// Restore the original doxygen settings
if (FILE.exists(path.join(documentationDir, "Cappuccino.doxygen.bak")))
mv(path.join(documentationDir, "Cappuccino.doxygen.bak"), path.join(documentationDir, "Cappuccino.doxygen"));
utilsFile.mv(path.join(documentationDir, "Cappuccino.doxygen.bak"), path.join(documentationDir, "Cappuccino.doxygen"));
colorPrint("Post-processing generated documentation...", "green");
@@ -188,7 +189,7 @@ function generateDocs(/* boolean */ noFrame)
for (var i = 0; i < processors.length; ++i)
if (OS.system([processors[i], documentationDir, path.join("Documentation", "html")]))
{
rm_rf("Documentation");
utilsFile.rm_rf("Documentation");
return;
}
@@ -197,13 +198,13 @@ function generateDocs(/* boolean */ noFrame)
if (!FILE.isDirectory($BUILD_DIR))
FILE.mkdirs($BUILD_DIR);
rm_rf($DOCUMENTATION_BUILD);
mv("debug.txt", path.join("Documentation", "debug.txt"));
mv("Documentation", $DOCUMENTATION_BUILD);
utilsFile.rm_rf($DOCUMENTATION_BUILD);
utilsFile.mv("debug.txt", path.join("Documentation", "debug.txt"));
utilsFile.mv("Documentation", $DOCUMENTATION_BUILD);
// There is a bug in doxygen 1.7.x preventing loading correctly the custom CSS
// So let's do it manually
cp(path.join(documentationDir, "doxygen.css"), path.join($DOCUMENTATION_BUILD, "html", "doxygen.css"));
utilsFile.cp(path.join(documentationDir, "doxygen.css"), path.join($DOCUMENTATION_BUILD, "html", "doxygen.css"));
}
}
@@ -222,14 +223,14 @@ task ("starter_download", [$STARTER_DOWNLOAD_APPLICATION, $STARTER_DOWNLOAD_READ
{
if (FILE.exists($DOCUMENTATION_BUILD))
{
rm_rf(path.join($STARTER_DOWNLOAD, 'Documentation'));
cp_r(path.join($DOCUMENTATION_BUILD, 'html', '.'), path.join($STARTER_DOWNLOAD, 'Documentation'));
utilsFile.rm_rf(path.join($STARTER_DOWNLOAD, 'Documentation'));
utilsFile.cp_r(path.join($DOCUMENTATION_BUILD, 'html', '.'), path.join($STARTER_DOWNLOAD, 'Documentation'));
}
});
filedir ($STARTER_DOWNLOAD_APPLICATION, ["CommonJS"], function()
{
rm_rf($STARTER_DOWNLOAD_APPLICATION);
utilsFile.rm_rf($STARTER_DOWNLOAD_APPLICATION);
FILE.mkdirs($STARTER_DOWNLOAD);
if (OS.system(["capp", "gen", $STARTER_DOWNLOAD_APPLICATION, "-t", "Application", "--noconfig"]))
@@ -242,7 +243,7 @@ filedir ($STARTER_DOWNLOAD_APPLICATION, ["CommonJS"], function()
filedir ($STARTER_DOWNLOAD_README, [$STARTER_README], function()
{
cp($STARTER_README, $STARTER_DOWNLOAD_README);
utilsFile.cp($STARTER_README, $STARTER_DOWNLOAD_README);
});
filedir ($STARTER_DOWNLOAD_BOOTSTRAP, [$STARTER_BOOTSTRAP], function()
@@ -260,7 +261,7 @@ task ("deploy", ["downloads", "demos"], function()
// zip the starter pack
var starter_zip_output = path.join($BUILD_DIR, 'Cappuccino', 'Starter.zip');
rm_rf(starter_zip_output);
utilsFile.rm_rf(starter_zip_output);
OS.system("cd " + OS.enquote(cappuccino_output_path) + " && zip -ry -8 Starter.zip Starter");
});
@@ -272,7 +273,7 @@ task ("demos", function()
demosQuoted = OS.enquote(demosDir),
zipQuoted = OS.enquote(zipDir);
rm_rf(demosDir);
utilsFile.rm_rf(demosDir);
FILE.mkdirs(demosDir);
OS.system("curl -L http://github.com/cappuccino/cappuccino-demos/zipball/master > " + zipQuoted);
@@ -320,14 +321,14 @@ task ("demos", function()
}).forEach(function(demo)
{
// copy frameworks into the demos
cp_r(path.join($STARTER_DOWNLOAD_APPLICATION, "Frameworks"), path.join(demo.path(), "Frameworks"));
rm_rf(path.join(demo.path(), "Frameworks", "Debug"));
utilsFile.cp_r(path.join($STARTER_DOWNLOAD_APPLICATION, "Frameworks"), path.join(demo.path(), "Frameworks"));
utilsFile.rm_rf(path.join(demo.path(), "Frameworks", "Debug"));
var outputPath = demo.name().replace(/\s/g, "-") + ".zip";
OS.system("cd " + OS.enquote(FILE.dirname(demo.path()))+" && zip -ry -8 " + OS.enquote(outputPath) + " " + OS.enquote(FILE.basename(demo.path())));
// remove the frameworks
rm_rf(path.join(demo.path(), "Frameworks"));
utilsFile.rm_rf(path.join(demo.path(), "Frameworks"));
});
});
+3 -2
View File
@@ -41,6 +41,7 @@ acorn = require("./acorn").acorn;
var compiler = require("./ObjJAcornCompiler").ObjJCompiler;
const term = ObjectiveJ.term;
const utilsFile = ObjectiveJ.utils.file;
//$BUILD_CONFIGURATION_DIR = "../Build"
$BROWSER_FILE = path.join("Browser", "Objective-J.js");
@@ -83,7 +84,7 @@ new FileList("CommonJS/**/*").forEach( async function(aFilename)
if (path.extname(aFilename) !== ".js")
{
term.stream.print("Copying... \0green(" + aFilename +"\0)");
cp(aFilename, buildFilename);
utilsFile.cp(aFilename, buildFilename);
}
else
gcc(aFilename,
@@ -111,7 +112,7 @@ $BUILD_CJS_OBJECTIVE_J_FRAMEWORK = path.join($BUILD_CJS_OBJECTIVE_J, "Frameworks
filedir($BUILD_CJS_OBJECTIVE_J_FRAMEWORK, function()
{
cp_r($BUILD_OBJECTIVE_J, $BUILD_CJS_OBJECTIVE_J_FRAMEWORK);
utilsFile.cp_r($BUILD_OBJECTIVE_J, $BUILD_CJS_OBJECTIVE_J_FRAMEWORK);
});
CLOBBER.include($BUILD_OBJECTIVE_J);
+5 -21
View File
@@ -28,13 +28,12 @@
var stream = ObjectiveJ.term.stream;
parser = new (ObjectiveJ.parser.Parser)();
var parser = new (ObjectiveJ.parser.Parser)();
var utilsFile = ObjectiveJ.utils.file;
// FIXME: lots of chaining using narwhals path wrapper, this file might still be broken
var fs = require("fs");
var node_path = require("path");
var child_process = require("child_process");
// FIXME: removing command line options for now
parser.usage("DESTINATION_DIRECTORY");
@@ -175,22 +174,7 @@ function gen(/*va_args*/)
}
else if (!fs.existsSync(destinationProject))
{
function copyRecursiveSync(src, dest) {
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
var isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest, { recursive: true });
fs.readdirSync(src).forEach(function(childItemName) {
copyRecursiveSync(node_path.join(src, childItemName), node_path.join(dest, childItemName));
});
} else {
fs.copyFileSync(src, dest);
}
};
// FIXME???
copyRecursiveSync(sourceTemplate, destinationProject);
utilsFile.copyRecursiveSync(sourceTemplate, destinationProject);
var files = (new ObjectiveJ.utils.filelist.FileList(node_path.join(destinationProject, "**", "*"))).toArray(),
count = files.length,
@@ -340,7 +324,7 @@ function installFramework(source, dest, force, symlink)
if (symlink) {
fs.symlinkSync(source, dest);
} else {
copyRecursiveSync(source, dest);
utilsFile.copyRecursiveSync(source, dest);
}
} else {
warn("Cannot find: " + logPath(source));
@@ -401,7 +385,7 @@ function installTheme(source, dest, force, symlink)
if (symlink)
fs.symlinkSync(source, dest);
else
copyRecursiveSync(source, dest);
utilsFile.copyRecursiveSync(source, dest);
}
else
warn("Cannot find: " + logPath(source));
@@ -81,7 +81,6 @@ var initilize = function(callback) {
}
process.env["CONFIG"] = "Debug";
ObjectiveJ.OBJJ_INCLUDE_PATHS.push(path.resolve(fs.realpathSync(process.argv[1]), "..", "..", "Frameworks"));
//ObjectiveJ.OBJJ_INCLUDE_PATHS.push(path.join(path.join($BUILD_DIR, "Debug"), "CommonJS", "cappuccino", "Frameworks"));
ObjectiveJ.make_narwhal_factory(blendTaskPath, null, null, localCallback)(require, anExports, module, typeof system !== "undefined" && system, console.log);
}
}
@@ -109,7 +108,6 @@ async function defineBlendTask() {
themeBlendTask.setIdentifier("__project.identifier__");
themeBlendTask.setResources(new FileList("Resources/*"));
});
task ("build", [productName + ".blend"]);
}
exports.jakePromise = promise;
+3 -48
View File
@@ -23,6 +23,7 @@ const fs = require('fs');
const child_process = require('child_process');
const path = require('path');
const { stream } = ObjectiveJ.term;
const utilsFile = ObjectiveJ.utils.file;
requiresSudo = false;
@@ -216,52 +217,6 @@ global.rm_rf = function(/*String*/ aFilename)
};
// from stackoverflow
global.copyRecursiveSync = function (src, dest) {
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
var isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest, { recursive: true });
fs.readdirSync(src).forEach(function(childItemName) {
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
});
} else {
fs.copyFileSync(src, dest);
}
};
global.cp_r = function(/*String*/ from, /*String*/ to)
{
if (fs.existsSync(to))
rm_rf(to);
if (fs.lstatSync(from).isDirectory())
copyRecursiveSync(from, to);
else
{
try
{
fs.copyFileSync(from, to);
}
catch (e)
{
print(e + fs.existsSync(from) + " " + fs.existsSync(path.dirname(to)));
}
}
};
global.cp = function(/*String*/ from, /*String*/ to)
{
fs.copyFileSync(from, to)
// FILE.chmod(to, FILE.mod(from));
};
global.mv = function(/*String*/ from, /*String*/ to)
{
fs.renameSync(from, to);
};
function systemSync(command)
{
//console.log("command: " + command)
@@ -313,7 +268,7 @@ $OBJJ_TEMPLATE_EXECUTABLE = path.join(__dirname, "Objective-J", "CommonJS", "obj
global.make_objj_executable = function(aPath)
{
cp($OBJJ_TEMPLATE_EXECUTABLE, aPath);
utilsFile.cp($OBJJ_TEMPLATE_EXECUTABLE, aPath);
fs.chmodSync(aPath, 0o755);
};
@@ -433,7 +388,7 @@ global.installCopy = function(sourcePath, useSudo)
if (useSudo)
child_process.execSync(["sudo", "cp", "-Rf", sourcePath, path.dirname(targetPath)].join(" "));
else
copyRecursiveSync(sourcePath, targetPath);
utilsFile.copyRecursiveSync(sourcePath, targetPath);
var binPath = path.resolve(path.join(targetPath, "bin"))