Skip to content

Commit

Permalink
fix(npmignore): add npm prepublish script to remove bower_components …
Browse files Browse the repository at this point in the history
…directory
  • Loading branch information
jyounce committed Aug 26, 2015
1 parent f0907c1 commit 03da374
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# folders
# =======
bower_components/
bower_components/ # also see scripts/prepublish.js
dist/

# dot files
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"node": ">=0.10.0"
},
"main": "gulpfile.js",
"scripts": {
"prepublish": "node scripts/prepublish"
},
"devDependencies": {
"conventional-changelog": "~0.4.2",
"prepend-file": "~1.3.0"
Expand Down
21 changes: 21 additions & 0 deletions scripts/helpers/log-msg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require('colors')

var getSeparator = function(msg) {
var i = 0
var sep = ''
var len = msg.length
for (; i < len; i++) {
sep += '-'
}
return sep
}

var logMsg = function(msg) {
var sep = getSeparator(msg)
console.log(sep)
console.log(msg.toUpperCase().yellow)
console.log(sep)
return
}

module.exports = logMsg
28 changes: 28 additions & 0 deletions scripts/prepublish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Ensure bower_components dir gets removed before publishing to npm.
* .npmignore is not enough because some bower packages
* contain: package.json and/or README.md
* and these files never get ignored.
**********************************************************************/
var bowerPath, cwd, fse, logMsg, path, q;

q = require('q')
path = require('path')
fse = require('fs-extra')
logMsg = require('./helpers/log-msg')
cwd = process.cwd()
bowerPath = path.join(cwd, 'src', 'client', 'bower_components'); // ; required

/**
* Init
*/
(function() {
var defer = q.defer()
logMsg('npm prepublish')
fse.remove(bowerPath, function(e) {
if (e) return console.log(e)
console.log('removed bower_components directory')
return defer.resolve()
})
return defer.promise
})()

0 comments on commit 03da374

Please sign in to comment.