UNPKG

clumsy-graphics

Version:

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

70 lines (69 loc) 3.06 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.animationDevelopmentSetupSaga = void 0; const esbuild_1 = require("esbuild"); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const redux_saga_1 = require("redux-saga"); const getAnimationModuleBundlerEventChannel_1 = require("../externals/getAnimationModuleBundlerEventChannel"); const getClientServerEventChannel_1 = require("../externals/getClientServerEventChannel"); const storeEffects_1 = require("../helpers/storeEffects"); function* animationDevelopmentSetupSaga(api) { const { generatedAssetsDirectoryPath, animationModulePath, clientServerPort, } = api; const generatedAssetsDirectoryAbsolutePath = path_1.default.resolve(generatedAssetsDirectoryPath); setupGeneratedAssetsDirectory({ generatedAssetsDirectoryAbsolutePath, }); const { animationModuleBundlerEventChannel } = (0, getAnimationModuleBundlerEventChannel_1.getAnimationModuleBundlerEventChannel)({ animationModulePath, }); const { clientServerEventChannel } = (0, getClientServerEventChannel_1.getClientServerEventChannel)({ clientServerPort, }); const graphicsRendererProcessManagerActionChannel = yield* (0, storeEffects_1.actionChannel)([ 'animationModuleBundler_initialBuildSucceeded', 'animationModuleBundler_rebuildSucceeded', 'animationModuleBundler_rebuildFailed', 'spawnGraphicsRendererProcess', ], redux_saga_1.buffers.expanding(3)); const { clientPageBundle } = yield* (0, storeEffects_1.call)(getClientPageBundle); const { localStorageSessionCacheId } = getLocalStorageSessionCacheId(); return { animationModuleBundlerEventChannel, clientServerEventChannel, graphicsRendererProcessManagerActionChannel, clientPageBundle, localStorageSessionCacheId, }; } exports.animationDevelopmentSetupSaga = animationDevelopmentSetupSaga; function setupGeneratedAssetsDirectory(api) { const { generatedAssetsDirectoryAbsolutePath } = api; fs_1.default.rmSync(generatedAssetsDirectoryAbsolutePath, { recursive: true, force: true, }); fs_1.default.mkdirSync(generatedAssetsDirectoryAbsolutePath); } async function getClientPageBundle() { const clientPageBundleBuildResult = await (0, esbuild_1.build)({ absWorkingDir: process.cwd(), entryPoints: [path_1.default.resolve(__dirname, '../browser/index.tsx')], tsconfig: path_1.default.resolve(__dirname, '../browser/tsconfig.json'), platform: 'browser', bundle: true, write: false, }); const clientPageBundle = clientPageBundleBuildResult.outputFiles[0].text; return { clientPageBundle, }; } function getLocalStorageSessionCacheId() { return { localStorageSessionCacheId: `${Math.random()}`, }; }