setup-php/src/config.ts

78 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-10-08 18:12:54 +05:30
import * as utils from './utils';
2019-11-24 02:04:12 +05:30
/**
* Add script to set custom ini values for unix
*
* @param ini_values_csv
*/
export async function addINIValuesUnix(
ini_values_csv: string
): Promise<string> {
2019-12-27 06:56:49 +05:30
const ini_values: Array<string> = await utils.CSVArray(ini_values_csv);
2020-06-20 06:25:19 +05:30
let script = '';
2020-05-08 05:41:00 +05:30
await utils.asyncForEach(ini_values, async function (line: string) {
2019-11-24 02:04:12 +05:30
script +=
2020-06-20 06:25:19 +05:30
'\n' + (await utils.addLog('$tick', line, 'Added to php.ini', 'linux'));
2019-11-24 02:04:12 +05:30
});
return 'echo "' + ini_values.join('\n') + '" >> $ini_file' + script;
}
/**
* Add script to set custom ini values for windows
*
* @param ini_values_csv
*/
export async function addINIValuesWindows(
ini_values_csv: string
): Promise<string> {
2019-12-27 06:56:49 +05:30
const ini_values: Array<string> = await utils.CSVArray(ini_values_csv);
2019-11-24 02:04:12 +05:30
let script = '\n';
2020-05-08 05:41:00 +05:30
await utils.asyncForEach(ini_values, async function (line: string) {
2019-11-24 02:04:12 +05:30
script +=
(await utils.addLog('$tick', line, 'Added to php.ini', 'win32')) + '\n';
});
return (
2020-05-17 03:39:04 +05:30
'Add-Content "$php_dir\\php.ini" "' + ini_values.join('\n') + '"' + script
2019-11-24 02:04:12 +05:30
);
}
2019-10-08 18:12:54 +05:30
/**
* Function to add custom ini values
*
* @param ini_values_csv
* @param os_version
2020-03-12 07:57:40 +05:30
* @param no_step
2019-10-08 18:12:54 +05:30
*/
2019-10-17 01:41:13 +05:30
export async function addINIValues(
ini_values_csv: string,
os_version: string,
no_step = false
): Promise<string> {
2019-11-24 02:04:12 +05:30
let script = '\n';
2019-10-17 01:41:13 +05:30
switch (no_step) {
case true:
script +=
(await utils.stepLog('Add php.ini values', os_version)) +
(await utils.suppressOutput(os_version)) +
'\n';
break;
case false:
default:
script += (await utils.stepLog('Add php.ini values', os_version)) + '\n';
break;
}
2019-10-08 18:12:54 +05:30
switch (os_version) {
case 'win32':
2019-10-17 01:41:13 +05:30
return script + (await addINIValuesWindows(ini_values_csv));
2019-10-08 18:12:54 +05:30
case 'darwin':
case 'linux':
2019-10-17 01:41:13 +05:30
return script + (await addINIValuesUnix(ini_values_csv));
2019-10-08 18:12:54 +05:30
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
2019-10-17 01:41:13 +05:30
'error'
2019-10-08 18:12:54 +05:30
);
}
}