瀏覽代碼

Create a global directory for node modules installed with npm

Bob Mottram 7 年之前
父節點
當前提交
88b9907f6f
共有 1 個檔案被更改,包括 17 行新增0 行删除
  1. 17
    0
      src/freedombone-utils-nodejs

+ 17
- 0
src/freedombone-utils-nodejs 查看文件

173
     fi
173
     fi
174
     rm "$rootdir/usr/bin/test_nodejs_install"
174
     rm "$rootdir/usr/bin/test_nodejs_install"
175
     NODE_UPGRADE=
175
     NODE_UPGRADE=
176
+
177
+    nodejs_setup_global_modules
176
 }
178
 }
177
 
179
 
178
 function nodejs_upgrade {
180
 function nodejs_upgrade {
201
     npm update -g
203
     npm update -g
202
 }
204
 }
203
 
205
 
206
+function nodejs_setup_global_modules {
207
+    if [ ! -d /root/.npm-global ]; then
208
+        mkdir /root/.npm-global
209
+    fi
210
+    npm config set prefix '/root/.npm-global'
211
+    export PATH=/root/.npm-global/bin:$PATH
212
+    if ! grep -q "PATH=/root/.npm-global/bin" /root/.bashrc; then
213
+        echo "PATH=/root/.npm-global/bin:\$PATH" >> /root/.bashrc
214
+    fi
215
+    if ! grep -q "NPM_CONFIG_PREFIX=" /root/.bashrc; then
216
+        echo "export NPM_CONFIG_PREFIX=/root/.npm-global" >> /root/.bashrc
217
+    fi
218
+    export NPM_CONFIG_PREFIX=/root/.npm-global
219
+}
220
+
204
 function remove_nodejs {
221
 function remove_nodejs {
205
     if [ ! "$1" ]; then
222
     if [ ! "$1" ]; then
206
         return
223
         return