instant_record 0.1.0 → 0.3.0
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/CHANGELOG.md +58 -0
- data/README.md +267 -61
- data/app/controllers/instant_record/bootstraps_controller.rb +39 -12
- data/app/controllers/instant_record/events_controller.rb +58 -6
- data/app/controllers/instant_record/files_controller.rb +116 -0
- data/app/controllers/instant_record/mutations_controller.rb +84 -5
- data/app/controllers/instant_record/native_screens_controller.rb +60 -0
- data/app/controllers/instant_record/records_controller.rb +86 -8
- data/app/controllers/instant_record/shells_controller.rb +64 -0
- data/app/controllers/instant_record/sync_notices_controller.rb +81 -0
- data/app/helpers/instant_record/sync_notices_helper.rb +41 -0
- data/app/jobs/instant_record/shell_build_job.rb +16 -0
- data/app/models/instant_record/change.rb +36 -3
- data/app/models/instant_record/mutation_applier.rb +633 -50
- data/app/views/instant_record/sync_notices/_notices.html.erb +63 -0
- data/compiled/README.md +272 -0
- data/compiled/pipeline/browser_migrations.rb +18 -0
- data/compiled/pipeline/build.rb +13 -0
- data/compiled/pipeline/build_native.rb +14 -0
- data/compiled/pipeline/native/host.c +78 -0
- data/compiled/pipeline/native/instant_record_native.h +57 -0
- data/compiled/pipeline/native_shim.c +149 -0
- data/compiled/pipeline/reactor_shim.c +66 -0
- data/compiled/pipeline/sqlite/rh_shim.c +5 -0
- data/compiled/pipeline/sqlite_release.rb +43 -0
- data/compiled/toolchain.env.example +22 -0
- data/compiled/web/index.html +20 -0
- data/compiled/web/package-lock.json +884 -0
- data/compiled/web/package.json +17 -0
- data/compiled/web/src/app-host-core.js +556 -0
- data/compiled/web/src/app-host.js +16 -0
- data/compiled/web/src/branch-manager.js +140 -0
- data/compiled/web/src/branch-preview.js +397 -0
- data/compiled/web/src/changes.js +191 -0
- data/compiled/web/src/faults.js +172 -0
- data/compiled/web/src/flight-recorder.js +347 -0
- data/compiled/web/src/history-fill.js +68 -0
- data/compiled/web/src/http-headers.js +100 -0
- data/compiled/web/src/leader-election.js +705 -0
- data/compiled/web/src/main.js +608 -0
- data/compiled/web/src/manifest.js +112 -0
- data/compiled/web/src/opfs-wasi-core.js +109 -0
- data/compiled/web/src/opfs-wasi-file.js +8 -0
- data/compiled/web/src/reactor-runtime.js +1692 -0
- data/compiled/web/src/redactor.js +518 -0
- data/compiled/web/src/release-updates.js +48 -0
- data/compiled/web/src/replay.js +338 -0
- data/compiled/web/src/schema-recovery.js +204 -0
- data/compiled/web/src/server-request.js +68 -0
- data/compiled/web/src/sha256.js +98 -0
- data/compiled/web/src/shell.js +52 -0
- data/compiled/web/src/snapshot-store.js +38 -0
- data/compiled/web/src/sqlite-redactor.js +111 -0
- data/compiled/web/src/storage-backend.js +159 -0
- data/compiled/web/src/stream-leader.js +675 -0
- data/compiled/web/src/sync-context.js +91 -0
- data/compiled/web/src/sync-drain.js +104 -0
- data/compiled/web/src/sync-schedule.js +9 -0
- data/compiled/web/src/wasi-minimal.js +275 -0
- data/compiled/web/src/worker.js +39 -0
- data/compiled/web/vite.config.js +27 -0
- data/config/routes.rb +25 -0
- data/db/migrate/20261119000201_add_scope_to_instant_record_changes.rb +7 -0
- data/db/migrate/20261121000001_create_instant_record_sync_notices.rb +21 -0
- data/db/migrate/20261121000101_add_partition_to_instant_record_changes.rb +8 -0
- data/db/migrate/20261121230300_add_delay_line_to_instant_record_outbox.rb +10 -0
- data/exe/instant_record_mcp +6 -0
- data/frontend/LiveList.js +67 -0
- data/frontend/chord.js +79 -0
- data/frontend/file.js +65 -0
- data/frontend/files.js +738 -0
- data/frontend/focus.js +10 -0
- data/frontend/held.js +192 -0
- data/frontend/http.js +76 -0
- data/frontend/index.js +53 -0
- data/frontend/keyboard.js +56 -0
- data/frontend/live.js +298 -0
- data/frontend/notices.js +118 -0
- data/frontend/package.json +15 -0
- data/frontend/range.js +10 -0
- data/frontend/selection.js +47 -0
- data/frontend/shortcuts.js +25 -0
- data/frontend/sync-notices.js +130 -0
- data/frontend/undo.js +48 -0
- data/frontend/window.js +181 -0
- data/lib/generators/instant_record/install/install_generator.rb +18 -30
- data/lib/generators/instant_record/install/templates/instant_record.rb +34 -0
- data/lib/generators/instant_record/ios/ios_generator.rb +71 -0
- data/lib/generators/instant_record/ios/templates/App.swift.tt +35 -0
- data/lib/generators/instant_record/ios/templates/Info.plist +11 -0
- data/lib/generators/instant_record/ios/templates/LibraryEngine.swift +30 -0
- data/lib/instant_record/branch/sqlite_store.rb +142 -0
- data/lib/instant_record/branch.rb +388 -0
- data/lib/instant_record/client/notifier.rb +8 -12
- data/lib/instant_record/client/rebaser.rb +565 -0
- data/lib/instant_record/client/transport.rb +64 -42
- data/lib/instant_record/client.rb +1600 -169
- data/lib/instant_record/compiled_site.rb +85 -0
- data/lib/instant_record/compiler/app_stage.rb +212 -0
- data/lib/instant_record/compiler/ast_lowerer.rb +659 -0
- data/lib/instant_record/compiler/browser_migrations.rb +161 -0
- data/lib/instant_record/compiler/entry_builder.rb +832 -0
- data/lib/instant_record/compiler/fts5_smoke.rb +205 -0
- data/lib/instant_record/compiler/gem_vendor.rb +194 -0
- data/lib/instant_record/compiler/host_adapters.rb +506 -0
- data/lib/instant_record/compiler/kotlin_codegen.rb +209 -0
- data/lib/instant_record/compiler/manifest.rb +178 -0
- data/lib/instant_record/compiler/native_build.rb +586 -0
- data/lib/instant_record/compiler/native_contracts.rb +338 -0
- data/lib/instant_record/compiler/path_scrubber.rb +31 -0
- data/lib/instant_record/compiler/reachability_tracer.rb +1188 -0
- data/lib/instant_record/compiler/route_analyzer.rb +623 -0
- data/lib/instant_record/compiler/runner.rb +42 -0
- data/lib/instant_record/compiler/schema_lock.rb +606 -0
- data/lib/instant_record/compiler/source_pages.rb +77 -0
- data/lib/instant_record/compiler/static_linter.rb +770 -0
- data/lib/instant_record/compiler/swift_codegen.rb +341 -0
- data/lib/instant_record/compiler/toolchain.rb +219 -0
- data/lib/instant_record/compiler/wasm_build.rb +704 -0
- data/lib/instant_record/compiler/wasm_tree.rb +518 -0
- data/lib/instant_record/compiler.rb +277 -0
- data/lib/instant_record/configuration.rb +104 -0
- data/lib/instant_record/engine.rb +68 -18
- data/lib/instant_record/file_store.rb +162 -0
- data/lib/instant_record/files.rb +92 -0
- data/lib/instant_record/hlc.rb +387 -0
- data/lib/instant_record/host.rb +66 -0
- data/lib/instant_record/inertia/renderer.rb +52 -0
- data/lib/instant_record/inertia.rb +222 -0
- data/lib/instant_record/mcp/cli.rb +319 -0
- data/lib/instant_record/mcp/host_process.rb +229 -0
- data/lib/instant_record/mcp/http_exchange.rb +233 -0
- data/lib/instant_record/mcp/replica.rb +556 -0
- data/lib/instant_record/mcp/runtime.rb +406 -0
- data/lib/instant_record/mcp/server.rb +429 -0
- data/lib/instant_record/mcp.rb +47 -0
- data/lib/instant_record/native/contract.rb +367 -0
- data/lib/instant_record/native/node.rb +125 -0
- data/lib/instant_record/native/screen.rb +366 -0
- data/lib/instant_record/native/xcode_project.rb +344 -0
- data/lib/instant_record/native.rb +41 -0
- data/lib/instant_record/outbox_mutation.rb +81 -9
- data/lib/instant_record/outbox_upcaster.rb +161 -0
- data/lib/instant_record/read_tracker.rb +610 -0
- data/lib/instant_record/routing.rb +33 -0
- data/lib/instant_record/runtime_scoped.rb +4 -0
- data/lib/instant_record/shell.rb +486 -0
- data/lib/instant_record/sync_actions.rb +800 -0
- data/lib/instant_record/sync_metadata.rb +17 -2
- data/lib/instant_record/sync_notice.rb +234 -0
- data/lib/instant_record/sync_partition.rb +63 -0
- data/lib/instant_record/sync_scope.rb +300 -0
- data/lib/instant_record/sync_shape.rb +102 -0
- data/lib/instant_record/sync_window.rb +92 -15
- data/lib/instant_record/syncable.rb +313 -17
- data/lib/instant_record/testing/authoritative_server.rb +547 -0
- data/lib/instant_record/testing/chaos_simulator.rb +429 -0
- data/lib/instant_record/testing/cruby_host_bridge.rb +370 -0
- data/lib/instant_record/testing/fault_network.rb +140 -0
- data/lib/instant_record/testing/parity_suite.rb +435 -0
- data/lib/instant_record/testing/runtimes/base.rb +184 -0
- data/lib/instant_record/testing/runtimes/cruby_runtime.rb +255 -0
- data/lib/instant_record/testing/runtimes/native_runtime.rb +346 -0
- data/lib/instant_record/testing/runtimes/wasm_runtime.rb +371 -0
- data/lib/instant_record/testing/wasm_host_bridge.mjs +240 -0
- data/lib/instant_record/testing.rb +333 -0
- data/lib/instant_record/trace/redactor.rb +278 -0
- data/lib/instant_record/trace/replayer.rb +126 -0
- data/lib/instant_record/trace/schema_extractor.rb +37 -0
- data/lib/instant_record/trace.rb +22 -0
- data/lib/instant_record/version.rb +1 -1
- data/lib/instant_record.rb +107 -37
- data/lib/tasks/instant_record.rake +299 -47
- data/native/ios/InstantRecordNative/Package.swift +12 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/AppHost.swift +706 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Engine.swift +64 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/FileStore.swift +1048 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/HTTPEngine.swift +36 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Icons.swift +19 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Node.swift +64 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/ScreenView.swift +481 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Screens.swift +94 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/StreamClient.swift +74 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/SyncNotice.swift +282 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/SyncSchedule.swift +153 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Theme.swift +140 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Transport.swift +108 -0
- data/native/ios/InstantRecordNative/Sources/InstantRecordNative/TypedContracts.swift +237 -0
- data/native/ios/README.md +341 -0
- data/sig/instant_record/inertia.rbs +47 -0
- data/sig/instant_record/native.rbs +38 -0
- metadata +194 -18
- data/lib/generators/instant_record/install/templates/database.js +0 -32
- data/lib/generators/instant_record/install/templates/index.html +0 -69
- data/lib/generators/instant_record/install/templates/rails.sw.js +0 -750
- data/lib/instant_record/local_schema.rb +0 -75
- data/lib/instant_record/pglite_compat.rb +0 -40
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "rack/files"
|
|
3
|
+
require "rack/request"
|
|
4
|
+
require "rack/sendfile"
|
|
5
|
+
|
|
6
|
+
module InstantRecord
|
|
7
|
+
# Serve the published browser artifact on the host chosen by the application.
|
|
8
|
+
# The sync engine, health checks and non-navigation requests still reach Rails.
|
|
9
|
+
class CompiledSite
|
|
10
|
+
# A tab can receive the old HTML just before a deploy and request its
|
|
11
|
+
# content-addressed worker or Wasm just after the release link switches.
|
|
12
|
+
FINGERPRINTED = %r{\A/(?:app-[0-9a-f]+\.wasm|harness/[\w.-]+-[\w-]{8}\.js)\z}
|
|
13
|
+
|
|
14
|
+
def initialize(app, host:, root:, sync_path:)
|
|
15
|
+
@app = app
|
|
16
|
+
@host = host
|
|
17
|
+
@root = root
|
|
18
|
+
@files = Rack::Files.new(root)
|
|
19
|
+
@releases = File.dirname(root)
|
|
20
|
+
@sync_path = sync_path
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def call(env)
|
|
24
|
+
request = Rack::Request.new(env)
|
|
25
|
+
path = request.path_info
|
|
26
|
+
return @app.call(env) unless request.host == @host && (request.get? || request.head?)
|
|
27
|
+
return @app.call(env) if path == "/up" || path == @sync_path || path.start_with?("#{@sync_path}/")
|
|
28
|
+
|
|
29
|
+
asset = path.start_with?("/assets/", "/harness/") || path.match?(%r{\A/app-[a-f0-9]+\.wasm\z}) ||
|
|
30
|
+
(path == "/service-worker.js" && File.file?(File.join(@root, "service-worker.js")))
|
|
31
|
+
manifest = path == "/instant-record-release.json" || path == "/instant_record.manifest.json"
|
|
32
|
+
html = request.get_header("HTTP_ACCEPT").to_s.include?("text/html")
|
|
33
|
+
return @app.call(env) unless asset || manifest || (html && local_island_path?(path))
|
|
34
|
+
status, headers, body = @files.call(asset || manifest ? env : env.merge("PATH_INFO" => "/index.html"))
|
|
35
|
+
immutable = FINGERPRINTED.match?(path)
|
|
36
|
+
if status == 404 && immutable
|
|
37
|
+
Dir.glob(File.join(@releases, "[a-f0-9]" * 64)).each do |release|
|
|
38
|
+
next unless File.file?(File.join(release, path.delete_prefix("/")))
|
|
39
|
+
body.close if body.respond_to?(:close)
|
|
40
|
+
status, headers, body = Rack::Files.new(release).call(env)
|
|
41
|
+
break
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
headers["cache-control"] = immutable && [200, 206, 304].include?(status) ? "public, max-age=31536000, immutable" : "no-cache"
|
|
45
|
+
[status, headers, body]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def local_island_path?(path)
|
|
51
|
+
manifest_file = File.join(@root, "instant_record.manifest.json")
|
|
52
|
+
return true unless File.file?(manifest_file)
|
|
53
|
+
|
|
54
|
+
data = JSON.parse(File.read(manifest_file))
|
|
55
|
+
return true unless data["mode"] == "island"
|
|
56
|
+
|
|
57
|
+
routes = Array(data["local_routes"]).select { |r| r["method"].to_s.upcase == "GET" && r["path"] }
|
|
58
|
+
return true if routes.empty?
|
|
59
|
+
|
|
60
|
+
normalized = path.to_s.gsub(%r{/+}, "/")
|
|
61
|
+
normalized = normalized.delete_suffix("/") if normalized.length > 1
|
|
62
|
+
routes.any? { |route| route_pattern_to_regex(route["path"]).match?(normalized) }
|
|
63
|
+
rescue JSON::ParserError, SystemCallError
|
|
64
|
+
true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def route_pattern_to_regex(pattern)
|
|
68
|
+
norm = pattern.to_s.gsub(%r{/+}, "/")
|
|
69
|
+
norm = "/#{norm}" unless norm.start_with?("/")
|
|
70
|
+
norm = norm.delete_suffix("/") if norm.length > 1
|
|
71
|
+
return /\A\/\z/ if norm == "/"
|
|
72
|
+
|
|
73
|
+
segments = norm.delete_prefix("/").split("/").map do |segment|
|
|
74
|
+
if segment.start_with?("*")
|
|
75
|
+
".+"
|
|
76
|
+
elsif segment.start_with?(":")
|
|
77
|
+
"[^/]+"
|
|
78
|
+
else
|
|
79
|
+
Regexp.escape(segment).gsub(/:[a-zA-Z_]\w*/, "[^/]+")
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
/\A\/#{segments.join("/")}\/?\z/
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
require "fileutils"
|
|
2
|
+
require "pathname"
|
|
3
|
+
require "set"
|
|
4
|
+
require_relative "manifest"
|
|
5
|
+
require_relative "reachability_tracer"
|
|
6
|
+
require_relative "route_analyzer"
|
|
7
|
+
require_relative "runner"
|
|
8
|
+
|
|
9
|
+
module InstantRecord
|
|
10
|
+
class Compiler
|
|
11
|
+
module FileCopy
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
def copy_tree(source, target, ignore: [], visited: Set.new)
|
|
15
|
+
source_path = Pathname(source)
|
|
16
|
+
real = source_path.realpath
|
|
17
|
+
return if visited.include?(real)
|
|
18
|
+
|
|
19
|
+
next_visited = visited + [real]
|
|
20
|
+
target_path = Pathname(target)
|
|
21
|
+
FileUtils.mkdir_p(target_path)
|
|
22
|
+
|
|
23
|
+
source_path.children.each do |entry|
|
|
24
|
+
name = entry.basename.to_s
|
|
25
|
+
next if ignore.include?(name)
|
|
26
|
+
|
|
27
|
+
dest = target_path.join(name)
|
|
28
|
+
if entry.directory?
|
|
29
|
+
copy_tree(entry, dest, ignore: ignore, visited: next_visited)
|
|
30
|
+
else
|
|
31
|
+
FileUtils.cp(entry, dest)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Stage a Rails app (or one declared local-first island within a monolith)
|
|
38
|
+
# for Roundhouse without touching the original checkout, and emit a
|
|
39
|
+
# canonical `instant_record.manifest.json`.
|
|
40
|
+
module AppStage
|
|
41
|
+
STATIC_FOLDERS = %w[app/assets app/javascript config/locales].freeze
|
|
42
|
+
|
|
43
|
+
FILES = %w[
|
|
44
|
+
Gemfile config/application.rb config/routes.rb config/importmap.rb db/schema.rb
|
|
45
|
+
].freeze
|
|
46
|
+
|
|
47
|
+
StageResult = Struct.new(:manifest, :route_analysis, :trace, :overrides, keyword_init: true)
|
|
48
|
+
|
|
49
|
+
module_function
|
|
50
|
+
|
|
51
|
+
def analyze(source:, native: false, island: nil, overrides: nil, models: nil, migration_paths: nil, overlay_dir: nil)
|
|
52
|
+
source_path = File.expand_path(source.to_s)
|
|
53
|
+
route_analysis = RouteAnalyzer.analyze(source_root: source_path, island: island)
|
|
54
|
+
file_config = Manifest.load_config(source_path, island: island)
|
|
55
|
+
merged_overrides = Manifest.merge_overrides(file_config, route_analysis.overrides, overrides)
|
|
56
|
+
|
|
57
|
+
trace = ReachabilityTracer.trace(
|
|
58
|
+
source_root: source_path,
|
|
59
|
+
route_analysis: route_analysis,
|
|
60
|
+
overrides: merged_overrides,
|
|
61
|
+
native: native,
|
|
62
|
+
migration_paths: migration_paths,
|
|
63
|
+
overlay_dir: overlay_dir
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
manifest_models = build_manifest_models(trace, explicit_models: models, island_mode: route_analysis.has_local_first)
|
|
67
|
+
server_routes = Manifest.deduplicate_routes(route_analysis.server_routes + merged_overrides[:server_routes])
|
|
68
|
+
|
|
69
|
+
manifest = Manifest.new(
|
|
70
|
+
"schema_version" => Manifest::SCHEMA_VERSION,
|
|
71
|
+
"mode" => route_analysis.has_local_first ? "island" : "full",
|
|
72
|
+
"island" => route_analysis.island,
|
|
73
|
+
"models" => manifest_models,
|
|
74
|
+
"local_routes" => route_analysis.local_routes,
|
|
75
|
+
"server_routes" => server_routes,
|
|
76
|
+
"staged" => {
|
|
77
|
+
"controllers" => trace.controllers,
|
|
78
|
+
"models" => trace.models,
|
|
79
|
+
"views" => trace.views,
|
|
80
|
+
"helpers" => trace.helpers,
|
|
81
|
+
"migrations" => trace.manifest_migrations,
|
|
82
|
+
"screens" => trace.screens
|
|
83
|
+
},
|
|
84
|
+
"includes" => merged_overrides[:include],
|
|
85
|
+
"diagnostics" => trace.diagnostics
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
StageResult.new(
|
|
89
|
+
manifest: manifest,
|
|
90
|
+
route_analysis: route_analysis,
|
|
91
|
+
trace: trace,
|
|
92
|
+
overrides: merged_overrides
|
|
93
|
+
)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def stage(source:, target:, native: false, island: nil, overrides: nil, models: nil, migration_paths: nil, overlay_dir: nil, manifest_path: nil)
|
|
97
|
+
source_path = Pathname(source).realpath
|
|
98
|
+
target_path = Pathname(target)
|
|
99
|
+
analysis = analyze(
|
|
100
|
+
source: source_path,
|
|
101
|
+
native: native,
|
|
102
|
+
island: island,
|
|
103
|
+
overrides: overrides,
|
|
104
|
+
models: models,
|
|
105
|
+
migration_paths: migration_paths,
|
|
106
|
+
overlay_dir: overlay_dir
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
FileUtils.rm_rf(target_path)
|
|
110
|
+
FileUtils.mkdir_p(target_path)
|
|
111
|
+
|
|
112
|
+
STATIC_FOLDERS.each do |rel|
|
|
113
|
+
dir = source_path.join(rel)
|
|
114
|
+
FileCopy.copy_tree(dir, target_path.join(rel)) if dir.directory?
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
static_files = analysis.route_analysis.has_local_first ? (FILES - ["config/routes.rb"]) : FILES
|
|
118
|
+
static_files.each do |rel|
|
|
119
|
+
copy_file_if_present(source_path, target_path, rel)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
if analysis.route_analysis.has_local_first
|
|
123
|
+
routes_dest = target_path.join("config/routes.rb")
|
|
124
|
+
FileUtils.mkdir_p(routes_dest.dirname)
|
|
125
|
+
File.write(routes_dest, analysis.route_analysis.local_routes_source)
|
|
126
|
+
else
|
|
127
|
+
routes_dir = source_path.join("config/routes")
|
|
128
|
+
FileCopy.copy_tree(routes_dir, target_path.join("config/routes")) if routes_dir.directory?
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
traced_files = analysis.trace.controllers +
|
|
132
|
+
analysis.trace.models +
|
|
133
|
+
analysis.trace.views +
|
|
134
|
+
analysis.trace.helpers +
|
|
135
|
+
analysis.trace.screens +
|
|
136
|
+
analysis.trace.extra_files
|
|
137
|
+
|
|
138
|
+
traced_files.uniq.each do |rel|
|
|
139
|
+
copy_file_if_present(source_path, target_path, rel)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
if overlay_dir && File.directory?(overlay_dir)
|
|
143
|
+
FileCopy.copy_tree(overlay_dir, target_path.join("app"))
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
unless target_path.join("db/schema.rb").file?
|
|
147
|
+
raise BuildError, "The compiled app needs db/schema.rb. Run bin/rails db:migrate and db:schema:dump first."
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
if manifest_path
|
|
151
|
+
FileUtils.mkdir_p(File.dirname(manifest_path))
|
|
152
|
+
File.write(manifest_path, analysis.manifest.to_json)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
analysis
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def copy_file_if_present(source_path, target_path, rel)
|
|
159
|
+
src_root = source_path.realpath.to_s
|
|
160
|
+
dst_root = File.expand_path(target_path.to_s)
|
|
161
|
+
path = File.expand_path(rel.to_s, src_root)
|
|
162
|
+
dest = File.expand_path(rel.to_s, dst_root)
|
|
163
|
+
unless path.start_with?("#{src_root}#{File::SEPARATOR}") && dest.start_with?("#{dst_root}#{File::SEPARATOR}")
|
|
164
|
+
raise BuildError, "Refusing to stage path outside app root: #{rel.inspect}"
|
|
165
|
+
end
|
|
166
|
+
return unless File.file?(path)
|
|
167
|
+
|
|
168
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
|
169
|
+
FileUtils.cp(path, dest)
|
|
170
|
+
end
|
|
171
|
+
private_class_method :copy_file_if_present
|
|
172
|
+
|
|
173
|
+
def build_manifest_models(trace, explicit_models:, island_mode:)
|
|
174
|
+
discovered = trace.model_metadata.values.select { |meta| meta["syncable"] }
|
|
175
|
+
by_name = discovered.each_with_object({}) do |meta, hash|
|
|
176
|
+
hash[meta["name"]] = format_model_entry(meta)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
if !island_mode && explicit_models
|
|
180
|
+
Array(explicit_models).each do |name|
|
|
181
|
+
next if by_name.key?(name)
|
|
182
|
+
|
|
183
|
+
meta = trace.model_metadata[name]
|
|
184
|
+
by_name[name] = meta ? format_model_entry(meta) : {
|
|
185
|
+
"name" => name,
|
|
186
|
+
"table" => ActiveSupport::Inflector.tableize(name),
|
|
187
|
+
"file" => nil,
|
|
188
|
+
"sync_window" => nil,
|
|
189
|
+
"sync_scope" => nil,
|
|
190
|
+
"sync_file" => false
|
|
191
|
+
}
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
by_name.keys.sort.map { |name| by_name[name] }
|
|
196
|
+
end
|
|
197
|
+
private_class_method :build_manifest_models
|
|
198
|
+
|
|
199
|
+
def format_model_entry(meta)
|
|
200
|
+
{
|
|
201
|
+
"name" => meta["name"],
|
|
202
|
+
"table" => meta["table"],
|
|
203
|
+
"file" => meta["file"],
|
|
204
|
+
"sync_window" => meta["sync_window"],
|
|
205
|
+
"sync_scope" => meta["sync_scope"],
|
|
206
|
+
"sync_file" => meta["sync_file"] == true
|
|
207
|
+
}
|
|
208
|
+
end
|
|
209
|
+
private_class_method :format_model_entry
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|