Setting the file. One moment.
Snapshot Capabilities · Wix Harmony Editor · wix/skills · Skills Docs
ContentsBack to the top of the page (opens in a new tab)
scripts/copy/ snapshot-capabilities.mjs
JavaScript · 40 lines · 4 KB
'./hide-scrollbars.mjs'
;
12 import fs from 'node:fs' ;
13
14 const args = process.argv. slice ( 2 );
15 const opt = ( n , d ) => { const i = args. indexOf ( `--${ n }` ); return i >= 0 ? args[i + 1 ] : d; };
16 const [ sectionId , out ] = args. filter (( a , i ) => ! a. startsWith ( '--' ) && ! (i > 0 && args[i - 1 ]. startsWith ( '--' )));
17 if ( ! sectionId || ! out) { console. error ( 'usage: snapshot-capabilities.mjs <scratchSectionId> <out.json> [--types …]' ); process. exit ( 2 ); }
18 const types = opt ( 'types' , 'wixEditorElements.WRichText,wixEditorElements.Image,wixEditorElements.Button' ). split ( ',' );
19 const b = await chromium. connectOverCDP ( `http://127.0.0.1:${ process . env . PW_PORT || 9333 }` );
20 const p = b. contexts (). flatMap (( c ) => c. pages ()). find (( x ) => x. url (). includes ( 'editor.wix.com/edit/' ));
21 if ( ! p) { console. error ( 'No Harmony editor page is open.' ); process. exit ( 3 ); }
22 await hideScrollbars (p); // canvas widths must not depend on the OS scrollbar setting
23 const raw = await p. evaluate ( async ( code ) => { const a = await repluggableAppDebug.host. getAPI ({ name: 'RunEditorLLMCodeToolAPI' , public: true , layer: 'DATA_SERVICE' }); return a. execute ({ code }, { biParams: {} }); }, `
24 const A = editorLLMApis; const out = {}; const temp = [];
25 await A.pages.navigate({ pageId: (await A.sections.get({ sectionId: ${ JSON . stringify ( sectionId ) } })).pageId }); await A.breakpoints.toggle({ device: 'desktop' });
26 for (const type of ${ JSON . stringify ( types ) }) {
27 const c = { id: (await A.components.add({ containerId: ${ JSON . stringify ( sectionId ) }, components: [{ componentType: type }], select: false })).added[0].componentId }; temp.push(c.id);
28 const ss = await A.appearance.getStyleSchema({ componentId: c.id }); const cs = await A.content.getSchema({ componentId: c.id });
29 let links = null; try { links = (await A.links.getAllowedTypes({ componentId: c.id })).allowedTypes; } catch (e) {}
30 out[type] = { styles: Object.fromEntries(ss.elements.filter((e) => e.writableProperties).map((e) => [e.elementPath.join('/') || 'root', Object.keys(e.writableProperties)])), content: cs.fields.map((f) => ({ key: f.key, dataType: f.dataType, options: f.options ? f.options.map((o) => o.value) : undefined })), links };
31 }
32 await A.components.remove({ componentIds: temp });
33 return { readAt: new Date().toISOString(), api: Object.fromEntries(Object.keys(A).map((ns) => [ns, Object.keys(A[ns])])), addable: (await A.components.listAddable()).components.map((c) => c.componentType), types: out, breakpoints: await A.breakpoints.list() };` );
34 const c = JSON . parse (raw.items[ 0 ].content);
35 if ( ! c.success) { console. error (c.summary); process. exit ( 1 ); }
36 let changed = null ;
37 if (fs. existsSync (out)) { const prev = JSON . parse (fs. readFileSync (out, 'utf8' )); changed = JSON . stringify (prev.types) !== JSON . stringify (c.result.types) || JSON . stringify (prev.addable) !== JSON . stringify (c.result.addable) || JSON . stringify (prev.api) !== JSON . stringify (c.result.api); }
38 fs. writeFileSync (out, JSON . stringify ({ ... c.result, addableCount: c.result.addable. length }, null , 1 ));
39 console. log ( JSON . stringify ({ out, types: Object. keys (c.result.types), addable: c.result.addable. length , changedSinceLastSnapshot: changed }));
40 await b. close ();