public Func <Stream> Transform(Func <Stream> openSourceStream, IAsset asset) { return(() => { var source = openSourceStream().ReadToEnd(); var output = ModulePathInserter.InsertModulePathIntoDefineCall(source, ModulePath); return output.AsStream(); }); }
public static string InsertModulePathIntoDefineCall(string moduleScript, string modulePath) { var inserter = new ModulePathInserter(); var parser = new JSParser(moduleScript); var sourceTree = parser.Parse(new CodeSettings { MinifyCode = false }); sourceTree.Accept(inserter); if (inserter.insertionIndex > 0) { return moduleScript.Insert(inserter.insertionIndex, "\"" + modulePath + "\","); } else { return moduleScript; } }
public static string InsertModulePathIntoDefineCall(string moduleScript, string modulePath) { var inserter = new ModulePathInserter(); var parser = new JSParser(moduleScript); var sourceTree = parser.Parse(new CodeSettings { MinifyCode = false }); sourceTree.Accept(inserter); if (inserter.insertionIndex > 0) { return(moduleScript.Insert(inserter.insertionIndex, "\"" + modulePath + "\",")); } else { return(moduleScript); } }