@tokens-studio/tokenscript-schemas 0.0.12 → 0.0.14
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.
- package/dist/cli/index.cjs +23 -8
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +23 -8
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.cts +158 -0
- package/dist/index.d.ts +158 -0
- package/package.json +1 -1
- package/src/cli/commands/bundle.ts +1 -4
- package/src/cli/commands/list.ts +36 -4
- package/src/cli/index.ts +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for schema bundler
|
|
3
|
+
*/
|
|
4
|
+
interface SchemaFile {
|
|
5
|
+
path: string;
|
|
6
|
+
content: string;
|
|
7
|
+
}
|
|
8
|
+
interface SchemaBundle {
|
|
9
|
+
slug: string;
|
|
10
|
+
name: string;
|
|
11
|
+
type: "type" | "function";
|
|
12
|
+
version: string;
|
|
13
|
+
schema?: unknown;
|
|
14
|
+
scripts: Record<string, string>;
|
|
15
|
+
metadata: {
|
|
16
|
+
id: string;
|
|
17
|
+
description: string;
|
|
18
|
+
contentType: string | null;
|
|
19
|
+
originalVersion: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
interface ScriptBlock {
|
|
23
|
+
type: string;
|
|
24
|
+
script: string;
|
|
25
|
+
}
|
|
26
|
+
interface Initializer {
|
|
27
|
+
title?: string;
|
|
28
|
+
keyword: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
schema?: unknown;
|
|
31
|
+
script: ScriptBlock;
|
|
32
|
+
}
|
|
33
|
+
interface Conversion {
|
|
34
|
+
source: string;
|
|
35
|
+
target: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
lossless: boolean;
|
|
38
|
+
script: ScriptBlock;
|
|
39
|
+
}
|
|
40
|
+
interface SpecProperty {
|
|
41
|
+
type: "number" | "string" | "color";
|
|
42
|
+
}
|
|
43
|
+
interface SpecSchema {
|
|
44
|
+
type: "object";
|
|
45
|
+
properties: Record<string, SpecProperty>;
|
|
46
|
+
required?: string[];
|
|
47
|
+
order?: string[];
|
|
48
|
+
additionalProperties?: boolean;
|
|
49
|
+
}
|
|
50
|
+
interface ColorSpecification {
|
|
51
|
+
name: string;
|
|
52
|
+
type: "color";
|
|
53
|
+
description?: string;
|
|
54
|
+
schema?: SpecSchema;
|
|
55
|
+
initializers: Initializer[];
|
|
56
|
+
conversions: Conversion[];
|
|
57
|
+
slug?: string;
|
|
58
|
+
}
|
|
59
|
+
interface FunctionSpecification {
|
|
60
|
+
name: string;
|
|
61
|
+
type: "function";
|
|
62
|
+
input?: {
|
|
63
|
+
type: "object";
|
|
64
|
+
properties?: Record<string, unknown>;
|
|
65
|
+
};
|
|
66
|
+
script: ScriptBlock;
|
|
67
|
+
keyword: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
requirements?: string[];
|
|
70
|
+
slug?: string;
|
|
71
|
+
}
|
|
72
|
+
type SchemaSpecification = ColorSpecification | FunctionSpecification;
|
|
73
|
+
interface BundledRegistry {
|
|
74
|
+
version: string;
|
|
75
|
+
types: ColorSpecification[];
|
|
76
|
+
functions: FunctionSpecification[];
|
|
77
|
+
metadata: {
|
|
78
|
+
generatedAt: string;
|
|
79
|
+
totalSchemas: number;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Schema bundler - bundles schemas for distribution
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Bundle all schemas from the schemas directory
|
|
89
|
+
*/
|
|
90
|
+
declare function bundleAllSchemas(schemasDir: string, outputDir: string): Promise<BundledRegistry>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Types for schema downloader
|
|
94
|
+
*/
|
|
95
|
+
interface LatestVersion {
|
|
96
|
+
id: string;
|
|
97
|
+
version: string;
|
|
98
|
+
created_at: string;
|
|
99
|
+
}
|
|
100
|
+
interface SchemaListItem {
|
|
101
|
+
id: string;
|
|
102
|
+
slug: string;
|
|
103
|
+
name: string;
|
|
104
|
+
description: string;
|
|
105
|
+
license_name: string | null;
|
|
106
|
+
type: "type" | "function";
|
|
107
|
+
latest: LatestVersion;
|
|
108
|
+
}
|
|
109
|
+
interface SchemaVersion {
|
|
110
|
+
id: string;
|
|
111
|
+
type: "type" | "function";
|
|
112
|
+
schema: string;
|
|
113
|
+
slug: string;
|
|
114
|
+
version: string;
|
|
115
|
+
content: unknown;
|
|
116
|
+
status?: string;
|
|
117
|
+
created_at?: string;
|
|
118
|
+
updated_at?: string;
|
|
119
|
+
}
|
|
120
|
+
interface SchemaDetails {
|
|
121
|
+
id: string;
|
|
122
|
+
slug: string;
|
|
123
|
+
name: string;
|
|
124
|
+
description: string;
|
|
125
|
+
type: "type" | "function";
|
|
126
|
+
version: string;
|
|
127
|
+
content: unknown;
|
|
128
|
+
metadata?: Record<string, unknown>;
|
|
129
|
+
}
|
|
130
|
+
interface SchemaConfig {
|
|
131
|
+
apiBaseUrl: string;
|
|
132
|
+
outputDir: string;
|
|
133
|
+
targetVersion: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Schema downloader - fetches schemas from the TokenScript API
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
declare const DEFAULT_CONFIG: SchemaConfig;
|
|
141
|
+
/**
|
|
142
|
+
* Fetch all schemas from the API
|
|
143
|
+
*/
|
|
144
|
+
declare function fetchSchemaList(config?: SchemaConfig): Promise<SchemaListItem[]>;
|
|
145
|
+
/**
|
|
146
|
+
* Fetch versions for a schema
|
|
147
|
+
*/
|
|
148
|
+
declare function fetchSchemaVersions(schemaSlug: string, config?: SchemaConfig): Promise<SchemaVersion[]>;
|
|
149
|
+
/**
|
|
150
|
+
* Download and organize a single schema
|
|
151
|
+
*/
|
|
152
|
+
declare function downloadSchema(schema: SchemaListItem, config?: SchemaConfig): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Download all schemas from the API
|
|
155
|
+
*/
|
|
156
|
+
declare function downloadAllSchemas(config?: Partial<SchemaConfig>): Promise<void>;
|
|
157
|
+
|
|
158
|
+
export { type BundledRegistry, type ColorSpecification, type Conversion, DEFAULT_CONFIG, type FunctionSpecification, type Initializer, type LatestVersion, type SchemaBundle, type SchemaConfig, type SchemaDetails, type SchemaFile, type SchemaListItem, type SchemaSpecification, type SchemaVersion, type ScriptBlock, type SpecProperty, type SpecSchema, bundleAllSchemas, downloadAllSchemas, downloadSchema, fetchSchemaList, fetchSchemaVersions };
|
package/package.json
CHANGED
|
@@ -70,10 +70,7 @@ function formatDependencyTree(
|
|
|
70
70
|
const isLastChild = idx === node.dependencies.length - 1;
|
|
71
71
|
const childKey = dep;
|
|
72
72
|
|
|
73
|
-
if (visited.has(childKey)) {
|
|
74
|
-
const childPrefix = childIndent + (isLastChild ? "└── " : "├── ");
|
|
75
|
-
lines.push(`${childPrefix + childKey} (already visited)`);
|
|
76
|
-
} else {
|
|
73
|
+
if (!visited.has(childKey)) {
|
|
77
74
|
formatNode(childKey, childIndent, isLastChild);
|
|
78
75
|
}
|
|
79
76
|
});
|
package/src/cli/commands/list.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
/// <reference types="../../../types/ulog" />
|
|
6
6
|
|
|
7
7
|
import { readdir } from "node:fs/promises";
|
|
8
|
-
import { join } from "node:path";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
9
10
|
import anylogger from "ulog";
|
|
10
11
|
|
|
11
12
|
const log = anylogger("list");
|
|
@@ -20,13 +21,44 @@ interface ListResult {
|
|
|
20
21
|
functions: string[];
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Find the schemas directory - works for both development/tests and installed package
|
|
26
|
+
*/
|
|
27
|
+
function findSchemasDir(): string {
|
|
28
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
29
|
+
const __dirname = dirname(__filename);
|
|
30
|
+
|
|
31
|
+
// From compiled dist/cli/index.js (bundled) to src/schemas
|
|
32
|
+
const fromDist = join(__dirname, "../../src/schemas");
|
|
33
|
+
|
|
34
|
+
// From source src/cli/commands/list.ts to src/schemas (for tests/dev)
|
|
35
|
+
const fromSource = join(__dirname, "../../schemas");
|
|
36
|
+
|
|
37
|
+
// Try to detect which one exists
|
|
38
|
+
try {
|
|
39
|
+
const fs = require("node:fs");
|
|
40
|
+
if (fs.existsSync(fromDist)) {
|
|
41
|
+
return fromDist;
|
|
42
|
+
}
|
|
43
|
+
if (fs.existsSync(fromSource)) {
|
|
44
|
+
return fromSource;
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
// If fs checks fail, default to dist structure
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Default to dist structure (for installed package)
|
|
51
|
+
return fromDist;
|
|
52
|
+
}
|
|
53
|
+
|
|
23
54
|
/**
|
|
24
55
|
* List all available schemas
|
|
25
56
|
*/
|
|
26
57
|
export async function listSchemas(
|
|
27
|
-
schemasDir
|
|
58
|
+
schemasDir?: string,
|
|
28
59
|
options: ListOptions = {},
|
|
29
60
|
): Promise<ListResult> {
|
|
61
|
+
const resolvedSchemasDir = schemasDir || findSchemasDir();
|
|
30
62
|
const showTypes = options.types || (!options.types && !options.functions);
|
|
31
63
|
const showFunctions = options.functions || (!options.types && !options.functions);
|
|
32
64
|
|
|
@@ -36,7 +68,7 @@ export async function listSchemas(
|
|
|
36
68
|
// List type schemas
|
|
37
69
|
if (showTypes) {
|
|
38
70
|
try {
|
|
39
|
-
const typesDir = join(
|
|
71
|
+
const typesDir = join(resolvedSchemasDir, "types");
|
|
40
72
|
const typeEntries = await readdir(typesDir, { withFileTypes: true });
|
|
41
73
|
types.push(
|
|
42
74
|
...typeEntries
|
|
@@ -52,7 +84,7 @@ export async function listSchemas(
|
|
|
52
84
|
// List function schemas
|
|
53
85
|
if (showFunctions) {
|
|
54
86
|
try {
|
|
55
|
-
const functionsDir = join(
|
|
87
|
+
const functionsDir = join(resolvedSchemasDir, "functions");
|
|
56
88
|
const funcEntries = await readdir(functionsDir, { withFileTypes: true });
|
|
57
89
|
functions.push(
|
|
58
90
|
...funcEntries
|