layered_stack 0.0.2 → 0.0.4
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/assets/page.js +1 -1
- data/lib/layered_stack/commands/create_command.rb +53 -33
- data/lib/layered_stack/commands/start_command.rb +17 -12
- data/lib/layered_stack/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6919ea27bbae60e44f91632de5468b13d525a44a55d3b95d768bd2516fd4c8c5
|
4
|
+
data.tar.gz: a1aec4ec02a336ea73c7c5be3cb41083ee95566b62be970a160b35983205e905
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f667ee0d4e7f5a05787fc4531c92d79c730b0b541c145525aeb675ec973120e483a143b61caba6903c7b00cfa4f2db5864213e58d8664ae2e53921886cac22f1
|
7
|
+
data.tar.gz: e91a6f41a8b8d1aed68aacdad4990fa6b81818a6389c9522fe230563c7738b22a874a99cd2a839ffd5f6f579a914ed7fb51baa0f64ca450b366607e6297dac43
|
data/assets/page.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'thor'
|
5
|
+
require 'logger'
|
5
6
|
|
6
7
|
module LayeredStack
|
7
8
|
module Cli
|
@@ -11,12 +12,16 @@ module LayeredStack
|
|
11
12
|
|
12
13
|
FRONTEND_DIR = "frontend"
|
13
14
|
|
15
|
+
def self.asset_path(relative_path)
|
16
|
+
File.expand_path("../../../../assets/#{relative_path}", __FILE__)
|
17
|
+
end
|
18
|
+
|
14
19
|
ASSET_FILES = {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
asset_path("tailwind.config.js") => "frontend/tailwind.config.js",
|
21
|
+
asset_path("layout.js") => "frontend/src/app/layout.js",
|
22
|
+
asset_path("page.js") => "frontend/src/app/page.js",
|
23
|
+
asset_path("images/logo_dark.svg") => "frontend/src/app/logo_dark.svg",
|
24
|
+
asset_path("images/logo_light.svg") => "frontend/src/app/logo_light.svg",
|
20
25
|
}
|
21
26
|
|
22
27
|
LOGO_FILES = {
|
@@ -30,23 +35,27 @@ module LayeredStack
|
|
30
35
|
|
31
36
|
no_commands do
|
32
37
|
def execute
|
33
|
-
|
38
|
+
logger.info("> layered_stack/create")
|
34
39
|
remove_existing_frontend
|
35
40
|
run_create_next_app
|
36
41
|
Dir.chdir(FRONTEND_DIR) do
|
37
42
|
install_dependencies
|
38
43
|
update_package_json
|
39
44
|
end
|
40
|
-
|
45
|
+
copy_asset_files
|
41
46
|
copy_logo_files
|
42
|
-
|
47
|
+
print_next_step
|
43
48
|
end
|
44
49
|
|
45
50
|
private
|
46
51
|
|
52
|
+
def logger
|
53
|
+
@logger ||= Logger.new(STDOUT)
|
54
|
+
end
|
55
|
+
|
47
56
|
def remove_existing_frontend
|
48
57
|
if Dir.exist?(FRONTEND_DIR)
|
49
|
-
|
58
|
+
logger.info("\n# Removing existing /#{FRONTEND_DIR} directory")
|
50
59
|
FileUtils.rm_rf(FRONTEND_DIR)
|
51
60
|
end
|
52
61
|
end
|
@@ -57,60 +66,71 @@ module LayeredStack
|
|
57
66
|
end
|
58
67
|
|
59
68
|
def install_dependencies
|
60
|
-
|
61
|
-
|
62
|
-
|
69
|
+
dependencies = [
|
70
|
+
"next-themes",
|
71
|
+
"@heroicons/react@latest",
|
72
|
+
"@layeredstack/ui@latest"
|
73
|
+
]
|
74
|
+
dependencies.each do |dep|
|
75
|
+
run_command("npm install #{dep}", "Installing #{dep}")
|
76
|
+
end
|
63
77
|
end
|
64
78
|
|
65
79
|
def update_package_json
|
66
|
-
|
80
|
+
logger.info("# Updating package.json to change the port to 3001")
|
67
81
|
update_file("package.json", '"dev": "next dev"', '"dev": "next dev -p 3001"')
|
68
82
|
update_file("package.json", '"start": "next start"', '"start": "next start -p 3001"')
|
69
83
|
end
|
70
84
|
|
71
|
-
def
|
72
|
-
|
73
|
-
|
74
|
-
ASSET_FILES.each do |src, dest|
|
75
|
-
FileUtils.cp(src, dest)
|
76
|
-
end
|
85
|
+
def copy_asset_files
|
86
|
+
logger.info("\n# Copying asset files to the frontend directory")
|
87
|
+
copy_files(ASSET_FILES)
|
77
88
|
end
|
78
89
|
|
79
90
|
def copy_logo_files
|
80
|
-
|
91
|
+
logger.info("\n# Copying logo files to the frontend directory")
|
92
|
+
copy_files(LOGO_FILES) { |src, dest| copy_logo_file(src, dest) }
|
93
|
+
end
|
81
94
|
|
82
|
-
|
83
|
-
|
95
|
+
def copy_files(files)
|
96
|
+
files.each do |src, dest|
|
97
|
+
if block_given?
|
98
|
+
yield(src, dest)
|
99
|
+
else
|
100
|
+
FileUtils.cp(src, dest)
|
101
|
+
end
|
84
102
|
end
|
85
103
|
end
|
86
104
|
|
87
105
|
def copy_logo_file(src, dest)
|
88
106
|
if File.exist?(src)
|
89
|
-
|
107
|
+
logger.info("User provided logo exists in assets, copying #{src} to #{dest}")
|
90
108
|
FileUtils.cp(src, dest)
|
91
109
|
else
|
92
110
|
template_src = ASSET_FILES.find { |k, _| k.include?(File.basename(src)) }&.first
|
93
111
|
if template_src
|
94
|
-
|
112
|
+
logger.info("No user provided logo found in 'assets/images/', copying default logo from #{template_src} to #{dest}")
|
95
113
|
FileUtils.cp(template_src, dest)
|
96
114
|
else
|
97
|
-
|
115
|
+
logger.warn("Default logo file #{src} not found")
|
98
116
|
end
|
99
117
|
end
|
100
118
|
end
|
101
119
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
120
|
+
def run_command(command, message)
|
121
|
+
logger.info(message)
|
122
|
+
system(command)
|
105
123
|
end
|
106
124
|
|
107
|
-
def
|
108
|
-
|
109
|
-
|
125
|
+
def update_file(file, old_content, new_content)
|
126
|
+
content = File.read(file)
|
127
|
+
new_content = content.gsub(old_content, new_content)
|
128
|
+
File.write(file, new_content)
|
110
129
|
end
|
111
130
|
|
112
|
-
def
|
113
|
-
|
131
|
+
def print_next_step
|
132
|
+
logger.info("\n# Next step:")
|
133
|
+
logger.info("bundle exec layered_stack start")
|
114
134
|
end
|
115
135
|
end
|
116
136
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'thor'
|
2
4
|
require 'logger'
|
3
5
|
|
@@ -5,6 +7,9 @@ module LayeredStack
|
|
5
7
|
module Cli
|
6
8
|
module Commands
|
7
9
|
class StartCommand < Thor
|
10
|
+
FRONTEND_DIR = "frontend"
|
11
|
+
LOCALHOST_URL = "http://localhost:3001"
|
12
|
+
|
8
13
|
def self.execute
|
9
14
|
new.execute
|
10
15
|
end
|
@@ -26,36 +31,36 @@ module LayeredStack
|
|
26
31
|
end
|
27
32
|
|
28
33
|
def change_directory
|
29
|
-
if Dir.exist?(
|
34
|
+
if Dir.exist?(FRONTEND_DIR)
|
30
35
|
begin
|
31
|
-
Dir.chdir(
|
32
|
-
logger.info("Changed directory to '
|
36
|
+
Dir.chdir(FRONTEND_DIR)
|
37
|
+
logger.info("Changed directory to '#{FRONTEND_DIR}'")
|
33
38
|
true
|
34
39
|
rescue => e
|
35
40
|
logger.error("Failed to change directory: #{e.message}")
|
36
41
|
false
|
37
42
|
end
|
38
43
|
else
|
39
|
-
logger.error("Directory '
|
44
|
+
logger.error("Directory '#{FRONTEND_DIR}' does not exist")
|
40
45
|
false
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
49
|
def open_browser
|
45
50
|
logger.info("\n# Opening the browser")
|
46
|
-
|
47
|
-
logger.info("Browser opened successfully")
|
48
|
-
else
|
49
|
-
logger.error("Failed to open the browser")
|
50
|
-
end
|
51
|
+
run_command("open #{LOCALHOST_URL}", "Browser opened successfully", "Failed to open the browser")
|
51
52
|
end
|
52
53
|
|
53
54
|
def run_development_server
|
54
55
|
logger.info("\n# Running the development server")
|
55
|
-
|
56
|
-
|
56
|
+
run_command("npm run dev", "Development server started successfully", "Failed to start the development server")
|
57
|
+
end
|
58
|
+
|
59
|
+
def run_command(command, success_message, error_message)
|
60
|
+
if system(command)
|
61
|
+
logger.info(success_message)
|
57
62
|
else
|
58
|
-
logger.error(
|
63
|
+
logger.error(error_message)
|
59
64
|
end
|
60
65
|
end
|
61
66
|
end
|