@adobe/design-data 3.1.0 → 3.2.0

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/guideline.js +22 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/design-data",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Node.js helpers for @adobe/design-data-wasm: filesystem dataset loading, token write operations, and authoring-session management",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/guideline.js CHANGED
@@ -15,7 +15,7 @@
15
15
  * guard) lives in exactly one place instead of being duplicated per server.
16
16
  */
17
17
 
18
- import { readFileSync, existsSync } from "node:fs";
18
+ import { readFileSync, existsSync, readdirSync } from "node:fs";
19
19
  import { resolve, sep } from "node:path";
20
20
 
21
21
  /**
@@ -44,3 +44,24 @@ export function loadGuideline(guidelinesDir, id) {
44
44
  }
45
45
  return JSON.parse(readFileSync(filePath, "utf-8"));
46
46
  }
47
+
48
+ /**
49
+ * List guideline catalog entries from the manifest, falling back to the files
50
+ * present in the directory when the manifest is unavailable.
51
+ *
52
+ * @param {string} guidelinesDir - absolute path to the guidelines directory.
53
+ * @returns {Array<object>} guideline catalog entries.
54
+ */
55
+ export function listGuidelines(guidelinesDir) {
56
+ const baseDir = resolve(guidelinesDir);
57
+ const manifestPath = resolve(baseDir, "manifest.json");
58
+ if (existsSync(manifestPath)) {
59
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
60
+ return manifest.guidelines ?? [];
61
+ }
62
+
63
+ return readdirSync(baseDir)
64
+ .filter((file) => file.endsWith(".json") && file !== "manifest.json")
65
+ .map((file) => ({ slug: file.replace(/\.json$/, "") }))
66
+ .sort((a, b) => a.slug.localeCompare(b.slug));
67
+ }