clumsy-graphics
Version:
a tool for rapidly developing animations where frames are described using svg elements à la react 🙃
95 lines (94 loc) • 3.56 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseCommandLineArgs = exports.ClumsyGraphicsCommandCodec = exports.StartDevelopmentCommandCodec = void 0;
const IO = __importStar(require("io-ts"));
const codecTypes_1 = require("../helpers/codecTypes");
exports.StartDevelopmentCommandCodec = IO.exact(IO.type({
commandName: IO.literal('startDevelopment'),
commandApi: IO.exact(IO.intersection([
IO.type({
animationModulePath: IO.string,
}),
IO.partial({
clientServerPort: codecTypes_1.NumberFromString,
generatedAssetsDirectoryPath: IO.string,
numberOfFrameRendererWorkers: codecTypes_1.NumberFromString,
}),
])),
}));
const RenderAnimationCommandCodec = IO.exact(IO.type({
commandName: IO.literal('renderAnimation'),
commandApi: IO.exact(IO.intersection([
IO.type({
animationModulePath: IO.string,
animationMp4OutputPath: IO.string,
}),
IO.partial({
numberOfFrameRendererWorkers: codecTypes_1.NumberFromString,
suppressWorkerStdout: codecTypes_1.BooleanFromString,
}),
])),
}));
const RenderAnimationFrameCommandCodec = IO.exact(IO.type({
commandName: IO.literal('renderAnimationFrame'),
commandApi: IO.exact(IO.type({
animationModulePath: IO.string,
frameFileOutputPath: IO.string,
frameIndex: codecTypes_1.NumberFromString,
})),
}));
const ConvertAnimationToGifCommandCodec = IO.exact(IO.type({
commandName: IO.literal('convertAnimationToGif'),
commandApi: IO.exact(IO.intersection([
IO.type({
animationMp4SourcePath: IO.string,
animationGifOutputPath: IO.string,
}),
IO.partial({
gifAspectRatioWidth: codecTypes_1.NumberFromString,
}),
])),
}));
exports.ClumsyGraphicsCommandCodec = IO.union([
exports.StartDevelopmentCommandCodec,
RenderAnimationCommandCodec,
RenderAnimationFrameCommandCodec,
ConvertAnimationToGifCommandCodec,
]);
function parseCommandLineArgs(api) {
const { processArgv } = api;
return {
commandName: processArgv[2],
commandApi: processArgv
.slice(3)
.reduce((result, someProcessArg) => {
const optionMatch = someProcessArg.match(/^--([a-zA-Z0-9]+)=(.+)$/);
if (optionMatch) {
const optionKey = optionMatch[1];
const optionValue = optionMatch[2];
result[optionKey] = optionValue;
}
return result;
}, {}),
};
}
exports.parseCommandLineArgs = parseCommandLineArgs;