twostraws / Ignite

A static site generator for Swift developers.
MIT License
984 stars 34 forks source link

[FR]: Making the buildDirectory changeable #15

Closed gdate closed 1 month ago

gdate commented 1 month ago

Nice to meet you! Thank you for the wonderful performance at try!Swift. I'm fascinated by the Ignite presentations! πŸ‘

Problem

I am currently working on creating and deploying a hosting server and web page using only Swift, by combining Vapor and Ignite. I tried to host a web page built with Ignite on Vapor and deploy it to Google Cloud Run, but encountered a strange issue. The issue is that the "Build" directory generated by Ignite is not uploaded for some reason when using the gcloud source upload command. (As a test, renaming it to "Workspace" or "Public" allowed successful uploads.) πŸ€”

Feature Request

Therefore, I would like to propose a fix to pass the buildDirectoryPath to the publish method of the Site.

implementation
// PublishingContext.swift

// Existing Implementation
    init(for site: any Site, rootURL: URL) throws {
        ...
        buildDirectory = rootDirectory.appending(path: "Build")

        try parseContent()
    }

    init(for site: any Site, from file: StaticString) throws {
        ...

        buildDirectory = rootDirectory.appending(path: "Build")

        try parseContent()
    }

// Alternative Implementation
    init(for site: any Site, rootURL: URL, buildDirectoryPath: String = "Build") throws {
        ...
        buildDirectory = rootDirectory.appending(path: buildDirectoryPath)

        try parseContent()
    }

    init(for site: any Site, from file: StaticString, buildDirectoryPath: String = "Build") throws {
        ...

        buildDirectory = rootDirectory.appending(path: buildDirectoryPath)

        try parseContent()
    }

// Site.swift

// Existing Implementation
public protocol Site {
    ...
    func publish(from file: StaticString) throws
}

extension Site {
    public func publish(from file: StaticString = #file) throws {
        let context = try PublishingContext(for: self, from: file)
        ...
    }
}

// Alternative Implementation
public protocol Site {
    ...
    func publish(from file: StaticString, buildDirectoryPath: String) throws
}

extension Site {
    ...
    public func publish(from file: StaticString = #file, buildDirectoryPath: String = "Build") throws {
        let context = try PublishingContext(for: self, from: file, buildDirectoryPath: buildDirectoryPath)
        ...
    }
}
Usage
let site = ExampleSite()

do {
    try site.publish(buildDirectoryPath: "Public")
} catch {
    print(error.localizedDescription)
}

Your consideration would be greatly appreciated πŸ™Œ

gdate commented 1 month ago

I'm sorry. This was due to my lack of knowledge about Google Cloud. πŸ™‡

I tried to host a web page built with Ignite on Vapor and deploy it to Google Cloud Run, but encountered a strange issue. The issue is that the "Build" directory generated by Ignite is not uploaded for some reason when using the gcloud source upload command. (As a test, renaming it to "Workspace" or "Public" allowed successful uploads.) πŸ€”

During the execution of gcloud run deploy, it was specified that if there is no .gcloudignore file present, it will refer to .gitignore, and anything listed there will not be uploaded. Therefore, because the Build directory was specified in .gitignore, it was not uploaded.

If a .gcloudignore file is absent and a .gitignore file is present in the local source directory, gcloud will use a generated Git-compatible .gcloudignore file that respects your .gitignored files. 

https://cloud.google.com/sdk/gcloud/reference/run/deploy

However, allowing the buildDirectory to be changeable at runtime seems like a useful modification for "Ignite". In fact, since the default publicDirectory name for Vapor projects is Public, it would be very convenient if "Ignite" could generate directories named Public.

Conversely, if this is not possible, it would be necessary to either rename the project generated by "Ignite" each time or change the specification of Vapor's publicDirectory.

I would appreciate it if you could consider this suggestion.

twostraws commented 1 month ago

This idea makes perfect sense – please go ahead and submit a pull request!

gdate commented 1 month ago

Thank you for considering my proposal! I've submitted the PR. Looking forward to your review! πŸ˜„ https://github.com/twostraws/Ignite/pull/16

twostraws commented 1 month ago

Nailed it! πŸ™Œ