musora-content-services 1.0.115 → 1.0.118

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.
Files changed (57) hide show
  1. package/.github/workflows/node.js.yml +0 -0
  2. package/CHANGELOG.md +6 -0
  3. package/README.md +0 -0
  4. package/babel.config.js +0 -0
  5. package/docs/config.js.html +0 -0
  6. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  7. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  8. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  9. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  10. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  11. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  12. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  13. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  14. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  15. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
  16. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  17. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  18. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  19. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  20. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
  21. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  22. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  23. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  24. package/docs/index.html +0 -0
  25. package/docs/module-Config.html +0 -0
  26. package/docs/module-Railcontent-Services.html +0 -0
  27. package/docs/module-Sanity-Services.html +0 -0
  28. package/docs/railcontent.js.html +0 -0
  29. package/docs/sanity.js.html +0 -0
  30. package/docs/scripts/collapse.js +0 -0
  31. package/docs/scripts/commonNav.js +0 -0
  32. package/docs/scripts/linenumber.js +0 -0
  33. package/docs/scripts/nav.js +0 -0
  34. package/docs/scripts/polyfill.js +0 -0
  35. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -0
  36. package/docs/scripts/prettify/lang-css.js +0 -0
  37. package/docs/scripts/prettify/prettify.js +0 -0
  38. package/docs/scripts/search.js +0 -0
  39. package/docs/styles/jsdoc.css +0 -0
  40. package/docs/styles/prettify.css +0 -0
  41. package/jest.config.js +0 -0
  42. package/jsdoc.json +0 -0
  43. package/package.json +2 -1
  44. package/src/contentMetaData.js +1091 -0
  45. package/src/contentTypeConfig.js +45 -1414
  46. package/src/filterBuilder.js +0 -0
  47. package/src/index.d.ts +137 -88
  48. package/src/index.js +135 -97
  49. package/src/services/config.js +1 -0
  50. package/src/services/railcontent.js +24 -12
  51. package/src/services/sanity.js +178 -77
  52. package/src/services/userContext.js +0 -0
  53. package/test/localStorageMock.js +0 -0
  54. package/test/log.js +0 -0
  55. package/test/sanityQueryService.test.js +154 -2
  56. package/test/userContext.test.js +0 -0
  57. package/tools/generate-index.js +85 -0
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Tool script to generate index.js and index.d.ts files based on exports from files in our services directory.
3
+ * This scans all files from the src/services directory and retrieves any functions that are declared with
4
+ * `export function` or `export async function`. It also retrieves ES module exports through `module.exports`. *
5
+ */
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const fileExports = {};
10
+
11
+ /**
12
+ * Helper function to extract function names from ES module and CommonJS exports
13
+ *
14
+ * @param filePath
15
+ * @returns {string[]}
16
+ */
17
+ function extractExportedFunctions(filePath) {
18
+ const fileContent = fs.readFileSync(filePath, 'utf-8');
19
+
20
+ const exportRegex = /export\s+(async\s+)?function\s+(\w+)/g;
21
+ const moduleExportsRegex = /module\.exports\s*=\s*{\s*([\s\S]+?)\s*};/g;
22
+
23
+ let matches = [...fileContent.matchAll(exportRegex)].map(match => match[2]);
24
+
25
+ const moduleExportsMatch = moduleExportsRegex.exec(fileContent);
26
+ if (moduleExportsMatch) {
27
+ const exportsList = moduleExportsMatch[1]
28
+ .split(',')
29
+ .map(exp => exp.split(':')[0].trim());
30
+ matches = matches.concat(exportsList);
31
+ }
32
+
33
+ return matches.sort();
34
+ }
35
+
36
+
37
+ // get all files in the services directory
38
+ const servicesDir = path.join(__dirname, '../src/services');
39
+ const files = fs.readdirSync(servicesDir);
40
+
41
+ files.forEach((file) => {
42
+ const filePath = path.join(servicesDir, file);
43
+ const functionNames = extractExportedFunctions(filePath);
44
+
45
+ if (functionNames.length > 0) {
46
+ fileExports[file] = functionNames;
47
+ }
48
+ });
49
+
50
+ // populate the index.js content string with the import/export of all functions
51
+ let content = '/*** This file was generated automatically. To recreate, please run `npm run build-index`. ***/\n';
52
+
53
+ Object.entries(fileExports).forEach(([file, functionNames]) => {
54
+ content += `\nimport {\n\t${functionNames.join(',\n\t')}\n} from './services/${file}';\n`;
55
+ });
56
+
57
+ const allFunctionNames = Object.values(fileExports).flat().sort();
58
+ content += '\nexport {\n';
59
+ content += `\t${allFunctionNames.join(',\n\t')},\n`;
60
+ content += '};\n';
61
+
62
+ // write the generated content to index.js
63
+ const outputPath = path.join(__dirname, '../src/index.js');
64
+ fs.writeFileSync(outputPath, content);
65
+
66
+ console.log('index.js generated successfully!');
67
+
68
+ // populate the index.d.ts content string with the import and module export of all functions
69
+ let dtsContent = '/*** This file was generated automatically. To recreate, please run `npm run build-index`. ***/\n';
70
+
71
+ Object.entries(fileExports).forEach(([file, functionNames]) => {
72
+ dtsContent += `\nimport {\n\t${functionNames.join(',\n\t')}\n} from './services/${file}';\n`;
73
+ });
74
+
75
+ dtsContent += '\ndeclare module \'musora-content-services\' {\n';
76
+ dtsContent += '\texport {\n';
77
+ dtsContent += `\t\t${allFunctionNames.join(',\n\t\t')},\n`;
78
+ dtsContent += '\t}\n';
79
+ dtsContent += '}\n';
80
+
81
+ // write the generated content to index.d.ts
82
+ const outputDtsPath = path.join(__dirname, '../src/index.d.ts');
83
+ fs.writeFileSync(outputDtsPath, dtsContent);
84
+
85
+ console.log('index.d.ts generated successfully!');