diff options
author | isaacs <i@izs.me> | 2010-08-25 04:52:31 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-08-25 16:21:51 +0400 |
commit | 6652d93ed561a1e4bcd24a506933efef442ad25e (patch) | |
tree | 67dc64ec27ca074f90f9e4db91646d15377427bb | |
parent | 3ff3ffe293e8191f0381680afe12a76d4a1db041 (diff) |
Load mans properly from the folder, and install them when building.
-rw-r--r-- | lib/build.js | 49 | ||||
-rw-r--r-- | lib/utils/load-package-defaults.js | 25 |
2 files changed, 67 insertions, 7 deletions
diff --git a/lib/build.js b/lib/build.js index de375682b..ef91bc90f 100644 --- a/lib/build.js +++ b/lib/build.js @@ -29,6 +29,7 @@ var npm = require("../npm") , asyncMap = require("./utils/async-map") , find = require("./utils/find") , loadPackageDefaults = require("./utils/load-package-defaults") + , exec = require("./utils/exec") module.exports = build @@ -45,7 +46,7 @@ function build (args, cb) { , [asyncMap, args, function (a, cb) { return resolveDependencies(a, cb) }] - , [asyncMap, args, buildStep, 2] + , [asyncMap, args, buildStep, 3] , [linkDependencies, args] , [finishBuild, args] , cb @@ -58,6 +59,7 @@ function buildStep (pkg, cb) { if (!pkg) return cb(new Error("Invalid package data "+sys.inspect(pkg))) linkModules(pkg, path.join(npm.root, pkg.name+"-"+pkg.version), cb) linkBins(pkg, cb) + linkMans(pkg, cb) } function autoUpdate (pkg, cb) { var auto = npm.config.get("update-dependents") @@ -182,9 +184,49 @@ function dependencyLink (pkg, cb) { }, 3, cb) } +// link ROOT/.npm/{name}/{ver}/package/{man} to +// {manroot}/{section}/{man-basename}-{ver}{man-extname} +function linkMans (pkg, cb) { + log.verbose(pkg._id, "linkMans") + log.silly(pkg.man, "linkMans") + var man = pkg.man + , manroot = npm.config.get("manroot") + , pkgDir = path.join(npm.dir, pkg.name, pkg.version, "package") + if (!man || !manroot) return cb() + exec("manpath", [], null, true, function (er, code, stdout, stderr) { + var manpath = er ? [] : stdout.trim().split(":") + if (manpath.indexOf(manroot) === -1) { + log.warn( "It seems " + manroot + " might not be visible to man\n" + + "For greater justice, please add it to your man path\n" + + "See: `man man`" + , pkg._id + " linkMans" + ) + } + asyncMap(man, function (man, cb) { + var parseMan = man.match(/(.*)\.([0-9]+)(\.gz)?$/) + , stem = parseMan[1] + , sxn = parseMan[2] + , gz = parseMan[3] || "" + , bn = path.basename(stem) + , manSrc = path.join( pkgDir, man ) + , manDest = path.join( manroot + , "man"+sxn + , bn.indexOf(pkg.name) === 0 ? bn + : pkg.name + "-" + bn + + "-" + pkg.version + + "." + sxn + gz + ) + // ln {cwd}/man {manroot}/man{sxn}/{bn}-{ver}.{sxn}{gz} + log.silly(manSrc, "manSrc") + log.silly(manDest, "manDest") + linkIfExists(manSrc, manDest, cb) + }, cb) + }) +} + // shim {target}/{module-name} to ROOT/.npm/{name}/{version}/package/{module-path} function linkModules (pkg, target, cb) { - log.silly(pkg, "linkModules") + log.silly(pkg.modules, "linkModules") log.verbose(target, "linkModules") var mod = pkg.modules @@ -228,7 +270,6 @@ function linkBins (pkg, cb) { }, log.er(cb, "failed to link bins")) } - function shimTest (from, to, dep, cb) { // if it needs a shim, then call writeShim // otherwise, just link it in. @@ -259,3 +300,5 @@ function finishBuild (args, cb) { return [ log, "Success: "+(pkg.name + "@"+pkg.version), "build" ] })).concat(cb)) } + + diff --git a/lib/utils/load-package-defaults.js b/lib/utils/load-package-defaults.js index c8632789c..ece20e25b 100644 --- a/lib/utils/load-package-defaults.js +++ b/lib/utils/load-package-defaults.js @@ -9,14 +9,31 @@ var path = require("path") function loadPackageDefaults (pkg, cb) { asyncMap([pkg], function (pkg, cb) { + log.verbose(pkg._id, "loadDefaults") readDefaultModules(pkg, cb) readDefaultBins(pkg, cb) - }, 2, function (er) { cb(er, pkg) }) + readDefaultMans(pkg, cb) + }, 3, function (er) { cb(er, pkg) }) +} + +function readDefaultMans (pkg, cb) { + var man = pkg.directories && pkg.directories.man + , pkgDir = path.join(npm.dir, pkg.name, pkg.version, "package") + , manDir = path.join(pkgDir, man) + if (pkg.man && !Array.isArray(pkg.man)) pkg.man = [pkg.man] + if (pkg.man || !man) return cb(null, pkg) + find(manDir, /\.[0-9]+(\.gz)?$/, function (er, filenames) { + if (er) return cb(er) + pkg.man = filenames.map(function (filename) { + var f = path.basename(filename) + return filename.substr(pkgDir.length + 1) + }) + cb(null,pkg) + }) } // shim ROOT/{name}-{version}/**/*.js to ROOT/.npm/{name}/{version}/{lib}/**/*.js -function readDefaultModules(pkg, cb) { - log.verbose("linking default modules", pkg._id) +function readDefaultModules (pkg, cb) { var lib = pkg.directories && pkg.directories.lib || pkg.lib , pkgDir = path.join(npm.dir, pkg.name, pkg.version, "package") , libDir = path.join(pkgDir, lib) @@ -35,7 +52,7 @@ function readDefaultModules(pkg, cb) { } function readDefaultBins (pkg, cb) { var binDir = pkg.directories && pkg.directories.bin - log.silly(pkg, binDir) + log.verbose(binDir, pkg._id) if (pkg.bin || !binDir) return cb(null, pkg) log.verbose("linking default bins", pkg._id) var pkgDir = path.join(npm.dir, pkg.name, pkg.version, "package") |