context_drop 0.2.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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +149 -12
  3. data/Rakefile +110 -1
  4. data/app/assets/javascripts/context_drop/context_drop.js +1230 -53
  5. data/app/controllers/context_drop/application_controller.rb +52 -3
  6. data/app/controllers/context_drop/configs_controller.rb +10 -1
  7. data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +15 -11
  8. data/app/controllers/context_drop/feedbacks_controller.rb +383 -17
  9. data/app/javascript/context_drop/__tests__/api-client.test.ts +255 -0
  10. data/app/javascript/context_drop/__tests__/widget.test.ts +355 -1
  11. data/app/javascript/context_drop/api-client.ts +306 -22
  12. data/app/javascript/context_drop/element-picker.ts +1 -1
  13. data/app/javascript/context_drop/icons.ts +4 -0
  14. data/app/javascript/context_drop/screenshot.ts +1 -1
  15. data/app/javascript/context_drop/styles.ts +181 -0
  16. data/app/javascript/context_drop/types.ts +96 -6
  17. data/app/javascript/context_drop/widget.ts +752 -29
  18. data/app/models/context_drop/feedback.rb +65 -8
  19. data/app/services/context_drop/ownership_token.rb +114 -0
  20. data/app/views/context_drop/dashboard/feedbacks/index.html.erb +8 -0
  21. data/app/views/context_drop/dashboard/feedbacks/show.html.erb +9 -0
  22. data/app/views/layouts/context_drop/application.html.erb +5 -0
  23. data/config/routes.rb +11 -0
  24. data/db/migrate/20261113000005_add_deleted_at_to_context_drop_feedbacks.rb +11 -0
  25. data/lib/context_drop/configuration.rb +26 -0
  26. data/lib/context_drop/mcp/prompts/investigate_feedback.rb +3 -1
  27. data/lib/context_drop/mcp/tools/get_feedback.rb +16 -5
  28. data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +3 -0
  29. data/lib/context_drop/mcp/tools/list_feedbacks.rb +22 -2
  30. data/lib/context_drop/mcp/tools/update_feedback_status.rb +3 -1
  31. data/lib/context_drop/version.rb +1 -1
  32. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7371b4248b4a488d001c322f7d413cd8f035906b7b2d98b3b920eec072e3aec2
4
- data.tar.gz: dd612c9772f816e414562e689c90841241800ee1fc32ebbf18834812836ca33d
3
+ metadata.gz: 16b4f077f07c74b89396fd21b1d7f7a980795113097d7548094405243d6bf610
4
+ data.tar.gz: fca494a14443de217b7e482659e9fabf092d57b2934859319b4b6bf5c2c81d1a
5
5
  SHA512:
6
- metadata.gz: 85ece3ddde42957a5cf113864284fa6725939770296090ea2ae9e68701c115f535c52acbf3fb98d5edea114c531f01ee3c12ff965411dd1f6a39788b9cd10f96
7
- data.tar.gz: 2643a634b4833e4cd73ad21c9ebe40a5ae5a5d3d45b50f5cb6236e860b0399e0e4151eacffd31dc2df6a18c6f3bc73c8f8350ef21c9ca814ac7eefccc8c56081
6
+ metadata.gz: 76371e87cb66793348ca628ac179a6fc49446ba1a11d50be822184c50d563d078da58c416842992e386022ada8fd4375847bef85b7f641eeb265a28fee8c0313
7
+ data.tar.gz: 06631140fc556a8629fd0fe884c8a31f90974c6f0537e1f33e5c54dda3bed6685fa5c62a9ea4401fcabf44bcef5b9979f55f984dd3b3957ca8aba9bd1dd6ead5
data/README.md CHANGED
@@ -1,27 +1,27 @@
1
1
  <p align="center">
2
- <img src="docs/images/context-drop-hero.svg" alt="ContextDrop, Self-hosted contextual feedback engine, tactile DOM pin-drop widget, and IDE MCP server for Ruby on Rails" width="100%" />
2
+ <img src="https://raw.githubusercontent.com/kemalelmizan/context-drop/main/docs/images/context-drop-hero.svg" alt="ContextDrop, Self-hosted contextual feedback engine, tactile DOM pin-drop widget, and IDE MCP server for Ruby on Rails" width="100%" />
3
3
  </p>
4
4
 
5
5
  <p align="center">
6
- <strong>Stop decoding vague bug reports! Let users pin the problem—and fix it right beside your Rails app</strong><br />
7
- Mountable Rails Engine · Book-Corner Peel-to-Pin Widget · Local BYOK Agentic Sidebar · Unified Multi-Env MCP Hub
6
+ <strong>Stop decoding vague bug reports! Let users pin the problem and fix it right beside your app</strong><br />
7
+ <a href="#nextjs--react-quickstart">Next.js</a> · <a href="#quickstart-ruby-on-rails">Rails</a> · <a href="#mcp">MCP</a>
8
8
  </p>
9
9
 
10
10
  <p align="center">
11
+ <a href="https://www.npmjs.com/package/context-drop"><img src="https://img.shields.io/npm/v/context-drop?label=NPM&color=cb3837&logo=npm" alt="NPM Version" /></a>
11
12
  <a href="https://rubygems.org/gems/context_drop"><img src="https://img.shields.io/gem/v/context_drop?label=RubyGems&color=2563eb" alt="Gem Version" /></a>
12
13
  <a href="https://rubygems.org/gems/context_drop"><img src="https://img.shields.io/gem/dt/context_drop?label=Downloads&color=0f172a" alt="Gem Downloads" /></a>
13
- <img src="https://img.shields.io/badge/Ruby-%3E%3D%203.1-CC342D?logo=ruby&logoColor=white" alt="Ruby >= 3.1" />
14
- <img src="https://img.shields.io/badge/Rails-%3E%3D%207.1-D30001?logo=rubyonrails&logoColor=white" alt="Rails >= 7.1" />
15
14
  <a href="MIT-LICENSE"><img src="https://img.shields.io/badge/License-MIT-16a34a" alt="MIT License" /></a>
16
15
  </p>
17
16
 
18
17
  <p align="center">
18
+ <a href="https://www.npmjs.com/package/context-drop">NPM</a> ·
19
19
  <a href="https://rubygems.org/gems/context_drop">RubyGems</a> ·
20
+ <a href="#nextjs--react-quickstart">Next.js Quickstart</a> ·
21
+ <a href="#quickstart">Rails Quickstart</a> ·
20
22
  <a href="#environment-adaptive-workflow">3-Tier Workflow</a> ·
21
- <a href="#quickstart">Quickstart</a> ·
22
23
  <a href="#interactive-playground">Live Demo</a> ·
23
24
  <a href="#smart--verbose-element-selection">Smart &amp; Verbose Selectors</a> ·
24
- <a href="#local-byok-agentic-sidebar-development-mode">Local Agentic Sidebar</a> ·
25
25
  <a href="#mcp">Unified MCP Hub</a> ·
26
26
  <a href="#zero-trust-privacy--redaction">Privacy &amp; Redaction</a> ·
27
27
  <a href="#configuration">Configuration</a>
@@ -80,7 +80,7 @@ flowchart TD
80
80
  > **Zero Signal Lost in Production!** Even though production users only see friendly labels like `“Complete Order” button` and an automatic surrounding-context screenshot, ContextDrop still captures the full sanitized `selector` (`#checkout-btn`), `dom_path`, `bounding_rect`, `metadata.friendly_label`, and `metadata.original_target_selector` (`span.inner-label`) under the hood—so engineers triaging `production:108` in their IDE via MCP get 100% exact technical coordinates. Need verbose mode in an internal-only production tool (or smart mode in staging)? Override `config.selection_mode = :verbose` or `:smart` in `config/initializers/context_drop.rb`.
81
81
 
82
82
  <p align="center">
83
- <img src="docs/images/demo-pinning-layers.jpg" alt="ContextDrop Pin Mode highlighting an overlapping DOM layer with live dimensions and the Compact Pinning Bar" width="100%" />
83
+ <img src="https://raw.githubusercontent.com/kemalelmizan/context-drop/main/docs/images/demo-pinning-layers.jpg" alt="ContextDrop Pin Mode highlighting an overlapping DOM layer with live dimensions and the Compact Pinning Bar" width="100%" />
84
84
  </p>
85
85
 
86
86
  > **Above:** Active **Pin Mode** on the live demo page. While hovering over a stacked UI card (`section #scenario-overlapping-layers · 681×350 · 1/6 layers`), ContextDrop frames the target in Inspector Cobalt, displays layer depth for mouse-wheel cycling, and collapses the chatbox into the **Compact Pinning Bar** (`Pinning`, live DOM ancestor breadcrumbs, Up/Down layer controls, and `Chat` toggle) so the host page stays completely unobstructed.
@@ -95,13 +95,13 @@ flowchart TD
95
95
  <tbody>
96
96
  <tr>
97
97
  <td valign="top">
98
- <img src="docs/images/demo-chatbox-composer.jpg" alt="ContextDrop floating chatbox composer with top-left Pin Element trigger and toolbar" width="100%" />
98
+ <img src="https://raw.githubusercontent.com/kemalelmizan/context-drop/main/docs/images/demo-chatbox-composer.jpg" alt="ContextDrop floating chatbox composer with top-left Pin Element trigger and toolbar" width="100%" />
99
99
  <p>
100
100
  Drop <code>&lt;%= context_drop_widget %&gt;</code> into your layout to render a flush <code>38×38px</code> folded <strong>Book Corner</strong>. Click the corner to open the normal feedback chatbox (or docked local Agentic Sidebar), or drag the corner to morph it into a pushpin and drop it straight onto an element.
101
101
  </p>
102
102
  </td>
103
103
  <td valign="top">
104
- <img src="docs/images/demo-pinned-element-chip.png" alt="ContextDrop chatbox with a pinned DOM element chip, camera screenshot button, and confirmation banner" width="100%" />
104
+ <img src="https://raw.githubusercontent.com/kemalelmizan/context-drop/main/docs/images/demo-pinned-element-chip.png" alt="ContextDrop chatbox with a pinned DOM element chip, camera screenshot button, and confirmation banner" width="100%" />
105
105
  <p>
106
106
  Every pinned element is added to the context tray (`#scenario-overlapping-layers`) with a live count badge (`Pin Element 1`). Hover the chip to highlight the element on the page, click the camera icon to crop a screenshot of that exact node, and hit <strong>Send</strong>.
107
107
  </p>
@@ -129,7 +129,140 @@ flowchart TD
129
129
 
130
130
  ---
131
131
 
132
- ## Quickstart
132
+ ## Next.js & React Quickstart
133
+
134
+ ContextDrop ships as a **zero-dependency** NPM package ([`context-drop`](https://www.npmjs.com/package/context-drop)) supporting both **standalone full-stack Next.js** (App Router & Pages Router + pluggable storage + `npx context-drop mcp`) and **decoupled Next.js / React frontends** connected to a Ruby on Rails `context_drop` backend.
135
+
136
+ ### 1. Install & Scaffold Route Handler
137
+
138
+ ```bash
139
+ npm install context-drop
140
+ npx context-drop init
141
+ ```
142
+
143
+ `npx context-drop init` auto-detects **App Router** (`app/api/context-drop/[[...path]]/route.ts`) or **Pages Router** (`pages/api/context-drop/[[...path]].ts`) and adds `.context-drop/` to `.gitignore`:
144
+
145
+ ```ts
146
+ // app/api/context-drop/[[...path]]/route.ts
147
+ import { createContextDropNextHandler } from "context-drop/next/server";
148
+
149
+ export const { GET, POST, OPTIONS } = createContextDropNextHandler({
150
+ // Zero-config local default stores SQLite/JSON + redacted screenshots in .context-drop/
151
+ mcp: {
152
+ enabled: Boolean(process.env.CONTEXT_DROP_MCP_API_KEY),
153
+ apiKey: process.env.CONTEXT_DROP_MCP_API_KEY
154
+ }
155
+ });
156
+ ```
157
+
158
+ ### 2. Mount `<ContextDrop />` in Your Root Layout
159
+
160
+ `context-drop/next` includes `"use client"` out of the box—drop `<ContextDrop />` directly into your Server Component `app/layout.tsx` with zero wrapper boilerplate and zero hydration mismatches:
161
+
162
+ ```tsx
163
+ // app/layout.tsx
164
+ import { ContextDrop } from "context-drop/next";
165
+
166
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
167
+ return (
168
+ <html lang="en">
169
+ <body>
170
+ {children}
171
+ <ContextDrop
172
+ position="bottom_right"
173
+ metadata={{ release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA }}
174
+ />
175
+ </body>
176
+ </html>
177
+ );
178
+ }
179
+ ```
180
+
181
+ Want to open ContextDrop from your own navbar or help menu? Call `useContextDrop()` from any client component:
182
+
183
+ ```tsx
184
+ "use client";
185
+ import { useContextDrop } from "context-drop/next";
186
+
187
+ export function ReportBugButton() {
188
+ const { open } = useContextDrop();
189
+ return <button onClick={open}>Report an issue</button>;
190
+ }
191
+ ```
192
+
193
+ ### 3. Connect Your IDE Coding Agent via MCP (`npx context-drop mcp`)
194
+
195
+ Register **one** unified `stdio` MCP server in `.mcp.json` (Claude Code), `~/.cursor/mcp.json` (Cursor), or `mcp_config.json` (Antigravity / Windsurf). It automatically loads `.env.local` / `.env` and federates `local` + remote `staging` & `production` Next.js (or Rails!) deployments:
196
+
197
+ ```json
198
+ {
199
+ "mcpServers": {
200
+ "context-drop": {
201
+ "command": "npx",
202
+ "args": ["context-drop", "mcp"],
203
+ "env": {
204
+ "CONTEXT_DROP_STAGING_MCP_URL": "https://staging.your-app.com/api/context-drop/mcp",
205
+ "CONTEXT_DROP_STAGING_MCP_API_KEY": "your-staging-mcp-bearer-token",
206
+ "CONTEXT_DROP_PRODUCTION_MCP_URL": "https://your-app.com/api/context-drop/mcp",
207
+ "CONTEXT_DROP_PRODUCTION_MCP_API_KEY": "your-production-mcp-bearer-token"
208
+ }
209
+ }
210
+ }
211
+ }
212
+ ```
213
+
214
+ ### 4. Production Storage Adapters (PostgreSQL, S3 / Vercel Blob, or Custom ORM)
215
+
216
+ Locally, ContextDrop works with zero configuration using Node's built-in SQLite (`node:sqlite`, or atomic JSON fallback) inside `.context-drop/`. For staging and production Next.js deployments (Vercel, Fly, AWS, Render, Railway), plug in `createPostgresStorageAdapter` (compatible with `pg.Pool`, `@vercel/postgres`, Neon, and Supabase) or implement the `StorageAdapter` interface for Prisma / Drizzle:
217
+
218
+ ```ts
219
+ // app/api/context-drop/[[...path]]/route.ts
220
+ import { Pool } from "pg";
221
+ import {
222
+ createContextDropNextHandler,
223
+ createPostgresStorageAdapter
224
+ } from "context-drop/next/server";
225
+
226
+ const pool = new Pool({ connectionString: process.env.DATABASE_URL });
227
+
228
+ export const { GET, POST, OPTIONS } = createContextDropNextHandler({
229
+ storage: createPostgresStorageAdapter({
230
+ pool,
231
+ autoMigrate: true // Creates context_drop_* tables automatically if missing
232
+ // Optional blobStore: { putBlob, getBlob, deleteBlob } for S3 / R2 / Vercel Blob
233
+ }),
234
+ resolveSubmitter: async (request) => {
235
+ // Optional: attach your NextAuth / Clerk / Supabase user identity
236
+ return null;
237
+ },
238
+ mcp: {
239
+ enabled: true,
240
+ apiKey: process.env.CONTEXT_DROP_MCP_API_KEY
241
+ }
242
+ });
243
+ ```
244
+
245
+ ### 5. Connecting Next.js to a Ruby on Rails Backend
246
+
247
+ Already running `ContextDrop::Engine` on Rails? Point `<ContextDrop />` at your Rails mount path:
248
+ - **Via Next.js Rewrites (Same-Origin, Recommended):** Proxy `/context_drop/:path*` to your Rails API in `next.config.ts` and render `<ContextDrop endpoint="/context_drop" />`.
249
+ - **Cross-Origin CORS:** Add `config.allowed_origins = ["http://localhost:3000", "https://app.example.com"]` in `config/initializers/context_drop.rb` and render `<ContextDrop endpoint="https://api.example.com/context_drop" credentials="include" />`.
250
+
251
+ ### NPM Package Exports Reference
252
+
253
+ | Import Path | Environment | Exports |
254
+ |---|---|---|
255
+ | `context-drop/next` | Client (`"use client"`) | Next.js `<ContextDrop />`, `<ContextDropWidget />`, `useContextDrop()` (defaults to `/api/context-drop`) |
256
+ | `context-drop/next/server` | Node / Server | `createContextDropNextHandler`, `createContextDropPagesHandler`, `createContextDropFetchHandler`, `createLocalStorageAdapter`, `createPostgresStorageAdapter`, `createMemoryStorageAdapter` |
257
+ | `context-drop/react` | Client (`"use client"`) | Framework-agnostic React `<ContextDrop />`, `useContextDrop()` (defaults to `/context_drop`) |
258
+ | `context-drop/mcp` | Node / Server | `createContextDropMcpServer`, `runContextDropMcpStdio`, `ContextDropMcpDispatcher`, `EnvironmentRouter` |
259
+ | `context-drop/widget` | Browser | Auto-registering `<context-drop-widget>` Web Component & `ContextDropApiClient` |
260
+ | `context-drop/bundle` | Browser IIFE | Self-contained `<script>` bundle (`context_drop.js`) |
261
+ | `npx context-drop` | CLI | `npx context-drop mcp` (stdio MCP server) & `npx context-drop init` (Next.js scaffolder) |
262
+
263
+ ---
264
+
265
+ ## Quickstart (Ruby on Rails)
133
266
 
134
267
  ### Requirements
135
268
 
@@ -289,7 +422,7 @@ Because user-submitted feedback messages from `staging` or `production` are untr
289
422
  ContextDrop ships with a built-in **Model Context Protocol (MCP)** server (`ContextDrop::MCP::Server`) so you or your AI coding agent can pull bug reports, inspect exact CSS selectors and DOM paths, view multimodal screenshots, and mark issues resolved without leaving your editor.
290
423
 
291
424
  <p align="center">
292
- <img src="docs/images/demo-mcp-agent.png" alt="ContextDrop MCP server tool calls (list_feedbacks and get_feedback) and root-cause diagnosis inside an AI coding agent" width="100%" />
425
+ <img src="https://raw.githubusercontent.com/kemalelmizan/context-drop/main/docs/images/demo-mcp-agent.png" alt="ContextDrop MCP server tool calls (list_feedbacks and get_feedback) and root-cause diagnosis inside an AI coding agent" width="100%" />
293
426
  </p>
294
427
 
295
428
  > **Above:** Triage flow inside an AI coding agent connected to the `context-drop` MCP server on the live playground. The agent invokes `list_feedbacks` (`{ status: "new" }`) and `get_feedback` (`{ id: 12, include_images: true }`), inspects both the structured `ElementReference` geometry (`button#upgrade-cluster-btn`, `169.1×33px`) and the redacted multimodal `image/png` screenshot block, and pinpoints the exact overlapping CSS rule in `demo/index.html`.
@@ -562,6 +695,10 @@ npm test
562
695
 
563
696
  # Run backend Ruby engine & MCP specs
564
697
  ruby spec/run_all.rb
698
+
699
+ # Bump synchronized Gem + NPM version and cut a signed unified release (GitHub + RubyGems + NPM)
700
+ bundle exec rake "version:bump[0.2.1]"
701
+ bundle exec rake release
565
702
  ```
566
703
 
567
704
  Further architectural documentation:
data/Rakefile CHANGED
@@ -1,8 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "json"
4
+ require "shellwords"
3
5
  require "bundler/gem_tasks"
4
6
  require "rake/testtask"
5
7
 
8
+ module ContextDropReleaseExtension
9
+ protected
10
+
11
+ def sign_git_tag?
12
+ !%w[n no nil false off 0].include?(ENV["sign_tag"].to_s.downcase)
13
+ end
14
+
15
+ def tag_version
16
+ tag_cmd = ["git", "tag"]
17
+ tag_cmd << "-s" if sign_git_tag?
18
+ tag_cmd.push("-m", "Version #{version}", version_tag)
19
+
20
+ tagged = false
21
+ Bundler.ui.debug(tag_cmd)
22
+ Bundler::SharedHelpers.chdir(base) do
23
+ unless Kernel.system(*tag_cmd)
24
+ raise("Running `#{tag_cmd.shelljoin}` failed. Ensure git signing (user.signingkey / gpg.format) is configured, or pass sign_tag=no.")
25
+ end
26
+ tagged = true
27
+ end
28
+
29
+ Bundler.ui.confirm "Tagged #{version_tag}#{sign_git_tag? ? ' (signed)' : ''}."
30
+ yield if block_given?
31
+ rescue RuntimeError
32
+ if tagged
33
+ Bundler.ui.error "Untagging #{version_tag} due to error."
34
+ sh_with_status %W[git tag -d #{version_tag}]
35
+ end
36
+ raise
37
+ end
38
+ end
39
+
40
+ Bundler::GemHelper.prepend(ContextDropReleaseExtension)
41
+
6
42
  Rake::TestTask.new(:test) do |t|
7
43
  t.libs << "lib"
8
44
  t.libs << "spec"
@@ -11,10 +47,83 @@ Rake::TestTask.new(:test) do |t|
11
47
  end
12
48
 
13
49
  namespace :assets do
14
- desc "Build the decoupled TypeScript widget into app/assets/javascripts/context_drop/context_drop.js"
50
+ desc "Build the TypeScript widget bundle and NPM dist/ artifacts"
15
51
  task :build do
16
52
  sh "npm run build"
17
53
  end
18
54
  end
19
55
 
56
+ namespace :version do
57
+ desc "Synchronize version across RubyGem, package.json, and TypeScript sources (e.g. rake 'version:bump[0.2.1]')"
58
+ task :bump, [:new_version] do |_, args|
59
+ new_version = args[:new_version].to_s.strip
60
+ unless new_version.match?(/\A\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?\z/)
61
+ abort "Usage: bundle exec rake 'version:bump[X.Y.Z]' (got #{new_version.inspect})"
62
+ end
63
+
64
+ root = File.expand_path(__dir__)
65
+
66
+ version_rb = File.join(root, "lib/context_drop/version.rb")
67
+ updated_rb = File.read(version_rb).sub(/VERSION\s*=\s*"[^"]+"/, %(VERSION = "#{new_version}"))
68
+ File.write(version_rb, updated_rb)
69
+
70
+ ts_types = File.join(root, "src/server/types.ts")
71
+ updated_ts = File.read(ts_types).sub(/export const VERSION\s*=\s*"[^"]+";/, %(export const VERSION = "#{new_version}";))
72
+ File.write(ts_types, updated_ts)
73
+
74
+ sh "npm", "version", new_version, "--no-git-tag-version", "--allow-same-version"
75
+ sh "npm", "run", "build"
76
+
77
+ puts "Synchronized ContextDrop version to #{new_version} across RubyGem and NPM."
78
+ end
79
+ end
80
+
81
+ namespace :release do
82
+ desc "Verify RubyGem, package.json, and TypeScript VERSION constants match"
83
+ task :verify_versions do
84
+ root = File.expand_path(__dir__)
85
+ gem_version = Bundler::GemHelper.instance.gemspec.version.to_s
86
+ pkg_version = JSON.parse(File.read(File.join(root, "package.json"))).fetch("version")
87
+ ts_content = File.read(File.join(root, "src/server/types.ts"))
88
+ ts_version = ts_content[/export const VERSION\s*=\s*"([^"]+)"/, 1]
89
+
90
+ if [gem_version, pkg_version, ts_version].uniq.size != 1
91
+ abort <<~MSG
92
+ Version mismatch detected before release!
93
+ lib/context_drop/version.rb : #{gem_version}
94
+ package.json : #{pkg_version}
95
+ src/server/types.ts : #{ts_version}
96
+ Run `bundle exec rake "version:bump[#{gem_version}]"` to synchronize them first.
97
+ MSG
98
+ end
99
+ end
100
+
101
+ desc "Publish context-drop NPM package to npmjs.org (skip with npm_push=no)"
102
+ task :npm_push do
103
+ next if %w[n no nil false off 0].include?(ENV["npm_push"].to_s.downcase)
104
+
105
+ pkg_version = JSON.parse(File.read(File.expand_path("package.json", __dir__))).fetch("version")
106
+ existing_out = IO.popen(%W[npm view context-drop@#{pkg_version} version], err: [:child, :out], &:read)
107
+ if $?.success? && existing_out.strip == pkg_version
108
+ Bundler.ui.confirm "context-drop@#{pkg_version} is already published on npmjs.org, skipping."
109
+ next
110
+ end
111
+
112
+ Bundler.ui.confirm "Publishing context-drop@#{pkg_version} to npmjs.org..."
113
+ abort "npm publish failed!" unless Kernel.system("npm", "publish", "--access", "public")
114
+ Bundler.ui.confirm "Pushed context-drop@#{pkg_version} to npmjs.org."
115
+ end
116
+ end
117
+
118
+ Rake::Task["build"].enhance(["assets:build"])
119
+ Rake::Task["release:guard_clean"].enhance(["release:verify_versions"])
120
+ Rake::Task["release"].enhance do
121
+ Rake::Task["release:npm_push"].invoke
122
+ end
123
+ Rake::Task["release"].clear_comments
124
+ Rake::Task["release"].add_description(
125
+ "Create signed tag v#{ContextDrop::VERSION}, build & push context_drop-#{ContextDrop::VERSION}.gem to RubyGems, " \
126
+ "and publish context-drop@#{ContextDrop::VERSION} to NPM (skip with gem_push=no / npm_push=no / sign_tag=no)"
127
+ )
128
+
20
129
  task default: :test