(primaryExample, allData)
| 240 | } |
| 241 | |
| 242 | async function mainUsageBlock(primaryExample, allData) { |
| 243 | const { data, pkg } = primaryExample |
| 244 | const platforms = getPlatforms(allData) |
| 245 | const main = data.jsdoc.find((doc) => Boolean(doc.examples)) |
| 246 | |
| 247 | const exampleFunctionName = main.name |
| 248 | const exampleCode = main.examples[0] |
| 249 | const code = ` |
| 250 | import Analytics from 'analytics' |
| 251 | import ${exampleFunctionName} from '${pkg.name}' |
| 252 | |
| 253 | const analytics = Analytics({ |
| 254 | app: 'awesome-app', |
| 255 | plugins: [ |
| 256 | ${exampleCode} |
| 257 | ] |
| 258 | }) |
| 259 | |
| 260 | ${renderRelevantMethods(data)} |
| 261 | ` |
| 262 | |
| 263 | const providerName = cleanName(pkg.projectMeta.provider.name) |
| 264 | const ABOUT_METHODS = aboutMethods(providerName) |
| 265 | |
| 266 | const API_METHODS = ['page', 'track', 'identify', 'reset'] |
| 267 | |
| 268 | const infos = await Promise.all(allData.map((d) => { |
| 269 | return getUsageExamples(d, data) |
| 270 | })) |
| 271 | |
| 272 | // console.log('infos', infos) |
| 273 | /* Get additional Usage examples */ |
| 274 | const additionalExamples = infos.flat() |
| 275 | .sort(sortUsageExamples) |
| 276 | .map((ex) => ex.text) |
| 277 | .join('\n') |
| 278 | |
| 279 | let exposedFuncs |
| 280 | const apiDocs = allData.map((y) => { |
| 281 | const name = getPlatformName(y) |
| 282 | exposedFuncs = getExposedFunctions(y.data) |
| 283 | const exp = exposedFuncs |
| 284 | const niceName = (name === 'node.js') ? `server-side` : name |
| 285 | const jsDoc = renderJsDocs(y.data, y, niceName) |
| 286 | const niceText = (name === 'node.js') ? `${niceName} ${name}` : `client side ${niceName}` |
| 287 | const capsName = capitalizeFirstLetter(niceName) |
| 288 | const apiMethodsExposed = exp |
| 289 | .filter((x) => API_METHODS.includes(x)) |
| 290 | .map((x) => { |
| 291 | const link = SRC_LINKS[x] |
| 292 | const linkText = (link) ? `[analytics.${x}](${link})` : x |
| 293 | return `- **${linkText}** - ${ABOUT_METHODS[x]}` |
| 294 | }).join('\n') |
| 295 | // console.log('apiMethodsExposed', apiMethodsExposed) |
| 296 | let renderMethods = 'See below from browser API' |
| 297 | if (apiMethodsExposed) { |
| 298 | renderMethods = `The ${providerName} ${niceText} plugin works with these analytic api methods: |
| 299 |
no test coverage detected