Page MenuHomeFreeBSD

Mk/Uses/node.mk Framework for NodeJS projects/ports
ActivePublic

Authored by yuri_rawbw.com on Nov 17 2015, 7:30 AM.
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=204577. And also the new www/etherpad-lite port based on USES=node:https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=204578
# $FreeBSD$
#
# Provide support for NodeJS based projects
#
# Feature: node
# Usage: USES=node
#
# MAINTAINER: portmgr@FreeBSD.org
.if !defined(_INCLUDE_USES_NODE_MK)
_INCLUDE_USES_NODE_MK= yes
FETCH_DEPENDS= npm:${PORTSDIR}/www/npm
BUILD_DEPENDS= npm:${PORTSDIR}/www/npm
RUN_DEPENDS= node:${PORTSDIR}/www/node
.if defined(NODE_MODULES)
FETCH_DEPENDS+= jq:${PORTSDIR}/textproc/jq
JQ_CMD= ${LOCALBASE}/bin/jq
.endif
.if defined(NODE_GH_ACCOUNT)
. if ! defined(NODE_GH_PROJECT)
NODE_GH_PROJECT= ${PORTNAME}
. endif
. if ! defined(NODE_GH_TAGNAME)
NODE_GH_TAGNAME= ${DISTVERSIONFULL}
. endif
_NODE_PROJECT_FILE= ${NODE_GH_ACCOUNT}-${NODE_GH_PROJECT}-${NODE_GH_TAGNAME}-node-project.tar.gz
_NODE_DIST_FILE= ${NODE_GH_PROJECT}-${NODE_GH_TAGNAME}.tar.gz
_NODE_DIR= ${NODE_GH_PROJECT}-${NODE_GH_TAGNAME}
_NODE_GH_URL= https://codeload.github.com/${NODE_GH_ACCOUNT}/${NODE_GH_PROJECT}/tar.gz/${NODE_GH_TAGNAME}?dummy=/${_NODE_PROJECT_FILE}
.endif
# commands
NPM_CMD= ${LOCALBASE}/bin/npm
NODE_CMD= ${LOCALBASE}/bin/node
# variables
NPM_ENV+= C=cc CXX=c++
NPM_FETCH_ARGS= --loglevel warn --ignore-scripts
NPM_BUILD_ARGS= --loglevel warn
NPM_SHRINKWRAP_ARGS= --dev
SHRINKWRAP_FILE= ${FILESDIR}/npm-shrinkwrap.json
NODE_INSTALL_BASE= ${LOCALBASE}/share/node-projects
NODE_INSTALL_DIR= ${NODE_INSTALL_BASE}/${NODE_GH_ACCOUNT}-${NODE_GH_PROJECT}
_NODE_MASTER_SITE_BACKUP_URLS= ${MASTER_SITE_BACKUP}${_NODE_DIST_FILE}
.if defined(NODE_SRCDIR)
_NODE_DO_CD=node_modules/${NODE_SUBDIR}
.else
_NODE_DO_CD=.
.endif
makeshrinkwrap: do-fetch
@cd ${_DISTDIR}; \
${TAR} xzf ${_NODE_DIST_FILE} && \
cd ${_NODE_DIR} && \
cd ${_NODE_DO_CD} && \
${NPM_ENV} ${NPM_CMD} shrinkwrap ${NPM_SHRINKWRAP_ARGS} && \
${CP} npm-shrinkwrap.json ${SHRINKWRAP_FILE} && \
cd ${_DISTDIR} && \
${RM} -r ${_NODE_DIR}
do-fetch:
@${MKDIR} ${_DISTDIR}
@cd ${_DISTDIR}; \
force_fetch=false; \
for afile in ${FORCE_FETCH}; do \
afile=$${afile##*/}; \
if [ "x$$afile" = "x${_NODE_DIST_FILE}" ]; then \
force_fetch=true; \
fi; \
done; \
if [ ! -f ${_NODE_DIST_FILE} -o "$$force_fetch" = "true" ]; then \
${RM} -rf ${_NODE_PROJECT_FILE} ${_NODE_DIR} ${_NODE_DIST_FILE}; \
for url in ${_NODE_MASTER_SITE_BACKUP_URLS}; do \
if ${ECHO_MSG} "=> Attempting to fetch ${PORTNAME} from the master backup site" && \
${SETENV} ${FETCH_ENV} ${FETCH_CMD} ${FETCH_BEFORE_ARGS} $${url} ${FETCH_AFTER_ARGS}; then \
return 0; \
fi; \
done; \
for url in ${_NODE_GH_URL}; do \
if ${ECHO_MSG} "=> Attempting to fetch ${PORTNAME} from github" && \
${SETENV} ${FETCH_ENV} ${FETCH_CMD} ${FETCH_BEFORE_ARGS} $${url} ${FETCH_AFTER_ARGS} && \
${ECHO_MSG} "=> Extracting node project source" && \
${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} ${_NODE_PROJECT_FILE} ${EXTRACT_AFTER_ARGS} && \
${RM} ${_NODE_PROJECT_FILE} && \
${ECHO_MSG} "=> Preparing the node project" && \
cd ${_NODE_DIR} && \
([ -z "${NODE_SRCDIR}" ] || \
(${MKDIR} node_modules && \
${MV} ${NODE_SRCDIR} node_modules/${NODE_SUBDIR} \
) \
) && cd ${_NODE_DO_CD} && \
for m in ${NODE_MODULES}; do \
${ECHO} $${m} | ${SED} -E "s/([[:alnum:]]+):([[:digit:].]+)/{\"dependencies\":{\"\1\":\"\2\"}}/" > package-delta.json && \
${JQ_CMD} -s '.[0] * .[1]' package.json package-delta.json > package-new.json && \
${MV} package-new.json package.json && \
${RM} package-delta.json; \
done && \
([ -f "${SHRINKWRAP_FILE}" ] || \
${ECHO} "Warning: no shrinkwrap file, you need to run 'make makeshrinkwrap' >&2") && \
([ ! -f "${SHRINKWRAP_FILE}" ] || \
${CP} ${SHRINKWRAP_FILE} npm-shrinkwrap.json) && \
${ECHO_MSG} "=> Downloading the project dependencies" && \
${NPM_ENV} ${NPM_CMD} install ${NPM_FETCH_ARGS} && \
cd ${_DISTDIR} && \
${FIND} ${_NODE_DIR} -and -exec ${TOUCH} -h -d 1970-01-01T00:00:00Z {} + && \
${FIND} ${_NODE_DIR} -print0 | sort -z | \
${TAR} czf ${_NODE_DIST_FILE} --options gzip:!timestamp --no-recursion --null -T - && \
${RM} -rf ${_NODE_DIR}; then \
return 0; \
fi; \
done; \
${ECHO_MSG} "=> Fetch failed for ${PORTNAME}"; \
exit 1; \
fi;
do-build:
@cd ${WRKSRC} && \
cd ${_NODE_DO_CD} && \
${NPM_ENV} ${NPM_CMD} rebuild ${NPM_BUILD_ARGS}
do-install:
@${ECHO} "=> Staging ${PKGNAME}"
@${MKDIR} ${STAGEDIR}${NODE_INSTALL_BASE}
@${CP} -r ${WRKSRC} ${STAGEDIR}${NODE_INSTALL_DIR}
@${RM} `${FIND} ${STAGEDIR}${NODE_INSTALL_DIR} -name Makefile`
@${RM} `${FIND} ${STAGEDIR}${NODE_INSTALL_DIR} -name "*.bat"`
@${RM} `${FIND} ${STAGEDIR}${NODE_INSTALL_DIR} -name "*.log"`
@${RM} `${FIND} ${STAGEDIR}${NODE_INSTALL_DIR} -name "*.orig"`
@${RM} `${FIND} ${STAGEDIR}${NODE_INSTALL_DIR} -name "*.bak"`
@${RM} `${FIND} ${STAGEDIR}${NODE_INSTALL_DIR} -name ".git*"`
@${RM} `${FIND} ${STAGEDIR}${NODE_INSTALL_DIR} -name npm-shrinkwrap.json`
@${STRIP_CMD} `${FIND} ${STAGEDIR}${NODE_INSTALL_DIR} -name "*.o"`
@${STRIP_CMD} `${FIND} ${STAGEDIR}${NODE_INSTALL_DIR} -name "*.node"`
.endif

Event Timeline

yuri_rawbw.com changed the title of this paste from untitled to Mk/Uses/node.mk Framework for NodeJS projects/ports.Nov 17 2015, 7:30 AM
yuri_rawbw.com edited the content of this paste. (Show Details)