setup-php/src/config.ts

80 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-10-08 19:42:54 +07:00
import * as utils from './utils';
/**
* Function to add custom ini values
*
* @param ini_values_csv
* @param os_version
*/
2019-10-17 03:11:13 +07:00
export async function addINIValues(
ini_values_csv: string,
os_version: string,
no_step = false
): Promise<string> {
let script: string = '\n';
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 19:42:54 +07:00
switch (os_version) {
case 'win32':
2019-10-17 03:11:13 +07:00
return script + (await addINIValuesWindows(ini_values_csv));
2019-10-08 19:42:54 +07:00
case 'darwin':
case 'linux':
2019-10-17 03:11:13 +07:00
return script + (await addINIValuesUnix(ini_values_csv));
2019-10-08 19:42:54 +07:00
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
2019-10-17 03:11:13 +07:00
'error'
2019-10-08 19:42:54 +07:00
);
}
}
/**
* Add script to set custom ini values for unix
*
* @param ini_values_csv
*/
export async function addINIValuesUnix(
ini_values_csv: string
): Promise<string> {
let ini_values: Array<string> = await utils.INIArray(ini_values_csv);
2019-10-17 03:11:13 +07:00
let script: string = '\n';
await utils.asyncForEach(ini_values, async function(line: string) {
script +=
(await utils.addLog('$tick', line, 'Added to php.ini', 'linux')) + '\n';
});
return 'echo "' + ini_values.join('\n') + '" >> $ini_file' + script;
2019-10-08 19:42:54 +07:00
}
/**
* Add script to set custom ini values for windows
*
* @param ini_values_csv
*/
export async function addINIValuesWindows(
ini_values_csv: string
): Promise<string> {
let ini_values: Array<string> = await utils.INIArray(ini_values_csv);
2019-10-17 03:11:13 +07:00
let script: string = '\n';
await utils.asyncForEach(ini_values, async function(line: string) {
script +=
(await utils.addLog('$tick', line, 'Added to php.ini', 'win32')) + '\n';
});
2019-10-11 06:11:25 +07:00
return (
2019-10-17 03:11:13 +07:00
'Add-Content C:\\tools\\php\\php.ini "' +
ini_values.join('\n') +
'"' +
script
2019-10-11 06:11:25 +07:00
);
2019-10-08 19:42:54 +07:00
}