m9sh 0.2.4 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60a17049e08e32e54ff30a314c07e746712f7d0cf10c84daef8794c44ac53520
4
- data.tar.gz: 8331db49172a68f2605c2b4cdc6d4feadfafc97a0199143a974f007646ccb69a
3
+ metadata.gz: 713b1bc8189ceef415cd47de7913c446532f80e5b1829ba6f8eddaed9880d694
4
+ data.tar.gz: 0017bef99ea8058bb0e512fcc4dec31605bce16a114bb7677bb33f8d5b8e5cc0
5
5
  SHA512:
6
- metadata.gz: b64d1a98d913d375cdc090d050177164c88037a75286723754a25f1f4b668c2f68873c6730b5baec9e76d3b83769c4e82f5b85a899b6607f57bcb5ad706c7a54
7
- data.tar.gz: e47067baeeed55078b0340573d333ec5d677d45cee791a6b33679a97b095f6194504f12f99647ccfcecf2b8254e22c08ddc2780e016badde22e6a18768ea7422
6
+ metadata.gz: c786785e431d5bdedd42630491de9c75052c31b5772bff05f2bce422097f5528b390bb44e325a4546c5627db51879ce785d356e27386c812c83a823309cbac43
7
+ data.tar.gz: d39c9c20cf68d450ec68734058bbd8596de20b299aa451030a7040fe81f27c898d4df6ffdb284abe43c454562974fcd58069328da07c7bfce4bd9f1d03f925b0
data/lib/m9sh/cli.rb CHANGED
@@ -5,6 +5,7 @@ require_relative "version"
5
5
  require_relative "config"
6
6
  require_relative "registry"
7
7
  require_relative "generator"
8
+ require_relative "setup"
8
9
 
9
10
  module M9sh
10
11
  class CLI < Thor
@@ -41,13 +42,20 @@ module M9sh
41
42
  FileUtils.mkdir_p(config.full_components_path)
42
43
  FileUtils.mkdir_p(config.full_javascript_path)
43
44
 
45
+ # Run additional setup
46
+ puts "\n📦 Setting up project files..."
47
+ Setup.new.run
48
+
44
49
  puts "\n✨ M9sh initialized successfully!"
45
50
  puts " Configuration saved to m9sh.yml"
46
51
  puts " Component path: #{config.components_path}"
47
52
  puts " JavaScript path: #{config.javascript_path}"
48
53
  puts "\nNext steps:"
49
- puts " Run 'bin/m9sh list' to see available components"
50
- puts " Run 'bin/m9sh add button' to add a component"
54
+ puts " 1. Run 'npm install' to install Tailwind CSS v4"
55
+ puts " 2. Run 'npm run build:css' to build your CSS"
56
+ puts " 3. Add <%= stylesheet_link_tag \"application\", \"data-turbo-track\": \"reload\" %> to your layout"
57
+ puts " 4. Run 'bin/m9sh list' to see available components"
58
+ puts " 5. Run 'bin/m9sh add button' to add a component"
51
59
  end
52
60
 
53
61
  desc "add COMPONENT", "Add a component (with dependencies)"
data/lib/m9sh/setup.rb ADDED
@@ -0,0 +1,195 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "json"
5
+
6
+ module M9sh
7
+ class Setup
8
+ attr_reader :root_path
9
+
10
+ def initialize(root_path = Dir.pwd)
11
+ @root_path = root_path
12
+ end
13
+
14
+ def run
15
+ setup_css_file
16
+ setup_package_json
17
+ setup_stimulus_registration
18
+ puts "✨ Additional setup complete!"
19
+ end
20
+
21
+ private
22
+
23
+ def setup_css_file
24
+ css_dir = File.join(@root_path, "app", "assets", "stylesheets")
25
+ FileUtils.mkdir_p(css_dir)
26
+
27
+ css_path = File.join(css_dir, "application.tailwind.css")
28
+
29
+ if File.exist?(css_path)
30
+ puts " ⏭️ application.tailwind.css already exists, skipping..."
31
+ return
32
+ end
33
+
34
+ File.write(css_path, css_template)
35
+ puts " ✅ Created app/assets/stylesheets/application.tailwind.css"
36
+ end
37
+
38
+ def setup_package_json
39
+ package_path = File.join(@root_path, "package.json")
40
+
41
+ if File.exist?(package_path)
42
+ # Update existing package.json
43
+ begin
44
+ package_data = JSON.parse(File.read(package_path))
45
+ package_data["scripts"] ||= {}
46
+
47
+ if package_data["scripts"]["build:css"]
48
+ puts " ⏭️ package.json scripts already configured, skipping..."
49
+ return
50
+ end
51
+
52
+ package_data["scripts"]["build:css"] = "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
53
+ package_data["scripts"]["build:css:watch"] = "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --watch"
54
+ package_data["devDependencies"] ||= {}
55
+ package_data["devDependencies"]["@tailwindcss/cli"] ||= "^4.0.0-beta.3"
56
+
57
+ File.write(package_path, JSON.pretty_generate(package_data))
58
+ puts " ✅ Updated package.json with build:css script"
59
+ rescue JSON::ParserError
60
+ puts " ⚠️ Could not parse package.json, skipping..."
61
+ end
62
+ else
63
+ # Create new package.json
64
+ File.write(package_path, package_json_template)
65
+ puts " ✅ Created package.json"
66
+ end
67
+ end
68
+
69
+ def setup_stimulus_registration
70
+ js_dir = File.join(@root_path, "app", "javascript", "controllers")
71
+ FileUtils.mkdir_p(js_dir)
72
+
73
+ index_path = File.join(js_dir, "index.js")
74
+
75
+ if File.exist?(index_path)
76
+ content = File.read(index_path)
77
+ if content.include?("m9sh")
78
+ puts " ⏭️ Stimulus controllers already registered, skipping..."
79
+ return
80
+ end
81
+
82
+ # Add m9sh controller registration
83
+ if content.include?("eagerLoadControllersFrom")
84
+ # Add after existing eagerLoadControllersFrom
85
+ updated_content = content.sub(
86
+ /(eagerLoadControllersFrom\([^)]+\))/,
87
+ "\\1\neagerLoadControllersFrom(\"m9sh\", application)"
88
+ )
89
+ File.write(index_path, updated_content)
90
+ puts " ✅ Added m9sh controllers to Stimulus registration"
91
+ else
92
+ puts " ⚠️ Could not find controller registration pattern, skipping..."
93
+ end
94
+ else
95
+ # Create new index.js
96
+ File.write(index_path, stimulus_index_template)
97
+ puts " ✅ Created app/javascript/controllers/index.js"
98
+ end
99
+ end
100
+
101
+ # Templates
102
+
103
+ def css_template
104
+ <<~CSS
105
+ @import "tailwindcss";
106
+
107
+ @theme {
108
+ --color-background: 0 0% 100%;
109
+ --color-foreground: 222.2 84% 4.9%;
110
+ --color-card: 0 0% 100%;
111
+ --color-card-foreground: 222.2 84% 4.9%;
112
+ --color-popover: 0 0% 100%;
113
+ --color-popover-foreground: 222.2 84% 4.9%;
114
+ --color-primary: 222.2 47.4% 11.2%;
115
+ --color-primary-foreground: 210 40% 98%;
116
+ --color-secondary: 210 40% 96.1%;
117
+ --color-secondary-foreground: 222.2 47.4% 11.2%;
118
+ --color-muted: 210 40% 96.1%;
119
+ --color-muted-foreground: 215.4 16.3% 46.9%;
120
+ --color-accent: 210 40% 96.1%;
121
+ --color-accent-foreground: 222.2 47.4% 11.2%;
122
+ --color-destructive: 0 84.2% 60.2%;
123
+ --color-destructive-foreground: 210 40% 98%;
124
+ --color-border: 214.3 31.8% 91.4%;
125
+ --color-input: 214.3 31.8% 91.4%;
126
+ --color-ring: 222.2 84% 4.9%;
127
+ --radius-sm: calc(0.5rem - 4px);
128
+ --radius-md: calc(0.5rem - 2px);
129
+ --radius-lg: 0.5rem;
130
+ }
131
+
132
+ @layer base {
133
+ * {
134
+ border-color: hsl(var(--color-border));
135
+ }
136
+ body {
137
+ background-color: hsl(var(--color-background));
138
+ color: hsl(var(--color-foreground));
139
+ }
140
+ }
141
+
142
+ @media (prefers-color-scheme: dark) {
143
+ @theme {
144
+ --color-background: 222.2 84% 4.9%;
145
+ --color-foreground: 210 40% 98%;
146
+ --color-card: 222.2 84% 4.9%;
147
+ --color-card-foreground: 210 40% 98%;
148
+ --color-popover: 222.2 84% 4.9%;
149
+ --color-popover-foreground: 210 40% 98%;
150
+ --color-primary: 210 40% 98%;
151
+ --color-primary-foreground: 222.2 47.4% 11.2%;
152
+ --color-secondary: 217.2 32.6% 17.5%;
153
+ --color-secondary-foreground: 210 40% 98%;
154
+ --color-muted: 217.2 32.6% 17.5%;
155
+ --color-muted-foreground: 215 20.2% 65.1%;
156
+ --color-accent: 217.2 32.6% 17.5%;
157
+ --color-accent-foreground: 210 40% 98%;
158
+ --color-destructive: 0 62.8% 30.6%;
159
+ --color-destructive-foreground: 210 40% 98%;
160
+ --color-border: 217.2 32.6% 17.5%;
161
+ --color-input: 217.2 32.6% 17.5%;
162
+ --color-ring: 212.7 26.8% 83.9%;
163
+ }
164
+ }
165
+ CSS
166
+ end
167
+
168
+ def package_json_template
169
+ JSON.pretty_generate({
170
+ name: "app",
171
+ private: true,
172
+ scripts: {
173
+ "build:css": "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify",
174
+ "build:css:watch": "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --watch"
175
+ },
176
+ devDependencies: {
177
+ "@tailwindcss/cli": "^4.0.0-beta.3"
178
+ }
179
+ })
180
+ end
181
+
182
+ def stimulus_index_template
183
+ <<~JS
184
+ // Import and register all your controllers from the importmap under controllers/*
185
+
186
+ import { application } from "./application"
187
+
188
+ // Eager load all controllers defined in the import map under controllers/**/*_controller
189
+ import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
190
+ eagerLoadControllersFrom("controllers", application)
191
+ eagerLoadControllersFrom("m9sh", application)
192
+ JS
193
+ end
194
+ end
195
+ end
data/lib/m9sh/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module M9sh
4
- VERSION = "0.2.4"
4
+ VERSION = "0.2.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: m9sh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Urbanski
@@ -307,6 +307,7 @@ files:
307
307
  - lib/m9sh/generator.rb
308
308
  - lib/m9sh/registry.rb
309
309
  - lib/m9sh/registry.yml
310
+ - lib/m9sh/setup.rb
310
311
  - lib/m9sh/version.rb
311
312
  - lib/tasks/tailwindcss.rake
312
313
  - m9sh.gemspec