go-dev 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "go-dev",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "main": "src/index.js",
5
5
  "bin": {
6
6
  "go-dev": "bin/go-dev"
@@ -0,0 +1,20 @@
1
+ function detectLatestColor(text, latestColor) {
2
+ const colorRegex = /\x1b\[[0-9;]*m/g;
3
+ const matches = text.match(colorRegex);
4
+
5
+ if (matches == null || matches.length <= 0) {
6
+ return latestColor;
7
+ }
8
+
9
+ for (const match of matches) {
10
+ if (match === '\x1b[0m' || match === '\x1b[m') {
11
+ latestColor = '';
12
+ } else if (!latestColor.includes(match)) {
13
+ latestColor += match;
14
+ }
15
+ }
16
+
17
+ return latestColor;
18
+ }
19
+
20
+ module.exports = detectLatestColor;
@@ -0,0 +1,20 @@
1
+ const detectLatestColor = require("./detect-last-color");
2
+
3
+ function prefixLines(text, prefix, latestColor) {
4
+ let prefixedText = text.split('\n').map(line => {
5
+ latestColor = detectLatestColor(line, latestColor);
6
+ return `${prefix} ${latestColor}${line}${latestColor !== '' ? '\x1b[0m' : ''}`;
7
+ }).join('\n');
8
+
9
+ if (prefixedText.endsWith(`${prefix} `)) {
10
+ prefixedText = prefixedText.slice(0, -(`${prefix} `).length);
11
+ }
12
+ if (!prefixedText.endsWith('\n')) {
13
+ prefixedText = prefixedText + '\n';
14
+ }
15
+ prefixedText = prefixedText.replace(/\x1b\[(?:2J|3J|H)|\x1bc|\x1b\[2K|\x1b\[K/gi, '');
16
+
17
+ return { prefixedText, latestColor };
18
+ }
19
+
20
+ module.exports = prefixLines;
@@ -1,6 +1,5 @@
1
1
  const { spawn, spawnSync } = require('child_process');
2
- const { appendFileSync } = require('fs');
3
-
2
+ const prefixLines = require("./prefix-lines");
4
3
 
5
4
  class ProcessManager {
6
5
  constructor() {
@@ -120,27 +119,16 @@ class ProcessManager {
120
119
  });
121
120
  processReference.process = startedProcess;
122
121
 
122
+ let latestColor = '';
123
123
  startedProcess.stdout.on('data', (data) => {
124
- let prefixedData = data.toString().split('\n').map(line => `${prefix} ${line}`).join('\n');
125
- if (prefixedData.endsWith(`${prefix} `)) {
126
- prefixedData = prefixedData.slice(0, -(`${prefix} `).length);
127
- }
128
- if (!prefixedData.endsWith('\n')) {
129
- prefixedData = prefixedData + '\n';
130
- }
131
- prefixedData = prefixedData.replace(/\x1b\[(?:2J|3J|H)/gi, '');
132
- process.stdout.write(prefixedData);
124
+ const result = prefixLines(data.toString(), prefix, latestColor);
125
+ latestColor = result.latestColor;
126
+ process.stdout.write(result.prefixedText);
133
127
  });
134
128
  startedProcess.stderr.on('data', (data) => {
135
- let prefixedData = data.toString().split('\n').map(line => `${prefix} ${line}`).join('\n');
136
- if (prefixedData.endsWith(`${prefix} `)) {
137
- prefixedData = prefixedData.slice(0, -(`${prefix} `).length);
138
- }
139
- if (!prefixedData.endsWith('\n')) {
140
- prefixedData = prefixedData + '\n';
141
- }
142
- prefixedData = prefixedData.replace(/\x1b\[(?:2J|H)/gi, '');
143
- process.stderr.write(prefixedData);
129
+ const result = prefixLines(data.toString(), prefix, latestColor);
130
+ latestColor = result.latestColor;
131
+ process.stderr.write(result.prefixedText);
144
132
  });
145
133
 
146
134
  this.managedProcesses.add(startedProcess);