{"size": 927, "ext": "js", "max_stars_repo_path": "doc/snipsonian-doc-site/bin/generateDoc/readFunctionSignature.js", "max_stars_repo_name": "dbeerten/snipsonian", "max_stars_repo_stars_event_min_datetime": "2019-08-19T19:12:02.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-19T19:12:02.000Z", "max_issues_repo_path": "doc/snipsonian-doc-site/bin/generateDoc/readFunctionSignature.js", "max_issues_repo_name": "dbeerten/snipsonian", "max_issues_repo_issues_event_min_datetime": "2019-11-14T09:52:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-24T13:51:38.000Z", "max_forks_repo_path": "doc/snipsonian-doc-site/bin/generateDoc/readFunctionSignature.js", "max_forks_repo_name": "dbeerten/snipsonian", "max_forks_repo_forks_event_min_datetime": "2019-04-01T12:48:57.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-22T09:33:43.000Z"}
{"max_stars_count": 1, "max_issues_count": 46, "max_forks_count": 4, "avg_line_length": 46.35, "max_line_length": 126, "alphanum_fraction": 0.5749730313}
const chalk = require('chalk');
const fs = require('fs');

const readFile = require('../../src/node/readFile');

module.exports = function readFunctionSignature(snippet) {
    console.log(chalk.bold('Reading the snippet file to get the signature...'));
    const updatedSnippet = snippet;
    return new Promise((resolve) => {
        readFile({filePath: updatedSnippet.path, options: 'utf8', fs})
            .then((content) => {
                if (content.includes(`function ${updatedSnippet.name}`)) {
                    updatedSnippet.signature = content.match(new RegExp(`function ${updatedSnippet.name}((.*)) {`))[1] || '';
                } else if (content.includes(`const ${updatedSnippet.name} = (`)) {
                    updatedSnippet.signature = content.match(new RegExp(`const ${updatedSnippet.name} = ((.*)) =>`))[1] || '';
                }
                resolve(updatedSnippet);
            });
    });
};