Shared core library for Spectrum diff generation tools (tokens, component schemas, etc.)
npm install @adobe/spectrum-diff-coreShared core library for Spectrum diff generation tools (tokens, component schemas, etc.).
This package provides the foundational components for creating consistent diff tools across the Spectrum ecosystem. It includes:
- Core utilities: File import/export, diff operations, type checking
- CLI framework: Base CLI structure with consistent option handling
- Template system: Handlebars-based formatting with shared helpers
- Output handling: File output and console formatting
``bash`
pnpm add @adobe/spectrum-diff-core
`javascript
import { BaseCLI, FileLoader, detailedDiff } from "@adobe/spectrum-diff-core";
class MyDiffTool extends BaseCLI {
constructor() {
super({
toolName: "mydiff",
dataType: "mydata",
packagePath: "packages/mydata/src",
manifestFile: "manifest.json",
});
}
async generateDiff(original, updated) {
const changes = detailedDiff(original, updated);
// Add your specific change detection logic here
return this.processChanges(changes);
}
}
`
`javascript
import { FileLoader } from "@adobe/spectrum-diff-core";
const loader = new FileLoader();
// Load from remote repository
const remoteData = await loader.loadRemoteFiles(
["file1.json", "file2.json"],
"v1.0.0",
null,
"owner/repo",
"api-key",
"packages/data/src",
);
// Load from local filesystem
const localData = await loader.loadLocalFiles("packages/data/src", [
"file1.json",
"file2.json",
]);
`
`javascript
import { HandlebarsFormatter } from "@adobe/spectrum-diff-core";
const formatter = new HandlebarsFormatter({
template: "cli",
dataType: "tokens",
});
const output = await formatter.format(diffResult, options);
`
The BaseCLI class provides a consistent CLI structure:
`bash`
mydiff report --old-version v1.0.0 --new-version v1.1.0 --format markdown --output report.md
Common CLI Options:
- --old-[type]-version / --new-[type]-version (version comparison)--old-[type]-branch
- / --new-[type]-branch (branch comparison)--local
- (local file comparison)--format
- (cli, markdown, handlebars)--template
- (built-in template names)--output
- (file output)--debug
- (debug output)
Templates are organized by data type:
``
templates/
├── base/ # Shared templates
│ ├── cli.hbs
│ ├── markdown.hbs
│ └── json.hbs
├── tokens/ # Token-specific templates
└── schemas/ # Schema-specific templates
- {{hasKeys obj}} - Check if object has properties{{totalItems result}}
- - Calculate total number of changes{{capitalize str}}
- - Capitalize string{{cleanPath path}}
- - Clean up property paths{{formatDate date}}
- - Format timestamps{{hilite}}
- , {{error}}, {{passing}} - Terminal colors{{bold}}
- , {{dim}}, {{emphasis}} - Text formatting
- detailedDiff(original, updated) - Generate detailed diffisObject(obj)
- , isString(str), etc. - Type checking utilitiesdeepClone(obj)
- - Deep clone objectsgetNestedProperty(obj, path)
- - Safe property access
- FileLoader - Main file loading orchestratorRemoteFileFetcher
- - Handle remote repository fetchingLocalFileSystem
- - Handle local file operations
- BaseCLI - Base class for creating CLI toolsnormalizeOptions(options)
- - Normalize CLI optionsdetermineStrategy(options)
- - Determine loading strategy
- HandlebarsFormatter - Template-based formattingstoreOutput(content, path)
- - File output utility
`bashInstall dependencies
pnpm install
Apache-2.0