-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathservice.js
37 lines (28 loc) · 944 Bytes
/
service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var os = require('os');
var path = require('path');
var platform = os.platform();
var Service;
if (platform === 'win32')
Service = require('node-windows').Service;
else if (platform === 'linux')
Service = require('node-linux').Service;
else if (platform === 'darwin')
Service = require('node-mac').Service;
else
throw new Error('Platform \'' + platform + '\' is not supported');
Service.create = function (argv) {
var package = require(path.join(process.cwd(), './package.json'));
var env = Object.keys(argv.env || {}).map(function (key) {
return { name: key, value: argv.env[key] };
});
var options = {
name: argv.name || package.name,
description: argv.description || package.description,
script: argv.script || package.main,
logmode: argv.logmode,
env: env
};
var service = new Service(options);
return service;
};
module.exports = Service;