# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 120338 2014-05-23 18:31:26Z ciserlohn@macports.org $

PortSystem          1.0

name                npm
version             1.4.12

categories          devel
platforms           darwin
license             MIT
maintainers         ciserlohn

supported_archs     noarch

description         node package manager
long_description    npm is a package manager for node. \
                    You can use it to install and publish your node programs. \
		            It manages dependencies and does other cool stuff.

homepage            http://www.npmjs.org/

master_sites        http://registry.npmjs.org/npm/-/

extract.suffix      .tgz

checksums           rmd160  027c238fa774848c89a57a6309fa3785b7814895 \
                    sha256  4f6214ddc81e19efb19d2ff8d5a1bdfa0e29571c4cb570988fa1f90c4ea76843

worksrcdir          "package"

depends_lib         path:bin/node:nodejs

use_configure       no

patchfiles          patch-lib-update.js.diff

post-patch {
    regsub -all {/} "^${prefix}/lib" {\\\/} npm_path_jsregex
    reinplace "s|@@NPM_PATH_JSREGEX@@|${npm_path_jsregex}|g" ${worksrcpath}/lib/update.js

    foreach f [concat ${worksrcpath}/cli.js \
                   ${worksrcpath}/bin/npm-cli.js \
                   ${worksrcpath}/node_modules/ansi/examples/beep/index.js \
                   ${worksrcpath}/node_modules/ansi/examples/clear/index.js \
                   ${worksrcpath}/node_modules/ansi/examples/cursorPosition.js \
                   ${worksrcpath}/node_modules/ansi/examples/progress/index.js \
                   ${worksrcpath}/node_modules/ansi/examples/starwars.js \
                   ${worksrcpath}/node_modules/cmd-shim/test/00-setup.js \
                   ${worksrcpath}/node_modules/lru-cache/test/memory-leak.js \
                   ${worksrcpath}/node_modules/node-gyp/bin/node-gyp.js \
                   ${worksrcpath}/node_modules/nopt/bin/nopt.js \
                   ${worksrcpath}/node_modules/nopt/examples/my-program.js \
                   ${worksrcpath}/node_modules/opener/opener.js \
                   ${worksrcpath}/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/run.js \
                   ${worksrcpath}/node_modules/request/node_modules/form-data/node_modules/combined-stream/test/run.js \
                   ${worksrcpath}/node_modules/rimraf/bin.js \
                   ${worksrcpath}/node_modules/semver/bin/semver \
                   ${worksrcpath}/node_modules/which/bin/which \
                   ${worksrcpath}/scripts/index-build.js \
                   ${worksrcpath}/scripts/relocate.sh \
                   ${worksrcpath}/test/disabled/package-config/test.js \
                   ${worksrcpath}/test/packages/npm-test-array-bin/bin/array-bin \
                   ${worksrcpath}/test/packages/npm-test-dir-bin/bin/dir-bin] {
        reinplace "s|/usr/bin/env node|${prefix}/bin/node|" ${f}
    }
}

build {}

destroot.cmd        ${prefix}/bin/node ./cli.js
destroot.args       --global .
destroot.destdir    --prefix=${destroot}${prefix}

post-destroot {
    set completions_path ${destroot}${prefix}/share/bash-completion/completions/
    xinstall -d ${completions_path}
    xinstall -m 644 ${worksrcpath}/lib/utils/completion.sh ${completions_path}/npm
}

variant bash_completion {
    depends_run-append path:etc/bash_completion:bash-completion
}

notes "
It is not recommended to install packages globally. But if you do so\
please be aware that they won't get cleaned up when you deactivate\
or uninstall ${name}. Globally installed packages will remain in\
${prefix}/lib/node_modules/ until you manually delete them.
" 

livecheck.type      regex
livecheck.url       http://registry.npmjs.org/npm
livecheck.regex     {"latest":"(.*?)"}
