embedoc 0.14.16 → 0.14.17
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.
package/cli-contract.yaml
CHANGED
package/dist/embedoc.bundle.mjs
CHANGED
|
@@ -84,7 +84,7 @@ cli_contracts: 0.1.0
|
|
|
84
84
|
|
|
85
85
|
info:
|
|
86
86
|
title: embedoc CLI
|
|
87
|
-
version: 0.14.
|
|
87
|
+
version: 0.14.17
|
|
88
88
|
description: >-
|
|
89
89
|
In-place document generator that auto-updates marker blocks in documents
|
|
90
90
|
and source code while preserving manually edited sections. Supports
|
|
@@ -430,7 +430,7 @@ command_sets:
|
|
|
430
430
|
"cli_contracts": "0.1.0",
|
|
431
431
|
"info": {
|
|
432
432
|
"title": "embedoc CLI",
|
|
433
|
-
"version": "0.14.
|
|
433
|
+
"version": "0.14.17",
|
|
434
434
|
"description": "In-place document generator that auto-updates marker blocks in documents and source code while preserving manually edited sections. Supports multiple datasources (SQLite, CSV, JSON, YAML, glob, TypeScript API), programmable TypeScript renderers, Handlebars file generation, and incremental builds with dependency tracking.",
|
|
435
435
|
"license": {
|
|
436
436
|
"name": "MIT"
|
|
@@ -894,7 +894,7 @@ command_sets:
|
|
|
894
894
|
`):l;await $m(s,f,{encoding:r.output?.encoding??"utf-8"})}}catch(a){o.success=!1,o.error=a instanceof Error?a:new Error(String(a))}return o}function tg(n,e){if(e===void 0)return n;let t=Object.entries(e).map(([r,i])=>{let s=Array.isArray(i)?i:[i];if(!s.every(o=>typeof o=="string"))throw new Error(`Generator "where.${r}" must be a string or a list of strings`);return{field:r,values:new Set(s)}});return n.filter(r=>t.every(({field:i,values:s})=>s.has(String(r[i]))))}async function ng(n,e,t){let r=n.replace(/\{[^}]+\}/g,"*"),i=[];for(let s of yt(r)){if(e.has(Dr(s)))continue;let o={filePath:s,success:!0,skipped:!1,removed:!0};try{t||await Wm(s)}catch(a){o.success=!1,o.error=a instanceof Error?a:new Error(String(a))}i.push(o)}return i}async function rg(n,e,t,r,i={}){let s=[];if(!e.generators||e.generators.length===0)return i.verbose&&console.log(`No generators defined for datasource: ${n}`),s;let o=r.templates_dir??".embedoc/templates",a=await t.getAll();i.verbose&&console.log(`Found ${a.length} records in datasource: ${n}`);for(let c of e.generators){if(i.generatorName&&c.template!==i.generatorName)continue;i.verbose&&console.log(` Generator: ${c.template}`);let l=new Set;for(let d of tg(a,c.where)){let f=await eg(d,c,o,r,i.dryRun);s.push(f),l.add(Dr(f.filePath)),i.verbose&&(f.skipped?console.log(` Skipped (exists): ${f.filePath}`):f.success?console.log(` Generated: ${f.filePath}`):console.log(` Failed: ${f.filePath} - ${f.error?.message}`))}if(c.prune){let d=await ng(c.output_path,l,i.dryRun??!1);if(s.push(...d),i.verbose)for(let f of d)console.log(` Removed: ${f.filePath}`)}}return s}async function hu(n,e,t={}){let r=[];if(!n.datasources)return r;for(let[i,s]of Object.entries(n.datasources)){if(t.datasourceName&&i!==t.datasourceName||!s.generators||s.generators.length===0)continue;let o=e[i];if(!o){t.verbose&&console.warn(`Datasource not initialized: ${i}`);continue}t.verbose&&console.log(`
|
|
895
895
|
Processing datasource: ${i}`);let a=await rg(i,s,o,n,t);r.push(...a)}return r}import{readFile as ig}from"node:fs/promises";import{resolve as $e,relative as io}from"node:path";var Dt=class{nodes=new Map;config;renderersDir;embeds;constructor(e,t){this.config=e,this.embeds=t,this.renderersDir=$e(e.renderers_dir??e.embeds_dir??".embedoc/renderers")}getOrCreateNode(e,t){let r=$e(t),i=this.nodes.get(r);return i||(i={type:e,path:r,dependsOn:new Set,dependedBy:new Set},this.nodes.set(r,i)),i}addDependency(e,t){let r=this.nodes.get($e(e)),i=this.nodes.get($e(t));r&&i&&(r.dependsOn.add(i.path),i.dependedBy.add(r.path))}async analyzeDocument(e,t){let r=$e(e),i=this.getOrCreateNode("document",r);try{let s=await ig(r,{encoding:"utf-8"}),o=Un(t.comment_style,this.config.comment_styles),{content:a}=jn(s),c=bt(a,o,{markdown:Wn(e)}),l=new Set(c.map(d=>d.templateName));for(let d of l){let f=this.embeds[d];if(f){let p=`embed:${d}`,g=this.getOrCreateNode("embed",p);if(i.dependsOn.add(g.path),g.dependedBy.add(i.path),f.dependsOn)for(let x of f.dependsOn){let A=this.config.datasources?.[x];if(A?.path){let L=$e(A.path),O=this.getOrCreateNode("datasource",L);g.dependsOn.add(O.path),O.dependedBy.add(g.path)}}}}}catch{}}async build(){this.nodes.clear();for(let e of this.config.targets){let t=await Kt(e);for(let r of t)await this.analyzeDocument(r,e)}}getAffectedDocuments(e){let t=$e(e),r=new Set,i=this.nodes.get(t);if(!i){for(let a of this.nodes.values())if(a.type==="datasource"&&a.path===t){i=a;break}}if(!i&&e.endsWith(".ts")){let a=e.split("/").pop()?.replace(".ts","");if(a&&a!=="index"){let c=`embed:${a}`;if(i=this.nodes.get($e(c)),!i){let l=a.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"");i=this.nodes.get($e(`embed:${l}`))}}}if(!i)return this.nodes.get(t)?.type==="document"?[t]:[];let s=new Set,o=[i];for(;o.length>0;){let a=o.shift();if(!s.has(a.path)){s.add(a.path),a.type==="document"&&r.add(a.path);for(let c of a.dependedBy){let l=this.nodes.get(c);l&&!s.has(c)&&o.push(l)}}}return Array.from(r)}getWatchPaths(){let e=[];if(this.config.datasources)for(let t of Object.values(this.config.datasources))t.path&&e.push($e(t.path));return e.push(this.renderersDir),e}dump(){console.log(`
|
|
896
896
|
=== Dependency Graph ===`);for(let[e,t]of this.nodes){if(console.log(`
|
|
897
|
-
[${t.type}] ${io(process.cwd(),e)}`),t.dependsOn.size>0){console.log(" depends on:");for(let r of t.dependsOn)console.log(` - ${io(process.cwd(),r)}`)}if(t.dependedBy.size>0){console.log(" depended by:");for(let r of t.dependedBy)console.log(` - ${io(process.cwd(),r)}`)}}}};var cg={version:"0.14.
|
|
897
|
+
[${t.type}] ${io(process.cwd(),e)}`),t.dependsOn.size>0){console.log(" depends on:");for(let r of t.dependsOn)console.log(` - ${io(process.cwd(),r)}`)}if(t.dependedBy.size>0){console.log(" depended by:");for(let r of t.dependedBy)console.log(` - ${io(process.cwd(),r)}`)}}}};var cg={version:"0.14.17"};async function oo(n){let e=Ne(n),t=await _u(e,{encoding:"utf-8"});return n.endsWith(".json")?JSON.parse(t):Fe.load(t)}async function Lt(n){try{return await sg(n),!0}catch{return!1}}function mu(n){return n.renderers_dir?n.renderers_dir:n.embeds_dir?(console.warn(V.default.yellow('Warning: "embeds_dir" is deprecated. Use "renderers_dir" instead.')),n.embeds_dir):".embedoc/renderers"}var gu=!1;async function bu(n){return gu||(lg(),gu=!0),ag(n,import.meta.url)}async function ao(n){let e=Ne(n,"index.ts"),t=Ne(n,"index.js");try{if(await Lt(e)){let r=await bu(e);return r.embeds??r.default?.embeds??{}}return await Lt(t)?(await import(yu(t).href)).embeds??{}:{}}catch(r){let i=r instanceof Error?r.message:String(r);throw new Error(`Could not load renderers from ${n}: ${i}`,{cause:r})}}async function lo(n){let e=Ne(n,"index.ts"),t=Ne(n,"index.js"),r={datasourceTypes:{},inlineFormats:{}};try{let i;return await Lt(e)?i=await bu(e):await Lt(t)&&(i=await import(yu(t).href)),i?{datasourceTypes:i.datasourceTypes??i.default?.datasourceTypes??{},inlineFormats:i.inlineFormats??i.default?.inlineFormats??{}}:r}catch(i){let s=i instanceof Error?i.message:String(i);throw new Error(`Could not load custom datasources from ${n}: ${s}`,{cause:i})}}var ug={init:async n=>{try{console.log(V.default.cyan(`\u{1F4C1} Initializing embedoc...
|
|
898
898
|
`));let e=[],t=[],r=async(c,l)=>{let d=Ne(c);if(!n.force&&await Lt(d)){t.push(c);return}let f=d.substring(0,d.lastIndexOf("/"));await og(f,{recursive:!0}),await pu(d,l,{encoding:"utf-8"}),e.push(c)};await r("embedoc.config.yaml",`version: "1.0"
|
|
899
899
|
|
|
900
900
|
targets:
|