@openfairygui/functions 0.2.0-alpha.34 → 0.2.0-alpha.35

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/src/publish.ts CHANGED
@@ -3,16 +3,21 @@ import {
3
3
  type BinaryWriterOptions,
4
4
  type Document,
5
5
  type FileSystem,
6
+ type MovieClipResource,
6
7
  type Package,
7
8
  type Transform,
8
9
  } from '@openfairygui/core';
9
10
  import { atlas } from './atlas.js';
11
+ import { prepareMovieClipResource } from './atlas/inputs.js';
12
+ import type { PreparedJtaData } from './atlas/jta.js';
10
13
  import { publishCodeGeneration, resolveProjectBasePath } from './codegen.js';
11
14
  import { dirname, isAbsolutePathLike, trimTrailingSlashes } from './path-utils.js';
12
15
  import { formatPluginError, type LoadedPlugin } from './plugins/types.js';
13
16
  import type { PublishFileSystem } from './publish/contracts.js';
14
17
  import {
15
18
  annotatePackagePublishArtifacts,
19
+ getAnnotatedPublishedResourceIds,
20
+ isMovieClipResource,
16
21
  } from './publish/package-context.js';
17
22
  import {
18
23
  exportPackageExternalResources,
@@ -217,7 +222,12 @@ export function publish(options: PublishOptions): Transform {
217
222
  },
218
223
  });
219
224
 
220
- const publishPackage = async (plan: ResolvedPackagePublishPlan, writerFs: FileSystem, packageIndex: number) => {
225
+ const publishPackage = async (
226
+ plan: ResolvedPackagePublishPlan,
227
+ writerFs: FileSystem,
228
+ packageIndex: number,
229
+ preparedMovieClips?: ReadonlyMap<MovieClipResource, PreparedJtaData>,
230
+ ) => {
221
231
  if (options.fs && !plan.outputDir) {
222
232
  throw new Error(
223
233
  'publish: no output directory resolved. Provide --output, or configure global publish.path / package publishPath.',
@@ -253,6 +263,7 @@ export function publish(options: PublishOptions): Transform {
253
263
  mkdir: options.fs ? options.fs.mkdir : undefined,
254
264
  readFileRaw: options.atlas?.readFileRaw ?? options.fs?.readFileRaw,
255
265
  strictOutput: options.fs !== undefined,
266
+ preparedMovieClips,
256
267
  packages: [plan.pkg.getName()],
257
268
  ...atlasRuntimeOptions,
258
269
  })(doc);
@@ -340,11 +351,43 @@ export function publish(options: PublishOptions): Transform {
340
351
  );
341
352
  }
342
353
 
354
+ // publishPackage starts with mkdir and loose-resource writes. Preflight the complete
355
+ // selected MovieClip set first so a failure in a later package leaves zero output.
356
+ const publishedMovieClips = allPackages.flatMap((pkg) => {
357
+ const publishedResourceIds = getAnnotatedPublishedResourceIds(pkg);
358
+ return pkg
359
+ .listResources()
360
+ .filter((resource): resource is MovieClipResource => {
361
+ return publishedResourceIds.has(resource.getId()) && isMovieClipResource(resource);
362
+ })
363
+ .map((resource) => ({ pkg, resource }));
364
+ });
365
+ const preparedMovieClips = new Map<MovieClipResource, PreparedJtaData>();
366
+ if (publishedMovieClips.length > 0) {
367
+ if (!options.encoder) {
368
+ throw new Error('publish: MovieClip output requires an encoder.');
369
+ }
370
+ if (!options.basePath) {
371
+ throw new Error('publish: MovieClip output requires basePath.');
372
+ }
373
+ const readFileRaw = options.atlas?.readFileRaw ?? options.fs.readFileRaw;
374
+ if (!readFileRaw) {
375
+ throw new Error('publish: MovieClip output requires readFileRaw.');
376
+ }
377
+
378
+ for (const { pkg, resource } of publishedMovieClips) {
379
+ preparedMovieClips.set(
380
+ resource,
381
+ await prepareMovieClipResource(resource, pkg, options.encoder, options.basePath, readFileRaw),
382
+ );
383
+ }
384
+ }
385
+
343
386
  const writerFs = toBinaryWriterFileSystem(options.fs);
344
387
 
345
388
  for (const plan of plans) {
346
389
  const pkgIndex = allDocPackages.indexOf(plan.pkg);
347
- await publishPackage(plan, writerFs, pkgIndex);
390
+ await publishPackage(plan, writerFs, pkgIndex, preparedMovieClips);
348
391
  }
349
392
 
350
393
  if (options.codeGeneration !== false) {
package/src/restore.ts CHANGED
@@ -466,6 +466,16 @@ class RestoreWorkflow {
466
466
  common: {},
467
467
  adaptation: {},
468
468
  });
469
+ for (const pkg of doc.getRoot().listPackages()) {
470
+ pkg.setSourceAtlasSettings({
471
+ ...pkg.getSourceAtlasSettings(),
472
+ atlases: pkg.listAtlases().map((atlas) => ({
473
+ index: atlas.getIndex(),
474
+ name: atlas.getIndex() === 0 ? 'Default' : atlas.getName(),
475
+ compression: false,
476
+ })),
477
+ });
478
+ }
469
479
  }
470
480
 
471
481
  private _initializeImageFileNames(doc: Document): void {