Ejemplo n.º 1
0
        void CompileAppFiles(OutputFile output, string originalSourceDir, string sourceDir, StreamWriter writer, string relativeAssetsDir)
        {
            if (sourceDir.Contains(".svn"))
                return;

            string[] files = Directory.GetFiles(sourceDir);
            string defineRequireTemplate = "(this.require.define({\n'{moduleName}': function(exports, require, module) {\n{content}\n}}));\n";

            foreach (string file in files)
            {
                string path = Path.GetFullPath(file);

                if (output.Compilers.Where(c => path.Contains(c.Extension)).Count() == 0)
                    continue;

                string moduleName = path.Replace(originalSourceDir, "").Replace(Path.GetExtension(file), "");
                if (moduleName.StartsWith("\\"))
                    moduleName = moduleName.Substring(1).Replace("\\", "/");

                string content = ReadContentAndReplaceAssetsDir(path, relativeAssetsDir);

                string compileCommand = output.Compilers.Where(c => path.Contains(c.Extension)).Select(c => c.CompileCommand).FirstOrDefault();

                if(!string.IsNullOrEmpty(compileCommand))
                {
                    string command = "";
                    if(compileCommand.Contains("{filename}"))
                        command = compileCommand.Replace("{filename}", path);
                    else if(compileCommand.Contains("{data}"))
                        command = compileCommand.Replace("{data}", "'\"" + content + "\"'");
                    content = this.ExecuteCommandSync(command, false);
                }

                if (output.RelativeFilename.Contains(".js"))
                    content = defineRequireTemplate.Replace("{moduleName}", moduleName).Replace("{content}", content);

                writer.Write(content);
            }

            string[] folders = Directory.GetDirectories(sourceDir);
            foreach (string folder in folders)
            {
                CompileAppFiles(output, originalSourceDir, folder, writer, relativeAssetsDir);
            }
        }
Ejemplo n.º 2
0
        void AddRequireContent(OutputFile output, StreamWriter writer)
        {
            if (!output.RelativeFilename.Contains(".js"))
                return;

            string sourceFilename = Directory.GetCurrentDirectory() + "\\requireDefinition.js";

            StreamReader sr = new StreamReader(sourceFilename);
            string requirecontent = sr.ReadToEnd();
            sr.Close();

            writer.Write(requirecontent);
        }