modified capp to work with node

This commit is contained in:
Alfred Wärnsäter
2021-08-10 12:27:50 +02:00
parent 9ab82e1e5e
commit 4a43e376ed
9 changed files with 200 additions and 180 deletions
+6 -4
View File
@@ -5,7 +5,7 @@
@import <Foundation/CPSet.j>
var fs = require("fs");
var path = require("path");
var PATH = require("path");
/* var FILE = require("file"),
SYSTEM = require("system"); */
@@ -44,6 +44,7 @@ var DefaultDictionary = nil,
+ (id)defaultConfiguration
{
debugger;
if (!DefaultConfiguration)
DefaultConfiguration = [[self alloc] initWithPath:nil];
@@ -52,8 +53,9 @@ var DefaultDictionary = nil,
+ (id)userConfiguration
{
debugger;
if (!UserConfiguration)
UserConfiguration = [[self alloc] initWithPath:FILE.join(process.env["HOME"], ".cappconfig")];
UserConfiguration = [[self alloc] initWithPath:PATH.join(process.env["HOME"], ".cappconfig")];
return UserConfiguration;
}
@@ -69,7 +71,7 @@ var DefaultDictionary = nil,
function isReadable(p) {
try {
fs.accessSync(p, constants.R_OK);
fs.accessSync(p, fs.constants.R_OK);
return true;
} catch (err) {
return false;
@@ -203,7 +205,7 @@ function config(/*va_args*/)
keyEnumerator = [configuration storedKeyEnumerator];
while ((key = [keyEnumerator nextObject]) !== nil)
print(key + '=' + [configuration valueForKey:key]);
console.log(key + '=' + [configuration valueForKey:key]);
}
else if (action === "get")
{
+42 -14
View File
@@ -28,8 +28,7 @@
var OBJJ = require("objj-runtime"),
stream = require("objj-runtime").term.stream;
// parser = new (require("narwhal/args").Parser)();
parser = new (require("objj-runtime").parser.Parser)();
// FIXME: lots of chaining using narwhals path wrapper, this file might still be broken
var fs = require("fs");
@@ -38,7 +37,7 @@ var child_process = require("child_process");
var jake = require("objj-jake");
// FIXME: removing command line options for now
/* parser.usage("DESTINATION_DIRECTORY");
parser.usage("DESTINATION_DIRECTORY");
parser.help("Generate a Cappuccino project or Frameworks directory");
@@ -93,7 +92,7 @@ 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,
@@ -103,28 +102,33 @@ var templatesDirectory = "/Users/alfred/Developer/cappuccino/Tools/capp/Resource
function gen(/*va_args*/)
{
console.log("in gen: " + arguments);
var args = ["capp gen"].concat(Array.prototype.slice.call(arguments));
var options = { args: args };
//options = parser.parse(args, null, null, true);
debugger;
var options = parser.parse(args, null, null, true);
console.log(options);
if (options.args.length > 1)
{
parser.printUsage(options);
process.exit(1);
}
console.log("a");
if (options.listTemplates)
{
listTemplates();
return;
}
console.log("b");
if (options.listFrameworks)
{
listFrameworks();
return;
}
console.log("c");
var destination = options.args[0];
@@ -139,43 +143,63 @@ function gen(/*va_args*/)
process.exit(1);
}
}
var sourceTemplate = null;
if (node_path.isAbsolute(options.template))
sourceTemplate = options.template;
else
sourceTemplate = node_path.join(templatesDirectory, options.template);
console.log(sourceTemplate);
if (!fs.lstatSync(sourceTemplate).isDirectory())
{
stream.print(colorize("Error: ", "red") + "The template " + logPath(sourceTemplate) + " cannot be found. Available templates are:");
listTemplates();
process.exit(1);
}
console.log("d");
var configFile = node_path.join(sourceTemplate, "template.config"),
config = {};
if (fs.lstatSync(configFile).isFile())
console.log(configFile);
if (fs.existsSync(configFile))
config = JSON.parse(fs.readFileSync(configFile, { encoding: "utf8" }));
//config = JSON.parse(FILE.read(configFile, { charset:"UTF-8" }));
console.log("e");
debugger;
var destinationProject = destination,
configuration = options.noconfig ? [Configuration defaultConfiguration] : [Configuration userConfiguration],
frameworks = options.frameworks,
themes = options.themes;
console.log("f");
if (!options.noFrameworks)
frameworks.push("Objective-J", "Foundation", "AppKit");
console.log("before if");
if (options.justFrameworks)
{
createFrameworksInFile(frameworks, destinationProject, options.symlink, options.useCappBuild, options.force);
createThemesInFile(themes, destinationProject, options.symlink, options.force);
}
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);
}
};
console.log("before copy: " + sourceTemplate + " " + destinationProject);
// FIXME???
copyRecursiveSync(sourceTemplate, destinationProject);
@@ -209,8 +233,12 @@ function gen(/*va_args*/)
key = null,
keyEnumerator = [configuration keyEnumerator];
function escapeRegex(string) {
return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
while ((key = [keyEnumerator nextObject]) !== nil)
contents = contents.replace(new RegExp("__" + RegExp.escape(key) + "__", 'g'), [configuration valueForKey:key]);
contents = contents.replace(new RegExp("__" + escapeRegex(key) + "__", 'g'), [configuration valueForKey:key]);
fs.writeFileSync(path, contents, { encoding: "utf8" });
//FILE.write(path, contents, { charset: "UTF-8"});
-6
View File
@@ -1,14 +1,8 @@
require ("../../common.jake");
var app = require("../../Jake/applicationtask.js").app;
var BundleTask = require("../../Jake/bundletask.js").BundleTask;
/* fileCreate = require("jake").fileCreate,
FILE = require("file"),
OS = require("os"),
stream = require("narwhal/term").stream; */
const path = require("path");
app ("capp", function(cappTask)
@@ -6,12 +6,15 @@
* Copyright __project.year__, __organization.name__ All rights reserved.
*/
var ENV = require("system").env,
FILE = require("file"),
JAKE = require("jake"),
const path = require("path");
const fs = require("fs");
var ENV = process.env,
//FILE = require("file"),
JAKE = require("objj-jake"),
task = JAKE.task,
FileList = JAKE.FileList,
app = require("cappuccino/jake").app,
app = require("/Users/alfred/Developer/cappuccino/Jake/applicationtask.js").app,
configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug",
OS = require("os"),
projectName = "__project.nameasidentifier__";
@@ -21,10 +24,10 @@ app (projectName, function(task)
ENV["OBJJ_INCLUDE_PATHS"] = "Frameworks";
if (configuration === "Debug")
ENV["OBJJ_INCLUDE_PATHS"] = FILE.join(ENV["OBJJ_INCLUDE_PATHS"], configuration);
ENV["OBJJ_INCLUDE_PATHS"] = path.join(ENV["OBJJ_INCLUDE_PATHS"], configuration);
task.setBuildIntermediatesPath(FILE.join("Build", "__project.nameasidentifier__.build", configuration));
task.setBuildPath(FILE.join("Build", configuration));
task.setBuildIntermediatesPath(path.join("Build", "__project.nameasidentifier__.build", configuration));
task.setBuildPath(path.join("Build", configuration));
task.setProductName("__project.name__");
task.setIdentifier("__project.identifier__");
@@ -32,7 +35,7 @@ app (projectName, function(task)
task.setAuthor("__organization.name__");
task.setEmail("__organization.email__");
task.setSummary("__project.name__");
task.setSources(new FileList("**/*.j").exclude(FILE.join("Build", "**")).exclude(FILE.join("Frameworks", "Source", "**")));
task.setSources(new FileList("**/*.j").exclude(path.join("Build", "**")).exclude(path.join("Frameworks", "Source", "**")));
task.setResources(new FileList("Resources/**"));
task.setIndexFilePath("index.html");
task.setInfoPlistPath("Info.plist");
@@ -67,45 +70,45 @@ task ("release", function()
task ("run", ["debug"], function()
{
OS.system(["open", FILE.join("Build", "Debug", projectName, "index.html")]);
OS.system(["open", path.join("Build", "Debug", projectName, "index.html")]);
});
task ("run-release", ["release"], function()
{
OS.system(["open", FILE.join("Build", "Release", projectName, "index.html")]);
OS.system(["open", path.join("Build", "Release", projectName, "index.html")]);
});
task ("deploy", ["release"], function()
{
FILE.mkdirs(FILE.join("Build", "Deployment", projectName));
OS.system(["press", "-f", FILE.join("Build", "Release", projectName), FILE.join("Build", "Deployment", projectName)]);
FILE.mkdirs(path.join("Build", "Deployment", projectName));
OS.system(["press", "-f", path.join("Build", "Release", projectName), path.join("Build", "Deployment", projectName)]);
printResults("Deployment")
});
task ("desktop", ["release"], function()
{
FILE.mkdirs(FILE.join("Build", "Desktop", projectName));
require("cappuccino/nativehost").buildNativeHost(FILE.join("Build", "Release", projectName), FILE.join("Build", "Desktop", projectName, "__project.nameasidentifier__.app"));
FILE.mkdirs(path.join("Build", "Desktop", projectName));
require("cappuccino/nativehost").buildNativeHost(path.join("Build", "Release", projectName), path.join("Build", "Desktop", projectName, "__project.nameasidentifier__.app"));
printResults("Desktop")
});
task ("run-desktop", ["desktop"], function()
{
OS.system([FILE.join("Build", "Desktop", projectName, "__project.nameasidentifier__.app", "Contents", "MacOS", "NativeHost"), "-i"]);
OS.system([path.join("Build", "Desktop", projectName, "__project.nameasidentifier__.app", "Contents", "MacOS", "NativeHost"), "-i"]);
});
function printResults(configuration)
{
print("----------------------------");
print(configuration+" app built at path: "+FILE.join("Build", configuration, projectName));
print("----------------------------");
console.log("----------------------------");
console.log(configuration+" app built at path: "+path.join("Build", configuration, projectName));
console.log("----------------------------");
}
function updateApplicationSize()
{
print("Calculating application file sizes...");
var contents = FILE.read(FILE.join("Build", configuration, projectName, "Info.plist"), { charset:"UTF-8" }),
console.log("Calculating application file sizes...");
var contents = fs.readFileSync(path.join("Build", configuration, projectName, "Info.plist"), { encoding: "utf8" }),
format = CFPropertyList.sniffedFormatOfString(contents),
plist = CFPropertyList.propertyListFromString(contents),
totalBytes = {executable:0, data:0, mhtml:0};
@@ -114,14 +117,19 @@ function updateApplicationSize()
var frameworksDir = "Frameworks";
if (configuration === "Debug")
frameworksDir = FILE.join(frameworksDir, "Debug");
frameworksDir = path.join(frameworksDir, "Debug");
var frameworks = FILE.list(frameworksDir);
var frameworks = [];
if (fs.existsSync(frameworksDir)) {
frameworks = fs.readdirSync(frameworksDir);
}
//var frameworks = FILE.list(frameworksDir);
frameworks.forEach(function(framework)
{
if (framework !== "Source")
addBundleFileSizes(FILE.join(frameworksDir, framework), totalBytes);
addBundleFileSizes(path.join(frameworksDir, framework), totalBytes);
});
// Read in the default theme name, and attempt to get its size
@@ -129,17 +137,17 @@ function updateApplicationSize()
themePath = nil;
if (themeName === "Aristo" || themeName === "Aristo2")
themePath = FILE.join(frameworksDir, "AppKit", "Resources", themeName + ".blend");
themePath = path.join(frameworksDir, "AppKit", "Resources", themeName + ".blend");
else
themePath = FILE.join("Frameworks", "Resources", themeName + ".blend");
themePath = path.join("Frameworks", "Resources", themeName + ".blend");
if (FILE.isDirectory(themePath))
if (fs.existsSync(themePath) && fs.lstatSync(themePath).isDirectory())
addBundleFileSizes(themePath, totalBytes);
// Add sizes for the app
addBundleFileSizes(FILE.join("Build", configuration, projectName), totalBytes);
addBundleFileSizes(path.join("Build", configuration, projectName), totalBytes);
print("Executables: " + totalBytes.executable + ", sprite data: " + totalBytes.data + ", total: " + (totalBytes.executable + totalBytes.data));
console.log("Executables: " + totalBytes.executable + ", sprite data: " + totalBytes.data + ", total: " + (totalBytes.executable + totalBytes.data));
var dict = new CFMutableDictionary();
@@ -148,37 +156,38 @@ function updateApplicationSize()
dict.setValueForKey("mhtml", totalBytes.mhtml);
plist.setValueForKey("CPApplicationSize", dict);
FILE.write(FILE.join("Build", configuration, projectName, "Info.plist"), CFPropertyList.stringFromPropertyList(plist, format), { charset:"UTF-8" });
fs.writeFileSync(path.join("Build", configuration, projectName, "Info.plist"), CFPropertyList.stringFromPropertyList(plist, format), { encoding: "utf8" });
//FILE.write(path.join("Build", configuration, projectName, "Info.plist"), CFPropertyList.stringFromPropertyList(plist, format), { charset:"UTF-8" });
}
function addBundleFileSizes(bundlePath, totalBytes)
{
var bundleName = FILE.basename(bundlePath),
var bundleName = path.basename(bundlePath),
environment = bundleName === "Foundation" ? "Objj" : "Browser",
bundlePath = FILE.join(bundlePath, environment + ".environment");
bundlePath = path.join(bundlePath, environment + ".environment");
if (FILE.isDirectory(bundlePath))
if (fs.existsSync(bundlePath) && fs.lstatSync(bundlePath).isDirectory())
{
var filename = bundleName + ".sj",
filePath = new FILE.Path(FILE.join(bundlePath, filename));
filePath = path.join(bundlePath, filename);
if (fs.existsSync(filePath)) {
totalBytes.executable += fs.lstatSync(filePath).size;
}
if (filePath.exists())
totalBytes.executable += filePath.size();
filePath = path.join(bundlePath, "dataURLs.txt");
if (fs.existsSync(filePath))
totalBytes.data += fs.lstatSync(filePath).size;
filePath = new FILE.Path(FILE.join(bundlePath, "dataURLs.txt"));
filePath = path.join(bundlePath, "MHTMLData.txt");
if (filePath.exists())
totalBytes.data += filePath.size();
if (fs.existsSync(filePath))
totalBytes.mhtml += fs.lstatSync(filePath).size;
filePath = new FILE.Path(FILE.join(bundlePath, "MHTMLData.txt"));
filePath = path.join(bundlePath, "MHTMLPaths.txt");
if (filePath.exists())
totalBytes.mhtml += filePath.size();
filePath = new FILE.Path(FILE.join(bundlePath, "MHTMLPaths.txt"));
if (filePath.exists())
totalBytes.mhtml += filePath.size();
if (fs.existsSync(filePath))
totalBytes.mhtml += fs.lstatSync(filePath).size;
}
}
@@ -0,0 +1,4 @@
{
"name": "application",
"version": "1.0.0"
}
@@ -25,11 +25,7 @@
// DO NOT REMOVE
//===========================================================
var SYS = require("system"),
ENV = SYS.env,
FILE = require("file"),
OS = require("os");
const env = process.env;
//===========================================================
// USER CONFIGURABLE VARIABLES
@@ -40,7 +36,8 @@ var SYS = require("system"),
it is built in $CAPP_BUILD if that is defined, otherwise
in a "Build" directory within the project directory.
*/
var buildDir = ENV["BUILD_PATH"] || ENV["CAPP_BUILD"] || "Build";
var buildDir = env["BUILD_PATH"] || env["CAPP_BUILD"] || "Build";
/*
The list of directories containing Objective-J source
@@ -59,17 +56,41 @@ var buildDir = ENV["BUILD_PATH"] || ENV["CAPP_BUILD"] || "Build";
"Modules/Bar"
];
*/
var sourceDirs = [
];
//===========================================================
// AUTOMATICALLY GENERATED
//
// Do not edit! (unless you know what you are doing)
//===========================================================
//===========================================================
// AUTOMATICALLY GENERATED
//
// Do not edit! (unless you know what you are doing)
//===========================================================
const path = require("path");
const fs = require("fs");
var stream = require("narwhal/term").stream,
const stream = require("objj-runtime/lib/term").stream;
const jake = require("objj-jake");
const CLEAN = require("objj-jake/lib/jake/clean").CLEAN;
const CLOBBER = require("objj-jake/lib/jake/clean").CLOBBER;
const FileList = jake.FileList;
const filedir = jake.filedir;
const task = jake.task;
const JAKE_EXTRAS_PATH = "/Users/alfred/Developer/cappuccino/Jake/";
const framework = require(path.join(JAKE_EXTRAS_PATH, "frameworktask.js")).framework;
const browserEnvironment = require(path.join(JAKE_EXTRAS_PATH, "environment.js"));
const configuration = env["CONFIG"] || env["CONFIGURATION"] || env["c"] || "Debug";
const productName = "__project.nameasidentifier__";
const buildPath = path.join(buildDir, productName + ".build");
const debugBuildPath = path.join("Build", "Debug");
/* var stream = require("narwhal/term").stream,
JAKE = require("jake"),
task = JAKE.task,
CLEAN = require("jake/clean").CLEAN,
@@ -78,17 +99,16 @@ var stream = require("narwhal/term").stream,
filedir = JAKE.filedir,
framework = require("cappuccino/jake").framework,
browserEnvironment = require("objective-j/jake/environment").Browser,
configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug",
configuration = env["CONFIG"] || env["CONFIGURATION"] || env["c"] || "Debug",
productName = "__project.nameasidentifier__",
buildPath = FILE.canonical(FILE.join(buildDir, productName + ".build")),
packageFrameworksPath = FILE.join(SYS.prefix, "packages", "cappuccino", "Frameworks"),
debugPackagePath = FILE.join(packageFrameworksPath, "Debug", productName);
releasePackagePath = FILE.join(packageFrameworksPath, productName);
buildPath = FILE.join(SYS.prefix, "packages", "cappuccino", "Frameworks"),
debugPackagePath = FILE.join(buildPath, "Debug", productName);
releasePackagePath = FILE.join(buildPath, productName); */
var frameworkTask = framework (productName, function(frameworkTask)
{
frameworkTask.setBuildIntermediatesPath(FILE.join(buildPath, configuration));
frameworkTask.setBuildPath(FILE.join(buildDir, configuration));
var frameworkTask = framework (productName, function(frameworkTask) {
frameworkTask.setBuildIntermediatesPath(path.join(buildPath, configuration));
frameworkTask.setBuildPath(path.join(debugBuildPath, configuration));
frameworkTask.setProductName(productName);
frameworkTask.setIdentifier("__project.identifier__");
@@ -97,8 +117,11 @@ var frameworkTask = framework (productName, function(frameworkTask)
frameworkTask.setEmail("__organization.email__");
frameworkTask.setSummary("__project.name__");
var includes = sourceDirs.map(function(dir) { return dir + "/*.j"; }),
fileList = new FileList();
var includes = sourceDirs.map(function(dir) {
return dir + "/*.j";
});
var fileList = new FileList();
includes.unshift("*.j");
fileList.include(includes);
@@ -109,34 +132,36 @@ var frameworkTask = framework (productName, function(frameworkTask)
frameworkTask.setLicense(BundleTask.License.LGPL_v2_1);
//frameworkTask.setEnvironments([browserEnvironment]);
if (configuration === "Debug")
if (configuration === "Debug") {
frameworkTask.setCompilerFlags("-DDEBUG -g -S --inline-msg-send");
else
} else {
frameworkTask.setCompilerFlags("-O2");
}
});
task ("debug", function()
{
ENV["CONFIGURATION"] = "Debug";
JAKE.subjake(["."], "build", ENV);
env["CONFIGURATION"] = "Debug";
jake.subjake(["."], "build", env);
});
task ("release", function()
{
ENV["CONFIGURATION"] = "Release";
JAKE.subjake(["."], "build", ENV);
env["CONFIGURATION"] = "Release";
jake.subjake(["."], "build", env);
});
task ("default", ["release"]);
var frameworkCJS = FILE.join(buildDir, configuration, "CommonJS", "cappuccino", "Frameworks", productName);
var frameworkCJS = path.join(buildDir, configuration, "CommonJS", "cappuccino", "Frameworks", productName);
filedir (frameworkCJS, [productName], function()
{
if (FILE.exists(frameworkCJS))
FILE.rmtree(frameworkCJS);
if (fs.existsSync(frameworkCJS))
fs.rmSync(frameworkCJS, { recursive: true });
FILE.copyTree(frameworkTask.buildProductPath(), frameworkCJS);
// TODO
//FILE.copyTree(frameworkTask.buildProductPath(), frameworkCJS);
});
task ("build", [productName, frameworkCJS]);
@@ -155,17 +180,17 @@ task ("install-symlinks", ["debug", "release"], function()
task ("help", function()
{
var app = JAKE.application().name();
var app = jake.application().name();
colorPrint("--------------------------------------------------------------------------", "bold+green");
colorPrint("__project.name__ - Framework", "bold+green");
colorPrint("--------------------------------------------------------------------------", "bold+green");
describeTask(app, "debug", "Builds a debug version at " + FILE.join(buildDir, "Debug", productName));
describeTask(app, "release", "Builds a release version at " + FILE.join(buildDir, "Release", productName));
describeTask(app, "debug", "Builds a debug version at " + path.join(buildDir, "Debug", productName));
describeTask(app, "release", "Builds a release version at " + path.join(buildDir, "Release", productName));
describeTask(app, "all", "Builds a debug and release version");
describeTask(app, "install", "Builds a debug and release version, then installs in " + packageFrameworksPath);
describeTask(app, "install-symlinks", "Builds a debug and release version, then symlinks the built versions into " + packageFrameworksPath);
describeTask(app, "install", "Builds a debug and release version, then installs in " + buildPath);
describeTask(app, "install-symlinks", "Builds a debug and release version, then symlinks the built versions into " + buildPath);
describeTask(app, "clean", "Removes the intermediate build files");
describeTask(app, "clobber", "Removes the intermediate build files and the installed frameworks");
@@ -173,27 +198,25 @@ task ("help", function()
});
CLEAN.include(buildPath);
CLOBBER.include(FILE.join(buildDir, "Debug", productName))
.include(FILE.join(buildDir, "Release", productName))
.include(debugPackagePath)
.include(releasePackagePath);
CLOBBER.include(path.join(buildDir, "Debug", productName))
.include(path.join(buildDir, "Release", productName))
.include(debugBuildPath)
.include(buildPath);
var install = function(action)
{
var packageFrameworksPath = FILE.join(SYS.prefix, "packages", "cappuccino", "Frameworks");
["Release", "Debug"].forEach(function(aConfig)
{
colorPrint((action === "symlink" ? "Symlinking " : "Copying ") + aConfig + "...", "cyan");
if (aConfig === "Debug")
packageFrameworksPath = FILE.join(packageFrameworksPath, aConfig);
buildPath = path.join(buildPath, aConfig);
if (!FILE.isDirectory(packageFrameworksPath))
sudo(["mkdir", "-p", packageFrameworksPath]);
var buildPath = FILE.absolute(FILE.join(buildDir, aConfig, productName)),
targetPath = FILE.join(packageFrameworksPath, productName);
if (fs.existsSync(buildPath) && !fs.lstatSync(buildPath).isDirectory())
sudo(["mkdir", "-p", buildPath]);
var buildPath = path.resolve(path.join(buildDir, aConfig, productName)),
targetPath = path.join(buildPath, productName);
if (action === "symlink")
directoryOp(["ln", "-sf", buildPath, targetPath]);
@@ -0,0 +1,4 @@
{
"name": "application",
"version": "1.0.0"
}
+12 -59
View File
@@ -1,28 +1,28 @@
@import <Foundation/Foundation.j>
@import "Configuration.j"
@import "Generate.j"
var path = require("path");
var fs = require("fs");
function main(args)
{
function main(args) {
debugger;
console.log(args);
args.shift();
if (args.length < 1)
if (args.length < 1) {
return printUsage();
}
var index = 0,
count = args.length;
var count = args.length;
for (; index < count; ++index)
{
for (var index = 0; index < count; ++index) {
var argument = args[index];
switch (argument)
{
switch (argument) {
case "version":
case "--version": return print(require("cappuccino").fullVersionString());
case "--version": return console.log(JSON.parse(fs.readFileSync('package.json', 'utf8')).version);
case "-h":
case "--help": return printUsage();
@@ -36,8 +36,7 @@ function main(args)
}
}
function printUsage()
{
function printUsage() {
print("capp [--version] COMMAND [OPTIONS] [ARGS]");
print(" --version Print version");
print(" -h, --help Print this help");
@@ -64,49 +63,3 @@ function printUsage()
print(" --get KEY Get the value for a given key");
print(" --remove KEY Remove the value for a given key");
}
function getFiles(/*File*/ sourceDirectory, /*nil|String|Array<String>*/ extensions, /*Array*/ exclusions)
{
var matches = [],
files = sourceDirectory.listFiles(),
hasMultipleExtensions = typeof extensions !== "string";
if (files)
{
var index = 0,
count = files.length;
for (; index < count; ++index)
{
var file = files[index],
name = FILE.basename(file),
isValidExtension = !extensions;
if (exclusions && fileArrayContainsFile(exclusions, file))
continue;
if (!isValidExtension)
if (hasMultipleExtensions)
{
var extensionCount = extensions.length;
while (extensionCount-- && !isValidExtension)
{
var extension = extensions[extensionCount];
if (name.substring(name.length - extension.length - 1) === ("." + extension))
isValidExtension = true;
}
}
else if (name.substring(name.length - extensions.length - 1) === ("." + extensions))
isValidExtension = true;
if (FILE.isDirectory(file))
matches = matches.concat(getFiles(file, extensions, exclusions));
else if (isValidExtension)
matches.push(file);
}
}
return matches;
}
+3
View File
@@ -0,0 +1,3 @@
{
"version": "1.0.0"
}