Description:Insatll npm modules into target except npm 75/55275/1
authorwchang kim <wchang.kim@samsung.com>
Tue, 22 Dec 2015 22:52:20 +0000 (07:52 +0900)
committerwchang kim <wchang.kim@samsung.com>
Tue, 22 Dec 2015 22:53:35 +0000 (07:53 +0900)
Adding the npm.class and modifying the recipe of nodejs to install npm modules.
Adding the scripts to instert the NODE_PATH to /etc/porfile.
Signed-off-by: wchang kim <wchang.kim@samsung.com>
Change-Id: I67300339bd3550563ec27503b68a63eedfeeae6e

meta-tizen-micro/classes/npm.bbclass [new file with mode: 0755]
meta-tizen-micro/recipes-devtools/nodejs/nodejs/nodejs.service [new file with mode: 0755]
meta-tizen-micro/recipes-devtools/nodejs/nodejs/nodejs.sh [new file with mode: 0755]
meta-tizen-micro/recipes-devtools/nodejs/nodejs_0.12.7.bb [changed mode: 0644->0755]

diff --git a/meta-tizen-micro/classes/npm.bbclass b/meta-tizen-micro/classes/npm.bbclass
new file mode 100755 (executable)
index 0000000..45e78a5
--- /dev/null
@@ -0,0 +1,63 @@
+#DEPENDS += " node-native"
+
+#RDEPENDS_${PN} += " node"
+
+PACKAGE_DEBUG_SPLIT_STYLE = "debug-file-directory"
+
+CCACHE = ""
+
+NPM ?= "npm"
+NPM_CACHE_DIR = "${WORKDIR}/npm_cache"
+NPM_ARCH ?= "${TARGET_ARCH}"
+NPM_LD ?= "${CXX}"
+NPM_FLAGS ?= ""
+
+# Target npm
+
+oe_runnpm() {
+
+       export NPM_CONFIG_CACHE="${NPM_CACHE_DIR}"
+
+       [ -n "${http_proxy}" ] && export NPM_CONFIG_PROXY="${http_proxy}"
+       [ -n "${https_proxy}" ] && export NPM_CONFIG_HTTPS_PROXY="${https_proxy}"
+       [ -n "${HTTP_PROXY}" ] && export NPM_CONFIG_PROXY="${HTTP_PROXY}"
+       [ -n "${HTTPS_PROXY}" ] && export NPM_CONFIG_HTTPS_PROXY="${HTTPS_PROXY}"
+
+       bbnote NPM target architecture: ${NPM_ARCH}
+       bbnote NPM cache directory: ${NPM_CONFIG_CACHE}
+       bbnote NPM HTTP proxy: ${NPM_CONFIG_PROXY}
+       bbnote NPM HTTPS proxy: ${NPM_CONFIG_HTTPS_PROXY}
+
+       bbnote ${NPM} --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} ${NPM_FLAGS} "$@"
+
+       LD="${NPM_LD}" ${NPM} --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} ${NPM_FLAGS} "$@" || die "oe_runnpm failed"
+
+}
+
+# Native npm
+
+NPM_NATIVE ?= "npm"
+NPM_CACHE_DIR_NATIVE = "${WORKDIR}/npm_cache"
+NPM_ARCH_NATIVE ?= "${BUILD_ARCH}"
+NPM_LD_NATIVE ?= "${BUILD_CXX}"
+NPM_FLAGS_NATIVE ?= ""
+
+oe_runnpm_native() {
+
+       export NPM_CONFIG_CACHE="${NPM_CACHE_DIR_NATIVE}"
+
+       [ -n "${http_proxy}" ] && export NPM_CONFIG_PROXY="${http_proxy}"
+       [ -n "${https_proxy}" ] && export NPM_CONFIG_HTTPS_PROXY="${https_proxy}"
+       [ -n "${HTTP_PROXY}" ] && export NPM_CONFIG_PROXY="${HTTP_PROXY}"
+       [ -n "${HTTPS_PROXY}" ] && export NPM_CONFIG_HTTPS_PROXY="${HTTPS_PROXY}"
+
+       bbnote NPM native architecture: ${NPM_ARCH_NATIVE}
+       bbnote NPM cache directory: ${NPM_CONFIG_CACHE}
+       bbnote NPM HTTP proxy: ${NPM_CONFIG_PROXY}
+       bbnote NPM HTTPS proxy: ${NPM_CONFIG_HTTPS_PROXY}
+
+       bbnote ${NPM_NATIVE} --arch=${NPM_ARCH_NATIVE} --target_arch=${NPM_ARCH_NATIVE} ${NPM_FLAGS_NATIVE} "$@"
+
+       LD="${NPM_LD_NATIVE}" ${NPM_NATIVE} --arch=${NPM_ARCH_NATIVE} --target_arch=${NPM_ARCH_NATIVE} ${NPM_FLAGS_NATIVE} "$@" || die "oe_runnpm_native failed"
+
+}
diff --git a/meta-tizen-micro/recipes-devtools/nodejs/nodejs/nodejs.service b/meta-tizen-micro/recipes-devtools/nodejs/nodejs/nodejs.service
new file mode 100755 (executable)
index 0000000..2b8d667
--- /dev/null
@@ -0,0 +1,9 @@
+[Unit]
+Description=nodejs service 
+
+[Service]
+
+ExecStart=/etc/init.d/nodejs.sh
+
+[Install]
+WantedBy=multi-user.target
\ No newline at end of file
diff --git a/meta-tizen-micro/recipes-devtools/nodejs/nodejs/nodejs.sh b/meta-tizen-micro/recipes-devtools/nodejs/nodejs/nodejs.sh
new file mode 100755 (executable)
index 0000000..49d3629
--- /dev/null
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+if [ ! -d "/opt/vc/bin" ]; then
+echo "export NODE_PATH=/usr/lib/node_modules/" >>/etc/profile
+fi
+
+mkdir -p /opt/vc/bin
+ln -sf  /usr/bin/raspistill /opt/vc/bin/
+ln -sf  /usr/bin/raspivid /opt/vc/bin/
old mode 100644 (file)
new mode 100755 (executable)
index 41eb5ee..10b134c
@@ -8,12 +8,18 @@ DEPENDS = "openssl"
 SRC_URI = "http://nodejs.org/dist/v${PV}/node-v${PV}.tar.gz \
     file://enable-armv5e-build.patch \
     file://no-registry.patch \
+    file://nodejs.sh \
+    file://nodejs.service \
 "
 SRC_URI[md5sum] = "5523ec4347d7fe6b0f6dda1d1c7799d5"
 SRC_URI[sha256sum] = "b23d64df051c9c969b0c583f802d5d71de342e53067127a5061415be7e12f39d"
 
 S = "${WORKDIR}/node-v${PV}"
 
