runem / web-component-analyzer

CLI that analyzes web components and emits documentation
https://runem.github.io/web-component-analyzer
MIT License
504 stars 64 forks source link

Question: What is the entry point to parse a source string instead of files? #118

Closed georges-gomes closed 4 years ago

georges-gomes commented 4 years ago

Like what you did in the playground? I would like to integrate in-browser parsing into webcomponents.dev

Thanks!

runem commented 4 years ago

I had to do a some manual work locally in order to get it working with the current exported library bundle. I plan on changing this, and I'm currently in the process of a big refactoring so that will become possible. Here are the current shortcomings that I'm adressing:

I will keep you updated on my progress here. When it's ready, I will commit the code for my playground and I will document the API in the readme :-)

georges-gomes commented 4 years ago

Cool, your description was also understanding so I'm not too stupid :)

I'm good with the typescript parser as I already have it loaded.

I look forward to it 🤗 Cheers!

runem commented 4 years ago

@georges-gomes It's now possible to run it in the browser using the beta npm publish of version 1.0.0 :-) The final release is not expected to change much from the beta version.

"web-component-analyzer": "1.0.0-next.9"

If you are interested in playing around with the API, here's a short example of how to use it:

const format = "markdown"; // or "json"
const code = "...";

const { transformAnalyzerResult, analyzeText } = await import("web-component-analyzer");

const { results, program } = analyzeText(code);
// or
const { results, program } = analyzeText([
  { fileName: "file1.js", text: code },
  { fileName: "file2.js", text: "..." }, // these files can depend on each other
  { fileName: "file3.js", text: "...", analyze: false }
]);
// each result in "results" is the result of analyzing the corresponding text where "analyze" is not false

const output = transformAnalyzerResult(format, results, program);

If you already have a TS source file you can analyze it using:

analyzeSourceFile(sourceFile, { checker })

Please don't hesitate to reach out to me with any questions or requests :+1:

runem commented 4 years ago

Version 1.0.0 is live now, so I'll close this issue :tada: