Skip to content

Commit

Permalink
Added file missing in previous commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
zeekay committed Jul 25, 2012
1 parent 8ff5e65 commit 7ef1c14
Show file tree
Hide file tree
Showing 30 changed files with 229 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/au
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib').cli()
19 changes: 19 additions & 0 deletions src/cli.coffee
@@ -0,0 +1,19 @@
program = require 'commander'

program
.command('new [name]')
.description('create a new app and/or extension')
.usage('[name] [options]')
.option('-t, --template [name]', 'template to use')
.option('-c, --config [config file]', 'config file to use')
.action (name, opts={}) ->
if not name
return console.log 'Name of project required'

require('./generator') name, opts

help = -> console.log program.helpInformation()

program.parse process.argv

help() unless program.args.length
38 changes: 38 additions & 0 deletions src/generator.coffee
@@ -0,0 +1,38 @@
fs = require 'fs'
mote = require 'mote'
wrench = require 'wrench'

{basename, join} = require 'path'
{encoding, exec, existsSync} = require './utils'

module.exports = (name, {config, template}) ->
template = template or 'default'
src = join __dirname, '../templates', template
dest = name

ctx =
name: basename dest
user: process.env.USER

# update context with config options.
if config
for key, val of require config
ctx[key] = val

# make sure we don't clobber an existing directory.
if existsSync dest
return console.log "#{dest} already exists."

# copy template to dest
wrench.copyDirSyncRecursive src, dest

# compile templates with configuration
for file in wrench.readdirSyncRecursive dest

file = join dest, file

if fs.statSync(file).isFile() and not (/\.png$/.test file)
console.log file
buffer = fs.readFileSync file
template = mote.compile buffer.toString()
fs.writeFileSync file, template ctx
10 changes: 10 additions & 0 deletions src/index.coffee
@@ -0,0 +1,10 @@
{existsSync} = require './utils'

# If `../src` exists then require the CoffeeScript source files.
if existsSync __dirname + '/../src'
require 'coffee-script'
wrapper = require '../src/wrapper'
else
wrapper = require './wrapper'

module.exports = wrapper
46 changes: 46 additions & 0 deletions src/utils.coffee
@@ -0,0 +1,46 @@
fs = require 'fs'
path = require 'path'
{spawn} = require 'child_process'

# The location of exists/existsSync changed in node v0.8.0.
if fs.existsSync
exports.existsSync = existsSync = fs.existsSync
exports.exists = fs.exists
else
exports.existsSync = existsSync = path.existsSync
exports.exists = path.exists

exports.exec = (args, callback) ->
# Simple serial execution of commands, no error handling
serial = (arr) ->
complete = 0
iterate = ->
exports.exec arr[complete], ->
complete += 1
if complete == arr.length
return
else
iterate()
iterate()
# passed callback as second argument
if typeof opts is 'function'
callback = opts

if Array.isArray args
return serial args

args = args.split(/\s+/g)
cmd = args.shift()
proc = spawn cmd, args

# echo stdout/stderr
proc.stdout.on 'data', (data) ->
process.stdout.write data

proc.stderr.on 'data', (data) ->
process.stderr.write data

# callback on completion
proc.on 'exit', (code) ->
if typeof callback is 'function'
callback null, code
2 changes: 2 additions & 0 deletions src/wrapper.coffee
@@ -0,0 +1,2 @@
exports.cli = -> require './cli'
exports.version = require('../package.json').version
Binary file added templates/chrome-app/icon_128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/chrome-app/icon_16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions templates/chrome-app/index.html
@@ -0,0 +1,8 @@
<html>
<head>
<title>Hello World App</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
3 changes: 3 additions & 0 deletions templates/chrome-app/main.js
@@ -0,0 +1,3 @@
chrome.experimental.app.onLaunched.addListener(function() {
chrome.app.window.create('index.html');
});
15 changes: 15 additions & 0 deletions templates/chrome-app/manifest.json
@@ -0,0 +1,15 @@
{
"manifest_version": 2,
"name": "Hello World",
"version": "1",
"icons": {
"16": "icon_16.png",
"128": "icon_128.png"
},
"app": {
"background": {
"scripts": ["main.js"]
}
},
"permissions": ["experimental"]
}
18 changes: 18 additions & 0 deletions templates/chrome-extension/background.js
@@ -0,0 +1,18 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var min = 1;
var max = 5;
var current = min;

function updateIcon() {
chrome.browserAction.setIcon({path:"icon" + current + ".png"});
current++;

if (current > max)
current = min;
}

chrome.browserAction.onClicked.addListener(updateIcon);
updateIcon();
Binary file added templates/chrome-extension/icon1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/chrome-extension/icon2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/chrome-extension/icon3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/chrome-extension/icon4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/chrome-extension/icon5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions templates/chrome-extension/manifest.json
@@ -0,0 +1,12 @@
{
"name": "A browser action which changes its icon when clicked.",
"version": "1.1",
"background": { "scripts": ["background.js"] },
"permissions": [
"tabs", "http://*/*"
],
"browser_action": {
"name": "Click to change the icon's color"
},
"manifest_version": 2
}
Binary file added templates/default/app/icon_128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/default/app/icon_16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions templates/default/app/index.html
@@ -0,0 +1,8 @@
<html>
<head>
<title>Hello World App</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
3 changes: 3 additions & 0 deletions templates/default/app/main.js
@@ -0,0 +1,3 @@
chrome.experimental.app.onLaunched.addListener(function() {
chrome.app.window.create('index.html');
});
15 changes: 15 additions & 0 deletions templates/default/app/manifest.json
@@ -0,0 +1,15 @@
{
"manifest_version": 2,
"name": "Hello World",
"version": "1",
"icons": {
"16": "icon_16.png",
"128": "icon_128.png"
},
"app": {
"background": {
"scripts": ["main.js"]
}
},
"permissions": ["experimental"]
}
18 changes: 18 additions & 0 deletions templates/default/ext/background.js
@@ -0,0 +1,18 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var min = 1;
var max = 5;
var current = min;

function updateIcon() {
chrome.browserAction.setIcon({path:"icon" + current + ".png"});
current++;

if (current > max)
current = min;
}

chrome.browserAction.onClicked.addListener(updateIcon);
updateIcon();
Binary file added templates/default/ext/icon1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/default/ext/icon2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/default/ext/icon3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/default/ext/icon4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/default/ext/icon5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions templates/default/ext/manifest.json
@@ -0,0 +1,12 @@
{
"name": "A browser action which changes its icon when clicked.",
"version": "1.1",
"background": { "scripts": ["background.js"] },
"permissions": [
"tabs", "http://*/*"
],
"browser_action": {
"name": "Click to change the icon's color"
},
"manifest_version": 2
}

0 comments on commit 7ef1c14

Please sign in to comment.