m9sh 0.2.4 → 0.2.5

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: 4999f0b66fd9fcb8c72042aa986a757c6b5a69a17cf8acf650330c22146ecd1f
4
+ data.tar.gz: 48bd5b66a35f216c487ca21a0525a2b89ec6d862a5b0c00c8c157ab0f367310e
5
5
  SHA512:
6
- metadata.gz: b64d1a98d913d375cdc090d050177164c88037a75286723754a25f1f4b668c2f68873c6730b5baec9e76d3b83769c4e82f5b85a899b6607f57bcb5ad706c7a54
7
- data.tar.gz: e47067baeeed55078b0340573d333ec5d677d45cee791a6b33679a97b095f6194504f12f99647ccfcecf2b8254e22c08ddc2780e016badde22e6a18768ea7422
6
+ metadata.gz: bdd1dfed0767fc23ba79aeb3b97946cff5bddcec818ee281362839450a405981070afd813e1139731ccdd65fc3d5ac1e0d1ca8501e535c44f630248ea6c5ceb9
7
+ data.tar.gz: e0affdf72dcacfeac608bd6a0e9fa1fbd3083fbfe23fd0327b839580446412484655d275b133239d23492b420cb28700a125b7771c8bac90b9e2ce30a7509563
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,19 @@ 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"
55
+ puts " 2. Run 'npm run build:css' to build your CSS"
56
+ puts " 3. Run 'bin/m9sh list' to see available components"
57
+ puts " 4. Run 'bin/m9sh add button' to add a component"
51
58
  end
52
59
 
53
60
  desc "add COMPONENT", "Add a component (with dependencies)"
