UNPKG

clumsy-graphics

Version:

a tool for rapidly developing animations where frames are described using svg elements à la react 🙃

81 lines (80 loc) 3.88 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAnimationModuleBundlerEventChannel = void 0; const esbuild_1 = require("esbuild"); const esbuild_node_externals_1 = __importDefault(require("esbuild-node-externals")); const path_1 = __importDefault(require("path")); const redux_saga_1 = require("redux-saga"); const getAnimationModule_1 = require("../../helpers/getAnimationModule"); const getAnimationModuleBundle_1 = require("../../helpers/getAnimationModuleBundle"); function getAnimationModuleBundlerEventChannel(api) { const { animationModulePath } = api; const animationModuleBundlerEventChannel = (0, redux_saga_1.eventChannel)((emitAnimationModuleSourceEvent) => { let nextBuildSessionVersion = 0; (0, esbuild_1.build)({ platform: 'node', bundle: true, write: false, incremental: true, logLevel: 'silent', absWorkingDir: process.cwd(), entryPoints: [path_1.default.resolve(animationModulePath)], plugins: [(0, esbuild_node_externals_1.default)()], watch: { onRebuild: async () => { try { const { animationModuleBundle } = await (0, getAnimationModuleBundle_1.getAnimationModuleBundle)({ animationModulePath, }); const nextAnimationModule = await (0, getAnimationModule_1.getAnimationModule)({ animationModuleBundle, }); nextBuildSessionVersion = nextBuildSessionVersion + 1; emitAnimationModuleSourceEvent({ eventType: 'animationModuleBundler_rebuildSucceeded', eventPayload: { nextBuildSessionVersion, nextAnimationModule, nextBuildStatus: 'validBuild', }, }); } catch (nextBundleError) { nextBuildSessionVersion = nextBuildSessionVersion + 1; emitAnimationModuleSourceEvent({ eventType: 'animationModuleBundler_rebuildFailed', eventPayload: { nextBuildSessionVersion, nextBuildStatus: 'invalidBuild', nextBuildErrorMessage: nextBundleError instanceof Error ? nextBundleError.message : 'Invalid animation module', }, }); } }, }, }).then(async () => { const { animationModuleBundle } = await (0, getAnimationModuleBundle_1.getAnimationModuleBundle)({ animationModulePath, }); const nextAnimationModule = await (0, getAnimationModule_1.getAnimationModule)({ animationModuleBundle, }); emitAnimationModuleSourceEvent({ eventType: 'animationModuleBundler_initialBuildSucceeded', eventPayload: { nextBuildSessionVersion, nextAnimationModule, nextBuildStatus: 'validBuild', }, }); }); return () => { }; }, redux_saga_1.buffers.sliding(1)); return { animationModuleBundlerEventChannel }; } exports.getAnimationModuleBundlerEventChannel = getAnimationModuleBundlerEventChannel;