private addData()

in templates/legacy/windows-admin-center-extension-template/gulps/gulp-svg-code/svg-code-convert.ts [47:111]


    private addData(current: any, segments: string[]): void {
        const ignores = [ '<?xml', '<!-- Generator:', '<!DOCTYPE' ];
        let nested: any[] = [];
        let keys = Object.keys(current);
        for (let key of keys) {
            let content = current[key];
            segments.push(key);

            if (typeof content === 'object') {
                let segs = segments.slice(0);
                nested.push({ content, segs });
            } else if (typeof content === 'string') {
                let cssName = '.svg-' + segments.join('--');
                this.outputCss.push(cssName + ' {\r\n');
                this.outputCss.push(this.indent(1) + 'background-image: url("data:image/svg+xml;');

                this.outputTs.push(this.indent(segments.length) + 'export const ' + key + ' = \'');

                let lines = content.split('\r');
                let svg = '';
                lines.forEach((value, index, array) => {
                    value = value.replace('\n', '');
                    if (value && value.length > 1) {
                        let skip = false;
                        for (let item of ignores) {
                            if (value.indexOf(item) >= 0) {
                                skip = true;
                                break;
                            }
                        }

                        if (!skip) {
                            svg += value;
                            // this.outputCss.push(value);
                            this.outputTs.push(value);
                        }
                    }
                });

                svg = this.replaceAll(svg, '"', '\'');
                svg = this.replaceAll(svg, '%', '%25');
                svg = this.replaceAll(svg, '#', '%23');       
                svg = this.replaceAll(svg, '{', '%7B');
                svg = this.replaceAll(svg, '}', '%7D');         
                svg = this.replaceAll(svg, '<', '%3C');
                svg = this.replaceAll(svg, '>', '%3E');
                this.outputCss.push('charset=utf8,' + svg);

                this.outputCss.push('");\r\n');
                this.outputCss.push('}\r\n');
                this.outputCss.push('\r\n');

                this.outputTs.push('\';\r\n');
            }

            segments.pop();
        }

        for (let index = 0; index < nested.length; index++) {
            let { content, segs } = nested[index];
            this.outputTs.push(this.indent(segs.length) + 'export module ' + segs[segs.length - 1] + ' {\r\n');
            this.addData(nested[index].content, nested[index].segs);
            this.outputTs.push(this.indent(segs.length) + '}\r\n');
        }
    }