Skip to content

Commit

Permalink
Resolved merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoncrief committed Apr 7, 2013
2 parents df568a2 + a7242d6 commit 0dbae35
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "coffeebar",
"version": "0.2.0",
"version": "0.2.2",
"author": "Charles Moncrief",
"description": "Simplified CoffeeScript build tool.",
"main": "lib/coffeebar.js",
Expand Down
2 changes: 1 addition & 1 deletion src/coffeebar.coffee
Expand Up @@ -65,7 +65,7 @@ class Coffeebar
addSources: ->
for inputPath in @inputPaths
files = glob.sync inputPath
@sources.push(new Source(@options, file)) for file in files
@sources.push(new Source(@options, file, inputPath)) for file in files
@offsetSources()

# Start-up the initial process by adding the sources, building them,
Expand Down
17 changes: 15 additions & 2 deletions src/source.coffee
Expand Up @@ -19,10 +19,11 @@ class Source

# Initilization consists of setting the timestamps to zero, then resolving
# the file name and reading it in.
constructor: (@options, @file = "") ->
constructor: (@options, @file = "", @inputPath = "") ->
@writeTime = 0
@compileTime = 0
@modTime = 0
@inputPath or= @file

if @file
@inputFile = path.resolve file
Expand Down Expand Up @@ -127,7 +128,19 @@ class Source
dir = path.dirname @file

if @options.output
dir = dir.replace @inputFile, @options.output
if @inputPath[0] is path.sep
baseInputDir = @inputPath.replace '**/*.{coffee,litcoffee,coffee.md}', ''
baseInputDir = baseInputDir.replace new RegExp("#{path.basename(baseInputDir)}/$"), ''
baseInputDir = path.normalize baseInputDir
baseOutputDir = dir.replace baseInputDir, ''
baseFragment = baseOutputDir.substr 0, baseOutputDir.indexOf(path.sep)
baseDir = baseOutputDir.replace new RegExp("^#{baseFragment}"), ''
dir = if baseFragment then path.join(@options.output, baseDir) else @options.output
else if @inputPath.indexOf path.sep
baseDir = @inputPath.substr 0, @inputPath.indexOf(path.sep)
dir = dir.replace new RegExp("^#{baseDir}"), @options.output
else
dir = @options.output

@outputPath = path.join dir, fileName

Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/output/input.coffee
@@ -0,0 +1,4 @@

numbers = [1,2,3,4]

console.log i for i in numbers
4 changes: 4 additions & 0 deletions test/fixtures/output/input/numbers.coffee
@@ -0,0 +1,4 @@

numbers = [1,2,3,4]

console.log i for i in numbers
3 changes: 3 additions & 0 deletions test/fixtures/output/input/sub/letters.coffee
@@ -0,0 +1,3 @@
letters = ['a','b','c','d','e', 'x']

console.log i for i in letters
3 changes: 3 additions & 0 deletions test/fixtures/output/input/sub/subsub/letters2.coffee
@@ -0,0 +1,3 @@
letters2 = ['x','y','z']

console.log i for i in letters2
41 changes: 41 additions & 0 deletions test/output.coffee
@@ -0,0 +1,41 @@
assert = require 'assert'
fs = require 'fs'
path = require 'path'
coffeebar = require '../lib/coffeebar'

fixturePath = path.join __dirname, 'fixtures/output'

inputFile = path.join fixturePath, 'input.coffee'
outputFile = path.join fixturePath, 'input.js'
inputDir = path.join fixturePath, 'input'
outputDir = path.join fixturePath, 'output'

files = [
"numbers.js"
"sub/letters.js"
"sub/subsub/letters2.js"
]

describe 'Output', ->

before ->
try fs.unlinkSync outputFile

it 'should write to the same directory', ->
coffeebar inputFile
assert fs.existsSync outputFile

it 'should write from an input dir to an output dir', ->
coffeebar inputDir, {output: outputDir}
for file in files
assert fs.existsSync path.join(outputDir, file)

it 'should write from an input file to an output dir', ->
coffeebar inputFile, {output: outputDir}
assert fs.existsSync path.join(outputDir, "input.js")

after ->
try fs.unlinkSync outputFile
try fs.unlinkSync path.join(outputDir, "input.js")
for file in files
try fs.unlinkSync path.join(outputDir, file)

0 comments on commit 0dbae35

Please sign in to comment.