Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPM Support #2

Merged
merged 16 commits into from
May 11, 2021
Merged

SPM Support #2

merged 16 commits into from
May 11, 2021

Conversation

Amzd
Copy link
Contributor

@Amzd Amzd commented Jan 28, 2021

Only have to change some images adn description in the readme and update the example project.

The build phase method doesn't work with local packages; In that case you have to copy the contents of build-script.sh into your build phase.

Other than that;

You can now use this with SPM;

  1. Add the url to your project with SPM
  2. Create an Icon.swift file
  3. Import SwiftUIcon and write your Icon
  4. Add the build script
  5. Run 🎉

@zac zac mentioned this pull request May 6, 2021
Copy link
Member

@zac zac left a comment

Choose a reason for hiding this comment

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

Wow, this is very cool! Thank you for your contribution!

Sorry for not seeing this sooner, but I wasn't even watching my own repo and I only noticed there were PRs after pushing my first attempt at an SPM approach 😅 Glad I didn't get too far though because this is an excellent take!

I have a couple comments, but it's all pretty minor stuff. Let me know if you aren't able to change/discuss these and I would be happy to merge and make a couple tweaks myself.

Thanks!

public struct IconPreviews<Icon: View>: View {
var icon: () -> Icon

public init(icon: @autoclosure @escaping () -> Icon) {
Copy link
Member

Choose a reason for hiding this comment

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

💯 Nice wrapper! Very helpful 👍

fi
}

[[ -s "$SCRIPT_OUTPUT_FILE_0" ]] || {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding the Assets.xcassets as an output. I think that makes a lot of sense 👍

build-script.sh Outdated
exit 1
}

HELPER=$PWD/Icon/Icon+PreviewHelpers.swift
Copy link
Member

Choose a reason for hiding this comment

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

☝️ One tweak here could be to get the location of the script itself instead of relying on the pwd. Stack Overflow tells me we could do this with:

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

build-script.sh Outdated
GENERATOR=$PWD/IconGenerator/IconGenerator.swift
MAIN=$PWD/IconGenerator/main.swift

cat $SCRIPT_INPUT_FILE_0 $HELPER $GENERATOR $MAIN > $TMPFILE
Copy link
Member

Choose a reason for hiding this comment

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

☝️ Minor thing, but you could do the grep -v here in one line, like:

# Concatenate all files and remove import that is most likely in the input file
cat $SCRIPT_INPUT_FILE_0 $HELPER $GENERATOR $MAIN | grep -v "import\sSwiftUIcon" > $TMPFILE

cat ${SCRIPT_INPUT_FILE_0%/*}/*.swift > $TMPFILE

xcrun -sdk macosx swift $TMPFILE
cd "${BUILD_ROOT}"/../../SourcePackages/checkouts/SwiftUIcon
Copy link
Member

Choose a reason for hiding this comment

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

👍 This is much simpler than before! But I think we might be able to simplify more.

I was also able to run the build script in the package without having to +x via chmod, so we might be able to remove that.

And if coupled with the comment below to get the PWD from within the script (and a little trick to trim the path back up before "Build"), we could make the Run Script phase a one-liner:

"${BUILD_ROOT%Build/*}SourcePackages/checkouts/SwiftUIcon/build-script.sh"

@Amzd
Copy link
Contributor Author

Amzd commented May 6, 2021

It sounds like you're a lot more fluent in bash than I am so please feel free to make changes on this. Is the best way to add you as maintainer to the fork?

@zac
Copy link
Member

zac commented May 6, 2021

It sounds like you're a lot more fluent in bash than I am so please feel free to make changes on this. Is the best way to add you as maintainer to the fork?

I think at this point if you just resolve the current conflicts by pulling over the Mac idiom support just merged, then we can merge this PR and I can do a follow-up with my tweaks and cut a SPM release (most likely 0.2.0).

Let me know if that works for you. Thanks!

@zac
Copy link
Member

zac commented May 11, 2021

@Amzd Just to follow-up on this, I did the merge locally and have attached a diff that you could apply to your fork to get it ready to merge. I'd be happy to then take it from there and get an SPM release out, with credit to you of course!

master-merge.diff.zip

@Amzd
Copy link
Contributor Author

Amzd commented May 11, 2021

I applied the diff before merging, whoops >.<

Hope it still works like this?

@zac
Copy link
Member

zac commented May 11, 2021

@Amzd Yep, all good. Thanks! I'll ping you when I'm able to make the release 👍

@zac zac merged commit 484a5f9 into velos:master May 11, 2021
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.

2 participants