shopify_toolkit 0.1.0 → 0.3.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 +4 -4
- data/README.md +6 -0
- data/exe/shopify-toolkit +12 -0
- data/lib/shopify_toolkit/metafield_statements.rb +1 -1
- data/lib/shopify_toolkit/migration/logging.rb +2 -3
- data/lib/shopify_toolkit/schema.rb +116 -0
- data/lib/shopify_toolkit/version.rb +1 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b5096d0e8a69b382a17ac046866f2386e2c1b06cf5b8c657138dafc1efef67b
|
4
|
+
data.tar.gz: 85d2b5e79156013fcd95a8aa35e21eb6db331d287ffab98d3cfc759ca76f1e98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eeed116a762958bc570bc258f7b22982130becad873278303249b1fddb29fc807ffe1ebbac00f8cff2d96602389e7a39f4a980cdfe97c9bb61cc54c92e38e09
|
7
|
+
data.tar.gz: b7b6f2de4725cc821bfd3f7c6fdac9172491ddfd7b8b70d89ab1c73707608c8b52afb150b50a2bb835e3d107586b19ba976d0526ea0b74bd6d8ca2c89debe0ff
|
data/README.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
A toolkit for working with Custom Shopify Apps built on Rails.
|
4
4
|
|
5
|
+
### Assumptions
|
6
|
+
|
7
|
+
- You are using Rails 7.0 or later
|
8
|
+
- The custom app is only installed on a single store
|
9
|
+
- In order for the schema dump/load to work, you need to have the `shopify_app` gem installed and configured
|
10
|
+
|
5
11
|
## Features/Roadmap
|
6
12
|
|
7
13
|
- [x] Shopify/Matrixify CSV tools
|
data/exe/shopify-toolkit
CHANGED
@@ -54,6 +54,18 @@ class ShopifyToolkit::CommandLine < Thor
|
|
54
54
|
IRB.conf[:IRB_NAME] = basename
|
55
55
|
Result.class_eval { binding.irb(show_code: false) }
|
56
56
|
end
|
57
|
+
|
58
|
+
desc "schema_load", 'Load schema from "config/shopify/schema.rb"'
|
59
|
+
def schema_load
|
60
|
+
require "./config/environment"
|
61
|
+
::Shop.sole.with_shopify_session { ShopifyToolkit::Schema.load! }
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "schema_dump", 'Dump schema to "config/shopify/schema.rb"'
|
65
|
+
def schema_dump
|
66
|
+
require "./config/environment"
|
67
|
+
::Shop.sole.with_shopify_session { ShopifyToolkit::Schema.dump! }
|
68
|
+
end
|
57
69
|
end
|
58
70
|
|
59
71
|
ShopifyToolkit::CommandLine.start(ARGV)
|
@@ -101,8 +101,8 @@ module ShopifyToolkit::MetafieldStatements
|
|
101
101
|
.tap { handle_shopify_admin_client_errors(_1, "metafieldDefinitionDelete.userErrors") }
|
102
102
|
end
|
103
103
|
|
104
|
-
def update_metafield(owner_type, key, namespace: :custom, **options)
|
105
104
|
log_time \
|
105
|
+
def update_metafield(owner_type, key, namespace: :custom, **options)
|
106
106
|
shopify_admin_client
|
107
107
|
.query(
|
108
108
|
# Documentation: https://shopify.dev/docs/api/admin-graphql/2024-10/mutations/metafieldDefinitionUpdate
|
@@ -6,9 +6,8 @@ module ShopifyToolkit::Migration::Logging
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def announce(message)
|
9
|
-
|
10
|
-
|
11
|
-
write "== %s %s" % [text, "=" * length]
|
9
|
+
length = [0, 75 - message.length].max
|
10
|
+
write "== %s %s" % [message, "=" * length]
|
12
11
|
end
|
13
12
|
|
14
13
|
# Takes a message argument and outputs it as is.
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module ShopifyToolkit::Schema
|
2
|
+
extend self
|
3
|
+
include ShopifyToolkit::MetafieldStatements
|
4
|
+
include ShopifyToolkit::Migration::Logging
|
5
|
+
SCHEMA_PATH = "config/shopify/schema.rb"
|
6
|
+
|
7
|
+
def load!
|
8
|
+
path = Rails.root.join(SCHEMA_PATH)
|
9
|
+
|
10
|
+
unless path.exist?
|
11
|
+
logger.warn "Schema file not found at #{path}."
|
12
|
+
return
|
13
|
+
end
|
14
|
+
|
15
|
+
announce "Loading metafield schema from #{path}"
|
16
|
+
say_with_time "Executing schema statements" do
|
17
|
+
load path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def dump!
|
22
|
+
schema_path = Rails.root.join(SCHEMA_PATH)
|
23
|
+
|
24
|
+
announce "Dumping metafield schema to #{schema_path}"
|
25
|
+
say_with_time "Generating schema" do
|
26
|
+
content = generate_schema_content
|
27
|
+
File.write(schema_path, content)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def define(&block)
|
32
|
+
instance_eval(&block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def fetch_definitions
|
36
|
+
query = <<~GRAPHQL
|
37
|
+
query {
|
38
|
+
metafieldDefinitions(first: 250, ownerType: PRODUCT) {
|
39
|
+
nodes {
|
40
|
+
id
|
41
|
+
name
|
42
|
+
key
|
43
|
+
type {
|
44
|
+
name
|
45
|
+
}
|
46
|
+
namespace
|
47
|
+
description
|
48
|
+
validations {
|
49
|
+
name
|
50
|
+
value
|
51
|
+
}
|
52
|
+
capabilities {
|
53
|
+
smartCollectionCondition {
|
54
|
+
enabled
|
55
|
+
}
|
56
|
+
adminFilterable {
|
57
|
+
enabled
|
58
|
+
}
|
59
|
+
}
|
60
|
+
access {
|
61
|
+
admin
|
62
|
+
customerAccount
|
63
|
+
storefront
|
64
|
+
}
|
65
|
+
ownerType
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
GRAPHQL
|
70
|
+
|
71
|
+
result = shopify_admin_client.query(query:).tap { handle_shopify_admin_client_errors(_1) }.body
|
72
|
+
|
73
|
+
result.dig("data", "metafieldDefinitions", "nodes") || []
|
74
|
+
end
|
75
|
+
|
76
|
+
def generate_schema_content
|
77
|
+
definitions = fetch_definitions
|
78
|
+
content = ["ShopifyToolkit::Schema.define do"]
|
79
|
+
|
80
|
+
definitions.each do |defn|
|
81
|
+
owner_type = defn["ownerType"].downcase.pluralize.to_sym
|
82
|
+
key = defn["key"].to_sym
|
83
|
+
type = defn["type"]["name"].to_sym
|
84
|
+
name = defn["name"]
|
85
|
+
namespace = defn["namespace"]&.to_sym
|
86
|
+
description = defn["description"]
|
87
|
+
validations = defn["validations"]&.map { |v| v.transform_keys(&:to_sym) }
|
88
|
+
capabilities = defn["capabilities"]&.transform_keys(&:to_sym)&.transform_values { |v| v.transform_keys(&:to_sym) }
|
89
|
+
|
90
|
+
args = [owner_type, key, type]
|
91
|
+
kwargs = { name: name }
|
92
|
+
kwargs[:namespace] = namespace if namespace && namespace != :custom
|
93
|
+
kwargs[:description] = description if description
|
94
|
+
kwargs[:validations] = validations if validations.present?
|
95
|
+
|
96
|
+
# Only include capabilities if they have non-default values
|
97
|
+
if capabilities.present?
|
98
|
+
has_non_default_capabilities =
|
99
|
+
capabilities.any? do |cap, value|
|
100
|
+
case cap
|
101
|
+
when :smartCollectionCondition, :adminFilterable
|
102
|
+
value[:enabled] == true
|
103
|
+
else
|
104
|
+
true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
kwargs[:capabilities] = capabilities if has_non_default_capabilities
|
108
|
+
end
|
109
|
+
|
110
|
+
content << " create_metafield #{args.map(&:inspect).join(", ")}, #{kwargs.map { |k, v| "#{k}: #{v.inspect}" }.join(", ")}"
|
111
|
+
end
|
112
|
+
|
113
|
+
content << "end"
|
114
|
+
content.join("\n")
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify_toolkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elia Schito
|
8
8
|
- Nebulab Team
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '7'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: thor
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +110,7 @@ files:
|
|
82
110
|
- lib/shopify_toolkit/admin_client.rb
|
83
111
|
- lib/shopify_toolkit/metafield_statements.rb
|
84
112
|
- lib/shopify_toolkit/migration/logging.rb
|
113
|
+
- lib/shopify_toolkit/schema.rb
|
85
114
|
- lib/shopify_toolkit/version.rb
|
86
115
|
- sig/shopify_toolkit.rbs
|
87
116
|
homepage: https://github.com/nebulab/shopify_toolkit?tab=readme-ov-file#readme
|