MCPcopy Index your code
hub / github.com/Unitech/pm2 / parseAndSwitch

Function parseAndSwitch

lib/API/Containerizer.js:60–87  ·  view source on GitHub ↗

* Switch Dockerfile mode * check test/programmatic/containerizer.mocha.js

(file_content, main_file, opts)

Source from the content-addressed store, hash-verified

58 * check test/programmatic/containerizer.mocha.js
59 */
60function parseAndSwitch(file_content, main_file, opts) {
61 var lines = file_content.split('\n');
62 var mode = opts.mode;
63
64 lines[0] = 'FROM keymetrics/pm2:' + opts.node_version;
65
66 for (var i = 0; i < lines.length; i++) {
67 var line = lines[i];
68
69 if (['## DISTRIBUTION MODE', '## DEVELOPMENT MODE'].indexOf(line) > -1 ||
70 i == lines.length - 1) {
71 lines.splice(i, lines.length);
72 lines[i] = '## ' + mode.toUpperCase() + ' MODE';
73 lines[i + 1] = 'ENV NODE_ENV=' + (mode == 'distribution' ? 'production' : mode);
74
75 if (mode == 'distribution') {
76 lines[i + 2] = 'COPY . /var/app';
77 lines[i + 3] = 'CMD ["pm2-docker", "' + main_file + '", "--env", "production"]';
78 }
79 if (mode == 'development') {
80 lines[i + 2] = 'CMD ["pm2-dev", "' + main_file + '", "--env", "development"]';
81 }
82 break;
83 }
84 };
85 lines = lines.join('\n');
86 return lines;
87};
88
89/**
90 * Replace ENV, COPY and CMD depending on the mode

Callers 2

switchDockerFileFunction · 0.85
generateDockerfileFunction · 0.85

Calls 1

indexOfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…