embedoc 0.14.13 → 0.14.14
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/README.md +2 -0
- package/cli-contract.yaml +1 -1
- package/dist/embedoc.bundle.mjs +3 -3
- package/dist/embedoc.bundle.mjs.map +1 -1
- package/dist/generated/contract.js +2 -2
- package/docs/cli-reference.md +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -134,6 +134,8 @@ export const embeds = {
|
|
|
134
134
|
|
|
135
135
|
> **Note**: embedoc can directly import TypeScript files, so **no compilation is required**.
|
|
136
136
|
|
|
137
|
+
> **Note**: Renderers can `import { defineEmbed } from 'embedoc'` in both ES module projects (`"type": "module"` in `package.json`) and CommonJS projects (no `"type"` field).
|
|
138
|
+
|
|
137
139
|
### 4. Add Markers to Your Document
|
|
138
140
|
|
|
139
141
|
```markdown
|
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.14
|
|
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.14",
|
|
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"
|
|
@@ -893,7 +893,7 @@ command_sets:
|
|
|
893
893
|
`):c;await yw(s,h,{encoding:n.output?.encoding??"utf-8"})}}catch(a){o.success=!1,o.error=a instanceof Error?a:new Error(String(a))}return o}function Ow(t,e){if(e===void 0)return t;let r=Object.entries(e).map(([n,i])=>{let s=Array.isArray(i)?i:[i];if(!s.every(o=>typeof o=="string"))throw new Error(`Generator "where.${n}" must be a string or a list of strings`);return{field:n,values:new Set(s)}});return t.filter(n=>r.every(({field:i,values:s})=>s.has(String(n[i]))))}async function Pw(t,e,r){let n=t.replace(/\{[^}]+\}/g,"*"),i=[];for(let s of(await Et(n,{nodir:!0})).sort()){if(e.has(id(s)))continue;let o={filePath:s,success:!0,skipped:!1,removed:!0};try{r||await ww(s)}catch(a){o.success=!1,o.error=a instanceof Error?a:new Error(String(a))}i.push(o)}return i}async function Tw(t,e,r,n,i={}){let s=[];if(!e.generators||e.generators.length===0)return i.verbose&&console.log(`No generators defined for datasource: ${t}`),s;let o=n.templates_dir??".embedoc/templates",a=await r.getAll();i.verbose&&console.log(`Found ${a.length} records in datasource: ${t}`);for(let l of e.generators){if(i.generatorName&&l.template!==i.generatorName)continue;i.verbose&&console.log(` Generator: ${l.template}`);let c=new Set;for(let f of Ow(a,l.where)){let h=await Aw(f,l,o,n,i.dryRun);s.push(h),c.add(id(h.filePath)),i.verbose&&(h.skipped?console.log(` Skipped (exists): ${h.filePath}`):h.success?console.log(` Generated: ${h.filePath}`):console.log(` Failed: ${h.filePath} - ${h.error?.message}`))}if(l.prune){let f=await Pw(l.output_path,c,i.dryRun??!1);if(s.push(...f),i.verbose)for(let h of f)console.log(` Removed: ${h.filePath}`)}}return s}async function sd(t,e,r={}){let n=[];if(!t.datasources)return n;for(let[i,s]of Object.entries(t.datasources)){if(r.datasourceName&&i!==r.datasourceName||!s.generators||s.generators.length===0)continue;let o=e[i];if(!o){r.verbose&&console.warn(`Datasource not initialized: ${i}`);continue}r.verbose&&console.log(`
|
|
894
894
|
Processing datasource: ${i}`);let a=await Tw(i,s,o,t,r);n.push(...a)}return n}import{readFile as Dw}from"node:fs/promises";import{resolve as it,relative as qa}from"node:path";var lr=class{nodes=new Map;config;renderersDir;embeds;constructor(e,r){this.config=e,this.embeds=r,this.renderersDir=it(e.renderers_dir??e.embeds_dir??".embedoc/renderers")}getOrCreateNode(e,r){let n=it(r),i=this.nodes.get(n);return i||(i={type:e,path:n,dependsOn:new Set,dependedBy:new Set},this.nodes.set(n,i)),i}addDependency(e,r){let n=this.nodes.get(it(e)),i=this.nodes.get(it(r));n&&i&&(n.dependsOn.add(i.path),i.dependedBy.add(n.path))}async analyzeDocument(e,r){let n=it(e),i=this.getOrCreateNode("document",n);try{let s=await Dw(n,{encoding:"utf-8"}),o=ti(r.comment_style,this.config.comment_styles),{content:a}=Zn(s),l=ei(a,o,{markdown:Xn(e)}),c=new Set(l.map(f=>f.templateName));for(let f of c){let h=this.embeds[f];if(h){let p=`embed:${f}`,m=this.getOrCreateNode("embed",p);if(i.dependsOn.add(m.path),m.dependedBy.add(i.path),h.dependsOn)for(let g of h.dependsOn){let _=this.config.datasources?.[g];if(_?.path){let O=it(_.path),b=this.getOrCreateNode("datasource",O);m.dependsOn.add(b.path),b.dependedBy.add(m.path)}}}}}catch{}}async build(){this.nodes.clear();for(let e of this.config.targets){let r=await qr(e);for(let n of r)await this.analyzeDocument(n,e)}}getAffectedDocuments(e){let r=it(e),n=new Set,i=this.nodes.get(r);if(!i){for(let a of this.nodes.values())if(a.type==="datasource"&&a.path===r){i=a;break}}if(!i&&e.endsWith(".ts")){let a=e.split("/").pop()?.replace(".ts","");if(a&&a!=="index"){let l=`embed:${a}`;if(i=this.nodes.get(it(l)),!i){let c=a.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"");i=this.nodes.get(it(`embed:${c}`))}}}if(!i)return this.nodes.get(r)?.type==="document"?[r]:[];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"&&n.add(a.path);for(let l of a.dependedBy){let c=this.nodes.get(l);c&&!s.has(l)&&o.push(c)}}}return Array.from(n)}getWatchPaths(){let e=[];if(this.config.datasources)for(let r of Object.values(this.config.datasources))r.path&&e.push(it(r.path));return e.push(this.renderersDir),e}dump(){console.log(`
|
|
895
895
|
=== Dependency Graph ===`);for(let[e,r]of this.nodes){if(console.log(`
|
|
896
|
-
[${r.type}] ${qa(process.cwd(),e)}`),r.dependsOn.size>0){console.log(" depends on:");for(let n of r.dependsOn)console.log(` - ${qa(process.cwd(),n)}`)}if(r.dependedBy.size>0){console.log(" depended by:");for(let n of r.dependedBy)console.log(` - ${qa(process.cwd(),n)}`)}}}};var Lw={version:"0.14.
|
|
896
|
+
[${r.type}] ${qa(process.cwd(),e)}`),r.dependsOn.size>0){console.log(" depends on:");for(let n of r.dependsOn)console.log(` - ${qa(process.cwd(),n)}`)}if(r.dependedBy.size>0){console.log(" depended by:");for(let n of r.dependedBy)console.log(` - ${qa(process.cwd(),n)}`)}}}};var Lw={version:"0.14.14"};async function $a(t){let e=Je(t),r=await ld(e,{encoding:"utf-8"});return t.endsWith(".json")?JSON.parse(r):Ze.load(r)}async function cr(t){try{return await Iw(t),!0}catch{return!1}}function ad(t){return t.renderers_dir?t.renderers_dir:t.embeds_dir?(console.warn(W.default.yellow('Warning: "embeds_dir" is deprecated. Use "renderers_dir" instead.')),t.embeds_dir):".embedoc/renderers"}async function ja(t){let e=Je(t,"index.ts"),r=Je(t,"index.js");try{if(await cr(e)){let n=await ud(e,import.meta.url);return n.embeds??n.default?.embeds??{}}return await cr(r)?(await import(cd(r).href)).embeds??{}:{}}catch(n){let i=n instanceof Error?n.message:String(n);throw new Error(`Could not load renderers from ${t}: ${i}`,{cause:n})}}async function Wa(t){let e=Je(t,"index.ts"),r=Je(t,"index.js"),n={datasourceTypes:{},inlineFormats:{}};try{let i;return await cr(e)?i=await ud(e,import.meta.url):await cr(r)&&(i=await import(cd(r).href)),i?{datasourceTypes:i.datasourceTypes??i.default?.datasourceTypes??{},inlineFormats:i.inlineFormats??i.default?.inlineFormats??{}}:n}catch(i){let s=i instanceof Error?i.message:String(i);throw new Error(`Could not load custom datasources from ${t}: ${s}`,{cause:i})}}var Nw={init:async t=>{try{console.log(W.default.cyan(`\u{1F4C1} Initializing embedoc...
|
|
897
897
|
`));let e=[],r=[],n=async(l,c)=>{let f=Je(l);if(!t.force&&await cr(f)){r.push(l);return}let h=f.substring(0,f.lastIndexOf("/"));await Rw(h,{recursive:!0}),await od(f,c,{encoding:"utf-8"}),e.push(l)};await n("embedoc.config.yaml",`version: "1.0"
|
|
898
898
|
|
|
899
899
|
targets:
|