]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/pack.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / lib / pack.js
1 // npm pack <pkg>
2 // Packs the specified package into a .tgz file, which can then
3 // be installed.
4
5 module.exports = pack
6
7 var npm = require("./npm.js")
8   , install = require("./install.js")
9   , cache = require("./cache.js")
10   , fs = require("graceful-fs")
11   , chain = require("slide").chain
12   , path = require("path")
13   , cwd = process.cwd()
14   , writeStreamAtomic = require('fs-write-stream-atomic')
15   , cachedPackageRoot = require("./cache/cached-package-root.js")
16
17 pack.usage = "npm pack <pkg>"
18
19 // if it can be installed, it can be packed.
20 pack.completion = install.completion
21
22 function pack (args, silent, cb) {
23   if (typeof cb !== "function") cb = silent, silent = false
24
25   if (args.length === 0) args = ["."]
26
27   chain(args.map(function (arg) { return function (cb) {
28     pack_(arg, cb)
29   }}), function (er, files) {
30     if (er || silent) return cb(er, files)
31     printFiles(files, cb)
32   })
33 }
34
35 function printFiles (files, cb) {
36   files = files.map(function (file) {
37     return path.relative(cwd, file)
38   })
39   console.log(files.join("\n"))
40   cb()
41 }
42
43 // add to cache, then cp to the cwd
44 function pack_ (pkg, cb) {
45   cache.add(pkg, null, null, false, function (er, data) {
46     if (er) return cb(er)
47
48     // scoped packages get special treatment
49     var name = data.name
50     if (name[0] === "@") name = name.substr(1).replace(/\//g, "-")
51     var fname = name + "-" + data.version + ".tgz"
52
53     var cached = path.join(cachedPackageRoot(data), "package.tgz")
54       , from = fs.createReadStream(cached)
55       , to = writeStreamAtomic(fname)
56       , errState = null
57
58     from.on("error", cb_)
59     to.on("error", cb_)
60     to.on("close", cb_)
61     from.pipe(to)
62
63     function cb_ (er) {
64       if (errState) return
65       if (er) return cb(errState = er)
66       cb(null, fname)
67     }
68   })
69 }