web-ext-native-app-packer 1.0.0

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
+ SHA1:
3
+ metadata.gz: '09c7d21d2f9ac671ad4e5e2b8b73be3ac1267fc3'
4
+ data.tar.gz: fcee4f7e4650138b70dc39fb715aebccaf7798a0
5
+ SHA512:
6
+ metadata.gz: b2836d75eb7b1df1e45fa40799156b44241c8c500dda1dde5943e5c8bec9e2be911e5e3f314289595b263d98cf02e0ef0e8c669bb66f0479aec34f6574386f88
7
+ data.tar.gz: fcd3e01e7ba510a2d74587672695be4517de8b54cc5dbe2ebd6923b0ce0b010dd131793320558c4e548ad3c0758175421c43783dab52e028df2b896667752be1
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+
2
+ # web ext native app packer
3
+
4
+ A tool to pack web extension native application.
5
+
6
+ # usage
7
+
8
+ 1. install gem
9
+ ```shell
10
+ gem install web-ext-native-app-packer
11
+ ```
12
+
13
+ 2. create pack.yaml in your native App directory
14
+ ```yaml
15
+ app_name: 'awesome_app'
16
+ app_description: 'description of awesome_app'
17
+ app_path: 'main.rb'
18
+ execute_cmd: 'ruby'
19
+ # your web extension's firefox extension id
20
+ extension_id: 'awesome_app@example.org'
21
+ # your web extension's chrome extension origin (format => "chrome-extension://$id/")
22
+ extension_origin: 'chrome-extension://abtwertkbasdftllwerwh/'
23
+ ```
24
+
25
+ 3. run pack command
26
+ ```shell
27
+ # web-ext-native-app-packer $native-app-directory $output-dir
28
+ web-ext-native-app-packer my-extension/native-app dist
29
+ ```
30
+
31
+
32
+ # result
33
+ ```shell
34
+ > tree ./dist
35
+ ./dist/
36
+ ├── awesome-app-linux-chrome.zip
37
+ ├── awesome-app-linux-chromium.zip
38
+ ├── awesome-app-linux-firefox.zip
39
+ ├── awesome-app-osx-chrome.zip
40
+ ├── awesome-app-osx-chromium.zip
41
+ ├── awesome-app-osx-firefox.zip
42
+ ├── awesome-app-windows-chrome.zip
43
+ ├── awesome-app-windows-chromium.zip
44
+ └── awesome-app-windows-firefox.zip
45
+ ```
46
+
47
+ It will generate some file to help extension user to Install(uninstall) native application
48
+
49
+ ```
50
+ # Windows
51
+ app_loader.bat # load native application
52
+ manifest.json # native application's manifest file
53
+ install.bat # install script
54
+ uninstall.bat # uninstall script
55
+
56
+ # Linux or OSX
57
+ manifest.json # native application's manifest file
58
+ install.sh # install script
59
+ uninstall.sh # uninstall script
60
+ ```
61
+
62
+
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def print_help
4
+ puts "Usage: web-ext-native-app-packer $native_app_dir $output_dir"
5
+ end
6
+
7
+ if ARGV.length != 2
8
+ print_help
9
+ exit 1
10
+ end
11
+
12
+ dir = ENV['PWD']
13
+ project_dir, output_dir = ARGV
14
+ project_dir = File.expand_path(project_dir, dir)
15
+ output_dir = File.expand_path(output_dir, dir)
16
+
17
+ def exit_if_not_exist(filename)
18
+ unless File.exist? filename
19
+ puts "Error: #{filename} not exist."
20
+ exit 1
21
+ end
22
+ end
23
+
24
+ exit_if_not_exist(project_dir)
25
+ exit_if_not_exist(output_dir)
26
+
27
+ yaml_path = File.join(project_dir, 'pack.yaml')
28
+ exit_if_not_exist(yaml_path)
29
+
30
+ require 'yaml'
31
+ require 'ostruct'
32
+ require File.expand_path('../../lib/web-ext-native-app-packer', __FILE__)
33
+
34
+ yaml = YAML.load_file(yaml_path)
35
+ input = OpenStruct.new(yaml)
36
+ input.project_dir = project_dir
37
+ input.output_dir = output_dir
38
+
39
+ WebExtNativeAppPacker.perform(input)
data/lib/pack.sh ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ input_path=$1
4
+ output_path=$2
5
+
6
+ cd $input_path
7
+ zip -r $output_path *
8
+ cd ..
9
+ rm -rf $input_path
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ <%= @v.execute_cmd %> "%~dp0/<%= @v.app_path %>" %*
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env bash
2
+
3
+ APP_NAME="<%= @v.app_name %>"
4
+ DIR=$(dirname $(realpath "$0"))
5
+
6
+ # Chrome
7
+ if [ "$(whoami)" = "root" ]; then
8
+ TARGET_DIR="<%= @v.target_path_system %>"
9
+ else
10
+ TARGET_DIR="<%= @v.target_path_user %>"
11
+ fi
12
+
13
+ # create directory
14
+ mkdir -p "$TARGET_DIR"
15
+
16
+ # copy to manifest file to target dir
17
+ cp "$DIR/manifest.json" "$TARGET_DIR/${APP_NAME}.json"
18
+
19
+ # Update host path in the manifest.
20
+ APP_PATH=$DIR/app.rb
21
+ ESCAPED_APP_PATH=${APP_PATH////\\/}
22
+ sed -i -e "s/APP_PATH/$ESCAPED_APP_PATH/" "$TARGET_DIR/$APP_NAME.json"
23
+
24
+ # set permissions
25
+ chmod o+r "$TARGET_DIR/${APP_NAME}.json"
26
+
27
+ echo "[Chrome] Native messaging host $APP_NAME has been installed."
@@ -0,0 +1 @@
1
+ REG ADD "<%= @v.target_path_user %>\<%= @v.app_name %>" /ve /t REG_SZ /d "%~dp0manifest.json" /f
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "<%= @v.app_name %>",
3
+ "description": "<%= @v.app_description %>",
4
+ "path": "<%= @v.app_path %>",
5
+ "type": "stdio",
6
+ "<%= @v.white_list_key %>": [ "<%= @v.extension_identify %>" ]
7
+ }
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+
3
+ APP_NAME="<%= @v.app_name %>"
4
+
5
+ if [ "$(whoami)" = "root" ]; then
6
+ TARGET_DIR="<%= @v.target_path_system %>"
7
+ else
8
+ TARGET_DIR="<%= @v.target_path_user %>"
9
+ fi
10
+
11
+ rm "$TARGET_DIR/${APP_NAME}.json"
12
+ echo "Native messaging host $APP_NAME has been uninstalled."
@@ -0,0 +1,2 @@
1
+ REG DELETE "<%= @v.target_path_system %>\<%= @v.app_name %>" /f
2
+ REG DELETE "<%= @v.target_path_user %>\<%= @v.app_name %>" /f
@@ -0,0 +1,224 @@
1
+
2
+ require 'ostruct'
3
+
4
+ module WebExtNativeAppPacker
5
+
6
+ TARGET_PATH_OSX = {
7
+ chrome: {
8
+ system: '/Library/Google/Chrome/NativeMessagingHosts',
9
+ user: '$HOME/Library/Application Support/Google/Chrome/NativeMessagingHosts'
10
+ },
11
+ chromium: {
12
+ system: '/Library/Application Support/Chromium/NativeMessagingHosts',
13
+ user: '$HOME/Library/Application Support/Chromium/NativeMessagingHosts'
14
+ },
15
+ firefox: {
16
+ system: '/Library/Application Support/Mozilla/NativeMessagingHosts',
17
+ user: '$HOME/Library/Application Support/Mozilla/NativeMessagingHosts'
18
+ }
19
+ }
20
+
21
+ TARGET_PATH_LINUX = {
22
+ chrome: {
23
+ system: '/etc/opt/chrome/native-messaging-hosts',
24
+ user: '$HOME/.config/google-chrome/NativeMessagingHosts'
25
+ },
26
+ chromium: {
27
+ system: '/etc/chromium/native-messaging-hosts',
28
+ user: '$HOME/.config/chromium/NativeMessagingHosts'
29
+ },
30
+ firefox: {
31
+ system: '/usr/lib64/mozilla/native-messaging-hosts',
32
+ user: '$HOME/.mozilla/native-messaging-hosts'
33
+ }
34
+ }
35
+
36
+ TARGET_PATH_WINDOWS = {
37
+ chrome: {
38
+ system: 'HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts',
39
+ user: 'HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts'
40
+ },
41
+ chromium: {
42
+ system: 'HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts',
43
+ user: 'HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts'
44
+ },
45
+ firefox: {
46
+ system: 'HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\NativeMessagingHosts',
47
+ user: 'HKEY_CURRENT_USER\SOFTWARE\Mozilla\NativeMessagingHosts'
48
+ }
49
+ }
50
+
51
+ def self.perform(input)
52
+ render_manifest(input)
53
+ render_app_loader(input)
54
+ render_unix_like_install_script(input)
55
+ render_unix_like_uninstall_script(input)
56
+ render_windows_install_script(input)
57
+ render_windows_uninstall_script(input)
58
+ copy_project_file(input)
59
+ zip_folds(input)
60
+ end
61
+
62
+ def self.copy_project_file(input)
63
+ input_path = File.join(input.project_dir, '*')
64
+ each_item do |platform, browser_name|
65
+ output_path = File.join(
66
+ input.output_dir,
67
+ [platform, browser_name].join('-'),
68
+ )
69
+ `cp -r #{input_path} #{output_path}`
70
+ end
71
+ end
72
+
73
+ def self.zip_folds(input)
74
+ each_item do |platform, browser_name|
75
+ name = input.app_name.gsub('_', '-').gsub('.', '-')
76
+ input_fold = File.join(
77
+ input.output_dir,
78
+ [platform, browser_name].join('-'),
79
+ )
80
+ archive_path = File.join(
81
+ input.output_dir,
82
+ [[name, platform, browser_name].join('-'), 'zip'].join('.')
83
+ )
84
+ pack_sh = File.expand_path('../pack.sh', __FILE__)
85
+ `#{pack_sh} #{input_fold} #{archive_path}`
86
+ end
87
+ end
88
+
89
+ def self.render_unix_like_install_script(input)
90
+ render_script(input,
91
+ erb_path: File.expand_path('../template/install-unix-like.sh.erb', __FILE__),
92
+ platforms: ['osx', 'linux'],
93
+ filename: 'install.sh')
94
+ end
95
+
96
+ def self.render_unix_like_uninstall_script(input)
97
+ render_script(input,
98
+ erb_path: File.expand_path('../template/uninstall-unix-like.sh.erb', __FILE__),
99
+ platforms: ['osx', 'linux'],
100
+ filename: 'uninstall.sh')
101
+ end
102
+
103
+ def self.render_windows_install_script(input)
104
+ render_script(input,
105
+ erb_path: File.expand_path('../template/install-windows.bat.erb', __FILE__),
106
+ platforms: ['windows'],
107
+ filename: 'install.bat')
108
+ end
109
+
110
+ def self.render_windows_uninstall_script(input)
111
+ render_script(input,
112
+ erb_path: File.expand_path('../template/uninstall-windows.bat.erb', __FILE__),
113
+ platforms: ['windows'],
114
+ filename: 'uninstall.bat')
115
+ end
116
+
117
+ def self.render_script(input, erb_path:, platforms:, filename:)
118
+ each_item do |platform, browser_name|
119
+ if platforms.include?(platform)
120
+ target_path = get_target_path(platform, browser_name)
121
+ v = OpenStruct.new({
122
+ app_name: input.app_name,
123
+ target_path_system: target_path[:system],
124
+ target_path_user: target_path[:user]
125
+ })
126
+ out_path = File.join(
127
+ input.output_dir,
128
+ [platform, browser_name].join('-'),
129
+ filename
130
+ )
131
+ Helper.render(v, erb_path, out_path)
132
+ end
133
+ end
134
+ end
135
+
136
+ def self.get_target_path(platform, browser_name)
137
+ dict = \
138
+ case platform
139
+ when 'osx' then TARGET_PATH_OSX
140
+ when 'linux' then TARGET_PATH_LINUX
141
+ when 'windows'then TARGET_PATH_WINDOWS
142
+ end
143
+ dict[browser_name.to_sym]
144
+ end
145
+
146
+
147
+ def self.render_app_loader(input)
148
+ erb_path = File.expand_path('../template/app-loader.bat.erb', __FILE__)
149
+ each_item do |platform, browser_name|
150
+ if platform == 'windows'
151
+ v = OpenStruct.new({
152
+ execute_cmd: input.execute_cmd,
153
+ app_path: input.app_path
154
+ })
155
+ out_path = File.join(
156
+ input.output_dir,
157
+ [platform, browser_name].join('-'),
158
+ 'app_loader.bat'
159
+ )
160
+ Helper.render(v, erb_path, out_path)
161
+ end
162
+ end
163
+ end
164
+
165
+ def self.render_manifest(input)
166
+ erb_path = File.expand_path('../template/manifest.json.erb', __FILE__)
167
+ each_item do |platform, browser_name|
168
+ v = OpenStruct.new({
169
+ app_name: input.app_name,
170
+ app_description: input.app_description
171
+ })
172
+ if browser_name == 'firefox'
173
+ v.white_list_key = 'allowed_extensions'
174
+ v.extension_identify = input['extension_id']
175
+ else
176
+ v.white_list_key = 'allowed_origins'
177
+ v.extension_identify = input['extension_origin']
178
+ end
179
+
180
+ if platform == 'windows'
181
+ v.app_path = 'app_loader.bat'
182
+ else
183
+ v.app_path = 'APP_PATH'
184
+ end
185
+
186
+ out_path = File.join(
187
+ input.output_dir,
188
+ [platform, browser_name].join('-'),
189
+ 'manifest.json'
190
+ )
191
+ Helper.render(v, erb_path, out_path)
192
+ end
193
+ end
194
+
195
+ def self.each_item
196
+ ['osx', 'linux', 'windows'].each do |platform|
197
+ ['chrome', 'chromium', 'firefox'].each do |browser_name|
198
+ yield platform, browser_name
199
+ end
200
+ end
201
+ end
202
+
203
+ module Helper
204
+ require 'erb'
205
+ require 'fileutils'
206
+ def self.render(v, erb_path, out_path)
207
+ mkdir(out_path)
208
+ @v = v
209
+ b = binding
210
+ erb = ::ERB.new(File.new(erb_path).read)
211
+ File.open(out_path, 'w') do |f|
212
+ f.write erb.result(b)
213
+ end
214
+ end
215
+
216
+ def self.mkdir(out_path)
217
+ dir = out_path[0, out_path.rindex('/')]
218
+ unless File.exist?(dir)
219
+ FileUtils.mkdir_p(dir)
220
+ end
221
+ end
222
+ end
223
+
224
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: web-ext-native-app-packer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mika
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: " web extension native application packer!\n"
14
+ email: Mika@nothing.org
15
+ executables:
16
+ - web-ext-native-app-packer
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - bin/web-ext-native-app-packer
22
+ - lib/pack.sh
23
+ - lib/template/app-loader.bat.erb
24
+ - lib/template/install-unix-like.sh.erb
25
+ - lib/template/install-windows.bat.erb
26
+ - lib/template/manifest.json.erb
27
+ - lib/template/uninstall-unix-like.sh.erb
28
+ - lib/template/uninstall-windows.bat.erb
29
+ - lib/web-ext-native-app-packer.rb
30
+ homepage: https://github.com/mika-cn/web-ext-native-app-packer
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.6.11
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: web extension native application packer!
54
+ test_files: []