Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ results

npm-debug.log
node_modules
bower_components
bower.json
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ SHELLSTUB=$(BINSRC_DIR)/shell_stub.txt
BINSRC=$(BINSRC_DIR)/cmd.js
BINOUTPUT=./bin/cmd.js

main: compile bin
all: **/*.js *.js $(BINOUTPUT)

compile:
coffee -c ./
%.js: %.coffee
npm run coffee -- ./$<

bin: compile
$(BINOUTPUT): $(SHELLSTUB) $(BINSRC)
cat $(SHELLSTUB) $(BINSRC) > $(BINOUTPUT)

6 changes: 3 additions & 3 deletions bin/cmd.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env node

// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.10.0
(function() {
var ArgumentParser, copyComponents, options, parser, path, resolveComponents, _mainPath, _ref;
var ArgumentParser, _mainPath, copyComponents, options, parser, path, ref, resolveComponents;

path = require("path");

_mainPath = path.join(__dirname, "../index.js");

_ref = require(_mainPath), resolveComponents = _ref.resolveComponents, copyComponents = _ref.copyComponents;
ref = require(_mainPath), resolveComponents = ref.resolveComponents, copyComponents = ref.copyComponents;

ArgumentParser = require("argparse").ArgumentParser;

Expand Down
6 changes: 3 additions & 3 deletions bin_src/cmd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 49 additions & 25 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,45 @@ readJSON = (filePath, cb) ->
_json = JSON.parse(res)
cb null, _json

# given the parsed JSON data, extract the "main" property
# and prepend the appropriate path.
extractMain = (filePath, data, cb) ->
_main = data.main

# get the relative path for "main" path from the bower components directory
joinPath = (bowerPath, main) ->
_main = main
# handle case where _main has a relative
# path like "./lib/someScript.js",
# which will incorrectly resolve to root package dir.
unless _main?
return null
relativeRegex = /^\.\/(.+)$/im
_match = relativeRegex.exec _main
if _match?
_main = _match[1]
path.join( path.dirname(bowerPath), main )


# given the parsed JSON data, extract the "main" property
# and prepend the appropriate path.
extractMain = (filePath, data, cb) ->
_main = data.main

#console.log _main
#console.log filePath
_pd = path.dirname(filePath)
#console.log _pd
mainPath = path.join( path.dirname(filePath), _main )
#console.log mainPath
unless _main?
return null

# console.log "main", _main
# console.log "filePath", filePath
mainPath = if Array.isArray _main then joinPath filePath,p for p in _main else [joinPath filePath,_main]

# mainPath = path.join( path.dirname(filePath), _main )
# console.log "mainPath", mainPath
mainPath

# given component's folder name, get the full path to
# the component's main script
mainFromFolder = (folderName, cb) ->
_filePath = inBowerDir(folderName, ".bower.json")
readJSON _filePath, (err, pkg) ->
# console.log "mainFromFolder::filepath", _filePath TODO: delete
mainPath = extractMain(_filePath, pkg)
if mainPath?

if mainPath.length > 0
cb null, {component: folderName, main: mainPath}
else
_filePath = inBowerDir(folderName, "package.json")
Expand All @@ -62,20 +71,35 @@ mainFromFolder = (folderName, cb) ->
cb null, {component: folderName, main: mainPath}




copyScript = (scriptRef, outputDir, cb) ->
scriptPath = scriptRef.main
outputPath = path.join(outputDir, scriptRef.component) + ".js"
fs.copy scriptPath, outputPath, (err) ->
cb null, {src: scriptPath, dest: outputPath}

copyScriptTo = (outputDir) ->
copyMain = (scriptRef, outputDir, cb) ->
scriptPaths = scriptRef.main
filesToCopy = scriptPaths.length

copyScript = (scriptRef, outputDir, cb) ->
scriptPath = scriptRef.main

cbHandler = (scriptPath, outputPath) -> (err) ->
if filesToCopy == 1 then cb null, {src: scriptPath, dest: outputPath}
filesToCopy--

scriptPaths.forEach (p) ->
outputPath = path.join(outputDir, path.basename(p))
fs.copy p, outputPath, cbHandler p, outputPath

# scriptPaths = scriptRef.main
# outputPath = scriptPath.map( (p) -> path.join(outputDir, path.basename(p)))
# #outputPath = path.join outputDir, path.basename p for p in scriptPath
# filesToCopy = scriptPath.length
# (scriptPath for scriptPath in scriptPaths)
# fs.copy scriptPath, outputPath, (err) ->
# cb null, {src: scriptPath, dest: outputPath}

copyMainTo = (outputDir) ->
(scriptRef, cb) ->
copyScript scriptRef, outputDir, cb
copyMain scriptRef, outputDir, cb

# copy components' main scripts to a target dir
copyComponents = (options, cb) ->
copyComponents = (options, cb) ->
_opts = _.clone(options)
_opts.src ?= "./bower_components"
unless _opts.dest?
Expand All @@ -84,7 +108,7 @@ copyComponents = (options, cb) ->
_copyFn = ->
fs.readdir _opts.src, (err, folders) ->
async.map folders, mainFromFolder, (err, completed) ->
async.map completed, copyScriptTo(_opts.dest), (err, copied) ->
async.map completed, copyMainTo(_opts.dest), (err, copied) ->
cb null, copied
fs.exists _opts.dest, (exists) ->
if exists
Expand Down
83 changes: 57 additions & 26 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepublish": "make"
"prepublish": "make -j",
"coffee": "coffee --compile"
},
"bin": {
"bower-copy": "./bin/cmd.js"
Expand All @@ -25,5 +26,8 @@
"async": "~0.2.9",
"fs-extra": "~0.8.1",
"argparse": "~0.1.15"
},
"devDependencies": {
"coffee-script": "^1.10.0"
}
}