예제 #1
0
        public Optional <AbsoluteFilePath> CreateFile(string name, Template template, Optional <AbsoluteDirectoryPath> destinationPath)
        {
            var location = destinationPath.HasValue ? destinationPath.Value : DirectoryPath.GetCurrentDirectory();

            var fileName        = location / new FileName(name);
            var fileNameWithExt = template.FileExt.MatchWith(fileName.AddExtension, () => fileName);

            var project = FindAndLoadProjectInDirectory(location);

            var nss = new NamespaceName(project.GetString("RootNamespace") ?? "");

            var rootDir     = location.ContainingDirectory;
            var relativeDir = location.RelativeTo(rootDir);
            var ns          = relativeDir.ToNamespace(nss).Or(new NamespaceName(""));

            var fullTypeName = ns.FullName == "" ? fileName.Name.ToString() : ns.FullName + "." + fileName.Name;

            var environment = new TemplateVariableResolver()
                              .With("filename", fileNameWithExt.Name.ToString())
                              .With("typename", fileName.Name.ToString())
                              .With("fulltypename", fullTypeName)
                              .With(ns.FullName == "" ? "exclude_namespace" : "include_namespace", "")   //we just check the existence of the key so no value is needed
                              .With("namespace", ns.FullName);

            var result = TemplateSpawner.SpawnTemplate(template, location, environment, _fileSystem);

            return(result.SpawnedProjectFiles.FirstOrNone());
        }
예제 #2
0
        public AbsoluteDirectoryPath CreateProject(string name, Template template, Optional <AbsoluteDirectoryPath> destinationPath)
        {
            var location = destinationPath.HasValue ? destinationPath.Value : DirectoryPath.GetCurrentDirectory();

            var projectDir = location / name;

            if (_fileSystem.Exists(projectDir) &&
                (_fileSystem.GetFiles(projectDir).Any() || _fileSystem.GetDirectories(projectDir).Any()))
            {
                throw new ProjectFolderNotEmpty();
            }

            var environment = new TemplateVariableResolver().With("filename", name);

            TemplateSpawner.SpawnTemplate(template, projectDir, environment, _fileSystem);

            return(projectDir);
        }
예제 #3
0
        public static SpawnedTemplate SpawnTemplate(Template template, AbsoluteDirectoryPath whereToSpawnTemplate, ITemplateVariableResolver variableResolver, IFileSystem fileSystem)
        {
            var spawner = new TemplateSpawner(variableResolver, fileSystem);

            return(new SpawnedTemplate(spawner.Spawn(template, whereToSpawnTemplate)));
        }