mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
<Query Kind="Program" />
|
|
|
|
void Main()
|
|
{
|
|
var files = Directory.GetFiles("c:\\git\\sonarr\\src\\UI","*.js", SearchOption.AllDirectories);
|
|
|
|
var moduleRegex = new Regex(@"module.exports\s*=\s*\(function\s*\(\)\s*{\n\s*return\s*(\w|\W)*\)\.call\(this\);$");
|
|
var functionHead = new Regex(@"\s*\(function\s*\(\)\s*{\n\s*return\s*");
|
|
var functionTail = new Regex(@"\}\).call\(this\);$");
|
|
var multiVar = new Regex(@"^(?<d>var\s*\w*\s*=\s*require\(.*\)),");
|
|
var seperateDeclearatuin = new Regex(@"^((\w|\$|_)*\s=\srequire\(.*\))(,|;)", RegexOptions.Multiline);
|
|
|
|
foreach (var filePath in files)
|
|
{
|
|
var text = File.ReadAllText(filePath);
|
|
|
|
var newContent = text.Replace("// Generated by uRequire v0.7.0-beta.14 template: 'nodejs'","");
|
|
|
|
newContent = newContent.Replace("var __isAMD = !!(typeof define === 'function' && define.amd),","");
|
|
newContent = newContent.Replace("__isNode = (typeof exports === 'object'),","");
|
|
newContent = newContent.Replace("__isWeb = !__isNode;","");
|
|
newContent = newContent.Replace("\"use strict\";","'use strict';");
|
|
|
|
newContent = newContent.Trim();
|
|
|
|
|
|
|
|
if(moduleRegex.IsMatch(newContent))
|
|
{
|
|
filePath.Dump();
|
|
|
|
newContent = functionHead.Replace(newContent," ");
|
|
newContent = functionTail.Replace(newContent,"");
|
|
}
|
|
|
|
if(multiVar.IsMatch(newContent))
|
|
{
|
|
newContent = multiVar.Replace(newContent,"$1;"); //first one
|
|
|
|
}
|
|
|
|
newContent = seperateDeclearatuin.Replace(newContent,"var $1;"); //ones after
|
|
newContent.Replace("var $ = require('jquery'), var","var $ = require('jquery');");
|
|
|
|
File.WriteAllText(filePath,newContent.Trim());
|
|
|
|
}
|
|
}
|
|
|
|
// Define other methods and classes here
|