55 * @param {* } path - the path to the *.config.js file, contains the user, domain, etc.
66 */
77
8+ const { version } = require ( 'os' ) ;
9+
810module . exports = function ( path ) {
911 // Get the app name, user, domain, other details given the file path
1012 const fs = require ( 'fs' ) ;
@@ -13,7 +15,7 @@ module.exports = function(path) {
1315 details . _config = parse . pop ( ) ;
1416 details . _app = details . _config . replace ( '.config.js' , '' ) ;
1517 details . _domain = parse [ 4 ] ;
16- details . name = details . _app + '- ' + details . _domain ;
18+ details . name = details . _app + ' | ' + details . _domain ;
1719 details . _user = parse [ 2 ] ;
1820 details . cwd = path . substr ( 0 , path . length - details . _config . length - 1 ) ;
1921 details . script = details . cwd + '/' + details . _app + '.js' ;
@@ -36,6 +38,15 @@ module.exports = function(path) {
3638 }
3739 details . interpreter = ver ;
3840
41+ // Get the interpreter version from path
42+ let versionMatch = ver . match ( / v \d + \. \d + \. \d + / ) ; // Regular expression to match 'v' followed by version numbers
43+ if ( versionMatch ) {
44+ let version = versionMatch [ 0 ] ; // Extract the matched version
45+ details . version = version ;
46+ } else {
47+ console . error ( 'Version not found in the path' ) ;
48+ }
49+
3950 // Pass the allocated port number as a -p argument
4051 let port = 0 ;
4152 let pfile = '/usr/local/hestia/data/hcpp/ports/' + details . _user + '/' + details . _domain + '.ports' ;
@@ -56,5 +67,34 @@ module.exports = function(path) {
5667 details . _debugPort = port + 3000 ;
5768 details . interpreter_args = '--inspect=' + details . _debugPort ;
5869 }
70+
71+
72+ details . linkGlobalModules = function ( modules ) {
73+
74+ // Ensure node_modules directory exists
75+ const fs = require ( 'fs' ) ;
76+ if ( ! fs . existsSync ( 'node_modules' ) ) {
77+ fs . mkdirSync ( 'node_modules' ) ;
78+ }
79+
80+ // Setup nvm, use npm version specified in .nvmrc
81+ let cmd = "bash -c 'export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh && nvm use " + this . version + " && " ;
82+ cmd += "cd " + this . cwd + " && " ;
83+
84+ // Link global modules to local node_modules
85+ for ( let i = 0 ; i < modules . length ; i ++ ) {
86+ cmd += "unlink node_modules/" + modules [ i ] + " > /dev/null 2>&1 ; npm link " + modules [ i ] + " > /dev/null 2>&1 ; " ;
87+ }
88+ cmd += "'" ;
89+ console . log ( cmd ) ;
90+
91+ // Update npm links
92+ try {
93+ const { execSync} = require ( 'child_process' ) ;
94+ execSync ( cmd ) ;
95+ } catch ( error ) {
96+ // Eat npm link permissions errors
97+ }
98+ }
5999 return details ;
60100}
0 commit comments