MCPcopy
hub / github.com/DevCloudFE/ng-devui / process

Function process

scripts/themeable/custom-theme-webpack-loader.js:140–182  ·  view source on GitHub ↗
(source, map)

Source from the content-addressed store, hash-verified

138}
139
140function 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// 返回结果
184this.callback(null, newSource, map);
185return newSource;

Callers

nothing calls this directly

Calls 5

getThemeDefinitionFunction · 0.85
cssReplaceVarValueFunction · 0.85
getOptionsFromConfigFunction · 0.70
parseMethod · 0.65

Tested by

no test coverage detected