document360-capture 0.2.1 → 0.2.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.
Files changed (2) hide show
  1. package/dist/cli.js +8 -8
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import{Command as yo}from"commander";import{createRequire as Po}from"node:module";import{input as Lt,confirm as Bt}from"@inquirer/prompts";import{existsSync as _,readFileSync as Mt}from"node:fs";import{basename as _t,join as Ft}from"node:path";import{readFileSync as O,writeFileSync as bt,existsSync as N}from"node:fs";import{basename as Rt,join as T}from"node:path";var At=".d360-capture.json",D={captureDir:"user-docs/_capture",outputDir:"user-docs/_screenshots",viewport:{width:1440,height:900},loginTimeoutMs:0,annotation:{enabled:!0}},x=class extends Error{};function f(t=process.cwd()){return T(t,At)}function d(t){if(!N(t))throw new Error(`No project config at ${t}. Run \`d360-capture init\` to create one.`);let o=JSON.parse(O(t,"utf8").replace(/^/,""));return Ut(o,t)}function S(t,o){bt(t,JSON.stringify(o,null,2)+`
3
- `,"utf8")}function It(t){try{return"^"+new URL(t).origin.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}catch{return"."}}function Ut(t,o,e=process.cwd()){kt(t,o);let r=Object.keys(t.profiles),n=t.defaultProfile??(r.length===1?r[0]:r.includes("staging")?"staging":r[0]);return{projectId:t.projectId||Ot(e)||Rt(e),captureDir:t.captureDir??D.captureDir,outputDir:t.outputDir??D.outputDir,viewport:t.viewport??{...D.viewport},loginTimeoutMs:t.loginTimeoutMs??D.loginTimeoutMs,annotation:t.annotation??{...D.annotation},profiles:t.profiles,defaultProfile:n}}function v(t,o){let e=o??t.defaultProfile,r=t.profiles[e];if(!r){let i=Object.keys(t.profiles).join(", ");throw new x(`Unknown profile "${e}". Available: ${i}`)}let n=r.connection.authBoundaryUrlPattern;return{name:e,connection:{startUrl:r.connection.startUrl,authBoundaryUrlPattern:n||It(r.connection.startUrl)},captureDir:r.captureDir??t.captureDir,outputDir:r.outputDir??t.outputDir,viewport:r.viewport??t.viewport,production:r.production===!0,authBoundaryDefaulted:!n}}function kt(t,o){if(t.environments&&!t.profiles)throw new x(`Config at ${o} uses the old "environments" shape, which is no longer supported. It is now "profiles" (each with a "connection" { startUrl }) + "defaultProfile". Re-run \`d360-capture init\`, then \`d360-capture auth --profile <name>\`.`);if(!t.profiles||Object.keys(t.profiles).length===0)throw new x(`Invalid config at ${o}: needs at least one profile under "profiles".`);for(let[e,r]of Object.entries(t.profiles))if(!r?.connection?.startUrl)throw new x(`Invalid config at ${o}: profile "${e}" is missing connection.startUrl.`);if(t.defaultProfile&&!t.profiles[t.defaultProfile])throw new x(`Invalid config at ${o}: defaultProfile "${t.defaultProfile}" is not in profiles.`)}function Ot(t){let o=T(t,"package.json");if(!N(o))return null;try{return JSON.parse(O(o,"utf8")).name??null}catch{return null}}import{existsSync as E,readFileSync as Nt}from"node:fs";import{join as Tt}from"node:path";var Et=".d360-writer.json";function L(t=process.cwd()){return Tt(t,Et)}function B(t=process.cwd()){return E(L(t))}function M(t=process.cwd()){let o=L(t);if(!E(o))return{};try{let e=JSON.parse(Nt(o,"utf8").replace(/^/,"")),r=e.docsDir?.replace(/\/+$/,"");return{projectId:e.projectId,captureDir:e.captureDir??(r?`${r}/_capture`:void 0),outputDir:e.outputDir??(r?`${r}/_screenshots`:void 0)}}catch{return{}}}async function F(t={}){let o=process.cwd(),e=f(o),r=t.yes===!0;if(_(e)&&!r&&!await Bt({message:`${e} already exists. Overwrite?`,default:!1})){console.log("Init cancelled.");return}let n=M(o),i=n.projectId||Wt(o)||_t(o),s=[n.projectId&&"project name",n.captureDir&&"directories"].filter(Boolean);s.length>0?(console.log(""),console.log(`Found .d360-writer.json \u2014 inheriting ${s.join(" + ")}.`)):B(o)&&(console.log(""),console.log("Found .d360-writer.json (could not read defaults from it \u2014 using built-in defaults)."));let a=r?"https://example.com/":await Lt({message:"Live app URL (where captures start):",default:"https://example.com/",validate:g=>g.startsWith("http")?!0:"Must be a full URL"}),l={projectId:i,...n.captureDir?{captureDir:n.captureDir}:{},...n.outputDir?{outputDir:n.outputDir}:{},profiles:{staging:{connection:{startUrl:a}}},defaultProfile:"staging"};S(e,l),console.log(""),console.log(`\u2713 Wrote ${e}`),r&&a==="https://example.com/"&&console.log(" \u26A0 Set the staging profile's connection.startUrl to your real app URL."),console.log(""),console.log("Next steps:"),console.log(" 1. d360-capture auth # log in once, no timeout"),console.log(" 2. d360-capture capture # run all specs in the capture dir"),console.log(""),console.log("Add a prod profile or tune the auth boundary later by editing .d360-capture.json."),console.log("")}function Wt(t){let o=Ft(t,"package.json");if(!_(o))return null;try{return JSON.parse(Mt(o,"utf8")).name??null}catch{return null}}import{chromium as Ht}from"playwright";import{existsSync as W,mkdirSync as Jt,statSync as qt}from"node:fs";import{homedir as zt}from"node:os";import{join as b,dirname as Lo}from"node:path";function J(){return b(zt(),".document360-capture","auth-states")}function C(t,o){return b(J(),t,`${o}.json`)}function q(t){let o=b(J(),t);W(o)||Jt(o,{recursive:!0})}function $(t,o){let e=C(t,o);if(!W(e))return{path:e,exists:!1};let r=qt(e);return{path:e,exists:!0,ageMs:Date.now()-r.mtimeMs}}async function z(t){let o=d(f()),e=v(o,t.profile);q(o.projectId);let r=C(o.projectId,e.name);console.log(""),e.production&&console.log(`\u26A0 Profile "${e.name}" is PRODUCTION.`),console.log(`Opening Chromium against ${e.connection.startUrl}`),console.log(`Auth-state will save to: ${r}`),console.log("");let n=await Ht.launch({headless:!1,args:["--start-maximized"]}),i=await n.newContext({viewport:null}),s=await i.newPage();await s.goto(e.connection.startUrl,{waitUntil:"domcontentloaded"}),console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),console.log(" Log in fully (MFA included) at your own pace."),console.log(" When you reach the post-login app, come back to this"),console.log(" terminal and press ENTER to save the session."),console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),console.log("");let a=new RegExp(e.connection.authBoundaryUrlPattern),l=setInterval(()=>{a.test(s.url())&&i.storageState({path:r}).catch(()=>{})},3e4);try{for(;;){await Gt();let g=s.url();if(a.test(g))break;console.log(""),console.log("\u2717 Login doesn't look complete yet \u2014 the browser is still at:"),console.log(` ${g}`),console.log(" Finish logging in until you can see the app, then press ENTER again."),console.log(" (Ctrl+C aborts without saving.)")}await i.storageState({path:r}),console.log(""),console.log(`\u2713 Session saved to ${r}`),console.log(" This file contains session cookies \u2014 never commit it to git.")}finally{clearInterval(l),await n.close().catch(()=>{})}}function Gt(){return new Promise(t=>{let o=()=>{process.stdin.off("data",o),process.stdin.pause(),t()};process.stdin.resume(),process.stdin.once("data",o)})}import{existsSync as po}from"node:fs";import{isAbsolute as lt,resolve as pt}from"node:path";import{writeFileSync as H,mkdirSync as Xt,existsSync as G}from"node:fs";import{createRequire as Yt}from"node:module";import{join as j,isAbsolute as X,resolve as Y}from"node:path";var R=Yt(import.meta.url);function V(t){let{cwd:o,profileName:e,captureDir:r,viewport:n,storageStatePath:i}=t,s=j(o,".d360-capture-cache");G(s)||Xt(s,{recursive:!0});let a=j(s,`playwright.${e}.config.cjs`),l=X(r)?r:Y(o,r),g=X(i)?i:Y(o,i),u=R.resolve("@playwright/test"),h=`// Generated by document360-capture \u2014 do not edit by hand.
4
- const { defineConfig } = require(${JSON.stringify(u)});
2
+ import{Command as yo}from"commander";import{createRequire as Po}from"node:module";import{input as Lt,confirm as Bt}from"@inquirer/prompts";import{existsSync as _,readFileSync as Mt}from"node:fs";import{basename as _t,join as Ft}from"node:path";import{readFileSync as O,writeFileSync as bt,existsSync as N}from"node:fs";import{basename as Rt,join as T}from"node:path";var At=".d360-capture.json",D={captureDir:"user-docs/_capture",outputDir:"user-docs/_screenshots",viewport:{width:1440,height:900},loginTimeoutMs:0,annotation:{enabled:!0}},x=class extends Error{};function d(t=process.cwd()){return T(t,At)}function h(t){if(!N(t))throw new Error(`No project config at ${t}. Run \`d360-capture init\` to create one.`);let o=JSON.parse(O(t,"utf8").replace(/^/,""));return It(o,t)}function S(t,o){bt(t,JSON.stringify(o,null,2)+`
3
+ `,"utf8")}function Ut(t){try{return"^"+new URL(t).origin.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}catch{return"."}}function It(t,o,e=process.cwd()){kt(t,o);let r=Object.keys(t.profiles),n=t.defaultProfile??(r.length===1?r[0]:r.includes("staging")?"staging":r[0]);return{projectId:t.projectId||Ot(e)||Rt(e),captureDir:t.captureDir??D.captureDir,outputDir:t.outputDir??D.outputDir,viewport:t.viewport??{...D.viewport},loginTimeoutMs:t.loginTimeoutMs??D.loginTimeoutMs,annotation:t.annotation??{...D.annotation},profiles:t.profiles,defaultProfile:n}}function v(t,o){let e=o??t.defaultProfile,r=t.profiles[e];if(!r){let i=Object.keys(t.profiles).join(", ");throw new x(`Unknown profile "${e}". Available: ${i}`)}let n=r.connection.authBoundaryUrlPattern;return{name:e,connection:{startUrl:r.connection.startUrl,authBoundaryUrlPattern:n||Ut(r.connection.startUrl)},captureDir:r.captureDir??t.captureDir,outputDir:r.outputDir??t.outputDir,viewport:r.viewport??t.viewport,production:r.production===!0,authBoundaryDefaulted:!n}}function kt(t,o){if(t.environments&&!t.profiles)throw new x(`Config at ${o} uses the old "environments" shape, which is no longer supported. It is now "profiles" (each with a "connection" { startUrl }) + "defaultProfile". Re-run \`d360-capture init\`, then \`d360-capture auth --profile <name>\`.`);if(!t.profiles||Object.keys(t.profiles).length===0)throw new x(`Invalid config at ${o}: needs at least one profile under "profiles".`);for(let[e,r]of Object.entries(t.profiles))if(!r?.connection?.startUrl)throw new x(`Invalid config at ${o}: profile "${e}" is missing connection.startUrl.`);if(t.defaultProfile&&!t.profiles[t.defaultProfile])throw new x(`Invalid config at ${o}: defaultProfile "${t.defaultProfile}" is not in profiles.`)}function Ot(t){let o=T(t,"package.json");if(!N(o))return null;try{return JSON.parse(O(o,"utf8")).name??null}catch{return null}}import{existsSync as E,readFileSync as Nt}from"node:fs";import{join as Tt}from"node:path";var Et=".d360-writer.json";function L(t=process.cwd()){return Tt(t,Et)}function B(t=process.cwd()){return E(L(t))}function M(t=process.cwd()){let o=L(t);if(!E(o))return{};try{let e=JSON.parse(Nt(o,"utf8").replace(/^/,"")),r=e.docsDir?.replace(/\/+$/,"");return{projectId:e.projectId,captureDir:e.captureDir??(r?`${r}/_capture`:void 0),outputDir:e.outputDir??(r?`${r}/_screenshots`:void 0)}}catch{return{}}}async function F(t={}){let o=process.cwd(),e=d(o),r=t.yes===!0;if(_(e)&&!r&&!await Bt({message:`${e} already exists. Overwrite?`,default:!1})){console.log("Init cancelled.");return}let n=M(o),i=n.projectId||Wt(o)||_t(o),a=[n.projectId&&"project name",n.captureDir&&"directories"].filter(Boolean);a.length>0?(console.log(""),console.log(`Found .d360-writer.json \u2014 inheriting ${a.join(" + ")}.`)):B(o)&&(console.log(""),console.log("Found .d360-writer.json (could not read defaults from it \u2014 using built-in defaults)."));let s=r?"https://example.com/":await Lt({message:"Live app URL (where captures start):",default:"https://example.com/",validate:p=>p.startsWith("http")?!0:"Must be a full URL"}),u={projectId:i,...n.captureDir?{captureDir:n.captureDir}:{},...n.outputDir?{outputDir:n.outputDir}:{},profiles:{staging:{connection:{startUrl:s}}},defaultProfile:"staging"};S(e,u),console.log(""),console.log(`\u2713 Wrote ${e}`),r&&s==="https://example.com/"&&console.log(" \u26A0 Set the staging profile's connection.startUrl to your real app URL."),console.log(""),console.log("Next steps:"),console.log(" 1. d360-capture auth # log in once, no timeout"),console.log(" 2. d360-capture capture # run all specs in the capture dir"),console.log(""),console.log("Add a prod profile or tune the auth boundary later by editing .d360-capture.json."),console.log("")}function Wt(t){let o=Ft(t,"package.json");if(!_(o))return null;try{return JSON.parse(Mt(o,"utf8")).name??null}catch{return null}}import{chromium as Ht}from"playwright";import{existsSync as W,mkdirSync as Jt,statSync as qt}from"node:fs";import{homedir as zt}from"node:os";import{join as b,dirname as Lo}from"node:path";function J(){return b(zt(),".document360-capture","auth-states")}function C(t,o){return b(J(),t,`${o}.json`)}function q(t){let o=b(J(),t);W(o)||Jt(o,{recursive:!0})}function $(t,o){let e=C(t,o);if(!W(e))return{path:e,exists:!1};let r=qt(e);return{path:e,exists:!0,ageMs:Date.now()-r.mtimeMs}}async function z(t){let o=h(d()),e=v(o,t.profile);q(o.projectId);let r=C(o.projectId,e.name);console.log(""),e.production&&console.log(`\u26A0 Profile "${e.name}" is PRODUCTION.`),console.log(`Opening Chromium against ${e.connection.startUrl}`),console.log(`Auth-state will save to: ${r}`),console.log("");let n=await Ht.launch({headless:!1,args:["--start-maximized"]}),i=await n.newContext({viewport:null}),a=await i.newPage();await a.goto(e.connection.startUrl,{waitUntil:"domcontentloaded"}),console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),console.log(" Log in fully (MFA included) at your own pace."),console.log(" When you reach the post-login app, come back to this"),console.log(" terminal and press ENTER to save the session."),console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),console.log("");let s=new RegExp(e.connection.authBoundaryUrlPattern),u=setInterval(()=>{s.test(a.url())&&i.storageState({path:r}).catch(()=>{})},3e4);try{for(;;){await Gt();let p=a.url();if(s.test(p))break;console.log(""),console.log("\u2717 Login doesn't look complete yet \u2014 the browser is still at:"),console.log(` ${p}`),console.log(" Finish logging in until you can see the app, then press ENTER again."),console.log(" (Ctrl+C aborts without saving.)")}await i.storageState({path:r}),console.log(""),console.log(`\u2713 Session saved to ${r}`),console.log(" This file contains session cookies \u2014 never commit it to git.")}finally{clearInterval(u),await n.close().catch(()=>{})}}function Gt(){return new Promise(t=>{let o=()=>{process.stdin.off("data",o),process.stdin.pause(),t()};process.stdin.resume(),process.stdin.once("data",o)})}import{existsSync as po}from"node:fs";import{isAbsolute as lt,resolve as pt}from"node:path";import{writeFileSync as H,mkdirSync as Xt,existsSync as G}from"node:fs";import{createRequire as Yt}from"node:module";import{join as j,isAbsolute as X,resolve as Y}from"node:path";var R=Yt(import.meta.url);function V(t){let{cwd:o,profileName:e,captureDir:r,viewport:n,storageStatePath:i}=t,a=j(o,".d360-capture-cache");G(a)||Xt(a,{recursive:!0});let s=j(a,`playwright.${e}.config.cjs`),u=X(r)?r:Y(o,r),p=X(i)?i:Y(o,i),f=R.resolve("@playwright/test"),c=`// Generated by document360-capture \u2014 do not edit by hand.
4
+ const { defineConfig } = require(${JSON.stringify(f)});
5
5
  module.exports = defineConfig({
6
- testDir: ${JSON.stringify(l)},
6
+ testDir: ${JSON.stringify(u)},
7
7
  testMatch: '**/*.spec.ts',
8
8
  fullyParallel: false,
9
9
  workers: 1,
@@ -12,12 +12,12 @@ module.exports = defineConfig({
12
12
  use: {
13
13
  headless: false,
14
14
  viewport: ${JSON.stringify(n)},
15
- storageState: ${JSON.stringify(g)},
15
+ storageState: ${JSON.stringify(p)},
16
16
  actionTimeout: 15000,
17
17
  navigationTimeout: 30000,
18
18
  contextOptions: { reducedMotion: 'reduce' },
19
19
  },
20
20
  });
21
- `;H(a,h,"utf8");let c=j(s,`tsconfig.${e}.json`),p=St=>St.replace(/\\/g,"/"),w=R.resolve("document360-capture/helpers"),m=j(R.resolve("@playwright/test/package.json"),".."),y=j(m,"index.mjs"),Ct=G(y)?y:u,jt={compilerOptions:{baseUrl:".",paths:{"document360-capture/helpers":[p(w)],"@playwright/test":[p(Ct)]}}};return H(c,JSON.stringify(jt,null,2),"utf8"),{configPath:a,tsconfigPath:c}}import{spawn as Vt}from"node:child_process";import{existsSync as Kt}from"node:fs";import{createRequire as Qt}from"node:module";import{fileURLToPath as Zt}from"node:url";import{delimiter as to,dirname as A,join as K}from"node:path";var oo=Qt(import.meta.url);async function Q(t){let{cwd:o,configPath:e,tsconfigPath:r,startUrl:n,authBoundaryUrlPattern:i,specId:s,captureDirAbs:a}=t,l=no();if(!l)return{exitCode:127,stdout:"",stderr:"Cannot locate @playwright/test CLI. Try: npm install -g document360-capture (reinstall)"};let g=[l,"test","--config",e,"--tsconfig",r];return s&&g.push(eo(`${s}.spec.ts`)),new Promise(u=>{let h="",c="",p=Vt(process.execPath,g,{cwd:o,env:{...process.env,CAPTURE_START_URL:n,CAPTURE_AUTH_BOUNDARY:i,NODE_PATH:ro()},shell:!1});p.stdout.on("data",w=>{let m=w.toString();h+=m,process.stdout.write(m)}),p.stderr.on("data",w=>{let m=w.toString();c+=m,process.stderr.write(m)}),p.on("error",w=>{c+=`
22
- [spawn error] ${w.message}`,u({exitCode:127,stdout:h,stderr:c})}),p.on("close",w=>{u({exitCode:w??1,stdout:h,stderr:c})})})}function eo(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ro(){let t=A(Zt(import.meta.url));for(let e=0;e<4&&!Kt(K(t,"package.json"));e++)t=A(t);let o=[K(t,"node_modules"),A(t)];return process.env.NODE_PATH&&o.push(process.env.NODE_PATH),o.join(to)}function no(){let t=["@playwright/test/cli","@playwright/test/cli.js","playwright/cli","playwright/cli.js"];for(let o of t)try{return oo.resolve(o)}catch{}return null}var io=[/login\.microsoftonline\.com/i,/login\.live\.com/i,/accounts\.google\.com/i,/\/oauth(2)?\/authorize/i,/\/sign[- ]?in/i,/\bauthn\b/i],so=[/waitForURL.*timed?[- ]?out/i,/page\.goto.*redirected/i,/storageState.*invalid/i];function Z(t){return io.some(o=>o.test(t))?!0:so.some(o=>o.test(t))}import{readdirSync as it,readFileSync as ao,existsSync as st,copyFileSync as co}from"node:fs";import{join as at}from"node:path";import I from"sharp";function tt(t){return t.replace(/[<>&"']/g,o=>({"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&apos;"})[o])}function ot(t){let e=Math.max(0,t.x-4),r=Math.max(0,t.y-4),n=t.width+8,i=t.height+8;return`<rect x="${e}" y="${r}" width="${n}" height="${i}" rx="6" ry="6" fill="rgba(255,213,0,0.18)" stroke="#f5a623" stroke-width="2.5"/>`}function et(t){return`<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" fill="#1f2328"/>`}function rt(t,o,e,r){let i=e.x+e.width+14+4,s=e.y+e.height/2,a=8,l=13,u=o.length*7.2+a*2,h=l+a*2,c=i+14+6,p=s-h/2;return c+u>r&&(c=e.x-u-14-6,c<0&&(c=e.x,p=e.y-h-6,p<0&&(p=e.y+e.height+6))),[`<circle cx="${i}" cy="${s}" r="14" fill="#d1242f" stroke="#fff" stroke-width="2"/>`,`<text x="${i}" y="${s+5}" font-family="-apple-system,Segoe UI,sans-serif" font-size="14" font-weight="700" fill="#fff" text-anchor="middle">${tt(t)}</text>`,`<rect x="${c}" y="${p}" width="${u}" height="${h}" rx="4" ry="4" fill="#1f2328" stroke="#fff" stroke-width="1.5"/>`,`<text x="${c+a}" y="${p+a+l-2}" font-family="-apple-system,Segoe UI,sans-serif" font-size="${l}" fill="#fff">${tt(o)}</text>`].join("")}async function lo(t){let o=JSON.parse(ao(t,"utf8"));if(!st(o.rawPath))return{id:o.id,ok:!1,reason:`raw missing: ${o.rawPath}`};let e=await I(o.rawPath).metadata(),r=e.width??1440,n=e.height??900,i=[];for(let a of o.highlight)i.push(ot(a.bbox));for(let a of o.redact)i.push(et(a.bbox));for(let a of o.annotations)i.push(rt(a.label,a.text,a.bbox,r));if(i.length===0)return await I(o.rawPath).toFile(o.finalPath),{id:o.id,ok:!0,finalPath:o.finalPath};let s=`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${n}">${i.join("")}</svg>`;return await I(o.rawPath).composite([{input:Buffer.from(s),top:0,left:0}]).toFile(o.finalPath),{id:o.id,ok:!0,finalPath:o.finalPath}}async function nt(t){let o=it(t).filter(r=>r.endsWith(".raw.png")),e=[];for(let r of o){let n=at(t,r),i=n.replace(/\.raw\.png$/,".png");try{co(n,i),e.push({id:r.replace(/\.raw\.png$/,""),ok:!0,finalPath:i})}catch(s){e.push({id:r,ok:!1,reason:String(s)})}}return e}async function ct(t,o){if(!st(t))return[];if(!o)return nt(t);let e=it(t).filter(n=>n.endsWith(".annotations.json"));if(e.length===0)return nt(t);let r=[];for(let n of e){let i=at(t,n);try{r.push(await lo(i))}catch(s){r.push({id:n,ok:!1,reason:String(s)})}}return r}async function ut(t,o){let e=process.cwd(),r=d(f(e)),n=v(r,o.profile),i=n.name,s=$(r.projectId,i);if(!s.exists)return console.error(""),console.error(`\u2717 No saved session for profile "${i}".`),console.error(` Expected at: ${s.path}`),console.error(` Run: d360-capture auth --profile ${i}`),2;let a=lt(n.captureDir)?n.captureDir:pt(e,n.captureDir);if(!po(a))return console.error(`\u2717 Capture directory missing: ${a}`),console.error(" Generate at least one spec there before running capture."),2;let{configPath:l,tsconfigPath:g}=V({cwd:e,profileName:i,captureDir:n.captureDir,viewport:n.viewport,storageStatePath:C(r.projectId,i)});console.log(""),n.production&&console.log(`\u26A0 Profile "${i}" is PRODUCTION (read-only capture).`),console.log(`\u25B6 Running specs against ${i} (${n.connection.startUrl})`),console.log(t?` Single spec: ${t}`:` All specs in ${n.captureDir}`),console.log("");let u=await Q({cwd:e,configPath:l,tsconfigPath:g,startUrl:n.connection.startUrl,authBoundaryUrlPattern:n.connection.authBoundaryUrlPattern,specId:t,captureDirAbs:a});if(u.exitCode!==0){let y=u.stdout+`
23
- `+u.stderr;return console.error(""),console.error(`\u2717 Playwright exited with code ${u.exitCode}`),Z(y)&&(console.error(""),console.error(" The output mentions a login page \u2014 if specs that previously passed now"),console.error(" fail this way, your saved session may have expired. Re-auth with:"),console.error(` d360-capture auth --profile ${i}`),console.error(" Otherwise, inspect the failure above (selector timeouts are spec bugs,"),console.error(" not auth bugs) and the error-context file Playwright printed.")),u.exitCode}let h=!o.noAnnotate&&r.annotation.enabled,c=lt(n.outputDir)?n.outputDir:pt(e,n.outputDir);console.log(""),console.log(h?"\u25B6 Annotating screenshots...":"\u25B6 Skipping annotation (--no-annotate or config off)");let p=await ct(c,h),w=p.filter(y=>y.ok).length,m=p.filter(y=>!y.ok);if(console.log(""),console.log(`\u2713 ${w} screenshot${w===1?"":"s"} ready in ${n.outputDir}`),m.length>0){console.log(`\u2717 ${m.length} annotation failure${m.length===1?"":"s"}:`);for(let y of m)console.log(` - ${y.id}: ${y.reason}`)}return m.length===0?0:1}import{existsSync as ft,readdirSync as uo,statSync as fo}from"node:fs";import{isAbsolute as gt,join as go,resolve as dt}from"node:path";async function ht(){let t=process.cwd(),o=d(f(t)),e=gt(o.captureDir)?o.captureDir:dt(t,o.captureDir),r=gt(o.outputDir)?o.outputDir:dt(t,o.outputDir);if(!ft(e)){console.log(`Capture dir does not exist: ${e}`);return}let n=uo(e).filter(i=>i.endsWith(".spec.ts")).sort();if(n.length===0){console.log(`No specs found in ${o.captureDir}.`);return}console.log(""),console.log(" Spec ID Last capture"),console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");for(let i of n){let s=i.replace(/\.spec\.ts$/,""),a=go(r,`${s}.png`),l=ft(a)?new Date(fo(a).mtimeMs).toISOString().slice(0,19).replace("T"," "):"(never)";console.log(` ${s.padEnd(47)} ${l}`)}console.log("")}import{existsSync as mt,readFileSync as wt}from"node:fs";import{isAbsolute as ho,resolve as mo}from"node:path";import{createRequire as wo}from"node:module";var yt=wo(import.meta.url);async function Pt(t){let o=process.cwd(),e=0,r=c=>console.log(` \u2713 ${c}`),n=c=>console.log(` \u26A0 ${c}`),i=c=>{console.log(` \u2717 ${c}`),e++};console.log(""),console.log("Checking document360-capture setup..."),console.log("");let s=f(o);if(!mt(s))return i(`Project config missing at ${s} \u2014 run \`d360-capture init\``),2;r(`Project config: ${s}`);let a;try{a=d(s),r(`Config parses; projectId="${a.projectId}"`)}catch(c){return i(`Config invalid: ${c.message}`),2}let l;try{l=v(a,t.profile),r(`Profile "${l.name}" resolved (startUrl=${l.connection.startUrl})${l.production?" \u26A0 PRODUCTION":""}`)}catch(c){return i(`Profile resolve failed: ${c.message}`),1}l.authBoundaryDefaulted&&n(`Auth boundary not set \u2014 using host heuristic (${l.connection.authBoundaryUrlPattern}). If auth save/validation misbehaves, set connection.authBoundaryUrlPattern.`);let g=ho(l.captureDir)?l.captureDir:mo(o,l.captureDir);mt(g)?r(`Capture dir exists: ${l.captureDir}`):i(`Capture dir missing: ${l.captureDir}`);let u=$(a.projectId,l.name);if(u.exists){let c=u.ageMs!=null?Math.floor(u.ageMs/864e5):null;r(`Auth-state present (${c}d old): ${u.path}`);try{let p=JSON.parse(wt(u.path,"utf8"));p&&typeof p=="object"?r("Auth-state parses as JSON"):i("Auth-state is not a valid object")}catch(p){i(`Auth-state unreadable: ${p.message}`)}}else i(`Auth-state missing for "${l.name}" \u2014 run \`d360-capture auth --profile ${l.name}\``);try{let c=yt.resolve("playwright/package.json"),p=JSON.parse(wt(c,"utf8"));r(`playwright@${p.version} installed`)}catch{i("playwright not resolvable \u2014 reinstall document360-capture")}return["@playwright/test/cli","@playwright/test/cli.js"].some(c=>{try{return yt.resolve(c),!0}catch{return!1}})?r("@playwright/test CLI resolvable"):i("@playwright/test CLI not resolvable \u2014 reinstall document360-capture"),console.log(""),console.log(e===0?"All checks passed.":`${e} check${e===1?"":"s"} failed.`),console.log(""),e===0?0:1}async function vt(){let t=d(f());console.log(""),console.log(`projectId: ${t.projectId}`),console.log(`captureDir: ${t.captureDir} (default)`),console.log(`outputDir: ${t.outputDir} (default)`),console.log(`viewport: ${t.viewport.width}x${t.viewport.height} (default)`),console.log(`annotation enabled: ${t.annotation.enabled}`),console.log(`defaultProfile: ${t.defaultProfile}`),console.log(""),console.log("Profiles:");for(let[o,e]of Object.entries(t.profiles)){let r=$(t.projectId,o),n=r.exists?`auth saved ${r.ageMs!=null?Math.floor(r.ageMs/864e5)+"d ago":""}`:"no auth-state",i=`${o===t.defaultProfile?" \u25CF":""}${e.production?" \u26A0 PRODUCTION":""}`;console.log(` ${o.padEnd(10)} ${e.connection.startUrl}${i}`),e.captureDir&&console.log(` captureDir: ${e.captureDir}`),console.log(` ${n}`)}console.log("")}function $t(){let t=d(f());console.log("");for(let[o,e]of Object.entries(t.profiles)){let r=o===t.defaultProfile?"\u25CF ":" ",n=e.production?" \u26A0 PRODUCTION":"",s=$(t.projectId,o).exists?"auth saved":"no auth-state";console.log(`${r}${o} \u2192 ${e.connection.startUrl}${n} [${s}]`)}console.log(""),console.log("\u25CF = default. Switch with: d360-capture profile use <name>"),console.log("")}function xt(t){let o=f(),e=d(o);if(!e.profiles[t])return console.error(`\u2717 Unknown profile "${t}". Available: ${Object.keys(e.profiles).join(", ")}`),1;e.defaultProfile=t,S(o,e);let r=e.profiles[t].production?" \u26A0 PRODUCTION":"";return console.log(`\u2713 Default profile is now "${t}"${r}`),0}function Dt(t){let o=d(f()),e=v(o,t);return console.log(""),console.log(`Profile ${e.name}${e.production?" \u26A0 PRODUCTION":""}`),console.log(` startUrl: ${e.connection.startUrl}`),console.log(` authBoundary:${e.connection.authBoundaryUrlPattern}`),console.log(` captureDir: ${e.captureDir}`),console.log(` outputDir: ${e.outputDir}`),console.log(` viewport: ${e.viewport.width}x${e.viewport.height}`),console.log(""),0}var vo=Po(import.meta.url),$o=vo("../package.json"),P=new yo;function U(t){t.env&&(console.error("\u2717 --env was replaced by --profile (connection profiles). Use: --profile <name>"),process.exit(2))}P.name("d360-capture").description("Capture product screenshots from Playwright specs. Login once, capture many.").version($o.version);P.command("init").description("Setup. Inherits from .d360-writer.json when present; asks only the app URL. Writes .d360-capture.json.").option("-y, --yes","Non-interactive: scaffold with defaults + a placeholder URL, no prompts").action(async t=>{await F(t)});P.command("auth").description("Open Chromium for interactive login. Press ENTER when done to save the session.").option("-p, --profile <name>","Profile name (default: defaultProfile from config)").option("-e, --env <name>",!1).action(async t=>{U(t),await z(t)});P.command("capture [spec-id]").description("Run one spec by id, or all specs if omitted.").option("-p, --profile <name>","Profile name (default: defaultProfile from config)").option("-e, --env <name>",!1).option("--no-annotate","Skip annotation overlay; emit raw screenshots only").action(async(t,o)=>{U(o);let e=await ut(t,o);e!==0&&process.exit(e)});P.command("list").description("List discovered specs and their last-capture times.").action(async()=>{await ht()});P.command("doctor").description("Validate config, auth-state, and browser install.").option("-p, --profile <name>","Profile to check").option("-e, --env <name>",!1).action(async t=>{U(t);let o=await Pt(t);o!==0&&process.exit(o)});P.command("status").description("Print resolved config and auth-state freshness.").action(async()=>{await vt()});var k=P.command("profile").description("Manage capture profiles for the current repo");k.command("list",{isDefault:!0}).description("List profiles (\u25CF = default)").action(()=>$t());k.command("use <name>").description("Set the default profile for this repo").action(t=>process.exit(xt(t)));k.command("show [name]").description("Print the resolved profile").action(t=>process.exit(Dt(t)));P.parseAsync(process.argv).catch(t=>{console.error(""),console.error(`\u2717 ${t.message}`),process.exit(1)});
21
+ `;H(s,c,"utf8");let l=j(a,`tsconfig.${e}.json`),g=St=>St.replace(/\\/g,"/"),w=R.resolve("document360-capture/helpers"),m=j(R.resolve("@playwright/test/package.json"),".."),y=j(m,"index.mjs"),Ct=G(y)?y:f,jt={compilerOptions:{baseUrl:".",paths:{"document360-capture/helpers":[g(w)],"@playwright/test":[g(Ct)]}}};return H(l,JSON.stringify(jt,null,2),"utf8"),{configPath:s,tsconfigPath:l}}import{spawn as Vt}from"node:child_process";import{existsSync as Kt}from"node:fs";import{createRequire as Qt}from"node:module";import{fileURLToPath as Zt}from"node:url";import{delimiter as to,dirname as A,join as K}from"node:path";var oo=Qt(import.meta.url);async function Q(t){let{cwd:o,configPath:e,tsconfigPath:r,startUrl:n,authBoundaryUrlPattern:i,specId:a,captureDirAbs:s}=t,u=no();if(!u)return{exitCode:127,stdout:"",stderr:"Cannot locate @playwright/test CLI. Try: npm install -g document360-capture (reinstall)"};let p=[u,"test","--config",e,"--tsconfig",r];return a&&p.push(eo(`${a}.spec.ts`)),new Promise(f=>{let c="",l="",g=Vt(process.execPath,p,{cwd:o,env:{...process.env,CAPTURE_START_URL:n,CAPTURE_AUTH_BOUNDARY:i,NODE_PATH:ro()},shell:!1});g.stdout.on("data",w=>{let m=w.toString();c+=m,process.stdout.write(m)}),g.stderr.on("data",w=>{let m=w.toString();l+=m,process.stderr.write(m)}),g.on("error",w=>{l+=`
22
+ [spawn error] ${w.message}`,f({exitCode:127,stdout:c,stderr:l})}),g.on("close",w=>{f({exitCode:w??1,stdout:c,stderr:l})})})}function eo(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ro(){let t=A(Zt(import.meta.url));for(let e=0;e<4&&!Kt(K(t,"package.json"));e++)t=A(t);let o=[K(t,"node_modules"),A(t)];return process.env.NODE_PATH&&o.push(process.env.NODE_PATH),o.join(to)}function no(){let t=["@playwright/test/cli","@playwright/test/cli.js","playwright/cli","playwright/cli.js"];for(let o of t)try{return oo.resolve(o)}catch{}return null}var io=[/login\.microsoftonline\.com/i,/login\.live\.com/i,/accounts\.google\.com/i,/\/oauth(2)?\/authorize/i,/\/sign[- ]?in/i,/\bauthn\b/i],so=[/waitForURL.*timed?[- ]?out/i,/page\.goto.*redirected/i,/storageState.*invalid/i];function Z(t){return io.some(o=>o.test(t))?!0:so.some(o=>o.test(t))}import{readdirSync as it,readFileSync as ao,existsSync as st,copyFileSync as co}from"node:fs";import{join as at}from"node:path";import U from"sharp";function tt(t){return t.replace(/[<>&"']/g,o=>({"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&apos;"})[o])}function ot(t){let e=Math.max(0,t.x-4),r=Math.max(0,t.y-4),n=t.width+8,i=t.height+8;return`<rect x="${e}" y="${r}" width="${n}" height="${i}" rx="6" ry="6" fill="rgba(255,213,0,0.18)" stroke="#f5a623" stroke-width="2.5"/>`}function et(t){return`<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" fill="#1f2328"/>`}function rt(t,o,e,r){let i=e.x+e.width+14+4,a=e.y+e.height/2,s=8,u=13,f=o.length*7.2+s*2,c=u+s*2,l=i+14+6,g=a-c/2;return l+f>r&&(l=e.x-f-14-6,l<0&&(l=e.x,g=e.y-c-6,g<0&&(g=e.y+e.height+6))),[`<circle cx="${i}" cy="${a}" r="14" fill="#d1242f" stroke="#fff" stroke-width="2"/>`,`<text x="${i}" y="${a+5}" font-family="-apple-system,Segoe UI,sans-serif" font-size="14" font-weight="700" fill="#fff" text-anchor="middle">${tt(t)}</text>`,`<rect x="${l}" y="${g}" width="${f}" height="${c}" rx="4" ry="4" fill="#1f2328" stroke="#fff" stroke-width="1.5"/>`,`<text x="${l+s}" y="${g+s+u-2}" font-family="-apple-system,Segoe UI,sans-serif" font-size="${u}" fill="#fff">${tt(o)}</text>`].join("")}async function lo(t){let o=JSON.parse(ao(t,"utf8"));if(!st(o.rawPath))return{id:o.id,ok:!1,reason:`raw missing: ${o.rawPath}`};let e=await U(o.rawPath).metadata(),r=e.width??1440,n=e.height??900,i=[];for(let s of o.highlight)i.push(ot(s.bbox));for(let s of o.redact)i.push(et(s.bbox));for(let s of o.annotations)i.push(rt(s.label,s.text,s.bbox,r));if(i.length===0)return await U(o.rawPath).toFile(o.finalPath),{id:o.id,ok:!0,finalPath:o.finalPath};let a=`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${n}">${i.join("")}</svg>`;return await U(o.rawPath).composite([{input:Buffer.from(a),top:0,left:0}]).toFile(o.finalPath),{id:o.id,ok:!0,finalPath:o.finalPath}}async function nt(t){let o=it(t).filter(r=>r.endsWith(".raw.png")),e=[];for(let r of o){let n=at(t,r),i=n.replace(/\.raw\.png$/,".png");try{co(n,i),e.push({id:r.replace(/\.raw\.png$/,""),ok:!0,finalPath:i})}catch(a){e.push({id:r,ok:!1,reason:String(a)})}}return e}async function ct(t,o){if(!st(t))return[];if(!o)return nt(t);let e=it(t).filter(n=>n.endsWith(".annotations.json"));if(e.length===0)return nt(t);let r=[];for(let n of e){let i=at(t,n);try{r.push(await lo(i))}catch(a){r.push({id:n,ok:!1,reason:String(a)})}}return r}async function ut(t,o){let e=process.cwd(),r=h(d(e)),n=v(r,o.profile),i=n.name,a=$(r.projectId,i);if(!a.exists)return console.error(""),console.error(`\u2717 No saved session for profile "${i}".`),console.error(` Expected at: ${a.path}`),console.error(` Run: d360-capture auth --profile ${i}`),2;let s=lt(n.captureDir)?n.captureDir:pt(e,n.captureDir);if(!po(s))return console.error(`\u2717 Capture directory missing: ${s}`),console.error(" Generate at least one spec there before running capture."),2;let{configPath:u,tsconfigPath:p}=V({cwd:e,profileName:i,captureDir:n.captureDir,viewport:n.viewport,storageStatePath:C(r.projectId,i)});console.log(""),n.production&&console.log(`\u26A0 Profile "${i}" is PRODUCTION (read-only capture).`),console.log(`\u25B6 Running specs against ${i} (${n.connection.startUrl})`),console.log(t?` Single spec: ${t}`:` All specs in ${n.captureDir}`),console.log("");let f=await Q({cwd:e,configPath:u,tsconfigPath:p,startUrl:n.connection.startUrl,authBoundaryUrlPattern:n.connection.authBoundaryUrlPattern,specId:t,captureDirAbs:s});if(f.exitCode!==0){let y=f.stdout+`
23
+ `+f.stderr;return console.error(""),console.error(`\u2717 Playwright exited with code ${f.exitCode}`),Z(y)&&(console.error(""),console.error(" The output mentions a login page \u2014 if specs that previously passed now"),console.error(" fail this way, your saved session may have expired. Re-auth with:"),console.error(` d360-capture auth --profile ${i}`),console.error(" Otherwise, inspect the failure above (selector timeouts are spec bugs,"),console.error(" not auth bugs) and the error-context file Playwright printed.")),f.exitCode}let c=!o.noAnnotate&&r.annotation.enabled,l=lt(n.outputDir)?n.outputDir:pt(e,n.outputDir);console.log(""),console.log(c?"\u25B6 Annotating screenshots...":"\u25B6 Skipping annotation (--no-annotate or config off)");let g=await ct(l,c),w=g.filter(y=>y.ok).length,m=g.filter(y=>!y.ok);if(console.log(""),console.log(`\u2713 ${w} screenshot${w===1?"":"s"} ready in ${n.outputDir}`),m.length>0){console.log(`\u2717 ${m.length} annotation failure${m.length===1?"":"s"}:`);for(let y of m)console.log(` - ${y.id}: ${y.reason}`)}return m.length===0?0:1}import{existsSync as ft,readdirSync as uo,statSync as fo}from"node:fs";import{isAbsolute as gt,join as go,resolve as dt}from"node:path";async function ht(){let t=process.cwd(),o=h(d(t)),e=gt(o.captureDir)?o.captureDir:dt(t,o.captureDir),r=gt(o.outputDir)?o.outputDir:dt(t,o.outputDir);if(!ft(e)){console.log(`Capture dir does not exist: ${e}`);return}let n=uo(e).filter(i=>i.endsWith(".spec.ts")).sort();if(n.length===0){console.log(`No specs found in ${o.captureDir}.`);return}console.log(""),console.log(" Spec ID Last capture"),console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");for(let i of n){let a=i.replace(/\.spec\.ts$/,""),s=go(r,`${a}.png`),u=ft(s)?new Date(fo(s).mtimeMs).toISOString().slice(0,19).replace("T"," "):"(never)";console.log(` ${a.padEnd(47)} ${u}`)}console.log("")}import{existsSync as mt,readFileSync as wt}from"node:fs";import{isAbsolute as ho,resolve as mo}from"node:path";import{createRequire as wo}from"node:module";var yt=wo(import.meta.url);async function Pt(t){let o=process.cwd(),e=0,r=c=>console.log(` \u2713 ${c}`),n=c=>{console.log(` \u2717 ${c}`),e++};console.log(""),console.log("Checking document360-capture setup..."),console.log("");let i=d(o);if(!mt(i))return n(`Project config missing at ${i} \u2014 run \`d360-capture init\``),2;r(`Project config: ${i}`);let a;try{a=h(i),r(`Config parses; projectId="${a.projectId}"`)}catch(c){return n(`Config invalid: ${c.message}`),2}let s;try{s=v(a,t.profile),r(`Profile "${s.name}" resolved (startUrl=${s.connection.startUrl})${s.production?" \u26A0 PRODUCTION":""}`)}catch(c){return n(`Profile resolve failed: ${c.message}`),1}s.authBoundaryDefaulted&&r(`Auth boundary: ${s.connection.authBoundaryUrlPattern} (auto-derived from start URL; set connection.authBoundaryUrlPattern to override)`);let u=ho(s.captureDir)?s.captureDir:mo(o,s.captureDir);mt(u)?r(`Capture dir exists: ${s.captureDir}`):n(`Capture dir missing: ${s.captureDir}`);let p=$(a.projectId,s.name);if(p.exists){let c=p.ageMs!=null?Math.floor(p.ageMs/864e5):null;r(`Auth-state present (${c}d old): ${p.path}`);try{let l=JSON.parse(wt(p.path,"utf8"));l&&typeof l=="object"?r("Auth-state parses as JSON"):n("Auth-state is not a valid object")}catch(l){n(`Auth-state unreadable: ${l.message}`)}}else n(`Auth-state missing for "${s.name}" \u2014 run \`d360-capture auth --profile ${s.name}\``);try{let c=yt.resolve("playwright/package.json"),l=JSON.parse(wt(c,"utf8"));r(`playwright@${l.version} installed`)}catch{n("playwright not resolvable \u2014 reinstall document360-capture")}return["@playwright/test/cli","@playwright/test/cli.js"].some(c=>{try{return yt.resolve(c),!0}catch{return!1}})?r("@playwright/test CLI resolvable"):n("@playwright/test CLI not resolvable \u2014 reinstall document360-capture"),console.log(""),console.log(e===0?"All checks passed.":`${e} check${e===1?"":"s"} failed.`),console.log(""),e===0?0:1}async function vt(){let t=h(d());console.log(""),console.log(`projectId: ${t.projectId}`),console.log(`captureDir: ${t.captureDir} (default)`),console.log(`outputDir: ${t.outputDir} (default)`),console.log(`viewport: ${t.viewport.width}x${t.viewport.height} (default)`),console.log(`annotation enabled: ${t.annotation.enabled}`),console.log(`defaultProfile: ${t.defaultProfile}`),console.log(""),console.log("Profiles:");for(let[o,e]of Object.entries(t.profiles)){let r=$(t.projectId,o),n=r.exists?`auth saved ${r.ageMs!=null?Math.floor(r.ageMs/864e5)+"d ago":""}`:"no auth-state",i=`${o===t.defaultProfile?" \u25CF":""}${e.production?" \u26A0 PRODUCTION":""}`;console.log(` ${o.padEnd(10)} ${e.connection.startUrl}${i}`),e.captureDir&&console.log(` captureDir: ${e.captureDir}`),console.log(` ${n}`)}console.log("")}function $t(){let t=h(d());console.log("");for(let[o,e]of Object.entries(t.profiles)){let r=o===t.defaultProfile?"\u25CF ":" ",n=e.production?" \u26A0 PRODUCTION":"",a=$(t.projectId,o).exists?"auth saved":"no auth-state";console.log(`${r}${o} \u2192 ${e.connection.startUrl}${n} [${a}]`)}console.log(""),console.log("\u25CF = default. Switch with: d360-capture profile use <name>"),console.log("")}function xt(t){let o=d(),e=h(o);if(!e.profiles[t])return console.error(`\u2717 Unknown profile "${t}". Available: ${Object.keys(e.profiles).join(", ")}`),1;e.defaultProfile=t,S(o,e);let r=e.profiles[t].production?" \u26A0 PRODUCTION":"";return console.log(`\u2713 Default profile is now "${t}"${r}`),0}function Dt(t){let o=h(d()),e=v(o,t);return console.log(""),console.log(`Profile ${e.name}${e.production?" \u26A0 PRODUCTION":""}`),console.log(` startUrl: ${e.connection.startUrl}`),console.log(` authBoundary:${e.connection.authBoundaryUrlPattern}`),console.log(` captureDir: ${e.captureDir}`),console.log(` outputDir: ${e.outputDir}`),console.log(` viewport: ${e.viewport.width}x${e.viewport.height}`),console.log(""),0}var vo=Po(import.meta.url),$o=vo("../package.json"),P=new yo;function I(t){t.env&&(console.error("\u2717 --env was replaced by --profile (connection profiles). Use: --profile <name>"),process.exit(2))}P.name("d360-capture").description("Capture product screenshots from Playwright specs. Login once, capture many.").version($o.version);P.command("init").description("Setup. Inherits from .d360-writer.json when present; asks only the app URL. Writes .d360-capture.json.").option("-y, --yes","Non-interactive: scaffold with defaults + a placeholder URL, no prompts").action(async t=>{await F(t)});P.command("auth").description("Open Chromium for interactive login. Press ENTER when done to save the session.").option("-p, --profile <name>","Profile name (default: defaultProfile from config)").option("-e, --env <name>",!1).action(async t=>{I(t),await z(t)});P.command("capture [spec-id]").description("Run one spec by id, or all specs if omitted.").option("-p, --profile <name>","Profile name (default: defaultProfile from config)").option("-e, --env <name>",!1).option("--no-annotate","Skip annotation overlay; emit raw screenshots only").action(async(t,o)=>{I(o);let e=await ut(t,o);e!==0&&process.exit(e)});P.command("list").description("List discovered specs and their last-capture times.").action(async()=>{await ht()});P.command("doctor").description("Validate config, auth-state, and browser install.").option("-p, --profile <name>","Profile to check").option("-e, --env <name>",!1).action(async t=>{I(t);let o=await Pt(t);o!==0&&process.exit(o)});P.command("status").description("Print resolved config and auth-state freshness.").action(async()=>{await vt()});var k=P.command("profile").description("Manage capture profiles for the current repo");k.command("list",{isDefault:!0}).description("List profiles (\u25CF = default)").action(()=>$t());k.command("use <name>").description("Set the default profile for this repo").action(t=>process.exit(xt(t)));k.command("show [name]").description("Print the resolved profile").action(t=>process.exit(Dt(t)));P.parseAsync(process.argv).catch(t=>{console.error(""),console.error(`\u2717 ${t.message}`),process.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document360-capture",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "CLI that captures product screenshots from Playwright specs. Login once, capture many. Companion to document360-writer.",
5
5
  "type": "module",
6
6
  "bin": {