MCPcopy Create free account
hub / github.com/DavidWells/analytics / mainUsageBlock

Function mainUsageBlock

scripts/docs.js:242–337  ·  view source on GitHub ↗
(primaryExample, allData)

Source from the content-addressed store, hash-verified

240}
241
242async 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 = `
250import Analytics from 'analytics'
251import ${exampleFunctionName} from '${pkg.name}'
252
253const 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

Callers 1

docs.jsFile · 0.85

Calls 12

getPlatformsFunction · 0.85
renderRelevantMethodsFunction · 0.85
cleanNameFunction · 0.85
aboutMethodsFunction · 0.85
getUsageExamplesFunction · 0.85
getPlatformNameFunction · 0.85
getExposedFunctionsFunction · 0.85
renderJsDocsFunction · 0.85
capitalizeFirstLetterFunction · 0.85
renderPlatformSentenceFunction · 0.85
formatCodeFunction · 0.85
whatThisEnablesTextFunction · 0.85

Tested by

no test coverage detected