stipa 0.1.1 → 0.1.2
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/lib/stipa/generators/api.rb +5 -0
- data/lib/stipa/generators/base.rb +33 -0
- data/lib/stipa/generators/vue.rb +16 -1
- data/lib/stipa/reloader.rb +85 -0
- data/lib/stipa/server.rb +5 -1
- data/lib/stipa/version.rb +1 -1
- data/lib/stipa.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c22dd3975ab3276a80054b24f2b9e04912139c30e57d2500ffbc79bdf9de37da
|
|
4
|
+
data.tar.gz: 8013ed53bddd21485caff447749c2c36fcdba2344930e283dc70003097b40337
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4f9cb7efbc203c13bd8fb2a0071761b3fa28c22b63d843a40eff56a6234a30a5ba342b29da7145f3af46ff6a42ce11e4ba3fa958083e09d1a99873fba19f736
|
|
7
|
+
data.tar.gz: cae5c45e818554b9732bf6668feff3b932cf9c0cacc107b5678e5a789debe4b89eea691c0f85514be026ae566801fe0159a70f457827722fdb1a0009097e37dc
|
data/lib/stipa/generators/api.rb
CHANGED
|
@@ -23,6 +23,7 @@ module Stipa
|
|
|
23
23
|
|
|
24
24
|
def files
|
|
25
25
|
{
|
|
26
|
+
'.gitignore' => t_gitignore,
|
|
26
27
|
'Gemfile' => t_gemfile,
|
|
27
28
|
'server.rb' => t_server,
|
|
28
29
|
'config/routes.rb' => t_routes(
|
|
@@ -34,6 +35,10 @@ module Stipa
|
|
|
34
35
|
}
|
|
35
36
|
end
|
|
36
37
|
|
|
38
|
+
def t_gitignore
|
|
39
|
+
t_gitignore_common
|
|
40
|
+
end
|
|
41
|
+
|
|
37
42
|
def t_server
|
|
38
43
|
<<~RUBY
|
|
39
44
|
require 'stipa'
|
|
@@ -23,6 +23,7 @@ module Stipa
|
|
|
23
23
|
make_dirs
|
|
24
24
|
write_files
|
|
25
25
|
post_generate
|
|
26
|
+
init_git
|
|
26
27
|
say done_message
|
|
27
28
|
end
|
|
28
29
|
|
|
@@ -41,14 +42,46 @@ module Stipa
|
|
|
41
42
|
|
|
42
43
|
def post_generate = nil
|
|
43
44
|
|
|
45
|
+
def init_git
|
|
46
|
+
return unless git_available?
|
|
47
|
+
|
|
48
|
+
Dir.chdir(target) do
|
|
49
|
+
system('git init -q')
|
|
50
|
+
system('git add .')
|
|
51
|
+
system("git commit -q -m 'Initial commit'")
|
|
52
|
+
end
|
|
53
|
+
say ' git initialized repository with initial commit'
|
|
54
|
+
rescue => e
|
|
55
|
+
say " warn git init failed: #{e.message}"
|
|
56
|
+
end
|
|
57
|
+
|
|
44
58
|
def say(msg) = puts(msg)
|
|
45
59
|
|
|
46
60
|
def app_title
|
|
47
61
|
name.split(/[-_]/).map(&:capitalize).join(' ')
|
|
48
62
|
end
|
|
49
63
|
|
|
64
|
+
def git_available?
|
|
65
|
+
system('git --version > /dev/null 2>&1')
|
|
66
|
+
end
|
|
67
|
+
|
|
50
68
|
# ── Shared templates ───────────────────────────────────────────────────────
|
|
51
69
|
|
|
70
|
+
def t_gitignore_common
|
|
71
|
+
<<~GITIGNORE
|
|
72
|
+
# Ruby
|
|
73
|
+
.bundle/
|
|
74
|
+
vendor/bundle/
|
|
75
|
+
Gemfile.lock
|
|
76
|
+
|
|
77
|
+
# OS
|
|
78
|
+
.DS_Store
|
|
79
|
+
Thumbs.db
|
|
80
|
+
*.swp
|
|
81
|
+
*.swo
|
|
82
|
+
GITIGNORE
|
|
83
|
+
end
|
|
84
|
+
|
|
52
85
|
def t_gemfile
|
|
53
86
|
<<~RUBY
|
|
54
87
|
source 'https://rubygems.org'
|
data/lib/stipa/generators/vue.rb
CHANGED
|
@@ -53,6 +53,7 @@ module Stipa
|
|
|
53
53
|
|
|
54
54
|
def files
|
|
55
55
|
{
|
|
56
|
+
'.gitignore' => t_gitignore,
|
|
56
57
|
'Gemfile' => t_gemfile,
|
|
57
58
|
'package.json' => t_package_json,
|
|
58
59
|
'rollup.config.js' => t_rollup_config,
|
|
@@ -75,6 +76,20 @@ module Stipa
|
|
|
75
76
|
}
|
|
76
77
|
end
|
|
77
78
|
|
|
79
|
+
def t_gitignore
|
|
80
|
+
t_gitignore_common + <<~GITIGNORE
|
|
81
|
+
|
|
82
|
+
# Node
|
|
83
|
+
node_modules/
|
|
84
|
+
package-lock.json
|
|
85
|
+
|
|
86
|
+
# Build output
|
|
87
|
+
public/app.js
|
|
88
|
+
public/app.js.map
|
|
89
|
+
public/vendor/
|
|
90
|
+
GITIGNORE
|
|
91
|
+
end
|
|
92
|
+
|
|
78
93
|
def t_package_json
|
|
79
94
|
JSON.pretty_generate(
|
|
80
95
|
name: name,
|
|
@@ -84,7 +99,7 @@ module Stipa
|
|
|
84
99
|
'copy:vue' => 'cp node_modules/vue/dist/vue.esm-browser.prod.js public/vendor/vue.esm-browser.prod.js',
|
|
85
100
|
build: 'npm run copy:vue && rollup -c',
|
|
86
101
|
watch: 'rollup -c --watch',
|
|
87
|
-
dev: 'npm run copy:vue && concurrently "bundle exec ruby server.rb" "rollup -c --watch"',
|
|
102
|
+
dev: 'npm run copy:vue && concurrently "STIPA_RELOAD=1 bundle exec ruby server.rb" "rollup -c --watch"',
|
|
88
103
|
typecheck: 'vue-tsc --noEmit',
|
|
89
104
|
},
|
|
90
105
|
devDependencies: {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
module Stipa
|
|
2
|
+
# Development file watcher that restarts the process when Ruby source files change.
|
|
3
|
+
#
|
|
4
|
+
# Enabled when:
|
|
5
|
+
# - STIPA_RELOAD=1 environment variable is set, OR
|
|
6
|
+
# - reload: true is passed to App#start / Server#start
|
|
7
|
+
#
|
|
8
|
+
# Strategy:
|
|
9
|
+
# A background thread polls the mtime of all .rb files visible to Ruby
|
|
10
|
+
# ($LOADED_FEATURES) plus any extra watch paths supplied by the user.
|
|
11
|
+
# When a change is detected it calls exec($0, *ARGV) which replaces the
|
|
12
|
+
# current process image with a fresh one — same PID namespace, same
|
|
13
|
+
# command line arguments, all changes picked up from scratch.
|
|
14
|
+
#
|
|
15
|
+
# Why exec instead of in-process reload:
|
|
16
|
+
# In-process reload requires clearing constants, unloading files, and
|
|
17
|
+
# rebuilding the route table. exec is simpler, safer, and handles any
|
|
18
|
+
# kind of change (routes, middleware, config, gems) without edge cases.
|
|
19
|
+
class Reloader
|
|
20
|
+
DEFAULT_INTERVAL = 0.5 # seconds between polls
|
|
21
|
+
|
|
22
|
+
def initialize(logger:, interval: DEFAULT_INTERVAL, watch: [])
|
|
23
|
+
@logger = logger
|
|
24
|
+
@interval = interval
|
|
25
|
+
@extra = Array(watch).map { |p| File.expand_path(p) }
|
|
26
|
+
@mtimes = {}
|
|
27
|
+
@thread = nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def start
|
|
31
|
+
snapshot!
|
|
32
|
+
@thread = Thread.new { watch_loop }
|
|
33
|
+
@thread.name = 'stipa-reloader'
|
|
34
|
+
@thread.abort_on_exception = false
|
|
35
|
+
@logger.warn('reloader active — watching for file changes')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def stop
|
|
39
|
+
@thread&.kill
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def watch_loop
|
|
45
|
+
loop do
|
|
46
|
+
sleep @interval
|
|
47
|
+
if changed?
|
|
48
|
+
@logger.warn('file change detected — restarting')
|
|
49
|
+
$stdout.flush
|
|
50
|
+
$stderr.flush
|
|
51
|
+
exec($0, *ARGV)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
rescue => e
|
|
55
|
+
@logger.error("reloader crashed: #{e.class}: #{e.message}")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Collect the current set of watched files: everything Ruby has loaded
|
|
59
|
+
# plus any extra paths the user specified.
|
|
60
|
+
def watched_files
|
|
61
|
+
($LOADED_FEATURES + @extra).uniq
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def snapshot!
|
|
65
|
+
watched_files.each do |path|
|
|
66
|
+
@mtimes[path] = mtime(path)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def changed?
|
|
71
|
+
watched_files.any? do |path|
|
|
72
|
+
current = mtime(path)
|
|
73
|
+
previous = @mtimes[path]
|
|
74
|
+
@mtimes[path] = current
|
|
75
|
+
current != previous
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def mtime(path)
|
|
80
|
+
File.mtime(path)
|
|
81
|
+
rescue Errno::ENOENT
|
|
82
|
+
nil
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
data/lib/stipa/server.rb
CHANGED
|
@@ -53,6 +53,7 @@ module Stipa
|
|
|
53
53
|
max_body_size: 1 * 1024 * 1024,
|
|
54
54
|
backpressure: :drop, # :drop (503) or :block (wait briefly)
|
|
55
55
|
log_level: :info,
|
|
56
|
+
reload: ENV['STIPA_RELOAD'] == '1',
|
|
56
57
|
}.freeze
|
|
57
58
|
|
|
58
59
|
def initialize(app:, **overrides)
|
|
@@ -64,7 +65,8 @@ module Stipa
|
|
|
64
65
|
queue_depth: @config[:queue_depth],
|
|
65
66
|
on_error: method(:pool_error),
|
|
66
67
|
)
|
|
67
|
-
@running
|
|
68
|
+
@running = false
|
|
69
|
+
@reloader = @config[:reload] ? Reloader.new(logger: @logger) : nil
|
|
68
70
|
end
|
|
69
71
|
|
|
70
72
|
# Start the server. Blocks until SIGTERM/SIGINT.
|
|
@@ -73,6 +75,7 @@ module Stipa
|
|
|
73
75
|
@running = true
|
|
74
76
|
|
|
75
77
|
register_signals
|
|
78
|
+
@reloader&.start
|
|
76
79
|
|
|
77
80
|
@logger.info(
|
|
78
81
|
req: nil, res: nil,
|
|
@@ -85,6 +88,7 @@ module Stipa
|
|
|
85
88
|
|
|
86
89
|
accept_loop
|
|
87
90
|
ensure
|
|
91
|
+
@reloader&.stop
|
|
88
92
|
@server&.close rescue nil
|
|
89
93
|
@logger.info(req: nil, res: nil, msg: 'Stīpa stopped')
|
|
90
94
|
end
|
data/lib/stipa/version.rb
CHANGED
data/lib/stipa.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stipa
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pedro Harbs
|
|
@@ -100,6 +100,7 @@ files:
|
|
|
100
100
|
- lib/stipa/generators/vue.rb
|
|
101
101
|
- lib/stipa/logger.rb
|
|
102
102
|
- lib/stipa/middleware.rb
|
|
103
|
+
- lib/stipa/reloader.rb
|
|
103
104
|
- lib/stipa/request.rb
|
|
104
105
|
- lib/stipa/response.rb
|
|
105
106
|
- lib/stipa/server.rb
|