const FILENAME = "Employees.json";
const KEYS = [
    "LastName",
    "FirstName",
    "BirthDate",
    "Photo",
    "Notes",
]

let extractString = `tx.executeSql('INSERT INTO Employees (LastName,FirstName,BirthDate,Photo,Notes) VALUES ("Davolio","Nancy","1968-12-08","EmpID1.pic","Education includes a BA in psychology from Colorado State University. She also completed (The Art of the Cold Call). Nancy is a member of \'Toastmasters International\'.")');
                        tx.executeSql('INSERT INTO Employees (LastName,FirstName,BirthDate,Photo,Notes) VALUES ("Fuller","Andrew","1952-02-19","EmpID2.pic","Andrew received his BTS commercial and a Ph.D. in international marketing from the University of Dallas. He is fluent in French and Italian and reads German. He joined the company as a sales representative, was promoted to sales manager and was then named vice president of sales. Andrew is a member of the Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers Association.")');
                        tx.executeSql('INSERT INTO Employees (LastName,FirstName,BirthDate,Photo,Notes) VALUES ("Leverling","Janet","1963-08-30","EmpID3.pic","Janet has a BS degree in chemistry from Boston College). She has also completed a certificate program in food retailing management. Janet was hired as a sales associate and was promoted to sales representative.")');
                        tx.executeSql('INSERT INTO Employees (LastName,FirstName,BirthDate,Photo,Notes) VALUES ("Peacock","Margaret","1958-09-19","EmpID4.pic","Margaret holds a BA in English literature from Concordia College and an MA from the American Institute of Culinary Arts. She was temporarily assigned to the London office before returning to her permanent post in Seattle.")');
                        tx.executeSql('INSERT INTO Employees (LastName,FirstName,BirthDate,Photo,Notes) VALUES ("Buchanan","Steven","1955-03-04","EmpID5.pic","Steven Buchanan graduated from St. Andrews University, Scotland, with a BSC degree. Upon joining the company as a sales representative, he spent 6 months in an orientation program at the Seattle office and then returned to his permanent post in London, where he was promoted to sales manager. Mr. Buchanan has completed the courses \'Successful Telemarketing\' and \'International Sales Management\'. He is fluent in French.")');
                        tx.executeSql('INSERT INTO Employees (LastName,FirstName,BirthDate,Photo,Notes) VALUES ("Suyama","Michael","1963-07-02","EmpID6.pic","Michael is a graduate of Sussex University (MA, economics) and the University of California at Los Angeles (MBA, marketing). He has also taken the courses \'Multi-Cultural Selling\' and \'Time Management for the Sales Professional\'. He is fluent in Japanese and can read and write French, Portuguese, and Spanish.")');
                        tx.executeSql('INSERT INTO Employees (LastName,FirstName,BirthDate,Photo,Notes) VALUES ("King","Robert","1960-05-29","EmpID7.pic","Robert King served in the Peace Corps and traveled extensively before completing his degree in English at the University of Michigan and then joining the company. After completing a course entitled \'Selling in Europe\', he was transferred to the London office.")');
                        tx.executeSql('INSERT INTO Employees (LastName,FirstName,BirthDate,Photo,Notes) VALUES ("Callahan","Laura","1958-01-09","EmpID8.pic","Laura received a BA in psychology from the University of Washington. She has also completed a course in business French. She reads and writes French.")');
                        tx.executeSql('INSERT INTO Employees (LastName,FirstName,BirthDate,Photo,Notes) VALUES ("Dodsworth","Anne","1969-07-02","EmpID9.pic","Anne has a BA degree in English from St. Lawrence College. She is fluent in French and German.")');
                        tx.executeSql('INSERT INTO Employees (LastName,FirstName,BirthDate,Photo,Notes) VALUES ("West","Adam","1928-09-19","EmpID10.pic","An old chum.")');`


const fs = require("fs");
const path = require("path");

let lines = extractString.split("\n");
lines = lines.map((line) => {
    line = line.trim();
    const valueStart = line.indexOf("(", line.indexOf("VALUES"));
    const valueEnd = line.indexOf("\")", valueStart);
    line = line.slice(valueStart+1,valueEnd);
    const regex = /"(.*?)"|([^,"]+)/g;
    let values = [...line.matchAll(regex)];
    return values.map(match => match[1] !== undefined ? match[1] : match[2].trim()).map(value => isNaN(value) ? value : Number(value));
});

lines = lines.map(line => {
    const obj = {};
    for (let i = 0; i < KEYS.length; i++){
        obj[KEYS[i]] = line[i];
    }
    return obj;
})

fs.writeFile(path.resolve(__dirname, "installRows", FILENAME), JSON.stringify(lines), "utf-8", (e)=>{
    console.log("DONE");
})