Skip to content

Add CLI and Swift Package Manager Plugin#4

Merged
ollieatkinson merged 14 commits intotrunkfrom
oliver/swift-package-manager-plugin
Jun 22, 2022
Merged

Add CLI and Swift Package Manager Plugin#4
ollieatkinson merged 14 commits intotrunkfrom
oliver/swift-package-manager-plugin

Conversation

@ollieatkinson
Copy link
Copy Markdown
Member

@ollieatkinson ollieatkinson commented May 29, 2022

Add lexicon-generate CLI and a Swift Package Manager Plugin for automatically generating swift identifiers from lexicon documents.

CLI

Generate identifiers for a given lexicon document

OVERVIEW: A utility for generating code from lexicon documents.

USAGE: lexicon-generate <input> [--output <output>] --type <type> [--quiet]

ARGUMENTS:
  <input>

OPTIONS:
  -o, --output <output>
  -t, --type <type>
  -q, --quiet
  --version               Show the version.
  -h, --help              Show help information.

Generate mindflare identifiers in swift, kotlin and json

$ lexicon-generate mindflare.lexicon --type swift,kotlin,json

Plugin

Automatically generates swift identifiers for all lexicon documents in your target, run at build time and generated to the derived plugin work directory

Comment thread Plugins/SwiftLibraryGeneratorPlugin/plugin.swift
@ollieatkinson
Copy link
Copy Markdown
Member Author

Inside of this P/R I noticed a problem with how inherited node own types were being resolved.

Given the following lexicon:

root:
  db:
    collection:
      id:
    user:
    + root.db.collection

root.user.id is inherited from root.db.collection.id, the is(_:) check which validated if the user id is of the same type of collection id was returning false. Inherited nodes should validate their types against their parent nodes with similar names to the one currently used.

A test has been added to ensure this case is covered

await root["user", "id"].is(root["db", "collection", "id"]) == true

@ollieatkinson
Copy link
Copy Markdown
Member Author

You can validate the plugins via this test package:

// swift-tools-version: 5.6

import PackageDescription

let package = Package(
    name: "Test",
    platforms: [.macOS(.v11)],
    products: [
        .library(name: "Test", targets: ["Test"])
    ],
    dependencies: [
        .package(url: "https://github.com/thousandyears/Lexicon", branch: "oliver/swift-package-manager-plugin")
    ],
    targets: [
        .target(
            name: "Test",
            resources: [
                .copy("example.taskpaper")
            ],
            plugins: [
                .plugin(name: "SwiftStandAloneGeneratorPlugin", package: "Lexicon")
            ]
        )
    ]
)

@ollieatkinson ollieatkinson marked this pull request as ready for review June 1, 2022 19:26
@screensailor
Copy link
Copy Markdown
Contributor

I've tested the plugin on macOS 13.0 Beta and XCode 14.0 Beta and it works 👍.
As you no doubt know, it is likely that Swift 5.7 and the new Xcode will allow you to refine and extend this further :)

1 similar comment
@screensailor
Copy link
Copy Markdown
Contributor

I've tested the plugin on macOS 13.0 Beta and XCode 14.0 Beta and it works 👍.
As you no doubt know, it is likely that Swift 5.7 and the new Xcode will allow you to refine and extend this further :)

Copy link
Copy Markdown
Contributor

@screensailor screensailor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor questions about naming conventions...

Wonderful to have the command line tool and the plugins!

And super important to also have the fix for the types of inherited nodes!

Thank you Ollie

Comment thread Sources/lexicon-generate/CodeGenerator.swift Outdated
Comment thread Sources/SwiftLexicon/Generator.swift Outdated
@ollieatkinson
Copy link
Copy Markdown
Member Author

@screensailor I also added the ability to pass a http URL to the generator, possibly useful in certain scenarios:

lexicon-generate https://raw.githubusercontent.com/thousandyears/MindFlare/trunk/App/Library/Sources/Library/Resources/Test.lexicon --output /tmp/test --type swift

@screensailor
Copy link
Copy Markdown
Contributor

URL argument is a lovely option Ollie 👍

Comment thread Sources/lexicon-generate/CodeGenerator.swift
Comment thread Sources/lexicon-generate/CodeGenerator.swift
Comment thread Sources/lexicon-generate/CodeGenerator.swift
Copy link
Copy Markdown

@NoahKnudsen NoahKnudsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work Ollie! This is a huge improvement to workflows!

@ollieatkinson ollieatkinson merged commit 7b264c1 into trunk Jun 22, 2022
@ollieatkinson ollieatkinson deleted the oliver/swift-package-manager-plugin branch June 22, 2022 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants