@openfairygui/functions 0.1.0 → 0.1.1
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/index.cjs +822 -7
- package/dist/index.d.cts +44 -1
- package/dist/index.d.ts +44 -1
- package/dist/index.js +823 -9
- package/package.json +26 -26
- package/src/atlas.ts +335 -335
- package/src/index.ts +13 -3
- package/src/inspect.ts +98 -98
- package/src/rename.ts +66 -66
- package/src/restore.ts +1277 -0
- package/src/validate.ts +173 -173
package/src/index.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
export { inspect, type InspectReport, type InspectCategoryReport } from './inspect.js';
|
|
2
|
-
export { validate, type ValidateOptions, type ValidationResult, type ValidationIssue, ValidationSeverity } from './validate.js';
|
|
3
|
-
export { prune, type PruneOptions } from './prune.js';
|
|
1
|
+
export { inspect, type InspectReport, type InspectCategoryReport } from './inspect.js';
|
|
2
|
+
export { validate, type ValidateOptions, type ValidationResult, type ValidationIssue, ValidationSeverity } from './validate.js';
|
|
3
|
+
export { prune, type PruneOptions } from './prune.js';
|
|
4
4
|
export { rename, type RenameOptions } from './rename.js';
|
|
5
5
|
export { atlas, type AtlasOptions } from './atlas.js';
|
|
6
6
|
export { publishCodeGeneration, AUTO_GENERATED_CODE_MARK, type PublishCodeGenerationOptions } from './codegen.js';
|
|
7
|
+
export {
|
|
8
|
+
restore,
|
|
9
|
+
type RestoreFileSystem,
|
|
10
|
+
type RestoreImageCropInput,
|
|
11
|
+
type RestoreImageCropper,
|
|
12
|
+
type RestoreImageExtractInput,
|
|
13
|
+
type RestoreImageExtractor,
|
|
14
|
+
type RestoreOptions,
|
|
15
|
+
type RestoreResult,
|
|
16
|
+
} from './restore.js';
|
|
7
17
|
export {
|
|
8
18
|
publish,
|
|
9
19
|
resolvePublishOptions,
|
package/src/inspect.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
1
|
import type { Document, Package } from '@openfairygui/core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Summary report for a single resource category.
|
|
5
|
-
*/
|
|
6
|
-
export interface InspectCategoryReport {
|
|
7
|
-
count: number;
|
|
8
|
-
details: Array<{ name: string; id: string; path?: string; exported?: boolean }>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Full inspection report for a FairyGUI project.
|
|
13
|
-
*/
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Summary report for a single resource category.
|
|
5
|
+
*/
|
|
6
|
+
export interface InspectCategoryReport {
|
|
7
|
+
count: number;
|
|
8
|
+
details: Array<{ name: string; id: string; path?: string; exported?: boolean }>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Full inspection report for a FairyGUI project.
|
|
13
|
+
*/
|
|
14
14
|
export interface InspectReport {
|
|
15
|
-
projectId: string;
|
|
16
|
-
projectType: number;
|
|
17
|
-
version: string;
|
|
18
|
-
packages: Array<{
|
|
19
|
-
name: string;
|
|
20
|
-
id: string;
|
|
21
|
-
publishName: string;
|
|
22
|
-
resources: {
|
|
23
|
-
images: InspectCategoryReport;
|
|
24
|
-
sounds: InspectCategoryReport;
|
|
25
|
-
fonts: InspectCategoryReport;
|
|
26
|
-
movieClips: InspectCategoryReport;
|
|
27
|
-
components: InspectCategoryReport;
|
|
28
|
-
};
|
|
29
|
-
componentDetails: Array<{
|
|
30
|
-
name: string;
|
|
31
|
-
id: string;
|
|
32
|
-
childCount: number;
|
|
33
|
-
controllerCount: number;
|
|
34
|
-
transitionCount: number;
|
|
35
|
-
}>;
|
|
36
|
-
}>;
|
|
37
|
-
totals: {
|
|
38
|
-
packages: number;
|
|
39
|
-
images: number;
|
|
40
|
-
sounds: number;
|
|
41
|
-
fonts: number;
|
|
42
|
-
movieClips: number;
|
|
43
|
-
components: number;
|
|
44
|
-
displayObjects: number;
|
|
45
|
-
gears: number;
|
|
46
|
-
controllers: number;
|
|
47
|
-
transitions: number;
|
|
15
|
+
projectId: string;
|
|
16
|
+
projectType: number;
|
|
17
|
+
version: string;
|
|
18
|
+
packages: Array<{
|
|
19
|
+
name: string;
|
|
20
|
+
id: string;
|
|
21
|
+
publishName: string;
|
|
22
|
+
resources: {
|
|
23
|
+
images: InspectCategoryReport;
|
|
24
|
+
sounds: InspectCategoryReport;
|
|
25
|
+
fonts: InspectCategoryReport;
|
|
26
|
+
movieClips: InspectCategoryReport;
|
|
27
|
+
components: InspectCategoryReport;
|
|
28
|
+
};
|
|
29
|
+
componentDetails: Array<{
|
|
30
|
+
name: string;
|
|
31
|
+
id: string;
|
|
32
|
+
childCount: number;
|
|
33
|
+
controllerCount: number;
|
|
34
|
+
transitionCount: number;
|
|
35
|
+
}>;
|
|
36
|
+
}>;
|
|
37
|
+
totals: {
|
|
38
|
+
packages: number;
|
|
39
|
+
images: number;
|
|
40
|
+
sounds: number;
|
|
41
|
+
fonts: number;
|
|
42
|
+
movieClips: number;
|
|
43
|
+
components: number;
|
|
44
|
+
displayObjects: number;
|
|
45
|
+
gears: number;
|
|
46
|
+
controllers: number;
|
|
47
|
+
transitions: number;
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -84,38 +84,38 @@ function mapComponentDetail(
|
|
|
84
84
|
transitionCount: transitions.length,
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Generates a detailed report of the project contents.
|
|
90
|
-
*
|
|
91
|
-
* Unlike other transforms, `inspect()` does NOT modify the document —
|
|
92
|
-
* it returns a structured report.
|
|
93
|
-
*
|
|
94
|
-
* ```ts
|
|
95
|
-
* const report = inspect(doc);
|
|
96
|
-
* console.log(`${report.totals.packages} packages, ${report.totals.components} components`);
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export function inspect(doc: Document): InspectReport {
|
|
100
|
-
const root = doc.getRoot();
|
|
101
|
-
const totals = {
|
|
102
|
-
packages: 0, images: 0, sounds: 0, fonts: 0,
|
|
103
|
-
movieClips: 0, components: 0, displayObjects: 0,
|
|
104
|
-
gears: 0, controllers: 0, transitions: 0,
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const packages = root.listPackages().map((pkg) => {
|
|
108
|
-
totals.packages++;
|
|
109
|
-
const resources = pkg.listResources();
|
|
110
|
-
|
|
111
|
-
const images = resources.filter((r) => r.propertyType === 'ImageResource');
|
|
112
|
-
const sounds = resources.filter((r) => r.propertyType === 'SoundResource');
|
|
113
|
-
const fonts = resources.filter((r) => r.propertyType === 'FontResource');
|
|
114
|
-
const movieClips = resources.filter((r) => r.propertyType === 'MovieClipResource');
|
|
115
|
-
const components = pkg.listComponents();
|
|
116
|
-
|
|
117
|
-
totals.images += images.length;
|
|
118
|
-
totals.sounds += sounds.length;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Generates a detailed report of the project contents.
|
|
90
|
+
*
|
|
91
|
+
* Unlike other transforms, `inspect()` does NOT modify the document —
|
|
92
|
+
* it returns a structured report.
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* const report = inspect(doc);
|
|
96
|
+
* console.log(`${report.totals.packages} packages, ${report.totals.components} components`);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export function inspect(doc: Document): InspectReport {
|
|
100
|
+
const root = doc.getRoot();
|
|
101
|
+
const totals = {
|
|
102
|
+
packages: 0, images: 0, sounds: 0, fonts: 0,
|
|
103
|
+
movieClips: 0, components: 0, displayObjects: 0,
|
|
104
|
+
gears: 0, controllers: 0, transitions: 0,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const packages = root.listPackages().map((pkg) => {
|
|
108
|
+
totals.packages++;
|
|
109
|
+
const resources = pkg.listResources();
|
|
110
|
+
|
|
111
|
+
const images = resources.filter((r) => r.propertyType === 'ImageResource');
|
|
112
|
+
const sounds = resources.filter((r) => r.propertyType === 'SoundResource');
|
|
113
|
+
const fonts = resources.filter((r) => r.propertyType === 'FontResource');
|
|
114
|
+
const movieClips = resources.filter((r) => r.propertyType === 'MovieClipResource');
|
|
115
|
+
const components = pkg.listComponents();
|
|
116
|
+
|
|
117
|
+
totals.images += images.length;
|
|
118
|
+
totals.sounds += sounds.length;
|
|
119
119
|
totals.fonts += fonts.length;
|
|
120
120
|
totals.movieClips += movieClips.length;
|
|
121
121
|
totals.components += components.length;
|
|
@@ -123,24 +123,24 @@ export function inspect(doc: Document): InspectReport {
|
|
|
123
123
|
|
|
124
124
|
return {
|
|
125
125
|
name: pkg.getName(),
|
|
126
|
-
id: pkg.getId(),
|
|
127
|
-
publishName: pkg.getPublishName() || pkg.getName(),
|
|
128
|
-
resources: {
|
|
129
|
-
images: { count: images.length, details: images.map(mapResource) },
|
|
130
|
-
sounds: { count: sounds.length, details: sounds.map(mapResource) },
|
|
131
|
-
fonts: { count: fonts.length, details: fonts.map(mapResource) },
|
|
132
|
-
movieClips: { count: movieClips.length, details: movieClips.map(mapResource) },
|
|
133
|
-
components: { count: components.length, details: components.map(mapResource) },
|
|
134
|
-
},
|
|
135
|
-
componentDetails,
|
|
136
|
-
};
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
projectId: root.getProjectId(),
|
|
141
|
-
projectType: root.getProjectType(),
|
|
142
|
-
version: root.getVersion(),
|
|
143
|
-
packages,
|
|
144
|
-
totals,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
126
|
+
id: pkg.getId(),
|
|
127
|
+
publishName: pkg.getPublishName() || pkg.getName(),
|
|
128
|
+
resources: {
|
|
129
|
+
images: { count: images.length, details: images.map(mapResource) },
|
|
130
|
+
sounds: { count: sounds.length, details: sounds.map(mapResource) },
|
|
131
|
+
fonts: { count: fonts.length, details: fonts.map(mapResource) },
|
|
132
|
+
movieClips: { count: movieClips.length, details: movieClips.map(mapResource) },
|
|
133
|
+
components: { count: components.length, details: components.map(mapResource) },
|
|
134
|
+
},
|
|
135
|
+
componentDetails,
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
projectId: root.getProjectId(),
|
|
141
|
+
projectType: root.getProjectType(),
|
|
142
|
+
version: root.getVersion(),
|
|
143
|
+
packages,
|
|
144
|
+
totals,
|
|
145
|
+
};
|
|
146
|
+
}
|
package/src/rename.ts
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import type { Document, Transform } from '@openfairygui/core';
|
|
2
|
-
import { createTransform } from './utils.js';
|
|
3
|
-
|
|
4
|
-
export interface RenameOptions {
|
|
5
|
-
/** Package name to rename from. Required. */
|
|
6
|
-
packageName: string;
|
|
7
|
-
/** Resource name to rename from. Required. */
|
|
8
|
-
resourceName: string;
|
|
9
|
-
/** New name for the resource. Required. */
|
|
10
|
-
newName: string;
|
|
11
|
-
/** If true, also update all `ui://` references pointing to this resource. Default: true. */
|
|
12
|
-
updateReferences?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Renames a resource and optionally updates all references to it.
|
|
17
|
-
*
|
|
18
|
-
* This searches all display objects' `src` attributes across all packages
|
|
19
|
-
* for `ui://` URLs that point to the renamed resource, and updates them
|
|
20
|
-
* to reflect the new name (the resource ID doesn't change, so references
|
|
21
|
-
* are already valid — but the name stored in package.xml is updated).
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* await doc.transform(rename({
|
|
25
|
-
* packageName: 'Basics',
|
|
26
|
-
* resourceName: 'Button',
|
|
27
|
-
* newName: 'PrimaryButton',
|
|
28
|
-
* }));
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export function rename(options: RenameOptions): Transform {
|
|
32
|
-
const updateReferences = options.updateReferences ?? true;
|
|
33
|
-
|
|
34
|
-
return createTransform('rename', (doc: Document): void => {
|
|
35
|
-
const root = doc.getRoot();
|
|
36
|
-
const logger = doc.getLogger();
|
|
37
|
-
const pkg = root.listPackages().find((p) => p.getName() === options.packageName);
|
|
38
|
-
|
|
39
|
-
if (!pkg) {
|
|
40
|
-
logger.warn(`rename: Package "${options.packageName}" not found.`);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Find the resource
|
|
45
|
-
const resource = pkg.listResources().find((r) => r.getName() === options.resourceName)
|
|
46
|
-
|| pkg.listComponents().find((c) => c.getName() === options.resourceName);
|
|
47
|
-
|
|
48
|
-
if (!resource) {
|
|
49
|
-
logger.warn(`rename: Resource "${options.resourceName}" not found in package "${options.packageName}".`);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const oldName = resource.getName();
|
|
54
|
-
resource.setName(options.newName);
|
|
55
|
-
logger.info(`rename: Renamed "${oldName}" → "${options.newName}" in package "${options.packageName}".`);
|
|
56
|
-
|
|
57
|
-
// If this is a component resource, we don't need to update src references
|
|
58
|
-
// because src references use resource IDs (not names)
|
|
59
|
-
if (updateReferences) {
|
|
60
|
-
// Resource IDs are stable, so ui:// references don't need updating
|
|
61
|
-
// unless the consumer relies on name-based lookups.
|
|
62
|
-
// The primary rename is the resource name itself.
|
|
63
|
-
logger.info(`rename: References use resource IDs — no src updates needed.`);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
1
|
+
import type { Document, Transform } from '@openfairygui/core';
|
|
2
|
+
import { createTransform } from './utils.js';
|
|
3
|
+
|
|
4
|
+
export interface RenameOptions {
|
|
5
|
+
/** Package name to rename from. Required. */
|
|
6
|
+
packageName: string;
|
|
7
|
+
/** Resource name to rename from. Required. */
|
|
8
|
+
resourceName: string;
|
|
9
|
+
/** New name for the resource. Required. */
|
|
10
|
+
newName: string;
|
|
11
|
+
/** If true, also update all `ui://` references pointing to this resource. Default: true. */
|
|
12
|
+
updateReferences?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Renames a resource and optionally updates all references to it.
|
|
17
|
+
*
|
|
18
|
+
* This searches all display objects' `src` attributes across all packages
|
|
19
|
+
* for `ui://` URLs that point to the renamed resource, and updates them
|
|
20
|
+
* to reflect the new name (the resource ID doesn't change, so references
|
|
21
|
+
* are already valid — but the name stored in package.xml is updated).
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* await doc.transform(rename({
|
|
25
|
+
* packageName: 'Basics',
|
|
26
|
+
* resourceName: 'Button',
|
|
27
|
+
* newName: 'PrimaryButton',
|
|
28
|
+
* }));
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function rename(options: RenameOptions): Transform {
|
|
32
|
+
const updateReferences = options.updateReferences ?? true;
|
|
33
|
+
|
|
34
|
+
return createTransform('rename', (doc: Document): void => {
|
|
35
|
+
const root = doc.getRoot();
|
|
36
|
+
const logger = doc.getLogger();
|
|
37
|
+
const pkg = root.listPackages().find((p) => p.getName() === options.packageName);
|
|
38
|
+
|
|
39
|
+
if (!pkg) {
|
|
40
|
+
logger.warn(`rename: Package "${options.packageName}" not found.`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Find the resource
|
|
45
|
+
const resource = pkg.listResources().find((r) => r.getName() === options.resourceName)
|
|
46
|
+
|| pkg.listComponents().find((c) => c.getName() === options.resourceName);
|
|
47
|
+
|
|
48
|
+
if (!resource) {
|
|
49
|
+
logger.warn(`rename: Resource "${options.resourceName}" not found in package "${options.packageName}".`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const oldName = resource.getName();
|
|
54
|
+
resource.setName(options.newName);
|
|
55
|
+
logger.info(`rename: Renamed "${oldName}" → "${options.newName}" in package "${options.packageName}".`);
|
|
56
|
+
|
|
57
|
+
// If this is a component resource, we don't need to update src references
|
|
58
|
+
// because src references use resource IDs (not names)
|
|
59
|
+
if (updateReferences) {
|
|
60
|
+
// Resource IDs are stable, so ui:// references don't need updating
|
|
61
|
+
// unless the consumer relies on name-based lookups.
|
|
62
|
+
// The primary rename is the resource name itself.
|
|
63
|
+
logger.info(`rename: References use resource IDs — no src updates needed.`);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|