Permalink
Browse files

fix order

  • Loading branch information...
1 parent 85cfec4 commit 2684695a5a7100797a691d556901dbe46d7f301f @dalssoft dalssoft committed Feb 14, 2013
View
@@ -10,4 +10,5 @@ my-reporter.js
*.sw*
lib/browser/diff.js
.idea
-*.iml
+*.iml
+example/project1/lib
@@ -7,9 +7,9 @@ build = ->
rehab = new Rehab()
files = rehab.process './src'
-
+ files = files.join " "
console.log "FILES:", files
- exec "coffee #{join_to_single_file} --compile --output lib/", (err, stdout, stderr) ->
+ exec "coffee #{join_to_single_file} --compile #{files}", (err, stdout, stderr) ->
throw err if err
task 'build', 'Build coffee2js using Rehab', sbuild = ->
@@ -0,0 +1,3 @@
+#_require ../repository/repo1.coffee
+
+class app.Model2
@@ -1,3 +1,3 @@
#_require ../repository/repo1.coffee
-class Model1
+class app.Model1
@@ -1 +1 @@
-class Repo1
+class app.Repo1
@@ -1,3 +1,3 @@
#_require ../model/model1.coffee
-class View1
+class app.View1
View
@@ -15,20 +15,21 @@ module.exports = class Rehab
process: (folder) ->
# create a graph from a folder name:
- # C <- A -> B.coffee -> C
+ # src/C <- A -> B.coffee -> C
depGraph = @processDependencyGraph(folder)
console.log "1: processDependencyGraph", depGraph
# normalize filenames:
- # C.coffee <- A.coffee -> B.coffee -> C.coffee
+ # src/C.coffee <- src/A.coffee -> src/B.coffee -> src/C.coffee
depGraph = @normalizeFilename(folder, depGraph)
console.log "2: normalizeFilename", depGraph
# create a graph from a folder name:
# A.coffee -> B.coffee -> C.coffee
depList = @processDependencyList depGraph
console.log "3: processDependencyList", depList
- depList
+
+ depList.reverse() #yeah!
processDependencyGraph: (folder) ->
depGraph = []
@@ -37,15 +38,11 @@ module.exports = class Rehab
depGraph
normalizeFilename: (folder, depGraph) ->
- # [[./fileA, fileB]] => [[fileA, fileB]]
for edge in depGraph
- file = edge[1]
- continue if file == @REQ_MAIN_NODE
+ continue if edge[1] == @REQ_MAIN_NODE
fileDep = @normalizeCoffeeFilename(edge[0])
- fileDep = path.normalize fileDep
-
- file = @normalizeCoffeeFilename(file)
+ file = @normalizeCoffeeFilename(edge[1])
fullPath = path.resolve path.dirname(fileDep), file
file = path.join(folder, path.relative(folder, fullPath))
@@ -54,9 +51,9 @@ module.exports = class Rehab
normalizeCoffeeFilename: (file) ->
file = "#{file}.coffee" unless file.endsWith ".coffee"
+ file = path.normalize file
file
-
processDependencyList: (depGraph) ->
depList = tsort(depGraph)
depList.filter (i) => not i.beginsWith @REQ_MAIN_NODE
View
@@ -4,7 +4,7 @@ Rehab = require '../src/rehab'
describe "rehab", ->
describe "normalizeFilePath", ->
describe "should return a graph", ->
- it "desnormalized file path", ->
+ it "normalized file path", ->
#given
files = [["fileA", "fileB"], ["./fileB", "fileC"]]
@@ -13,9 +13,9 @@ describe "rehab", ->
sorted = rehab.normalizeFilename '.', files
#then
- sorted.should.eql files = [["fileA.coffee", "fileB.coffee"], ["fileB.coffee", "fileC.coffee"]]
+ sorted.should.eql [["fileA.coffee", "fileB.coffee"], ["fileB.coffee", "fileC.coffee"]]
- it "desnormalized relative file path", ->
+ it "normalized relative file path", ->
#given
files = [["src/model/mode1", "../repo/repo1"], ["src/view/view1", "../model/model1"]]
@@ -24,7 +24,18 @@ describe "rehab", ->
sorted = rehab.normalizeFilename '.', files
#then
- sorted.should.eql files = [["src/model/mode1.coffee", "src/repo/repo1.coffee"], ["src/view/view1.coffee", "src/model/model1.coffee"]]
+ sorted.should.eql [["src/model/mode1.coffee", "src/repo/repo1.coffee"], ["src/view/view1.coffee", "src/model/model1.coffee"]]
+
+ it "normalized relative file path", ->
+ #given
+ files = [["src/model/mode1", "../repo/repo1"], ["src/view/view1", "../model/model1"]]
+
+ #when
+ rehab = new Rehab()
+ sorted = rehab.normalizeFilename './project/', files
+
+ #then
+ sorted.should.eql [["project/src/model/mode1.coffee", "project/src/repo/repo1.coffee"], ["project/src/view/view1.coffee", "project/src/model/model1.coffee"]]
describe "processDependencyList", ->
describe "should return a ordered list when", ->

0 comments on commit 2684695

Please sign in to comment.