next_rails_scaffold 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35a1af872af2ffdab09af7df8cf1e5f337554642acd6e9325b9cf112ac4ff76c
|
4
|
+
data.tar.gz: 811159cc9f59924938ebeacfab6ce6ab39fd225c563f5f75babaf2d64ee0b418
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8904f7044947b2f53e55f71f37d7f47afe51b887f46fff09efb2b62e999aa5361d2f931c7601e27a35f5d4d3b51cf185cc0e63542e77b84665cfafd5d5d82d27
|
7
|
+
data.tar.gz: 1202d6c99bc7bc359796e76d1367379b08f6e458f179ae43bf6238cdb8f486560ce0fa6c78b173ec4ca2c1d2b5fc830cda475a5232172b7b02e07a2ace8feb6f
|
@@ -1,20 +1,46 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
PackageManager = Struct.new(:fetch, :run, :add, :lock_file) do
|
4
|
+
def to_s = fetch
|
5
|
+
end
|
6
|
+
|
3
7
|
module Rails
|
4
8
|
class NextRailsScaffoldGenerator < Rails::Generators::NamedBase
|
5
9
|
include ::NextRailsScaffold::Actions
|
6
10
|
|
7
11
|
source_root File.expand_path("templates", __dir__)
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
13
|
+
PACKAGE_MANAGERS = {
|
14
|
+
"npm" => PackageManager.new("npx", "npm run", "npm install", "package-lock.json"),
|
15
|
+
"yarn" => PackageManager.new("yarn dlx", "yarn", "yarn add", "yarn.lock"),
|
16
|
+
"pnpm" => PackageManager.new("pnpm dlx", "pnpm", "pnpm add", "pnpm-lock.yaml"),
|
17
|
+
"bun" => PackageManager.new("bunx", "bun run", "bun add", "bun.lock.json")
|
18
|
+
}.freeze
|
19
|
+
NODE_REQUIRED_VERSION = ENV.fetch("NODE_REQUIRED_VERSION", ">= 18.20")
|
20
|
+
NEXT_VERSION = ENV.fetch("NEXT_VERSION", "15.1.6")
|
12
21
|
|
13
22
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
23
|
+
class_option :package_manager, type: :string, desc: "Package manager to use for frontend project"
|
24
|
+
class_option :skip_build, type: :boolean, default: false, desc: "Skip running Next.js build"
|
25
|
+
class_option :skip_routes, type: :boolean, default: false, desc: "Skip adding resources to routes.rb"
|
26
|
+
|
27
|
+
attr_accessor :selected_package_manager
|
14
28
|
|
15
29
|
def initialize(args, *options) # :nodoc:
|
16
30
|
super
|
31
|
+
|
17
32
|
self.attributes = shell.base.attributes
|
33
|
+
|
34
|
+
package_manager = shell.base.options[:package_manager]
|
35
|
+
until PACKAGE_MANAGERS.keys.include?(package_manager)
|
36
|
+
puts "Invalid package manager" unless package_manager.nil?
|
37
|
+
package_manager = ask(
|
38
|
+
"Which package manager do you want to use? " \
|
39
|
+
"(#{PACKAGE_MANAGERS.keys.to_sentence(words_connector: " or ")}): "
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
self.selected_package_manager = PACKAGE_MANAGERS[package_manager]
|
18
44
|
end
|
19
45
|
|
20
46
|
# Properly nests namespaces passed into a generator
|
@@ -31,12 +57,12 @@ module Rails
|
|
31
57
|
# end
|
32
58
|
# end
|
33
59
|
def add_resource_route
|
34
|
-
return if options[:actions].present?
|
60
|
+
return if options[:actions].present? || options[:skip_routes]
|
35
61
|
|
36
62
|
route "resources :#{file_name.pluralize}", namespace: regular_class_path, scope: "/api"
|
37
63
|
end
|
38
64
|
|
39
|
-
# Check Javascript
|
65
|
+
# Check Javascript dependencies and create a new Next.js project. Install the the useful packages and create the
|
40
66
|
# scaffold code for frontend application.
|
41
67
|
def create_frontend_project
|
42
68
|
return say_status :remove, "skip frontend folder", :yellow if shell.base.behavior == :revoke
|
@@ -52,8 +78,10 @@ module Rails
|
|
52
78
|
|
53
79
|
language = File.exist?("tsconfig.json") ? "typescript" : "javascript"
|
54
80
|
|
55
|
-
run("
|
56
|
-
|
81
|
+
run("#{selected_package_manager} hygen scaffold #{language} #{name} #{mapped_attributes.join(" ")}")
|
82
|
+
if !options[:skip_build] && yes?("Do you want to build your Next.js project? (y/N)")
|
83
|
+
run("#{selected_package_manager.run} build")
|
84
|
+
end
|
57
85
|
end
|
58
86
|
end
|
59
87
|
|
@@ -83,16 +111,17 @@ module Rails
|
|
83
111
|
def create_next_app!
|
84
112
|
return if File.exist?("package.json")
|
85
113
|
|
86
|
-
run(
|
87
|
-
|
88
|
-
|
114
|
+
run(
|
115
|
+
"#{selected_package_manager.fetch} create-next-app@#{NEXT_VERSION} . " \
|
116
|
+
"--no-app --src-dir --import-alias \"@/*\""
|
117
|
+
)
|
89
118
|
end
|
90
119
|
|
91
120
|
def install_hygen!
|
92
121
|
return if Dir.exist?("_templates")
|
93
122
|
|
94
|
-
run("
|
95
|
-
run("
|
123
|
+
run("#{selected_package_manager.add} -D hygen hygen-add")
|
124
|
+
run("#{selected_package_manager} hygen-add next-rails-scaffold")
|
96
125
|
end
|
97
126
|
|
98
127
|
def mapped_attributes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: next_rails_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raphael Araújo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|