-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathserviceProperties.js
More file actions
40 lines (35 loc) · 973 Bytes
/
serviceProperties.js
File metadata and controls
40 lines (35 loc) · 973 Bytes
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
38
39
40
'use strict';
const truncate = require('./truncate');
function convertToKeyValueFromSpec(spec, prop) {
if (spec && prop in spec) {
return Object.keys(spec[prop]).map((key) => {
return { key, value: spec[prop][key] };
});
}
}
const serviceDefaults = {
ExecStart: '/usr/bin/npm start',
Restart: 'always',
StandardOutput: 'syslog',
StandardError: 'syslog'
};
function createServiceDefaults(spec = {}) {
const combinedConfig = Object.assign(
{},
serviceDefaults,
spec.serviceOptions
);
return convertToKeyValueFromSpec({ combinedConfig }, 'combinedConfig');
}
module.exports = function (pkg) {
return Object.assign(
{
name: pkg.name,
username: truncate(pkg.name),
description: pkg.description,
environment: convertToKeyValueFromSpec(pkg.spec, 'environment'),
serviceOptions: createServiceDefaults(pkg.spec),
unitOptions: convertToKeyValueFromSpec(pkg.spec, 'unitOptions')
}
);
};