Natalie icon indicating copy to clipboard operation
Natalie copied to clipboard

Allow additional imports with natalie-imports.json

Open ldiqual opened this issue 9 years ago • 8 comments

@krzyzanowskim

Here's a proposed fix for https://github.com/krzyzanowskim/Natalie/issues/37, as per phimage's suggestion.

This commit modifies natalie.swift so it can take a second argument imports_file_json. This JSON file must contain an array of all the framework names to import and that natalie might not be able to autodetect (see original issue).

For example, in natalie-imports.json:

["FlatUIKit"]

and then:

$ natalie.swift <path_to_project> natalie-imports.json

which will add import FlatUIKit right before custom module imports.

A couple notes:

  • In a perfect world I would love natalie-imports.json to be automatically detected in projectdir, but since the documentation says that the path should be projectdir/projectname we'd have to go one directory up and that seems a bit hacky.
  • Having a long argument like --additional-imports natalie-imports.json would be best, but I didn't want to add too much code without your approval (since we'd need to hack around Process.argv)

Let me know what you think about this solution and how to possibly improve it.

ldiqual avatar Jul 13 '15 06:07 ldiqual

To be automatically detected in our perfect world you can put the file near the storyboard with specific extension, as I do with my PR https://github.com/krzyzanowskim/Natalie/pull/48/files Without that XNatalie or a generic launcher will not add the additional command parameter

phimage avatar Jul 13 '15 08:07 phimage

what is wrong with specyfying module in storyboard? this is the easiest way to handle it. Configuration file introduce complication how to deal with the file, where to store etc. I'd like to realy avoid that as long as possible.

krzyzanowskim avatar Jul 13 '15 16:07 krzyzanowskim

you can't specify module for objective-c framework, this is what I understand in the corresponding issue

phimage avatar Jul 13 '15 19:07 phimage

@phimage --additional-imports or any option would be good to have for this.

krzyzanowskim avatar Jul 29 '15 08:07 krzyzanowskim

Yes option is far better than adding an extra argument behind the file path But option

  • break XNatalie (or need to ask options, register it by project) or other launch shortcut
  • more codes and dev , except if third party command line parser is included in Natalie

I prefer configuration files by storyboard because

  • Natalie generade code for multiple storyboards and each storyboard have its own issue and could be generated alone for test (and option could be forgotten)
  • No need to change generic command line, launcher, etc...
  • Easy to add other configuration options for other issues

that's why I make "plist" into PR #48

then plist VS json, the two are easy to read, but in Xcode I prefer create and edit plist file

phimage avatar Jul 29 '15 10:07 phimage

As a side note, if a solution is found to the issue #64 I just opened where I ask for a feature to have Natalie parse an xcodeproj file to generate target specific files, Natalie could automatically find out which frameworks each target is linked with.

hartbit avatar Aug 05 '15 11:08 hartbit

@phimage I like the solution of a configuration file next to the storyboard. Not really a big fan of the plist format but at least it's consistent with what apple uses. @hartbit Agreed that your solution would be best, maybe we could iterate by merging https://github.com/krzyzanowskim/Natalie/pull/48 and https://github.com/krzyzanowskim/Natalie/issues/64 when it's code-ready?

ldiqual avatar Aug 10 '15 13:08 ldiqual

hello, I want merge this change, can you please rebase to current codebase ? :+1: This feature need documentation in README too.

krzyzanowskim avatar Dec 10 '15 11:12 krzyzanowskim