replace method
Iterable<ResolveScript>
replace(
- Script script,
- ScriptsConfig config, {
- EnvConfig? parentEnvConfig,
- OptionalFlags? flags,
Implementation
Iterable<ResolveScript> replace(
Script script,
ScriptsConfig config, {
EnvConfig? parentEnvConfig,
OptionalFlags? flags,
}) sync* {
late final sipVariables = populate();
Iterable<ResolveScript> resolve(String command, Script script) sync* {
yield* replaceVariables(
command,
sipVariables: sipVariables,
config: config,
flags: flags,
script: script,
envConfigOfParent: parentEnvConfig,
);
}
final envCommands = <EnvConfig>{
if (script.env?.commands case final commands)
for (final command in commands ?? <String>[])
EnvConfig(
commands: resolve(command, script)
.map((e) => e.command)
.whereType<String>(),
files: script.env?.files,
workingDirectory: directory,
),
};
final envConfig = {
...envCommands,
};
final commands = <ResolveScript>[];
for (final command in script.commands) {
final resolved = resolve(command, script).toList();
commands.addAll(resolved);
envConfig.addAll([
if (parentEnvConfig != null) parentEnvConfig,
for (final e in resolved)
if (e.envConfig case final config?) config,
]);
}
yield ResolveScript(
resolvedScripts: commands,
envConfig: envConfig.combine(directory: directory),
script: script,
);
}