コード例 #1
0
        void AddRequiredModules(StringBuilder sb, String clientScript)
        {
            const String tmlHeader =
                @"
	app.modules['$(Module)'] = function() {
	let module = { exports: undefined };
	(function(module, exports) {
";

            const String tmlFooter =
                @"
	})(module, module.exports);
	return module.exports;
};";

            if (String.IsNullOrEmpty(clientScript))
            {
                return;
            }
            var   _modulesWritten = new HashSet <String>();
            Int32 iIndex          = 0;

            while (true)
            {
                String moduleName = FindModuleNameFromString(clientScript, ref iIndex);
                if (moduleName == null)
                {
                    return;                     // not found
                }
                if (String.IsNullOrEmpty(moduleName))
                {
                    continue;
                }
                if (moduleName.ToLowerInvariant().StartsWith("global/"))
                {
                    continue;
                }
                if (moduleName.ToLowerInvariant().StartsWith("std:"))
                {
                    continue;
                }
                if (moduleName.ToLowerInvariant().StartsWith("app:"))
                {
                    continue;
                }
                if (_modulesWritten.Contains(moduleName))
                {
                    continue;
                }
                var    fileName  = moduleName.AddExtension("js");
                var    appReader = _host.ApplicationReader;
                String filePath  = appReader.MakeFullPath(String.Empty, fileName.RemoveHeadSlash());
                //var filePath = Path.GetFullPath(Path.Combine(_host.AppPath, _host.AppKey ?? String.Empty, fileName.RemoveHeadSlash()));
                if (!appReader.FileExists(filePath))
                {
                    throw new FileNotFoundException(filePath);
                }
                String moduleText = appReader.FileReadAllText(filePath);

                if (moduleText.Contains("define([\"require\", \"exports\"]"))
                {
                    sb.Append($"if (app.modules['{moduleName}'] == undefined) {{")
                    .AppendLine()
                    .Append($"app.modules['{moduleName}'] = function() {{return ")
                    .AppendLine(Localize(moduleText))
                    .AppendLine()
                    .AppendLine("}};");
                }
                else
                {
                    sb.AppendLine(tmlHeader.Replace("$(Module)", moduleName))
                    .AppendLine(Localize(moduleText))
                    .AppendLine(tmlFooter)
                    .AppendLine();
                }
                _modulesWritten.Add(moduleName);
                AddRequiredModules(sb, moduleText);
            }
        }
コード例 #2
0
        void AddRequiredModules(StringBuilder sb, String clientScript)
        {
            const String tmlHeader =
                @"
    app.modules['$(Module)'] = function() {
    let module = { exports: undefined };
    (function(module, exports) {
";

            const String tmlFooter =
                @"
    })(module, module.exports);
    return module.exports;
};";

            if (String.IsNullOrEmpty(clientScript))
            {
                return;
            }
            if (_modulesWritten == null)
            {
                _modulesWritten = new HashSet <String>();
            }
            Int32 iIndex = 0;

            while (true)
            {
                String moduleName = FindModuleNameFromString(clientScript, ref iIndex);
                if (moduleName == null)
                {
                    return;                     // not found
                }
                if (String.IsNullOrEmpty(moduleName))
                {
                    continue;
                }
                if (moduleName.ToLowerInvariant().StartsWith("global/"))
                {
                    continue;
                }
                if (moduleName.ToLowerInvariant().StartsWith("std:"))
                {
                    continue;
                }
                if (moduleName.ToLowerInvariant().StartsWith("app:"))
                {
                    continue;
                }
                if (_modulesWritten.Contains(moduleName))
                {
                    continue;
                }
                var fileName = moduleName.AddExtension("js");
                var filePath = Path.GetFullPath(Path.Combine(_host.AppPath, _host.AppKey, fileName.RemoveHeadSlash()));
                if (!File.Exists(filePath))
                {
                    throw new FileNotFoundException(filePath);
                }
                String moduleText = File.ReadAllText(filePath);
                sb.AppendLine(tmlHeader.Replace("$(Module)", moduleName))
                .AppendLine(_localizer.Localize(null, moduleText, replaceNewLine: false))
                .AppendLine(tmlFooter)
                .AppendLine();
                _modulesWritten.Add(moduleName);
                AddRequiredModules(sb, moduleText);
            }
        }