+inherit npm
+NPM_INSTALL ?= "mqtt onoff request"
+NPM_INSTALL_FLAGS ?= ""
+
 # v8 errors out if you have set CCACHE
 CCACHE = ""
 
@@ -48,6 +54,32 @@ do_compile () {
 
 do_install () {
     oe_runmake install DESTDIR=${D}
+
+    cd ${D}/usr/lib
+    oe_runnpm config set registry=http://registry.npmjs.org/ 
+    oe_runnpm ${NPM_INSTALL_FLAGS} install ${NPM_INSTALL}
+
+    for i in ${NPM_INSTALL}; 
+    do 
+        rm -rf  ${D}/usr/lib/node_modules/$i/doc 
+        rm -rf  ${D}/usr/lib/node_modules/$i/example* 
+       rm -rf  ${D}/usr/lib/node_modules/$i/test        
+    done
+
+    install -d ${D}${sysconfdir}/init.d
+    install -m 0755 ${WORKDIR}/nodejs.sh ${D}${sysconfdir}/init.d    
+    update-rc.d -r ${D} nodejs.sh start 92 5 .    
+    
+    if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)};then
+        install -d ${D}${systemd_unitdir}/system
+        install -m 0644 ${WORKDIR}/nodejs.service ${D}${systemd_unitdir}/system/
+
+        install -d ${D}${systemd_unitdir}/system/multi-user.target.wants
+        cd ${D}${systemd_unitdir}/system/multi-user.target.wants/
+        ln -sf ../nodejs.service ${D}${systemd_unitdir}/system/multi-user.target.wants/nodejs.service
+    fi
+
+    rm -rf ${D}/usr/lib/node_modules/npm
 }
 
 do_install_append_class-native() {
@@ -62,19 +94,23 @@ do_install_append_class-native() {
     # /usr/bin/npm is symlink to /usr/lib/node_modules/npm/bin/npm-cli.js
     # use sed on npm-cli.js because otherwise symlink is replaced with normal file and
     # npm-cli.js continues to use old shebang
-    sed "1s^.*^#\!/usr/bin/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
+#    sed "1s^.*^#\!/usr/bin/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
 }
 
 do_install_append_class-target() {
-    sed "1s^.*^#\!${bindir}/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
+#    sed "1s^.*^#\!${bindir}/env node^g" -i ${D}${exec_prefix}/lib/node_modules/npm/bin/npm-cli.js
 }
 
 PACKAGES =+ "${PN}-npm"
-FILES_${PN}-npm = "${exec_prefix}/lib/node_modules ${bindir}/npm"
+FILES_${PN}-npm = "${bindir}/npm"
 RDEPENDS_${PN}-npm = "bash python-shell python-datetime python-subprocess python-textutils"
 
 PACKAGES =+ "${PN}-systemtap"
 FILES_${PN}-systemtap = "${datadir}/systemtap"
 
+FILES_${PN} += "${systemd_unitdir}/system/nodejs.service \
+                ${systemd_unitdir}/system/multi-user.target.wants/nodejs.service \
+               ${exec_prefix}/lib/node_modules \
+                "
 
 BBCLASSEXTEND = "native"