data/lib/m9sh/setup.rb ADDED
@@ -0,0 +1,264 @@
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_tailwind_config
16
+ setup_css_file
17
+ setup_package_json
18
+ setup_stimulus_registration
19
+ puts "✨ Additional setup complete!"
20
+ end
21
+
22
+ private
23
+
24
+ def setup_tailwind_config
25
+ config_path = File.join(@root_path, "tailwind.config.js")
26
+
27
+ if File.exist?(config_path)
28
+ puts " ⏭️ tailwind.config.js already exists, skipping..."
29
+ return
30
+ end
31
+
32
+ File.write(config_path, tailwind_config_template)
33
+ puts " ✅ Created tailwind.config.js"
34
+ end
35
+
36
+ def setup_css_file
37
+ css_dir = File.join(@root_path, "app", "assets", "stylesheets")
38
+ FileUtils.mkdir_p(css_dir)
39
+
40
+ css_path = File.join(css_dir, "application.tailwind.css")
41
+
42
+ if File.exist?(css_path)
43
+ puts " ⏭️ application.tailwind.css already exists, skipping..."
44
+ return
45
+ end
46
+
47
+ File.write(css_path, css_template)
48
+ puts " ✅ Created app/assets/stylesheets/application.tailwind.css"
49
+ end
50
+
51
+ def setup_package_json
52
+ package_path = File.join(@root_path, "package.json")
53
+
54
+ if File.exist?(package_path)
55
+ # Update existing package.json
56
+ begin
57
+ package_data = JSON.parse(File.read(package_path))
58
+ package_data["scripts"] ||= {}
59
+
60
+ if package_data["scripts"]["build:css"]
61
+ puts " ⏭️ package.json scripts already configured, skipping..."
62
+ return
63
+ end
64
+
65
+ package_data["scripts"]["build:css"] = "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
66
+ package_data["devDependencies"] ||= {}
67
+ package_data["devDependencies"]["tailwindcss"] ||= "^3.4.0"
68
+
69
+ File.write(package_path, JSON.pretty_generate(package_data))
70
+ puts " ✅ Updated package.json with build:css script"
71
+ rescue JSON::ParserError
72
+ puts " ⚠️ Could not parse package.json, skipping..."
73
+ end
74
+ else
75
+ # Create new package.json
76
+ File.write(package_path, package_json_template)
77
+ puts " ✅ Created package.json"
78
+ end
79
+ end
80
+
81
+ def setup_stimulus_registration
82
+ js_dir = File.join(@root_path, "app", "javascript", "controllers")
83
+ FileUtils.mkdir_p(js_dir)
84
+
85
+ index_path = File.join(js_dir, "index.js")
86
+
87
+ if File.exist?(index_path)
88
+ content = File.read(index_path)
89
+ if content.include?("m9sh")
90
+ puts " ⏭️ Stimulus controllers already registered, skipping..."
91
+ return
92
+ end
93
+
94
+ # Add m9sh controller registration
95
+ if content.include?("eagerLoadControllersFrom")
96
+ # Add after existing eagerLoadControllersFrom
97
+ updated_content = content.sub(
98
+ /(eagerLoadControllersFrom\([^)]+\))/,
99
+ "\\1\neagerLoadControllersFrom(\"m9sh\", application)"
100
+ )
101
+ File.write(index_path, updated_content)
102
+ puts " ✅ Added m9sh controllers to Stimulus registration"
103
+ else
104
+ puts " ⚠️ Could not find controller registration pattern, skipping..."
105
+ end
106
+ else
107
+ # Create new index.js
108
+ File.write(index_path, stimulus_index_template)
109
+ puts " ✅ Created app/javascript/controllers/index.js"
110
+ end
111
+ end
112
+
113
+ # Templates
114
+
115
+ def tailwind_config_template
116
+ <<~JS
117
+ /** @type {import('tailwindcss').Config} */
118
+ module.exports = {
119
+ content: [
120
+ './app/views/**/*.html.erb',
121
+ './app/helpers/**/*.rb',
122
+ './app/components/**/*.{rb,erb}',
123
+ './app/javascript/**/*.js'
124
+ ],
125
+ theme: {
126
+ extend: {
127
+ colors: {
128
+ border: "hsl(var(--border))",
129
+ input: "hsl(var(--input))",
130
+ ring: "hsl(var(--ring))",
131
+ background: "hsl(var(--background))",
132
+ foreground: "hsl(var(--foreground))",
133
+ primary: {
134
+ DEFAULT: "hsl(var(--primary))",
135
+ foreground: "hsl(var(--primary-foreground))",
136
+ },
137
+ secondary: {
138
+ DEFAULT: "hsl(var(--secondary))",
139
+ foreground: "hsl(var(--secondary-foreground))",
140
+ },
141
+ destructive: {
142
+ DEFAULT: "hsl(var(--destructive))",
143
+ foreground: "hsl(var(--destructive-foreground))",
144
+ },
145
+ muted: {
146
+ DEFAULT: "hsl(var(--muted))",
147
+ foreground: "hsl(var(--muted-foreground))",
148
+ },
149
+ accent: {
150
+ DEFAULT: "hsl(var(--accent))",
151
+ foreground: "hsl(var(--accent-foreground))",
152
+ },
153
+ popover: {
154
+ DEFAULT: "hsl(var(--popover))",
155
+ foreground: "hsl(var(--popover-foreground))",
156
+ },
157
+ card: {
158
+ DEFAULT: "hsl(var(--card))",
159
+ foreground: "hsl(var(--card-foreground))",
160
+ },
161
+ },
162
+ borderRadius: {
163
+ lg: "var(--radius)",
164
+ md: "calc(var(--radius) - 2px)",
165
+ sm: "calc(var(--radius) - 4px)",
166
+ },
167
+ },
168
+ },
169
+ plugins: [],
170
+ }
171
+ JS
172
+ end
173
+
174
+ def css_template
175
+ <<~CSS
176
+ @import "tailwindcss/base";
177
+ @import "tailwindcss/components";
178
+ @import "tailwindcss/utilities";
179
+
180
+ @layer base {
181
+ :root {
182
+ --background: 0 0% 100%;
183
+ --foreground: 222.2 84% 4.9%;
184
+ --card: 0 0% 100%;
185
+ --card-foreground: 222.2 84% 4.9%;
186
+ --popover: 0 0% 100%;
187
+ --popover-foreground: 222.2 84% 4.9%;
188
+ --primary: 222.2 47.4% 11.2%;
189
+ --primary-foreground: 210 40% 98%;
190
+ --secondary: 210 40% 96.1%;
191
+ --secondary-foreground: 222.2 47.4% 11.2%;
192
+ --muted: 210 40% 96.1%;
193
+ --muted-foreground: 215.4 16.3% 46.9%;
194
+ --accent: 210 40% 96.1%;
195
+ --accent-foreground: 222.2 47.4% 11.2%;
196
+ --destructive: 0 84.2% 60.2%;
197
+ --destructive-foreground: 210 40% 98%;
198
+ --border: 214.3 31.8% 91.4%;
199
+ --input: 214.3 31.8% 91.4%;
200
+ --ring: 222.2 84% 4.9%;
201
+ --radius: 0.5rem;
202
+ }
203
+
204
+ .dark {
205
+ --background: 222.2 84% 4.9%;
206
+ --foreground: 210 40% 98%;
207
+ --card: 222.2 84% 4.9%;
208
+ --card-foreground: 210 40% 98%;
209
+ --popover: 222.2 84% 4.9%;
210
+ --popover-foreground: 210 40% 98%;
211
+ --primary: 210 40% 98%;
212
+ --primary-foreground: 222.2 47.4% 11.2%;
213
+ --secondary: 217.2 32.6% 17.5%;
214
+ --secondary-foreground: 210 40% 98%;
215
+ --muted: 217.2 32.6% 17.5%;
216
+ --muted-foreground: 215 20.2% 65.1%;
217
+ --accent: 217.2 32.6% 17.5%;
218
+ --accent-foreground: 210 40% 98%;
219
+ --destructive: 0 62.8% 30.6%;
220
+ --destructive-foreground: 210 40% 98%;
221
+ --border: 217.2 32.6% 17.5%;
222
+ --input: 217.2 32.6% 17.5%;
223
+ --ring: 212.7 26.8% 83.9%;
224
+ }
225
+ }
226
+
227
+ @layer base {
228
+ * {
229
+ @apply border-border;
230
+ }
231
+ body {
232
+ @apply bg-background text-foreground;
233
+ }
234
+ }
235
+ CSS
236
+ end
237
+
238
+ def package_json_template
239
+ JSON.pretty_generate({
240
+ name: "app",
241
+ private: true,
242
+ scripts: {
243
+ "build:css": "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
244
+ },
245
+ devDependencies: {
246
+ tailwindcss: "^3.4.0"
247
+ }
248
+ })
249
+ end
250
+
251
+ def stimulus_index_template
252
+ <<~JS
253
+ // Import and register all your controllers from the importmap under controllers/*
254
+
255
+ import { application } from "./application"
256
+
257
+ // Eager load all controllers defined in the import map under controllers/**/*_controller
258
+ import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
259
+ eagerLoadControllersFrom("controllers", application)
260
+ eagerLoadControllersFrom("m9sh", application)
261
+ JS
262
+ end
263
+ end
264
+ 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.5"
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.5
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