|
1 | | -const fs = require('fs'); |
2 | | -const readline = require('readline'); |
| 1 | +const fs = require("fs"); |
| 2 | +const readline = require("readline"); |
3 | 3 |
|
4 | 4 | const readInterface = readline.createInterface({ |
5 | | - input: fs.createReadStream(process.argv[2]), |
6 | | - output: process.stdout, |
7 | | - terminal: false |
| 5 | + input: fs.createReadStream(process.argv[2]), |
| 6 | + output: process.stdout, |
| 7 | + terminal: false, |
8 | 8 | }); |
9 | 9 |
|
10 | | -const stripQuotes = (str) => str.startsWith('"') || str.startsWith("'") ? str.slice(1, -1) : str; |
| 10 | +const stripQuotes = (str) => |
| 11 | + str.startsWith('"') || str.startsWith("'") ? str.slice(1, -1) : str; |
11 | 12 |
|
12 | 13 | const replaceEnvVars = (str) => { |
13 | | - const value = str |
14 | | - .replaceAll(/\$\{([a-zA-Z0-9_]+):\+:\$[a-zA-Z0-9_]+\}/g, (_, key) => (v => v ? `:${v}` : '')(process.env[key])) |
15 | | - .replaceAll(/\$\{([a-zA-Z0-9_]+)\}/g, (_, key) => process.env[key] ?? '') |
16 | | - .replaceAll(/\$([a-zA-Z0-9_]+)/g, (_, key) => process.env[key] ?? '') |
17 | | - console.error("FOO", str, value) |
18 | | - return value |
| 14 | + const value = str |
| 15 | + .replaceAll( |
| 16 | + /\$\{([a-zA-Z0-9_]+):\+:\$[a-zA-Z0-9_]+\}/g, |
| 17 | + (_, key) => ((v) => v ? `:${v}` : "")(process.env[key]), |
| 18 | + ) |
| 19 | + .replaceAll(/\$\{([a-zA-Z0-9_]+)\}/g, (_, key) => process.env[key] ?? "") |
| 20 | + .replaceAll(/\$([a-zA-Z0-9_]+)/g, (_, key) => process.env[key] ?? ""); |
| 21 | + console.error("FOO", str, value); |
| 22 | + return value; |
19 | 23 | }; |
20 | 24 |
|
21 | | -readInterface.on('line', (line) => { |
22 | | - const match = line.match(/^export ([^=]+)=(.*)$/); |
23 | | - if (match) { |
24 | | - const [_, key, value_] = match; |
25 | | - const value = stripQuotes(value_); |
26 | | - if (key === 'PATH') { |
27 | | - value |
28 | | - .replaceAll('${PATH:+:$PATH}', '') |
29 | | - .replaceAll('$PATH', '') |
30 | | - .replaceAll('${PATH}', '') |
31 | | - .split(':').forEach(path => { |
32 | | - fs.appendFileSync(process.env['GITHUB_PATH'], `${path}\n`); |
33 | | - }); |
34 | | - } else { |
35 | | - let v = replaceEnvVars(value); |
36 | | - fs.appendFileSync(process.env['GITHUB_ENV'], `${key}=${v}\n`); |
37 | | - } |
| 25 | +readInterface.on("line", (line) => { |
| 26 | + const match = line.match(/^export ([^=]+)=(.*)$/); |
| 27 | + if (match) { |
| 28 | + const [_, key, value_] = match; |
| 29 | + const value = stripQuotes(value_); |
| 30 | + if (key === "PATH") { |
| 31 | + value |
| 32 | + .replaceAll("${PATH:+:$PATH}", "") |
| 33 | + .replaceAll("$PATH", "") |
| 34 | + .replaceAll("${PATH}", "") |
| 35 | + .split(":").forEach((path) => { |
| 36 | + fs.appendFileSync(process.env["GITHUB_PATH"], `${path}\n`); |
| 37 | + }); |
| 38 | + } else { |
| 39 | + let v = replaceEnvVars(value); |
| 40 | + fs.appendFileSync(process.env["GITHUB_ENV"], `${key}=${v}\n`); |
38 | 41 | } |
| 42 | + } |
39 | 43 | }); |
0 commit comments