1 | 'use strict';
|
2 |
|
3 | const path = require('path');
|
4 |
|
5 | const RE_ILLEGAL_ID = /[\- .*]/g;
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | module.exports = function env(key, value, id) {
|
14 | id = id != null ? id.replace(RE_ILLEGAL_ID, '').toUpperCase() + '_' : '';
|
15 | if (!Array.isArray(value)) value = [value];
|
16 |
|
17 | value = value.reduce(
|
18 | (value, item) => {
|
19 | const isFile = 'object' == typeof item && 'extension' in item;
|
20 |
|
21 | switch (key) {
|
22 | case 'INPUT':
|
23 | value += isFile ? path.relative(process.cwd(), item.filepath) : item;
|
24 | break;
|
25 | case 'INPUT_HASH':
|
26 | value += isFile ? item.hash : item;
|
27 | break;
|
28 | case 'INPUT_DATE':
|
29 | value += isFile ? item.date : item;
|
30 | break;
|
31 | case 'OUTPUT':
|
32 | value += isFile ? path.relative(process.cwd(), item.writepath) : item;
|
33 | break;
|
34 | case 'OUTPUT_HASH':
|
35 | value += isFile ? item.writeHash : item;
|
36 | break;
|
37 | case 'OUTPUT_DATE':
|
38 | value += isFile ? item.writeDate : item;
|
39 | break;
|
40 | case 'OUTPUT_URL':
|
41 | value += isFile ? item.writeUrl : item;
|
42 | break;
|
43 | }
|
44 |
|
45 | return value;
|
46 | },
|
47 | ''
|
48 | );
|
49 |
|
50 | process.env[`BUDDY_${id}${key}`] = value;
|
51 | };
|