GithubHelp home page GithubHelp logo

namex44 / swiftgenplugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bookbeat/swiftgenplugin

0.0 0.0 0.0 35 KB

SwiftGen plugin for SPM

License: MIT License

Shell 2.18% Ruby 76.08% Swift 21.74%

swiftgenplugin's Introduction

SwiftGenPlugin

SwiftGen code generation for Swift packages that works on any machine. No installation required, simply add the package to your Package.swift's dependencies:

  dependencies: [
    .package(url: "https://github.com/SwiftGen/SwiftGenPlugin", from: "6.6.0")
  ]

Using it as a (pre-)build tool

Adding SwiftGen as a prebuild tool will execute it and generate your files before each build.

Add to Package.swift

After adding the dependency to your Package.swift, include the SwiftGenPlugin plugin in any targets for which you would like it to run.

  targets: [
    .target(
      name: "YourTargetName",
      dependencies: [],
      plugins: [
        .plugin(name: "SwiftGenPlugin", package: "SwiftGenPlugin")
      ]
    )
  ]

Add a SwiftGen config

Add a swiftgen.yml file to your project following the configuration file format, and prefix each of your output paths with ${DERIVED_SOURCES_DIR}/. Or set this globally in your configuration by setting the output_dir to that value.

Take a look at this repository's swiftgen.yml for an example.

Supporting Multiple Targets

Each time the plugin is invoked it will look for a swiftgen.yml configuration file in 2 places:

  1. The root of your package (same folder as Package.swift).
  2. Your target's folder, for example Sources/MyExample.

It will invoke SwiftGen for each found configuration file, so you could choose either option, or combine both. This can be useful if you need some target-specific configuration and some shared configuration, without repeating yourself.

Do note that the paths (to resources) in a configuration will need to change depending on where the configuration is located:

  1. Root configurations will need the full path to resources, such as Sources/MyExample/Resources/Localizable.strings. Or set the config's input_dir to Sources/MyExample/Resources. See an example of a top-level configuration.
  2. Target configurations will need the relative path to resources, such as Resources/Localizable.strings. Or set the config's input_dir to Resources. See an example of a target specific configuration.

Using it as a command

You can manually invoke SwiftGen using the following command:

swift package --allow-writing-to-package-directory generate-code-for-resources

The command will automatically search for swiftgen.yml configuration files in each of your targets' (or top-level) folder, and invoke SwiftGen for them.

If you want to manually provide the configuration file and other settings, pass them along as extra arguments:

swift package --allow-writing-to-package-directory generate-code-for-resources --config MyConfig.yml

Licence

This code and tool is under the MIT Licence. See the LICENCE file in this repository.

Attributions

These plugins are powered by SwiftGen.

It is currently mainly maintained by @AliSoftware and @djbe. But I couldn't thank enough all the other contributors to this tool along the different versions which helped make SwiftGen awesome! ๐ŸŽ‰

If you want to contribute, don't hesitate to open a Pull Request, or even join the team!

swiftgenplugin's People

Contributors

djbe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.