chrome_extension 0.0.0 → 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 +4 -4
- data/bin/chrome_extension +26 -2
- data/bin/chrome_extension_cli/generator.rb +105 -0
- data/bin/templates/base/base.rb +10 -0
- data/bin/templates/base/icon.png +0 -0
- data/bin/templates/base/popup.html +5 -0
- data/lib/chrome_extension/version.rb +3 -0
- data/lib/chrome_extension.rb +2 -0
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 314aa6d57b39a18245b5281bb69396cb8f23621473a82e09a5419a856e423431
|
|
4
|
+
data.tar.gz: ad6237cfcad20c156f8694fd960176adf1520dea927af6924052c60e50f88a77
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1adf4319b9408151b71d787598a398a9501986953310889cf4a774d18e56209ff589dcd17d996fc4cb70230297565fbeac62a9f8510a49c368fb859d394520f6
|
|
7
|
+
data.tar.gz: d46cde8de2689df0e44a2fa755317cc46f0bb4a64a630999b1b6bbcc41d7f92009da87b44271674e8ae28a83e9ee3131b2e0982eea829620123a9efe3d75f316
|
data/bin/chrome_extension
CHANGED
|
@@ -5,7 +5,7 @@ require 'pry'
|
|
|
5
5
|
require 'json'
|
|
6
6
|
|
|
7
7
|
class ChromeExtensionCLI < Thor
|
|
8
|
-
|
|
8
|
+
include Thor::Actions
|
|
9
9
|
desc "build FILE_PATH", "Builds a chrome extension from your ruby file"
|
|
10
10
|
def build(file_path)
|
|
11
11
|
@generator = ChromeExtensionCLI::Generator.new(file_path)
|
|
@@ -18,8 +18,32 @@ class ChromeExtensionCLI < Thor
|
|
|
18
18
|
@extension_options = @generator.get_extension_options
|
|
19
19
|
say "Extension options: #{JSON.pretty_generate(@extension_options)}"
|
|
20
20
|
end
|
|
21
|
+
|
|
22
|
+
desc "new NAME", "Creates a basic ruby chrome extension project"
|
|
23
|
+
def new(name)
|
|
24
|
+
directory("base", name)
|
|
25
|
+
old_ruby_file = File.join(name, "base.rb")
|
|
26
|
+
new_ruby_file = File.join(name, "#{name}.rb")
|
|
27
|
+
FileUtils.mv old_ruby_file, new_ruby_file
|
|
28
|
+
gsub_file(new_ruby_file, /Base/, name.capitalize)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
desc "-v, --version", "show version"
|
|
32
|
+
def version
|
|
33
|
+
say "ChromeExtension v#{ChromeExtension::VERSION}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.source_root
|
|
37
|
+
File.join(File.dirname(__FILE__), 'templates')
|
|
38
|
+
end
|
|
21
39
|
end
|
|
22
40
|
|
|
23
41
|
require_relative './chrome_extension_cli/generator'
|
|
24
42
|
|
|
25
|
-
|
|
43
|
+
|
|
44
|
+
# Version command seperate from thor for simplicity
|
|
45
|
+
if ["-v", "--version"].include?(ARGV[0])
|
|
46
|
+
puts "ChromeExtension v#{ChromeExtension::VERSION}"
|
|
47
|
+
else
|
|
48
|
+
ChromeExtensionCLI.start(ARGV)
|
|
49
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
class ChromeExtensionCLI
|
|
2
|
+
class Generator
|
|
3
|
+
attr_reader :file_path, :current_location
|
|
4
|
+
def initialize(file_path)
|
|
5
|
+
@file_path = file_path
|
|
6
|
+
@current_location = Dir.pwd
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call
|
|
10
|
+
load_chrome_extension_file
|
|
11
|
+
extract_extension_options
|
|
12
|
+
builds_folder = File.join(current_location, 'builds')
|
|
13
|
+
FileUtils.mkdir_p(builds_folder)
|
|
14
|
+
existing_build_files = Dir.glob(File.join(builds_folder, '*'))
|
|
15
|
+
|
|
16
|
+
formatted_extension_name = format_name(@extension_options[:extension_name])
|
|
17
|
+
index_value = if existing_build_files.any?
|
|
18
|
+
"-#{existing_build_files.count}"
|
|
19
|
+
else
|
|
20
|
+
""
|
|
21
|
+
end
|
|
22
|
+
build_path = File.join(builds_folder, "#{formatted_extension_name}#{index_value}")
|
|
23
|
+
FileUtils.mkdir_p(build_path)
|
|
24
|
+
|
|
25
|
+
manifest_json_path = File.join(build_path, 'manifest.json')
|
|
26
|
+
|
|
27
|
+
popup_file_name = @extension_options[:extension_default_popup].split("/")[-1]
|
|
28
|
+
icon_file_name = @extension_options[:extension_default_icon].split("/")[-1]
|
|
29
|
+
|
|
30
|
+
File.open(manifest_json_path, "w") do |localfile|
|
|
31
|
+
localfile.write <<~MANIFEST
|
|
32
|
+
{
|
|
33
|
+
"name": "#{@extension_options[:extension_name]}",
|
|
34
|
+
"description": "#{@extension_options[:extension_description]}",
|
|
35
|
+
"version": "#{@extension_options[:extension_version]}",
|
|
36
|
+
"manifest_version": #{@extension_options[:extension_manifest_version]},
|
|
37
|
+
"action": {
|
|
38
|
+
"default_popup": "#{popup_file_name}",
|
|
39
|
+
"default_icon": "#{icon_file_name}"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
MANIFEST
|
|
43
|
+
original_popup_path = File.join(current_location, @extension_options[:extension_default_popup])
|
|
44
|
+
build_popup_path = File.join(build_path, popup_file_name)
|
|
45
|
+
FileUtils.cp(original_popup_path, build_popup_path)
|
|
46
|
+
|
|
47
|
+
original_icon_path = File.join(current_location, @extension_options[:extension_default_icon])
|
|
48
|
+
build_icon_path = File.join(build_path, icon_file_name)
|
|
49
|
+
FileUtils.cp(original_icon_path, build_icon_path)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Side option for "show" CLI command
|
|
56
|
+
def get_extension_options
|
|
57
|
+
load_chrome_extension_file
|
|
58
|
+
extract_extension_options
|
|
59
|
+
end
|
|
60
|
+
private
|
|
61
|
+
def extract_extension_options
|
|
62
|
+
chrome_extension_class = ChromeExtension.subclasses.first
|
|
63
|
+
extension_name = chrome_extension_class.instance_variable_get(:@extension_name)
|
|
64
|
+
extension_description = chrome_extension_class.instance_variable_get(:@description)
|
|
65
|
+
extension_version = chrome_extension_class.instance_variable_get(:@version)
|
|
66
|
+
extension_manifest_version = chrome_extension_class.instance_variable_get(:@manifest_version)
|
|
67
|
+
extension_default_popup = chrome_extension_class.instance_variable_get(:@default_popup)
|
|
68
|
+
extension_default_icon = chrome_extension_class.instance_variable_get(:@default_icon)
|
|
69
|
+
|
|
70
|
+
@extension_options = {
|
|
71
|
+
extension_name: extension_name,
|
|
72
|
+
extension_description: extension_description,
|
|
73
|
+
extension_version: extension_version,
|
|
74
|
+
extension_manifest_version: extension_manifest_version,
|
|
75
|
+
extension_default_popup: extension_default_popup,
|
|
76
|
+
extension_default_icon: extension_default_icon,
|
|
77
|
+
}
|
|
78
|
+
@extension_options
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def load_chrome_extension_file
|
|
82
|
+
ruby_extension_file = File.join(current_location, file_path)
|
|
83
|
+
if !File.exist?(ruby_extension_file)
|
|
84
|
+
puts "File does not exist!"
|
|
85
|
+
puts "Make sure you pass in a correct ruby file with your chrome extension class"
|
|
86
|
+
return
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
require_relative ruby_extension_file
|
|
90
|
+
|
|
91
|
+
if !ChromeExtension.subclasses.any?
|
|
92
|
+
puts "You must create a ruby class that inherits from ChromeExtension"
|
|
93
|
+
puts "Heres an example"
|
|
94
|
+
puts "class MyChromeExtension < ChromeExtension"
|
|
95
|
+
puts "end"
|
|
96
|
+
return
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def format_name(name)
|
|
101
|
+
# Example -> example
|
|
102
|
+
name.split(" ").join("_").downcase
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
Binary file
|
data/lib/chrome_extension.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chrome_extension
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Indigo Tech Tutorials
|
|
@@ -31,7 +31,12 @@ extensions: []
|
|
|
31
31
|
extra_rdoc_files: []
|
|
32
32
|
files:
|
|
33
33
|
- bin/chrome_extension
|
|
34
|
+
- bin/chrome_extension_cli/generator.rb
|
|
35
|
+
- bin/templates/base/base.rb
|
|
36
|
+
- bin/templates/base/icon.png
|
|
37
|
+
- bin/templates/base/popup.html
|
|
34
38
|
- lib/chrome_extension.rb
|
|
39
|
+
- lib/chrome_extension/version.rb
|
|
35
40
|
homepage: https://rubygems.org/gems/chrome_extension
|
|
36
41
|
licenses:
|
|
37
42
|
- MIT
|