(data, pkg, dir)
| 645 | } |
| 646 | |
| 647 | async function browserStandaloneUsage(data, pkg, dir) { |
| 648 | const browserFile = path.join(dir, 'dist', `${pkg.name}.js`) |
| 649 | |
| 650 | const xx = await parseSourceCode(browserFile, 'browserfile') |
| 651 | |
| 652 | let initSet = false |
| 653 | // console.log('xx', xx) |
| 654 | const exportData = xx.ast.foundExports.filter((x) => { |
| 655 | return x.isDefault |
| 656 | }).reduce((acc, curr) => { |
| 657 | if (initSet) return acc |
| 658 | if (curr.name === 'init') { |
| 659 | initSet = true |
| 660 | return curr |
| 661 | } |
| 662 | return curr |
| 663 | }, {}) |
| 664 | |
| 665 | const defaultExportName = (exportData && exportData.name) ? `${pkg.globalName}.${exportData.name}` : pkg.globalName |
| 666 | // console.log('defaultExportName', defaultExportName) |
| 667 | // Find doc block with example (should only be one the main function) |
| 668 | const main = data.jsdoc.find((doc) => Boolean(doc.examples)) |
| 669 | |
| 670 | const exampleCode = main.examples[0] |
| 671 | // TODO cross reference the main exports and named exports to verify whatever.init |
| 672 | const code = ` |
| 673 | <!doctype html> |
| 674 | <html> |
| 675 | <head> |
| 676 | <title>Using ${pkg.name} in HTML</title> |
| 677 | <script src="https://unpkg.com/analytics/dist/analytics.min.js"></script> |
| 678 | <script src="https://unpkg.com/${pkg.name}/dist/${pkg.name}.min.js"></script> |
| 679 | <script type="text/javascript"> |
| 680 | /* Initialize analytics */ |
| 681 | var Analytics = _analytics.init({ |
| 682 | app: 'my-app-name', |
| 683 | plugins: [ |
| 684 | ${exampleCode.replace(main.name, `${defaultExportName}`)} |
| 685 | ] |
| 686 | }) |
| 687 | |
| 688 | ${renderRelevantMethods(data)} |
| 689 | </script> |
| 690 | </head> |
| 691 | <body> |
| 692 | .... |
| 693 | </body> |
| 694 | </html> |
| 695 | ` |
| 696 | |
| 697 | return `<details> |
| 698 | <summary>Using in HTML</summary> |
| 699 | |
| 700 | Below is an example of importing via the unpkg CDN. Please note this will pull in the latest version of the package. |
| 701 | |
| 702 | \`\`\`html |
| 703 | ${indentString(formatCode(code, 'html'), 2)} |
| 704 | \`\`\` |
no test coverage detected