From 2d96fcf87ff4886ea91eff406040d28b92a2bd3e Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Sat, 7 May 2011 13:10:33 -0400 Subject: [PATCH] Improvements to the ThemeDescriptor capp template: - New/improved jake tasks: debug, release, all, clean, clobber, test, test-release, help. - help task shows comprehensive, formatted documentation for the available tasks. - BlendKit is automatically symlinked into the Frameworks directory if necessary as part of the build process, so that the showcase will always work. - User can easily change the build directory by changing one line. - Fixed incorrect placeholders in main.j. --- .../Templates/ThemeDescriptor/Jakefile | 170 ++++++++++++++++-- .../ThemeDescriptor/ThemeDescriptors.j | 8 +- .../ThemeDescriptor/index-debug.html | 2 +- .../Templates/ThemeDescriptor/index.html | 2 +- .../Templates/ThemeDescriptor/main.j | 6 +- 5 files changed, 165 insertions(+), 23 deletions(-) diff --git a/Tools/capp/Resources/Templates/ThemeDescriptor/Jakefile b/Tools/capp/Resources/Templates/ThemeDescriptor/Jakefile index 162d7f564..f4a6d9a5d 100644 --- a/Tools/capp/Resources/Templates/ThemeDescriptor/Jakefile +++ b/Tools/capp/Resources/Templates/ThemeDescriptor/Jakefile @@ -3,28 +3,172 @@ * __project.name__ * * Created by __user.name__ on __project.date__. - * Copyright __project.year__, __organization.name__ All rights reserved. + * Copyright __project.year__, __organization.name__. All rights reserved. */ +//=========================================================== +// DO NOT REMOVE +//=========================================================== + var ENV = require("system").env, FILE = require("file"), - task = require("jake").task, - FileList = require("jake").FileList, + OS = require("os"); + + +//=========================================================== +// USER CONFIGURABLE VARIABLES +//=========================================================== + +/* + The directory in which the project will be built. By default + it is built in a "Build" directory within the project directory. + To use your $CAPP_BUILD directory, change the declaration to: + + var buildDir = ENV["CAPP_BUILD"]; +*/ +var buildDir = "Build"; + + +//=========================================================== +// AUTOMATICALLY GENERATED +// +// Do not edit! (unless you know what you are doing) +//=========================================================== + +var productName = "__project.nameasidentifier__" + stream = require("narwhal/term").stream, + JAKE = require("jake"), + task = JAKE.task, + CLEAN = require("jake/clean").CLEAN, + CLOBBER = require("jake/clean").CLOBBER, + FileList = JAKE.FileList, blend = require("cappuccino/jake").blend, - configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug"; + configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug", + productName = "__project.nameasidentifier__", + debugBlendKitPath = FILE.join("Frameworks", "Debug", "BlendKit"), + releaseBlendKitPath = FILE.join("Frameworks", "BlendKit"), + buildPath = FILE.canonical(FILE.join(buildDir, productName + ".build")); - -blend ("__project.nameasidentifier__.blend", function(__project.nameasidentifier__Task) +blend (productName + ".blend", function(themeBlendTask) { - __project.nameasidentifier__Task.setBuildIntermediatesPath(FILE.join("Build", "__project.nameasidentifier__.build", configuration)) - __project.nameasidentifier__Task.setBuildPath(FILE.join("Build", configuration)); + themeBlendTask.setBuildIntermediatesPath(FILE.join(buildPath, configuration)) + themeBlendTask.setBuildPath(FILE.join(buildDir, configuration)); - __project.nameasidentifier__Task.setThemeDescriptors(new FileList("ThemeDescriptors.j")); - __project.nameasidentifier__Task.setIdentifier("com.280n.__project.identifier__"); - __project.nameasidentifier__Task.setResources(new FileList("Resources/*")); + themeBlendTask.setThemeDescriptors(new FileList("ThemeDescriptors.j")); + themeBlendTask.setIdentifier("__project.identifier__"); + themeBlendTask.setResources(new FileList("Resources/*")); }); -task ("default", ["__project.nameasidentifier__.blend"]); +task ("debug", function() +{ + ENV["CONFIGURATION"] = "Debug"; + JAKE.subjake(["."], "build", ENV); -task ("build", ["default"]); + symlinkBlendKit(debugBlendKitPath); +}); +task ("release", function() +{ + ENV["CONFIGURATION"] = "Release"; + JAKE.subjake(["."], "build", ENV); + + symlinkBlendKit(releaseBlendKitPath); +}); + +task ("default", ["release"]); + +task ("build", [productName + ".blend"]); + +task ("all", ["debug", "release"]); + +task ("test", ["debug"], function() +{ + OS.system(["open", "index-debug.html"]); +}); + +task ("test-release", ["release"], function() +{ + OS.system(["open", "index.html"]); +}); + +CLEAN.include(buildPath); +CLOBBER.include(buildDir); + +task ("help", function() +{ + var app = JAKE.application().name(); + + colorPrint("--------------------------------------------------------------------------", "bold+green"); + colorPrint("__project.name__ - Theme Blend", "bold+green"); + colorPrint("--------------------------------------------------------------------------", "bold+green"); + + describeTask(app, "debug", "Builds a debug version at " + FILE.join(buildDir, "Debug")); + describeTask(app, "release", "Builds a release version at " + FILE.join(buildDir, "Release")); + describeTask(app, "all", "Builds a debug and release version"); + describeTask(app, "test", "Builds a debug version, symlinks to the installed BlendKit framework,\nand opens the theme showcase in the default browser"); + describeTask(app, "test-release", "Builds a release version, symlinks to the installed BlendKit framework,\nand opens the theme showcase in the default browser"); + describeTask(app, "clean", "Removes the intermediate build files"); + describeTask(app, "clobber", "Removes the intermediate build files and the built theme"); + + colorPrint("--------------------------------------------------------------------------", "bold+green"); +}); + +var describeTask = function(application, task, description) +{ + colorPrint("\n" + application + " " + task, "violet"); + description.split("\n").forEach(function(line) + { + print(" " + line); + }); +} + +var symlinkBlendKit = function(destinationPath) +{ + if (FILE.isDirectory(destinationPath)) + return; + + var blendKitPath = null, + path = FILE.join(require("system").prefix, "packages", "cappuccino", "Frameworks", "BlendKit"); + + if (FILE.isDirectory(path)) + blendKitPath = path; + + if (!blendKitPath) + { + cappBuild = ENV["CAPP_BUILD"]; + + if (cappBuild) + { + var buildTypes = ["Release", "Debug"]; + + for (var i = 0; i < buildTypes.length; ++i) + { + var path = FILE.join(cappBuild, buildTypes[i], "BlendKit"); + + if (FILE.isDirectory(path)) + { + blendKitPath = path; + break; + } + } + } + } + + if (blendKitPath) + FILE.symlink(blendKitPath, destinationPath); +} + +function colorPrint(message, color) +{ + var matches = color.match(/(bold(?: |\+))?(.+)/); + + if (!matches) + return; + + message = "\0" + matches[2] + "(" + message + "\0)"; + + if (matches[1]) + message = "\0bold(" + message + "\0)"; + + stream.print(message); +} diff --git a/Tools/capp/Resources/Templates/ThemeDescriptor/ThemeDescriptors.j b/Tools/capp/Resources/Templates/ThemeDescriptor/ThemeDescriptors.j index c30d70946..a5c99969c 100644 --- a/Tools/capp/Resources/Templates/ThemeDescriptor/ThemeDescriptors.j +++ b/Tools/capp/Resources/Templates/ThemeDescriptor/ThemeDescriptors.j @@ -3,15 +3,13 @@ * __project.name__ * * Created by __user.name__ on __project.date__. - * Copyright __project.year__, __organization.name__ All rights reserved. + * Copyright __project.year__, __organization.name__. All rights reserved. */ @import @implementation __project.nameasidentifier__ThemeDescriptor : BKThemeDescriptor -{ -} + (CPString)themeName { @@ -21,7 +19,7 @@ + (CPButton)themedButton { var button = [[CPButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 20.0)]; - + [button setValue:[CPColor blueColor] forThemeAttribute:@"bezel-color"]; [button setValue:[CPColor greenColor] forThemeAttribute:@"bezel-color" inState:CPThemeStateHighlighted]; @@ -29,7 +27,7 @@ [button setValue:[CPColor yellowColor] forThemeAttribute:@"text-color" inState:CPThemeStateHighlighted]; [button setTitle:@"Yikes!"]; - + return button; } diff --git a/Tools/capp/Resources/Templates/ThemeDescriptor/index-debug.html b/Tools/capp/Resources/Templates/ThemeDescriptor/index-debug.html index a4ae05fdd..abd95b259 100644 --- a/Tools/capp/Resources/Templates/ThemeDescriptor/index-debug.html +++ b/Tools/capp/Resources/Templates/ThemeDescriptor/index-debug.html @@ -7,7 +7,7 @@ __project.name__ Created by __user.name__ on __project.date__. - Copyright __project.year__, __organization.name__ All rights reserved. + Copyright __project.year__, __organization.name__. All rights reserved. --> diff --git a/Tools/capp/Resources/Templates/ThemeDescriptor/index.html b/Tools/capp/Resources/Templates/ThemeDescriptor/index.html index 6b239b45e..3a0fc2ce9 100644 --- a/Tools/capp/Resources/Templates/ThemeDescriptor/index.html +++ b/Tools/capp/Resources/Templates/ThemeDescriptor/index.html @@ -7,7 +7,7 @@ __project.name__ Created by __user.name__ on __project.date__. - Copyright __project.year__, __organization.name__ All rights reserved. + Copyright __project.year__, __organization.name__. All rights reserved. --> diff --git a/Tools/capp/Resources/Templates/ThemeDescriptor/main.j b/Tools/capp/Resources/Templates/ThemeDescriptor/main.j index cb02f4859..1b51d9542 100755 --- a/Tools/capp/Resources/Templates/ThemeDescriptor/main.j +++ b/Tools/capp/Resources/Templates/ThemeDescriptor/main.j @@ -1,9 +1,9 @@ /* * main.j - * __Product__ + * __project.name__ * - * Created by __Me__ on __Date__. - * Copyright 2008 __MyCompanyName__. All rights reserved. + * Created by __user.name__ on __project.date__. + * Copyright __project.year__, __organization.name__. All rights reserved. */ @import