function getVariablesFromFile(file, data) {
    const regex = /(\$[\w-]*)\s*:\s*(.*);/g;
    let match = regex.exec(data);

    while (match) {

        /* check if variable is an background icon, if so replace it directly by the SVG */
        if (match[0].indexOf('../../images/backgrounds') >= 0) {

            const iconregex = /(\$[\w-]+)\s*:\s*"\.\.\/\.\.\/images\/backgrounds\/([\w./-]+)" !default;/g;
            const iconmatch = iconregex.exec(match[0]);
            let svg = fs.readFileSync(`src/images/backgrounds/${iconmatch[2]}`).toString();
            svg = `"${svg.replace(/\r?\n|\r/g, '%0A')
                .replace(/"/g, '\'')
                .replace(/\s/g, '%20')
                .replace(/</g, '%3C')
                .replace(/=/g, '%3D')
                .replace(/'/g, '%22')
                .replace(/:/g, '%3A')
                .replace(/\//g, '%2F')
                .replace(/>/g, '%3E')
                .replace(/%3Csvg/, 'data:image/svg+xml;charset=UTF-8,%3Csvg')}"`;

            /* add SVG to the coreVar and themeVar only if it is a theme file and make it optional */
            if (file.indexOf('theme/') < 0) {
                coreVar[iconmatch[1]] = {value: `${svg} !default;`, dependencies: []};
            }

            themeVar[iconmatch[1]] = {value: `${svg} !default;`, dependencies: []};

            /* add SVG to the variable within the file itself as well */
            const inlineSVG = `${iconmatch[1]}: ${svg} !default;`;
            data = data.replace(match[0], inlineSVG);

            /* when it is not an SVG add the variable and search for its dependencies */
        } else {

            const variablesRegex = /(\$[\w-]+)/g;
            let variablesMatch = variablesRegex.exec(match[2]);
            const dependencies = [];

            while (variablesMatch) {
                dependencies.push(variablesMatch[1]);
                variablesMatch = variablesRegex.exec(match[2]);
            }

            /* add variables only to the core Variables if it is not a theme file */
            if (file.indexOf('theme/') < 0) {
                coreVar[match[1]] = {value: `${match[2]};`, dependencies: Array.from(dependencies)};
            }

            themeVar[match[1]] = {value: `${match[2]};`, dependencies: Array.from(dependencies)};
        }

        match = regex.exec(data);
    }

    return data;
}
function getVariablesFromFile(file, data) {
    const regex = /(\$[\w-]*)\s*:\s*(.*);/g;
    let match = regex.exec(data);

    while (match) {

        /* check if variable is an background icon, if so replace it directly by the SVG */
        if (match[0].indexOf('../../images/backgrounds') >= 0) {

            const iconregex = /(\$[\w-]+)\s*:\s*"\.\.\/\.\.\/images\/backgrounds\/([\w./-]+)" !default;/g;
            const iconmatch = iconregex.exec(match[0]);
            let svg = fs.readFileSync(`src/images/backgrounds/${iconmatch[2]}`).toString();
            svg = `"${svg.replace(/\r?\n|\r/g, '%0A')
                .replace(/"/g, '\'')
                .replace(/\s/g, '%20')
                .replace(/</g, '%3C')
                .replace(/=/g, '%3D')
                .replace(/'/g, '%22')
                .replace(/:/g, '%3A')
                .replace(/\//g, '%2F')
                .replace(/>/g, '%3E')
                .replace(/%3Csvg/, 'data:image/svg+xml;charset=UTF-8,%3Csvg')}"`;

            /* add SVG to the coreVar and themeVar only if it is a theme file and make it optional */
            if (file.indexOf('theme/') < 0) {
                coreVar[iconmatch[1]] = {value: `${svg} !default;`, dependencies: []};
            }

            themeVar[iconmatch[1]] = {value: `${svg} !default;`, dependencies: []};

            /* add SVG to the variable within the file itself as well */
            const inlineSVG = `${iconmatch[1]}: ${svg} !default;`;
            data = data.replace(match[0], inlineSVG);

            /* when it is not an SVG add the variable and search for its dependencies */
        } else {

            const variablesRegex = /(\$[\w-]+)/g;
            let variablesMatch = variablesRegex.exec(match[2]);
            const dependencies = [];

            while (variablesMatch) {
                dependencies.push(variablesMatch[1]);
                variablesMatch = variablesRegex.exec(match[2]);
            }

            /* add variables only to the core Variables if it is not a theme file */
            if (file.indexOf('theme/') < 0) {
                coreVar[match[1]] = {value: `${match[2]};`, dependencies: Array.from(dependencies)};
            }

            themeVar[match[1]] = {value: `${match[2]};`, dependencies: Array.from(dependencies)};
        }

        match = regex.exec(data);
    }

    return data;
}
function getVariablesFromFile ( file , data ) { const regex = / (\$[\w-]*)\s*:\s*(.*); / g ; let match = regex . exec ( data ) ; while ( match ) { /* check if variable is an background icon, if so replace it directly by the SVG */ if ( match [ 0 ] . indexOf ( '../../images/backgrounds' ) >= 0 ) { const iconregex = / (\$[\w-]+)\s*:\s*"\.\.\/\.\.\/images\/backgrounds\/([\w./-]+)" !default; / g ; const iconmatch = iconregex . exec ( match [ 0 ] ) ; let svg = fs . readFileSync ( ` ${ iconmatch [ 2 ] } ` ) . toString ( ) ; svg = ` ${ svg . replace ( / \r?\n|\r / g , '%0A' ) . replace ( / " / g , '\'' ) . replace ( / \s / g , '%20' ) . replace ( / < / g , '%3C' ) . replace ( / = / g , '%3D' ) . replace ( / ' / g , '%22' ) . replace ( / : / g , '%3A' ) . replace ( / \/ / g , '%2F' ) . replace ( / > / g , '%3E' ) . replace ( / %3Csvg / , 'data:image/svg+xml;charset=UTF-8,%3Csvg' ) } ` ; /* add SVG to the coreVar and themeVar only if it is a theme file and make it optional */ if ( file . indexOf ( 'theme/' ) < 0 ) { coreVar [ iconmatch [ 1 ] ] = { value : ` ${ svg } ` , dependencies : [ ] } ; } themeVar [ iconmatch [ 1 ] ] = { value : ` ${ svg } ` , dependencies : [ ] } ; /* add SVG to the variable within the file itself as well */ const inlineSVG = ` ${ iconmatch [ 1 ] } ${ svg } ` ; data = data . replace ( match [ 0 ] , inlineSVG ) ; /* when it is not an SVG add the variable and search for its dependencies */ } else { const variablesRegex = / (\$[\w-]+) / g ; let variablesMatch = variablesRegex . exec ( match [ 2 ] ) ; const dependencies = [ ] ; while ( variablesMatch ) { dependencies . push ( variablesMatch [ 1 ] ) ; variablesMatch = variablesRegex . exec ( match [ 2 ] ) ; } /* add variables only to the core Variables if it is not a theme file */ if ( file . indexOf ( 'theme/' ) < 0 ) { coreVar [ match [ 1 ] ] = { value : ` ${ match [ 2 ] } ` , dependencies : Array . from ( dependencies ) } ; } themeVar [ match [ 1 ] ] = { value : ` ${ match [ 2 ] } ` , dependencies : Array . from ( dependencies ) } ; } match = regex . exec ( data ) ; } return data ; }
/*
function to extract all the variables from a given file with its data.
@return an updated data where the icons have been replaced by the actual SVG data.
/ * function to extract all the variables from a given file with its data .
get variables from file