mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-08-19 20:14:44 +07:00
Move tools config to tools.json
Refactor tools functions to use Records and object literals
This commit is contained in:
43
src/utils.ts
43
src/utils.ts
@ -207,10 +207,14 @@ export async function addLog(
|
||||
* Read the scripts
|
||||
*
|
||||
* @param filename
|
||||
* @param directory
|
||||
*/
|
||||
export async function readScript(filename: string): Promise<string> {
|
||||
export async function readFile(
|
||||
filename: string,
|
||||
directory: string
|
||||
): Promise<string> {
|
||||
return fs.readFileSync(
|
||||
path.join(__dirname, '../src/scripts/' + filename),
|
||||
path.join(__dirname, '../' + directory, filename),
|
||||
'utf8'
|
||||
);
|
||||
}
|
||||
@ -231,6 +235,41 @@ export async function writeScript(
|
||||
return script_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get information about a tool
|
||||
*
|
||||
* @param tool
|
||||
*/
|
||||
export async function getToolData(
|
||||
tool: string
|
||||
): Promise<Record<string, string>> {
|
||||
const tools_json: string = await readFile('tools.json', 'src/configs');
|
||||
const json_data: Record<string, Record<string, string>> =
|
||||
JSON.parse(tools_json);
|
||||
let tool_data: Record<string, string>;
|
||||
const tools: string[] = Object.keys(json_data);
|
||||
if (tools.includes(tool)) {
|
||||
tool_data = json_data[tool];
|
||||
tool_data['tool'] = tool;
|
||||
} else {
|
||||
const tool_key: string | undefined = Object.keys(json_data).find(
|
||||
(key: string) => {
|
||||
return (
|
||||
json_data[key]['alias'] == tool ||
|
||||
json_data[key]['repository'] == tool
|
||||
);
|
||||
}
|
||||
);
|
||||
if (tool_key) {
|
||||
tool_data = json_data[tool_key];
|
||||
tool_data['tool'] = tool_key;
|
||||
} else {
|
||||
tool_data = {tool: tool};
|
||||
}
|
||||
}
|
||||
return tool_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to break extension csv into an array
|
||||
*
|
||||
|
Reference in New Issue
Block a user