Created
November 30, 2012 02:49
-
-
Save thehydroimpulse/4173485 to your computer and use it in GitHub Desktop.
Tower Package Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Register a new package: | |
| Tower.Package.register -> | |
| # Require some core modules: | |
| fs = require("fs") | |
| path = require("path") | |
| # Add information to the package. | |
| @info | |
| name: "Auth" | |
| description: "Hello, World" | |
| version: "0.0.1" | |
| author: "Daniel Fagnan" | |
| # Depend on these packages: | |
| @dependencies ["routing", "sockets", "models", "controllers", "views", "templates", "core"] | |
| # Register files the package is going to use: | |
| @addFile "client.js", "client" | |
| @addFile "server.js", "server" | |
| @addFile "shared.js", "*" | |
| @addFiles "base/", ["login.js", "logout.js", "features.js", "security.js"], "*" | |
| # Start these files automatically! | |
| @init ["server.js"] | |
| # Simple, coffee-script bundler extension: | |
| # Obviously this is a bit weird, having a coffee-script file that registers coffee-script files and compiles them. | |
| # Take this as a simple example, nothing more (though this example fully works in js) and if you include this coffee-script | |
| # package, then OTHER `package.coffee` files will be accepted. | |
| @registerExtension "coffee", (source_path, serve_path, type) -> | |
| contents = fs.readFileSync(source_path, "utf-8") | |
| options = | |
| bare: true | |
| filename: source_path | |
| try | |
| contents = coffee.compile(contents, options) | |
| catch e | |
| return @error(e.message) | |
| # Create a buffer instead of passing the raw data. | |
| contents = new Buffer(contents) | |
| # Add the resource to the bundler so it can be served | |
| # publicly. | |
| @addResource | |
| extension: "js" | |
| path: serve_path | |
| data: contents | |
| type: type # Client or Server | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Register a new package: | |
| Tower.Package.register(function(){ | |
| // Require some core modules: | |
| var fs = require('fs'); | |
| var path = require('path'); | |
| // Add information to the package. | |
| this.info({ | |
| name: "Auth", | |
| description: "Hello, World", | |
| version: "0.0.1", | |
| author: "Daniel Fagnan" | |
| }); | |
| // Depend on these packages: | |
| this.dependencies(['routing', 'sockets', 'models', 'controllers', 'views', 'templates', 'core']); | |
| // Register files the package is going to use: | |
| this.addFile('client.js', 'client'); | |
| this.addFile('server.js', 'server'); | |
| this.addFile('shared.js', '*'); | |
| this.addFiles('base/', [ | |
| 'login.js', | |
| 'logout.js', | |
| 'features.js', | |
| 'security.js' | |
| ], '*'); | |
| // Start these files automatically! | |
| this.init(['server.js']); | |
| // Simple, coffee-script bundler extension: | |
| this.registerExtension("coffee", function(source_path, serve_path, type){ | |
| var contents = fs.readFileSync(source_path, 'utf-8'); | |
| var options = {bare: true, filename: source_path}; | |
| try { | |
| contents = coffee.compile(contents, options); | |
| } catch (e) { | |
| return this.error(e.message); | |
| } | |
| // Create a buffer instead of passing the raw data. | |
| contents = new Buffer(contents); | |
| // Add the resource to the bundler so it can be served | |
| // publicly. | |
| this.addResource({ | |
| extension: 'js', | |
| path: serve_path, | |
| data: contents, | |
| type: type // Client or Server | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment