Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

strongloop / node-foreman / 218

2 May 2016 - 1:32 coverage: 88.78%. First build
218

Pull #116

travis-ci

8bd1dd86bbf8705a5a702b86a2f3a390?size=18&default=identiconrmg
disable coverage on appveyor builds
Pull Request #116: update to support node v6

4 of 5 new or added lines in 1 file covered. (80.0%)

546 of 615 relevant lines covered (88.78%)

93.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.18
/lib/exporters.js
1
var colors  = require('./colors');
70×
2
var ppath   = require('path');
70×
3
var mu      = require('mustache');
70×
4
var fs      = require('fs');
70×
5

6
var display = require('./console').Console;
70×
7

8
// Procfile to System Service Export //
9

10
function render(filename, conf, callback) {
70×
11
  fs.readFile(filename, {encoding: 'utf8'}, function(err, template) {
215×
12
    if (err) {
215×
NEW
13
      throw err;
!
14
    }
15
    callback(mu.render(template, conf));
215×
16
  });
17
}
18

19
function templatePath(conf, type, file) {
70×
20
  if(conf.template) {
215×
21
    return ppath.resolve(conf.template, file);
70×
22
  } else {
23
    return ppath.resolve(__dirname, type, file);
145×
24
  }
25
}
26

27
function writeout(path) {
70×
28
  return function(data) {
215×
29
    if (fs.existsSync(path)) {
215×
30
      display.Warn(colors.bright_yellow('Replacing: %s'), path);
!
31
    }
32

33
    fs.writeFileSync(path,data);
215×
34
    display.Alert('Wrote  :',ppath.normalize(path));
215×
35
  };
36
}
37

38
function upstart(conf, outdir) {
70×
39
  var path = outdir + "/" + conf.application + ".conf";
15×
40
  render(templatePath(conf, 'upstart', 'foreman.conf'), conf, writeout(path));
15×
41
}
42

43
function upstart_app(conf, outdir) {
70×
44
  var path = outdir + "/" + conf.application + "-" + conf.process + ".conf";
45×
45
  render(templatePath(conf, 'upstart', 'foreman-APP.conf'), conf, writeout(path));
45×
46
}
47

48
function upstart_app_n(conf, outdir) {
70×
49
  var path = outdir + "/" + conf.application + "-" + conf.process + "-" + conf.number + ".conf";
45×
50
  render(templatePath(conf, 'upstart','foreman-APP-N.conf'), conf, writeout(path));
45×
51
}
52

53
function upstart_single(conf, outdir) {
70×
54
  var path = outdir + "/" + conf.application + ".conf";
15×
55
  render(templatePath(conf, 'upstart-single', 'foreman.conf'), conf, writeout(path));
15×
56
  display.Warn('upstart-single jobs attempt to raise limits and will fail ' +
15×
57
               'to  start if the limits cannot be raised to the desired ' +
58
               'levels.  Some manual editing may be required.');
59
}
60

61
function upstart_single_app(conf, outdir) {
70×
62
  var path = outdir + "/" + conf.application + "-" + conf.process + ".conf";
25×
63
  render(templatePath(conf, 'upstart-single', 'foreman-APP.conf'), conf, writeout(path));
25×
64
}
65

66
function systemd(conf, outdir){
70×
67
  var path = outdir + "/" + conf.application + ".target";
5×
68
  render(templatePath(conf, 'systemd', 'foreman.target'), conf, writeout(path));
5×
69
}
70

71
function systemd_app(conf, outdir) {
70×
72
  var path = outdir + "/" + conf.application + "-" + conf.process + ".target";
15×
73
  render(templatePath(conf, 'systemd', 'foreman-APP.target'), conf, writeout(path));
15×
74
}
75

76
function systemd_app_n(conf, outdir) {
70×
77
  var path = outdir + "/" + conf.application + "-" + conf.process + "-" + conf.number + ".service";
15×
78
  render(templatePath(conf, 'systemd', 'foreman-APP-N.service'), conf, writeout(path));
15×
79
}
80

81
function supervisord(conf, outdir) {
70×
82
  var path = outdir + "/" + conf.application + ".conf";
5×
83
  var programs = [];
5×
84

85
  // Supervisord requires comma separated lists and they are
86
  // quite ugly to handle in Moustache.
87
  for(var i = 0; i < conf.processes.length; i++) {
5×
88
    var process = conf.processes[i].process;
15×
89
    var n = conf.processes[i].n;
15×
90

91
    for(var j = 1; j <= n; j++) {
15×
92
      programs.push(conf.application + "-" + process + "-" + j);
15×
93
    }
94
  }
95

96
  conf.programs = programs.join(',');
5×
97

98
  render(templatePath(conf, 'supervisord', 'foreman.conf'), conf, writeout(path));
5×
99
}
100

101
function supervisord_app_n(conf, outdir) {
70×
102
  var path = outdir + "/" + conf.application + "-" + conf.process + "-" + conf.number + ".conf";
15×
103
  var envs = [];
15×
104

105
  // We have to do the same thing for env variables.
106
  for(var i in conf.envs) {
15×
107
    var key = conf.envs[i].key;
120×
108
    var value = conf.envs[i].value;
120×
109

110
    // Some variables like 'web.1' breaks supervisor confg so we
111
    // escape quotes and wrap values in quotes.
112
    if(typeof value === 'string') {
120×
113
      value = value.replace(/"/, '\\"');
105×
114
    }
115

116
    envs.push(key + "=" + '"' + value  + '"');
120×
117
  }
118

119
  conf.envs = envs.join(',');
15×
120

121
  render(templatePath(conf, 'supervisord', 'foreman-APP-N.conf'), conf, writeout(path));
15×
122
}
123

124
function smf_app(conf, outdir) {
70×
125
  var path = outdir + "/" + conf.application + "-" + conf.process + ".xml";
15×
126
  render(templatePath(conf, 'smf', 'foreman-APP.xml'), conf, writeout(path));
15×
127
}
128

129
var export_formats = {
70×
130
  "upstart": {
131
    foreman       : upstart,
132
    foreman_app   : upstart_app,
133
    foreman_app_n : upstart_app_n,
134
  },
135
  "upstart-single": {
136
    foreman       : upstart_single,
137
    foreman_app   : upstart_single_app,
138
    foreman_app_n : function noop() {},
139
  },
140
  "systemd": {
141
    foreman       : systemd,
142
    foreman_app   : systemd_app,
143
    foreman_app_n : systemd_app_n,
144
  },
145
  "supervisord": {
146
    foreman       : supervisord,
147
    foreman_app   : function noop() {},
148
    foreman_app_n : supervisord_app_n,
149
  },
150
  "smf": {
151
    foreman       : function noop() {},
152
    foreman_app   : smf_app,
153
    foreman_app_n : function noop() {},
154
  }
155
};
156

157
module.exports = export_formats;
70×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc