@mayson-org/inject-script
v1.0.32
Published
CLI and library to inject Mayson watermark, ascii, and PWA into Next.js App Router layouts.
Downloads
2,183
Readme
@mayson-org/inject-script
Locate the Next.js App Router root layout, generate Mayson plugin components next to it, and inject imports + JSX into the layout. Injection logic is unchanged; plugins supply component source. The pwa plugin also writes project-level artifacts (public/, manifest.ts, layout meta).
Requires Node 20+.
Install
bun add -d @mayson-org/inject-script@latest
# or
npx @mayson-org/inject-script --type=watermarkQuick usage
npx @mayson-org/inject-script # watermark + ascii + pwa
npx @mayson-org/inject-script --type=watermark
npx @mayson-org/inject-script --type=pwa
npx @mayson-org/inject-script --type=all
npx @mayson-org/inject-script --no-pwa
npx @mayson-org/inject-script --type=watermark --dry-run
npx @mayson-org/inject-script --dir=./my-appWatermark
--type=watermark writes MaysonWatermark.tsx beside the root layout and injects <MaysonWatermark /> before </body>.
The pill:
- Fixed bottom-right “Edit with Mayson” (logo + label)
- Dismiss (×) hides it for the session
- Click navigates to https://mayson.dev/ (hardcoded for now)
API gating (show_remix_pill / enable_remix)
At inject time the CLI fetches generated-app-metadata (same API as the old build plugins):
GET {MAYSON_API_BASE_URL}/sigma/web/v1/generated-app-metadata/workspaces/{id}/collections/{id}
Header: M-Web-Token: {MAYSON_WEB_TOKEN}
| API field | Effect |
|-----------|--------|
| show_remix_pill | If false, watermark is not injected; if true, inject |
| enable_remix | Still fetched for later use; click target is hardcoded to https://mayson.dev/ for now |
| website_title | Optional; used as PWA manifest name / short_name when present |
Metadata not found (404): if the API returns HTTP 404 or a body like { "response_code": 404, "message": "Generated app metadata not found", "value": {} }, treat as show_remix_pill=true and enable_remix=true (show watermark).
Defaults when the API is not called or fails for other reasons: showRemixPill=false, enableRemix=false (watermark skipped).
Env vars (inject-time)
| Variable | Purpose |
|----------|---------|
| MAYSON_WORKSPACE_ID | Workspace id |
| MAYSON_COLLECTION_ID | Collection id (also baked into remix URL) |
| MAYSON_API_BASE_URL | API base for metadata |
| MAYSON_APP_BASE_URL | App base (default https://mayson.dev) |
| MAYSON_WEB_TOKEN | Auth for generated-app-metadata |
| MAYSON_WEBSITE_TITLE | Optional PWA/manifest app name (else API website_title, else "My App") |
PWA
Default-on (like ascii). Skip with --no-pwa.
Writes / patches:
| Target | Behavior |
|--------|----------|
| {layoutDir}/MaysonServiceWorkerRegister.tsx | Prod-only /sw.js register; layout-injected |
| {layoutDir}/MaysonInstallPrompt.tsx | Install UI (beforeinstallprompt, iOS hint, ?pwa_install=1); inline styles |
| {appDir}/manifest.ts | Write if missing; refresh if marked @mayson-pwa-manifest; else skip |
| {projectRoot}/public/sw.js | Write/overwrite if missing or marked @mayson-pwa-sw (mayson-pwa-v1 cache) |
| {projectRoot}/public/icons/*.png | Copy default Mayson icons if missing (never overwrite) |
| Root layout metadata | Insert appleWebApp / viewport.themeColor when absent |
No next-pwa / Workbox deps. Custom unmarked manifest.ts / sw.js are left alone.
Programmatic API
import { runAutoInject } from '@mayson-org/inject-script';
const result = await runAutoInject(process.cwd()); // watermark + ascii + pwa
await runAutoInject(process.cwd(), { types: ['pwa'], dryRun: true });
await runAutoInject(process.cwd(), { pwa: false }); // skip PWAPackage layout
src/
cli.ts / index.ts
core/ # find-root-layout, injector, generators
plugins/watermark/ # remix pill template
plugins/ascii|metadata
plugins/pwa/ # multi-artifact injectProject
shared/ # config, generated-app-metadata, remix-url
assets/pwa/ # default PWA icons shipped with the packageNotes
- Default inject is watermark + ascii + pwa (override with
--type/--no-pwa). - Watermark is gated by
show_remix_pill; ascii and pwa always inject when selected. - Idempotent: skips components already present; does not clobber custom icons or unmarked PWA files.
- Does not patch
.nextHTML; source inject only.
