(source, map)
| 138 | } |
| 139 | |
| 140 | function process(source, map) { |
| 141 | this.cacheable && this.cacheable(); |
| 142 | |
| 143 | // 获取配置文件里的主题数据 |
| 144 | const option = getOptionsFromConfig(this); |
| 145 | const themeData = getThemeDefinition(option.theme, option.themeType); |
| 146 | let newSource = source; |
| 147 | if (Object.keys(themeData).length > 0) { |
| 148 | const themeDataVar = Object.keys(themeData).join('|'); |
| 149 | const reg = new RegExp(String.raw`(?<=var\(\-\-(${themeDataVar}),)(?:.*?)(?=\))`, 'g'); |
| 150 | const replaceFn = (match, varName, value) => themeData[varName]; |
| 151 | const fallbackReg = new RegExp(String.raw`var\(\-\-(?:${themeDataVar}),(.*?)\)`, 'g'); |
| 152 | const fallbackFn = (match, item) => item; |
| 153 | const fallbackHandler = option.handleFallBack && option.handleFallBack !== 'nothing' |
| 154 | ? { reg: fallbackReg, replaceFn: fallbackFn } |
| 155 | : null; |
| 156 | |
| 157 | // 处理针对文件类型定位处理的位置 |
| 158 | switch (option.loaderType) { |
| 159 | case 'ng-lib-js': |
| 160 | const styleGroup = locateNgComponentDecoratorStyleString(source); |
| 161 | if (styleGroup) { |
| 162 | styleGroup.map(content => ({ |
| 163 | content, |
| 164 | newContent: JSON.stringify( |
| 165 | JSON.parse(content).map(partCss => cssReplaceVarValue(partCss, reg, replaceFn, fallbackHandler, option.handleFallBack)) |
| 166 | ) |
| 167 | })).forEach(({ content, newContent }) => { |
| 168 | newSource = newSource.replace(content, newContent) |
| 169 | }); |
| 170 | } |
| 171 | break; |
| 172 | case 'css': |
| 173 | newSource = cssReplaceVarValue(source, reg, replaceFn, fallbackHandler, option.handleFallBack); |
| 174 | break; |
| 175 | case 'other': // 不管源码内容直接替换, 暂不支持降级方案的处理 |
| 176 | default: |
| 177 | newSource = source.replace(reg, replaceFn); |
| 178 | } |
| 179 | |
| 180 | } |
| 181 | |
| 182 | } |
| 183 | // 返回结果 |
| 184 | this.callback(null, newSource, map); |
| 185 | return newSource; |
nothing calls this directly
no test coverage detected