예제 #1
0
        public static void Transpile(RunnerArgs args)
        {
            string projectDirectory = args.Options["-p", "--project"]?.Value ?? Environment.CurrentDirectory;
            string rootNamespace    = args.Options["-ns", "--namespace"]?.Value;
            string sourcePath       = Path.GetDirectoryName(typeof(DotNetJerryHost).Assembly.Location);
            string skeletonPath     = Path.Combine(sourcePath, "skeleton.jerry");
            string outputDirectory  = args.Options["-o", "--output"]?.Value;

            if (!Directory.Exists(projectDirectory))
            {
                throw new RunnerException($"Project directory '{projectDirectory}' does not exist.");
            }

            if (!File.Exists(skeletonPath))
            {
                throw new RunnerException("Skeleton file not found.");
            }

            projectDirectory = PathHelper.MakeAbsolutePath(Environment.CurrentDirectory, projectDirectory);
            outputDirectory  = PathHelper.MakeAbsolutePath(projectDirectory, outputDirectory ?? RazorProjectConventions.DefaultIntermediateDirectory);

            RazorProject project = new RazorProject()
            {
                ProjectDirectory      = projectDirectory,
                RootNamespace         = rootNamespace,
                Items                 = new List <RazorProjectItem>(),
                IntermediateDirectory = outputDirectory,
            };

            if (args.Options["-f", "--file"] != null)
            {
                foreach (string file in args.Options["-f", "--file"].Values)
                {
                    foreach (string expandedFile in ResponseFile.ExpandStrings(file, project.ProjectDirectory))
                    {
                        if (!HasPipeFormat(expandedFile, out var fullPath, out var projectPath))
                        {
                            project.AddItem(expandedFile);
                        }
                        else if (!string.IsNullOrEmpty(fullPath))
                        {
                            project.Items.Add(new RazorProjectItem()
                            {
                                FullPath = MakeAbsolutePath(fullPath), ProjectPath = projectPath
                            });
                        }
                    }