cocoapods-nativescript 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4b71e07e45139b97609ca8dbe4a437d1276f92ac563afde6976e9b137e2fe412
4
+ data.tar.gz: e7d2023cfc90b9f02c57f92931111f972921e8231dd3597d28cf9b9832d3f6d2
5
+ SHA512:
6
+ metadata.gz: b52ce74991f42e4dbe199ecaf54564bca933f1052a89b03e7b368e76ceca0c151810dec162df6dc90592c993df3c37dca7cf0aba4ed8e4645b4759c3e73d1dc6
7
+ data.tar.gz: da7ee68f7d7caa262b1e8357a929b9e09229ba239d636bc7517c8bbaef749fd21455f52adab4530fc1f6431515c896a66363bbdc253728dd3108dd1281cc8735
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cocoapods-nativescript.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'cocoapods'
8
+
9
+ gem 'mocha'
10
+ gem 'bacon'
11
+ gem 'mocha-on-bacon'
12
+ gem 'prettybacon'
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2022 Dermendzhiev, Teodor (external - Project) <tdermendjievft@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # cocoapods-nativescript
2
+
3
+ A description of cocoapods-nativescript.
4
+
5
+ ## Installation
6
+
7
+ $ gem install cocoapods-nativescript
8
+
9
+ ## Usage
10
+
11
+ $ pod spec nativescript POD_NAME
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ def specs(dir)
4
+ FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
5
+ end
6
+
7
+ desc 'Runs all the specs'
8
+ task :specs do
9
+ sh "bundle exec bacon #{specs('**')}"
10
+ end
11
+
12
+ task :default => :specs
13
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cocoapods-nativescript/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cocoapods-nativescript'
8
+ spec.version = CocoapodsNativescript::VERSION
9
+ spec.authors = ['Dermendzhiev, Teodor (external - Project)']
10
+ spec.email = ['tdermendjievft@gmail.com']
11
+ spec.description = %q{A short description of cocoapods-nativescript.}
12
+ spec.summary = %q{A longer description of cocoapods-nativescript.}
13
+ spec.homepage = 'https://github.com/EXAMPLE/cocoapods-nativescript'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
@@ -0,0 +1,58 @@
1
+ require 'xcodeproj'
2
+
3
+ module Pod
4
+ class Command
5
+ # This is an example of a cocoapods plugin adding a top-level subcommand
6
+ # to the 'pod' command.
7
+ #
8
+ # You can also create subcommands of existing or new commands. Say you
9
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
10
+ # (e.g. `pod list deprecated`), there are a few things that would need
11
+ # to change.
12
+ #
13
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
14
+ # the class to exist in the the Pod::Command::List namespace
15
+ # - change this class to extend from `List` instead of `Command`. This
16
+ # tells the plugin system that it is a subcommand of `list`.
17
+ # - edit `lib/cocoapods_plugins.rb` to require this file
18
+ #
19
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
20
+ # in the `plugins.json` file, once your plugin is released.
21
+ #
22
+ class Nativescript < Command
23
+ self.summary = 'NativeScript plugin for Xcode'
24
+
25
+ self.description = 'Use this pod to add NativeScript settings or to remove all NativeScript traces from your Xcode project'
26
+
27
+ self.arguments = 'COMMAND'
28
+
29
+ def initialize(argv)
30
+ @name = argv.shift_argument
31
+ super
32
+ end
33
+
34
+ def validate!
35
+ super
36
+ help! 'A Pod name is required.' unless @name
37
+ end
38
+
39
+ def get_project(path)
40
+ main_dir = Dir.new(path)
41
+ children = main_dir.children
42
+ for name in children
43
+ if name.end_with?('.xcodeproj')
44
+ return Xcodeproj::Project.open("#{main_dir.path}/#{name}")
45
+ else
46
+ return
47
+ end
48
+ end
49
+ end
50
+
51
+ def run
52
+ project = get_project(".")
53
+ UI.puts "Add your implementation for the cocoapods-nativescript plugin in #{__FILE__}"
54
+ puts Dir.entries(".")
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-nativescript/command/nativescript'
@@ -0,0 +1,3 @@
1
+ module CocoapodsNativescript
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,288 @@
1
+ require 'cocoapods-nativescript/gem_version'
2
+
3
+ @command = ARGV[0]
4
+ @path = ARGV[1]
5
+
6
+ @internal_dest = nil
7
+
8
+ def addfiles (direc, current_group, main_target)
9
+ Dir.glob(direc) do |item|
10
+ next if item == '.' or item == '.DS_Store'
11
+
12
+ if File.directory?(item)
13
+ new_folder = File.basename(item)
14
+ created_group = current_group.new_group(new_folder)
15
+ addfiles("#{item}/*", created_group, main_target)
16
+ else
17
+ i = current_group.new_file(item)
18
+ if item.include? ".m"
19
+ main_target.add_file_references([i])
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+
26
+ def nativescript_post_install(installer)
27
+
28
+ save_current_state(installer)
29
+
30
+ pods_path = File.expand_path("..", installer.pods_project.path)
31
+ internal_path = pods_path + "/NativeScript/resources"
32
+ src_root = File.expand_path("..", pods_path)
33
+ @internal_dest = File.expand_path("internal", src_root)
34
+ FileUtils.copy_entry internal_path, @internal_dest
35
+ main_target = nil
36
+ installer.aggregate_targets.each do |target|
37
+ user_project = target.user_project
38
+ user_project.build_configurations.each do |config|
39
+
40
+ config.build_settings["ENABLE_BITCODE"] = "NO"
41
+ config.build_settings["CLANG_ENABLE_MODULES"] = "NO"
42
+ config.build_settings["LD"] = "$SRCROOT/internal/nsld.sh"
43
+ config.build_settings["LDPLUSPLUS"] = "$SRCROOT/internal/nsld.sh"
44
+ config.build_settings["OTHER_LDFLAGS"] = '$(inherited) -framework WebKit$(inherited) -ObjC -sectcreate __DATA __TNSMetadata $(CONFIGURATION_BUILD_DIR)/metadata-$(CURRENT_ARCH).bin -F $(SRCROOT)/internal -licucore -lz -lc++ -framework Foundation -framework UIKit -framework CoreGraphics -framework MobileCoreServices -framework Security'
45
+ end
46
+ main_target = user_project.targets.first
47
+
48
+ end
49
+
50
+
51
+ sources_index = nil
52
+ main_target.build_phases.each_with_index do |phase, i|
53
+ if phase.class.name == "Xcodeproj::Project::Object::PBXSourcesBuildPhase"
54
+ sources_index = i
55
+ end
56
+ end
57
+
58
+ pre_build = main_target.new_shell_script_build_phase("NativeScript PreBuild")
59
+ pre_build.shell_script = "${SRCROOT}/internal/nativescript-pre-build"
60
+
61
+ main_target.build_phases.move_from(main_target.build_phases.length-1, sources_index)
62
+
63
+ link_index = nil
64
+ main_target.build_phases.each_with_index do |phase, i|
65
+ if phase.class.name == "Xcodeproj::Project::Object::PBXFrameworksBuildPhase"
66
+ link_index = i
67
+ end
68
+ end
69
+
70
+ pre_link = main_target.new_shell_script_build_phase("NativeScript PreLink")
71
+ pre_link.shell_script = "${SRCROOT}/internal/nativescript-pre-link"
72
+
73
+ main_target.build_phases.move_from(main_target.build_phases.length-1, link_index)
74
+
75
+
76
+ end
77
+
78
+ def save_current_state(installer)
79
+ @state = Hash.new
80
+
81
+ main_target = nil
82
+
83
+ user_project = nil
84
+ installer.aggregate_targets.each do |target|
85
+ user_project = target.user_project
86
+
87
+ end
88
+
89
+ user_project.build_configurations.each do |config|
90
+ @state[config.name] = Hash.new
91
+ @state[config.name]["settings"] = {
92
+ "ENABLE_BITCODE": config.build_settings["ENABLE_BITCODE"],
93
+ "CLANG_ENABLE_MODULES": config.build_settings["ENABLE_BITCODE"],
94
+ "LD": config.build_settings["LD"],
95
+ "LDPLUSPLUS": config.build_settings["LDPLUSPLUS"],
96
+ "OTHER_LDFLAGS": config.build_settings["OTHER_LDFLAGS"],
97
+ "USER_HEADER_SEARCH_PATHS": config.build_settings["USER_HEADER_SEARCH_PATHS"],
98
+ "SWIFT_OBJC_BRIDGING_HEADER": config.build_settings["SWIFT_OBJC_BRIDGING_HEADER"]
99
+ }
100
+ end
101
+
102
+ main_target = user_project.targets.first
103
+ @state["main_target_build_phases"] = main_target.build_phases
104
+ json = @state.to_json
105
+
106
+ File.write('./pre-ns-state.json', json)
107
+
108
+ end
109
+
110
+ def nativescript_restore_state(installer)
111
+ file = File.read('./pre-ns-state.json')
112
+ state_hash = JSON.parse(file)
113
+ #restore settings
114
+ user_project = nil
115
+ installer.aggregate_targets.each do |target|
116
+ user_project = target.user_project
117
+
118
+ end
119
+
120
+ restore_state(user_project)
121
+ end
122
+
123
+ def get_appdelegate_path(user_project)
124
+ src_root = File.expand_path("..", user_project.path)
125
+ app_delegate_path = File.expand_path('./App/AppDelegate.swift', src_root)
126
+ return app_delegate_path
127
+ end
128
+
129
+ def save_appdelegate(content, user_project)
130
+ File.write(get_appdelegate_path(user_project), content)
131
+ end
132
+
133
+ def get_podfile_path(user_project)
134
+ src_root = File.expand_path("..", user_project.path)
135
+ podfile_path = File.expand_path('./Podfile', src_root)
136
+ return podfile_path
137
+ end
138
+
139
+ def save_podfile(content, user_project)
140
+ File.write(get_podfile_path(user_project), content)
141
+ end
142
+
143
+ def get_ns_state_path(user_project)
144
+ src_root = File.expand_path("..", user_project.path)
145
+ state_path = File.expand_path('./pre-ns-state.json', src_root)
146
+ return state_path
147
+ end
148
+
149
+ def get_ns_state_hash(user_project)
150
+ state_path = get_ns_state_path(user_project)
151
+ file = File.read(state_path)
152
+ state_hash = JSON.parse(file)
153
+ return state_hash
154
+ end
155
+
156
+ def save_ns_state_hash(hash, user_project)
157
+ json = hash.to_json
158
+ state_path = get_ns_state_path(user_project)
159
+ File.write(state_path, json)
160
+ end
161
+
162
+ def restore_state(user_project)
163
+
164
+ state_hash = get_ns_state_hash(user_project)
165
+ main_target = user_project.targets.first
166
+
167
+ user_project.build_configurations.each do |config|
168
+ state_hash[config.name]["settings"].each do |key, value|
169
+ if value
170
+ config.build_settings[key] = value
171
+ puts key
172
+ else
173
+ puts "deleting key " + key
174
+ config.build_settings.delete(key)
175
+ end
176
+ end
177
+ end
178
+
179
+ main_target.build_phases.each do |phase|
180
+ unless state_hash["main_target_build_phases"].include? phase.to_s
181
+ puts "REMOVING PHASE:"
182
+ puts phase.to_s
183
+ phase.remove_from_project
184
+ end
185
+ end
186
+
187
+ groups = state_hash["added_groups"]
188
+ if groups && groups.length > 0
189
+ groups.each do |groupName|
190
+ user_project.groups.each do |group|
191
+ if group.name == groupName
192
+ group.remove_from_project
193
+ end
194
+ end
195
+ end
196
+ end
197
+
198
+ added_dirs = state_hash["added_dirs"]
199
+ if added_dirs && added_dirs.length > 0
200
+ added_dirs.each do |path|
201
+ FileUtils.rm_rf(path)
202
+ end
203
+ end
204
+
205
+ user_project.save
206
+
207
+ podfile = File.read(get_podfile_path(user_project))
208
+ podfile.slice! "require_relative '../../node_modules/@nativescript/capacitor/ios/nativescript.rb'"
209
+ podfile.slice! "pod 'NativeScript'"
210
+ podfile.slice! "pod 'NativeScriptUI'"
211
+ podfile.slice! "nativescript_capacitor_post_install(installer)"
212
+
213
+ save_podfile(podfile, user_project)
214
+
215
+ appdelegate = File.read(get_appdelegate_path(user_project))
216
+ to_slice = [
217
+ "var nativescript: NativeScript?",
218
+ "// NativeScript init",
219
+ "let nsConfig = Config.init()",
220
+ "nsConfig.metadataPtr = runtimeMeta()",
221
+ "// can turn off in production",
222
+ "nsConfig.isDebug = true",
223
+ "nsConfig.logToSystemConsole = nsConfig.isDebug",
224
+ 'nsConfig.baseDir = URL(string: "public", relativeTo: Bundle.main.resourceURL)?.path',
225
+ 'nsConfig.applicationPath = "nativescript"',
226
+ "self.nativescript = NativeScript.init(config: nsConfig)"
227
+ ]
228
+
229
+ to_slice.each do |line|
230
+ appdelegate.slice! line
231
+ end
232
+
233
+ save_appdelegate(appdelegate, user_project)
234
+ end
235
+
236
+ def command_restore_state(project_path)
237
+ puts "Restoring project state..."
238
+ require 'xcodeproj'
239
+ require 'json'
240
+ project = Xcodeproj::Project.open(project_path)
241
+ puts project
242
+ restore_state(project)
243
+ end
244
+
245
+ def nativescript_capacitor_post_install(installer)
246
+ nativescript_post_install(installer)
247
+
248
+ main_target = nil
249
+
250
+ user_project = nil
251
+ installer.aggregate_targets.each do |target|
252
+ user_project = target.user_project
253
+ user_project.build_configurations.each do |config|
254
+ config.build_settings["SWIFT_OBJC_BRIDGING_HEADER"] = "$(SRCROOT)/NativeScript/App-Bridging-Header.h"
255
+ config.build_settings["USER_HEADER_SEARCH_PATHS"] = "$(SRCROOT)/NativeScript"
256
+ end
257
+ main_target = user_project.targets.first
258
+
259
+ end
260
+
261
+ state_hash = get_ns_state_hash(user_project)
262
+
263
+ #Add NativeScript group
264
+ pods_path = File.expand_path("..", installer.pods_project.path)
265
+ nativescript_dir_path = File.expand_path("../../../../node_modules/@nativescript/capacitor/embed/ios/NativeScript", installer.pods_project.path)
266
+ src_root = File.expand_path("..", pods_path)
267
+ ns_dir_dest = File.expand_path("NativeScript", src_root)
268
+
269
+ FileUtils.copy_entry(nativescript_dir_path, ns_dir_dest)
270
+
271
+ state_hash['added_dirs'] = [ns_dir_dest]
272
+
273
+ ns_group = user_project.new_group('NativeScript')
274
+ ns_path = ns_dir_dest
275
+ addfiles("#{ns_path}/*", ns_group, main_target)
276
+
277
+ state_hash['added_groups'] = ["NativeScript"]
278
+
279
+ save_ns_state_hash(state_hash, user_project)
280
+
281
+ user_project.save
282
+
283
+ end
284
+
285
+ if (@command == "clean")
286
+ command_restore_state(@path)
287
+ end
288
+
@@ -0,0 +1 @@
1
+ require 'cocoapods-nativescript/command'
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Pod
4
+ describe Command::Nativescript do
5
+ describe 'CLAide' do
6
+ it 'registers it self' do
7
+ Command.parse(%w{ nativescript }).should.be.instance_of Command::Nativescript
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,50 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $:.unshift((ROOT + 'lib').to_s)
4
+ $:.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'bacon'
8
+ require 'mocha-on-bacon'
9
+ require 'pretty_bacon'
10
+ require 'pathname'
11
+ require 'cocoapods'
12
+
13
+ Mocha::Configuration.prevent(:stubbing_non_existent_method)
14
+
15
+ require 'cocoapods_plugin'
16
+
17
+ #-----------------------------------------------------------------------------#
18
+
19
+ module Pod
20
+
21
+ # Disable the wrapping so the output is deterministic in the tests.
22
+ #
23
+ UI.disable_wrap = true
24
+
25
+ # Redirects the messages to an internal store.
26
+ #
27
+ module UI
28
+ @output = ''
29
+ @warnings = ''
30
+
31
+ class << self
32
+ attr_accessor :output
33
+ attr_accessor :warnings
34
+
35
+ def puts(message = '')
36
+ @output << "#{message}\n"
37
+ end
38
+
39
+ def warn(message = '', actions = [])
40
+ @warnings << "#{message}\n"
41
+ end
42
+
43
+ def print(message)
44
+ @output << message
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ #-----------------------------------------------------------------------------#
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-nativescript
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dermendzhiev, Teodor (external - Project)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A short description of cocoapods-nativescript.
42
+ email:
43
+ - tdermendjievft@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - cocoapods-nativescript.gemspec
54
+ - lib/cocoapods-nativescript.rb
55
+ - lib/cocoapods-nativescript/command.rb
56
+ - lib/cocoapods-nativescript/command/nativescript.rb
57
+ - lib/cocoapods-nativescript/gem_version.rb
58
+ - lib/cocoapods_plugin.rb
59
+ - spec/command/nativescript_spec.rb
60
+ - spec/spec_helper.rb
61
+ homepage: https://github.com/EXAMPLE/cocoapods-nativescript
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.0.3.1
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: A longer description of cocoapods-nativescript.
84
+ test_files:
85
+ - spec/command/nativescript_spec.rb
86
+ - spec/spec_helper.rb