Closed akaguny closed 4 years ago
To the best of my knowledge this is not currently possible or supported.
You can do multiple different replacements, https://github.com/adamreisnz/replace-in-file#multiple-values-with-different-replacements, but on the same files only.
I think the workaround is currently the only option.
@adamreisnz ,
To the best of my knowledge this is not currently possible or supported.
maybe its for next major realize or minor improvement?
I think the workaround is currently the only option.
maybe add this workaround to readme docs?
Sure, open to a PR with ideas on how to implement it
On Wed, 17 Jun 2020, 00:25 Alexey, notifications@github.com wrote:
@adamreisnz https://github.com/adamreisnz , maybe its for next major realize or minor improvement?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/adamreisnz/replace-in-file/issues/119#issuecomment-644729791, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADXYQVXTT2QZTC6TI7W3DDRW5QDDANCNFSM4NXEOGAQ .
now i have no enough time for the research for create solution for single run replace in file for different replacements in different files (optimization) correct workaround, someone may be usefully
const normalizes = {
from: function normalizeFroms(
configFiles: UpdateVersionsFileReplaceConfig
): Array<string | RegExp> {
return configFiles.replace.flatMap(({ from }) => from);
},
to: function normalizeFroms(
configFiles: UpdateVersionsFileReplaceConfig
): Array<string> {
return configFiles.replace.flatMap(({ to }) => to);
},
};
export const normalizeConfigs = (
config,
globOptions: { cwd: string; absolute: boolean }
): Array<ReplaceInFileConfig> => {
const normalizedConfigs = [];
for (const configFile of config.files) {
normalizedConfigs.push({
files: configFile.path,
from: normalizes.from(configFile),
to: normalizes.to(configFile),
...(configFile.encoding ? { encoding: configFile.encoding } : {}),
glob: { ...globOptions },
});
}
return normalizedConfigs;
};
and run replace file function multiply with arguments =)
I have config for my replacement:
In my case for different files need different replacements. Now i need something like for normalize
but in can create bugs because in normalize i simple concat all
UpdateVersionsFileReplaceConfig
. In this way i have a bug with this conditions: