MCPcopy
hub / github.com/Unitech/pm2 / runInstall

Function runInstall

lib/API/Modules/TAR.js:113–165  ·  view source on GitHub ↗
(PM2, target_path, module_name, opts, cb)

Source from the content-addressed store, hash-verified

111}
112
113function runInstall(PM2, target_path, module_name, opts, cb) {
114 var config_file = path.join(target_path, 'package.json')
115 var conf
116
117 try {
118 conf = require(config_file)
119 module_name = conf.name
120 } catch(e) {
121 Common.errMod(new Error('Cannot find package.json file with name attribute at least'));
122 }
123
124 // Force with the name in the package.json
125 opts.started_as_module = true
126 opts.cwd = target_path
127
128 if (needPrefix(conf))
129 opts.name_prefix = module_name
130
131 if (opts.install) {
132 Common.logMod(`Running YARN install...`)
133
134 sexec(`cd ${target_path} ; yarn install`, {silent: false}, function(code) {
135 // Start apps under "apps" or "pm2" attribute
136 Common.logMod(`Starting ${target_path}`)
137 PM2.start(conf, opts, function(err, data) {
138 if (err) return cb(err)
139
140 Configuration.setSync(`${cst.MODULE_CONF_PREFIX_TAR}:${module_name}`, {
141 source: 'tarball',
142 install_url: opts.install_url,
143 installed_at: Date.now()
144 })
145
146 Common.logMod(`Module INSTALLED and STARTED`)
147 return cb(null, 'Module installed & Started')
148 })
149 })
150 }
151 else {
152 PM2.start(conf, opts, function(err, data) {
153 if (err) return cb(err)
154
155 Configuration.setSync(`${cst.MODULE_CONF_PREFIX_TAR}:${module_name}`, {
156 source: 'tarball',
157 install_url: opts.install_url,
158 installed_at: Date.now()
159 })
160
161 Common.logMod(`Module INSTALLED and STARTED`)
162 return cb(null, 'Module installed & Started')
163 })
164 }
165}
166
167function start(PM2, module_name, cb) {
168 var module_path = path.join(cst.DEFAULT_MODULE_PATH, module_name);

Callers 1

installLocalFunction · 0.85

Calls 3

needPrefixFunction · 0.85
cbFunction · 0.85
startMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…