-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcustom-start.js
More file actions
36 lines (28 loc) · 1.17 KB
/
custom-start.js
File metadata and controls
36 lines (28 loc) · 1.17 KB
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
console.log('Please click on the Copy Preview URL at the top right corner in order to Copy the preview URL and view your changes. You can also use the preview URL in the console below.');
const spawn = require('child_process').spawn;
const startProcess = spawn('react-scripts', ['start'], { stdio: 'pipe' });
let buffer = ''
startProcess.stdout.setEncoding('utf8');
startProcess.stdout.on('data', (data) => {
const output = buffer + data.toString();
// Split the output into lines
const lines = output.split('\n');
// The last element of the array is incomplete, store it in the buffer
buffer = lines.pop();
// Remove everything from "Local:" to the end of the line
const modifiedLines = lines.map(line => {
if (line.includes('Local:')) {
return line.replace(/Local:.*$/, Preview URL: ${process.env.PREVIEW_URL})
} else if (line.includes('On Your Network:')) {
return line.replace(/On Your Network:.*$/, '');
} else {
return line;
}
});
// Log the modified lines
console.log(modifiedLines.join('\n'));
})
startProcess.on('error', (err) => {
console.error('Error starting the development server:', err.message);
process.exit(1);
});