Add .gitignore to exclude all node packages and lock files
This commit is contained in:
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
import type { File } from '@babel/types';
|
||||
import { type ApplyVisualControlCodemod } from '@remotion/studio-shared';
|
||||
import type { ApplyCodeModReturnType, Change } from './recast-mods';
|
||||
export declare const applyVisualControl: ({ file, transformation, changesMade, }: {
|
||||
file: File;
|
||||
transformation: ApplyVisualControlCodemod;
|
||||
changesMade: Change[];
|
||||
}) => ApplyCodeModReturnType;
|
||||
Generated
Vendored
+82
@@ -0,0 +1,82 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (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 () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.applyVisualControl = void 0;
|
||||
const studio_shared_1 = require("@remotion/studio-shared");
|
||||
const recast = __importStar(require("recast"));
|
||||
const parse_ast_1 = require("./parse-ast");
|
||||
const expectString = (node) => {
|
||||
if (node.type === 'StringLiteral') {
|
||||
return node.value;
|
||||
}
|
||||
if (node.type === 'TemplateLiteral') {
|
||||
if (node.expressions.length > 0) {
|
||||
throw new Error('applyVisualControl() must use a static identifier, the string may not be dynamic.');
|
||||
}
|
||||
return node.quasis[0].value.raw;
|
||||
}
|
||||
throw new Error('Expected a string literal');
|
||||
};
|
||||
const applyVisualControl = ({ file, transformation, changesMade, }) => {
|
||||
recast.types.visit(file.program, {
|
||||
visitCallExpression(path) {
|
||||
const { node } = path;
|
||||
if (node.type !== 'CallExpression') {
|
||||
throw new Error('Expected a call expression');
|
||||
}
|
||||
if (node.callee.type !== 'Identifier') {
|
||||
return this.traverse(path);
|
||||
}
|
||||
if (node.callee.name !== 'visualControl') {
|
||||
return this.traverse(path);
|
||||
}
|
||||
const firstArgument = node.arguments[0];
|
||||
const str = expectString(firstArgument);
|
||||
for (const change of transformation.changes) {
|
||||
if (change.id !== str) {
|
||||
continue;
|
||||
}
|
||||
const parsed = (0, parse_ast_1.parseAst)(`a = ${(0, studio_shared_1.stringifyDefaultProps)({ props: JSON.parse(change.newValueSerialized), enumPaths: change.enumPaths })}`).program.body[0].expression.right;
|
||||
node.arguments[1] = parsed;
|
||||
changesMade.push({
|
||||
description: `Applied visual control ${change.id}`,
|
||||
});
|
||||
}
|
||||
return this.traverse(path);
|
||||
},
|
||||
});
|
||||
return { newAst: file, changesMade };
|
||||
};
|
||||
exports.applyVisualControl = applyVisualControl;
|
||||
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
import type { RecastCodemod } from '@remotion/studio-shared';
|
||||
import type { Change } from './recast-mods';
|
||||
export declare const formatOutput: (tsContent: string) => Promise<string>;
|
||||
export declare const parseAndApplyCodemod: ({ input, codeMod, }: {
|
||||
input: string;
|
||||
codeMod: RecastCodemod;
|
||||
}) => {
|
||||
newContents: string;
|
||||
changesMade: Change[];
|
||||
};
|
||||
Generated
Vendored
+77
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (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 () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseAndApplyCodemod = exports.formatOutput = void 0;
|
||||
const parse_ast_1 = require("./parse-ast");
|
||||
const recast_mods_1 = require("./recast-mods");
|
||||
const getPrettier = async () => {
|
||||
try {
|
||||
return await Promise.resolve().then(() => __importStar(require('prettier')));
|
||||
}
|
||||
catch (_a) {
|
||||
throw new Error('Prettier cannot be found in the current project.');
|
||||
}
|
||||
};
|
||||
const formatOutput = async (tsContent) => {
|
||||
const prettier = await getPrettier();
|
||||
const { format, resolveConfig, resolveConfigFile } = prettier;
|
||||
const configFilePath = await resolveConfigFile();
|
||||
if (!configFilePath) {
|
||||
throw new Error('The Prettier config file was not found. For this feature, the "prettier" package must be installed and a .prettierrc file must exist.');
|
||||
}
|
||||
const prettierConfig = await resolveConfig(configFilePath);
|
||||
if (!prettierConfig) {
|
||||
throw new Error(`The Prettier config at ${configFilePath} could not be read`);
|
||||
}
|
||||
const newContents = await format(tsContent, {
|
||||
...prettierConfig,
|
||||
filepath: 'test.tsx',
|
||||
});
|
||||
return newContents;
|
||||
};
|
||||
exports.formatOutput = formatOutput;
|
||||
const parseAndApplyCodemod = ({ input, codeMod, }) => {
|
||||
const ast = (0, parse_ast_1.parseAst)(input);
|
||||
const { newAst, changesMade } = (0, recast_mods_1.applyCodemod)({
|
||||
file: ast,
|
||||
codeMod,
|
||||
});
|
||||
if (changesMade.length === 0) {
|
||||
throw new Error('Unable to calculate the changes needed for this file. Edit the root file manually.');
|
||||
}
|
||||
const output = (0, parse_ast_1.serializeAst)(newAst);
|
||||
return { changesMade, newContents: output };
|
||||
};
|
||||
exports.parseAndApplyCodemod = parseAndApplyCodemod;
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import type { File } from '@babel/types';
|
||||
export declare const parseAst: (input: string) => File;
|
||||
export declare const serializeAst: (ast: File) => string;
|
||||
Generated
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (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 () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.serializeAst = exports.parseAst = void 0;
|
||||
const recast = __importStar(require("recast"));
|
||||
const tsParser = __importStar(require("recast/parsers/babel-ts"));
|
||||
const parseAst = (input) => {
|
||||
return recast.parse(input, {
|
||||
parser: tsParser,
|
||||
});
|
||||
};
|
||||
exports.parseAst = parseAst;
|
||||
const serializeAst = (ast) => {
|
||||
return recast.print(ast, {
|
||||
parser: tsParser,
|
||||
}).code;
|
||||
};
|
||||
exports.serializeAst = serializeAst;
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
import type { File } from '@babel/types';
|
||||
import type { RecastCodemod } from '@remotion/studio-shared';
|
||||
export type Change = {
|
||||
description: string;
|
||||
};
|
||||
export type ApplyCodeModReturnType = {
|
||||
newAst: File;
|
||||
changesMade: Change[];
|
||||
};
|
||||
export declare const applyCodemod: ({ file, codeMod, }: {
|
||||
file: File;
|
||||
codeMod: RecastCodemod;
|
||||
}) => ApplyCodeModReturnType;
|
||||
Generated
Vendored
+358
@@ -0,0 +1,358 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.applyCodemod = void 0;
|
||||
const apply_visual_control_1 = require("./apply-visual-control");
|
||||
const applyCodemod = ({ file, codeMod, }) => {
|
||||
const changesMade = [];
|
||||
if (codeMod.type === 'apply-visual-control') {
|
||||
return (0, apply_visual_control_1.applyVisualControl)({ file, transformation: codeMod, changesMade });
|
||||
}
|
||||
const body = file.program.body.map((node) => {
|
||||
return mapAll(node, codeMod, changesMade);
|
||||
});
|
||||
return {
|
||||
newAst: {
|
||||
...file,
|
||||
program: {
|
||||
...file.program,
|
||||
body,
|
||||
},
|
||||
},
|
||||
changesMade,
|
||||
};
|
||||
};
|
||||
exports.applyCodemod = applyCodemod;
|
||||
const mapAll = (node, transformation, changesMade) => {
|
||||
if (isRecognizedType(node)) {
|
||||
return mapRecognizedType(node, transformation, changesMade);
|
||||
}
|
||||
return node;
|
||||
};
|
||||
const isRecognizedType = (t) => {
|
||||
return (t.type === 'ArrowFunctionExpression' ||
|
||||
t.type === 'FunctionExpression' ||
|
||||
t.type === 'JSXFragment' ||
|
||||
t.type === 'JSXElement' ||
|
||||
t.type === 'BlockStatement' ||
|
||||
t.type === 'ReturnStatement' ||
|
||||
t.type === 'VariableDeclaration' ||
|
||||
t.type === 'FunctionDeclaration' ||
|
||||
t.type === 'ExportNamedDeclaration' ||
|
||||
t.type === 'ExportDefaultDeclaration');
|
||||
};
|
||||
const mapVariableDeclarator = (variableDeclarator, transformation, changesMade) => {
|
||||
return {
|
||||
...variableDeclarator,
|
||||
init: variableDeclarator.init
|
||||
? mapAll(variableDeclarator.init, transformation, changesMade)
|
||||
: variableDeclarator.init,
|
||||
};
|
||||
};
|
||||
const mapBlockStatement = (blockStatement, transformation, changesMade) => {
|
||||
return {
|
||||
...blockStatement,
|
||||
body: blockStatement.body.map((a) => {
|
||||
return mapAll(a, transformation, changesMade);
|
||||
}),
|
||||
};
|
||||
};
|
||||
const mapReturnStatement = (statement, transformation, changesMade) => {
|
||||
if (!statement.argument) {
|
||||
return statement;
|
||||
}
|
||||
return {
|
||||
...statement,
|
||||
argument: mapAll(statement.argument, transformation, changesMade),
|
||||
};
|
||||
};
|
||||
const mapJsxElementOrFragment = (jsxFragment, transformation, changesMade) => {
|
||||
return {
|
||||
...jsxFragment,
|
||||
children: jsxFragment.children
|
||||
.map((c) => {
|
||||
if (c.type !== 'JSXElement') {
|
||||
return c;
|
||||
}
|
||||
return mapJsxChild(c, transformation, changesMade);
|
||||
})
|
||||
.flat(1),
|
||||
};
|
||||
};
|
||||
const mapJsxChild = (c, transformation, changesMade) => {
|
||||
const compId = getCompositionIdFromJSXElement(c);
|
||||
if (transformation === null) {
|
||||
return [c];
|
||||
}
|
||||
if (transformation.type === 'duplicate-composition' &&
|
||||
compId === transformation.idToDuplicate) {
|
||||
return [
|
||||
c,
|
||||
changeComposition({
|
||||
jsxElement: c,
|
||||
newCompositionId: transformation.newId,
|
||||
newCompositionFps: transformation.newFps,
|
||||
newCompositionDurationInFrames: transformation.newDurationInFrames,
|
||||
newCompositionHeight: transformation.newHeight,
|
||||
newCompositionWidth: transformation.newWidth,
|
||||
newTagToUse: transformation.tag,
|
||||
changesMade,
|
||||
}),
|
||||
];
|
||||
}
|
||||
if (transformation.type === 'rename-composition' &&
|
||||
compId === transformation.idToRename) {
|
||||
return [
|
||||
changeComposition({
|
||||
jsxElement: c,
|
||||
newCompositionId: transformation.newId,
|
||||
newCompositionFps: null,
|
||||
newCompositionDurationInFrames: null,
|
||||
newCompositionHeight: null,
|
||||
newCompositionWidth: null,
|
||||
changesMade,
|
||||
newTagToUse: null,
|
||||
}),
|
||||
];
|
||||
}
|
||||
if (transformation.type === 'delete-composition' &&
|
||||
compId === transformation.idToDelete) {
|
||||
changesMade.push({
|
||||
description: 'Deleted composition',
|
||||
});
|
||||
return [];
|
||||
}
|
||||
return [mapAll(c, transformation, changesMade)];
|
||||
};
|
||||
const mapRecognizedType = (expression, transformation, changesMade) => {
|
||||
if (expression.type === 'JSXFragment' || expression.type === 'JSXElement') {
|
||||
return mapJsxElementOrFragment(expression, transformation, changesMade);
|
||||
}
|
||||
if (expression.type === 'ArrowFunctionExpression' ||
|
||||
expression.type === 'FunctionExpression') {
|
||||
return {
|
||||
...expression,
|
||||
body: mapAll(expression.body, transformation, changesMade),
|
||||
};
|
||||
}
|
||||
if (expression.type === 'VariableDeclaration') {
|
||||
const declarations = expression.declarations.map((d) => {
|
||||
return mapVariableDeclarator(d, transformation, changesMade);
|
||||
});
|
||||
return { ...expression, declarations };
|
||||
}
|
||||
if (expression.type === 'FunctionDeclaration') {
|
||||
return {
|
||||
...expression,
|
||||
body: mapBlockStatement(expression.body, transformation, changesMade),
|
||||
};
|
||||
}
|
||||
if (expression.type === 'ExportNamedDeclaration' ||
|
||||
expression.type === 'ExportDefaultDeclaration') {
|
||||
if (!expression.declaration) {
|
||||
return expression;
|
||||
}
|
||||
return {
|
||||
...expression,
|
||||
declaration: mapAll(expression.declaration, transformation, changesMade),
|
||||
};
|
||||
}
|
||||
if (expression.type === 'ReturnStatement') {
|
||||
return mapReturnStatement(expression, transformation, changesMade);
|
||||
}
|
||||
if (expression.type === 'BlockStatement') {
|
||||
return mapBlockStatement(expression, transformation, changesMade);
|
||||
}
|
||||
return expression;
|
||||
};
|
||||
const getCompositionIdFromJSXElement = (jsxElement) => {
|
||||
if (jsxElement.type !== 'JSXElement') {
|
||||
return null;
|
||||
}
|
||||
const { openingElement } = jsxElement;
|
||||
const { name } = openingElement;
|
||||
if (name.type !== 'JSXIdentifier') {
|
||||
return null;
|
||||
}
|
||||
if (name.name !== 'Composition' && name.name !== 'Still') {
|
||||
return null;
|
||||
}
|
||||
const id = openingElement.attributes
|
||||
.map((attribute) => {
|
||||
if (attribute.type === 'JSXSpreadAttribute') {
|
||||
return null;
|
||||
}
|
||||
if (attribute.name.type === 'JSXNamespacedName') {
|
||||
return null;
|
||||
}
|
||||
if (attribute.name.name !== 'id') {
|
||||
return null;
|
||||
}
|
||||
if (!attribute.value) {
|
||||
return null;
|
||||
}
|
||||
if (attribute.value.type === 'StringLiteral') {
|
||||
return attribute.value.value;
|
||||
}
|
||||
if (attribute.value.type === 'JSXExpressionContainer' &&
|
||||
attribute.value.expression.type === 'StringLiteral') {
|
||||
return attribute.value.expression.value;
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.filter(Boolean);
|
||||
return id[0];
|
||||
};
|
||||
const changeComposition = ({ jsxElement, newCompositionId, newCompositionFps, newCompositionDurationInFrames, newCompositionHeight, newCompositionWidth, changesMade, newTagToUse, }) => {
|
||||
const { openingElement } = jsxElement;
|
||||
const { name } = openingElement;
|
||||
if (name.type !== 'JSXIdentifier') {
|
||||
return jsxElement;
|
||||
}
|
||||
if (name.name !== 'Composition' && name.name !== 'Still') {
|
||||
return jsxElement;
|
||||
}
|
||||
const attributes = openingElement.attributes
|
||||
.map((attribute) => {
|
||||
if (attribute.type === 'JSXSpreadAttribute') {
|
||||
return attribute;
|
||||
}
|
||||
if (attribute.name.type === 'JSXNamespacedName') {
|
||||
return attribute;
|
||||
}
|
||||
if (attribute.name.name === 'fps' && newTagToUse === 'Still') {
|
||||
changesMade.push({ description: 'Removed fps attribute' });
|
||||
return null;
|
||||
}
|
||||
if (attribute.name.name === 'durationInFrames' &&
|
||||
newTagToUse === 'Still') {
|
||||
changesMade.push({ description: 'Removed durationInFrames' });
|
||||
return null;
|
||||
}
|
||||
// id="one"
|
||||
if (attribute.name.name === 'id' &&
|
||||
attribute.value &&
|
||||
attribute.value.type === 'StringLiteral') {
|
||||
changesMade.push({
|
||||
description: 'Replaced composition id',
|
||||
});
|
||||
return {
|
||||
...attribute,
|
||||
value: { ...attribute.value, value: newCompositionId },
|
||||
};
|
||||
}
|
||||
// id={"one"}
|
||||
if (attribute.name.name === 'id' &&
|
||||
attribute.value &&
|
||||
attribute.value.type === 'JSXExpressionContainer' &&
|
||||
attribute.value.expression.type === 'StringLiteral') {
|
||||
changesMade.push({
|
||||
description: 'Replaced composition id',
|
||||
});
|
||||
return {
|
||||
...attribute,
|
||||
value: {
|
||||
...attribute.value,
|
||||
expression: {
|
||||
...attribute.value.expression,
|
||||
value: newCompositionId,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
if (attribute.name.name === 'fps' &&
|
||||
attribute.value &&
|
||||
attribute.value.type === 'JSXExpressionContainer' &&
|
||||
attribute.value.expression.type === 'NumericLiteral' &&
|
||||
newCompositionFps !== null) {
|
||||
changesMade.push({
|
||||
description: 'Replaced FPS',
|
||||
});
|
||||
return {
|
||||
...attribute,
|
||||
value: {
|
||||
...attribute.value,
|
||||
expression: {
|
||||
...attribute.value.expression,
|
||||
value: newCompositionFps,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
if (attribute.name.name === 'durationInFrames' &&
|
||||
attribute.value &&
|
||||
attribute.value.type === 'JSXExpressionContainer' &&
|
||||
attribute.value.expression.type === 'NumericLiteral' &&
|
||||
newCompositionDurationInFrames !== null) {
|
||||
changesMade.push({
|
||||
description: 'Replaced durationInFrames',
|
||||
});
|
||||
return {
|
||||
...attribute,
|
||||
value: {
|
||||
...attribute.value,
|
||||
expression: {
|
||||
...attribute.value.expression,
|
||||
value: newCompositionDurationInFrames,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
if (attribute.name.name === 'width' &&
|
||||
attribute.value &&
|
||||
attribute.value.type === 'JSXExpressionContainer' &&
|
||||
attribute.value.expression.type === 'NumericLiteral' &&
|
||||
newCompositionWidth !== null) {
|
||||
changesMade.push({
|
||||
description: 'Replaced width',
|
||||
});
|
||||
return {
|
||||
...attribute,
|
||||
value: {
|
||||
...attribute.value,
|
||||
expression: {
|
||||
...attribute.value.expression,
|
||||
value: newCompositionWidth,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
if (attribute.name.name === 'height' &&
|
||||
attribute.value &&
|
||||
attribute.value.type === 'JSXExpressionContainer' &&
|
||||
attribute.value.expression.type === 'NumericLiteral' &&
|
||||
newCompositionHeight !== null) {
|
||||
changesMade.push({
|
||||
description: 'Replaced height',
|
||||
});
|
||||
return {
|
||||
...attribute,
|
||||
value: {
|
||||
...attribute.value,
|
||||
expression: {
|
||||
...attribute.value.expression,
|
||||
value: newCompositionHeight,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
return attribute;
|
||||
})
|
||||
.filter(Boolean);
|
||||
const newName = newTagToUse !== null && newTagToUse !== void 0 ? newTagToUse : name.name;
|
||||
if (newName !== name.name) {
|
||||
changesMade.push({
|
||||
description: `Changed tag`,
|
||||
});
|
||||
}
|
||||
return {
|
||||
...jsxElement,
|
||||
openingElement: {
|
||||
...jsxElement.openingElement,
|
||||
name: {
|
||||
...name,
|
||||
name: newName,
|
||||
},
|
||||
attributes,
|
||||
},
|
||||
};
|
||||
};
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import type { SimpleDiff } from '@remotion/studio-shared';
|
||||
export declare const simpleDiff: ({ oldLines, newLines, }: {
|
||||
oldLines: string[];
|
||||
newLines: string[];
|
||||
}) => SimpleDiff;
|
||||
Generated
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.simpleDiff = void 0;
|
||||
const findDeletions = ({ oldLines, newLines, }) => {
|
||||
const linesChecked = [];
|
||||
let totalDeletions = 0;
|
||||
for (const line of oldLines) {
|
||||
if (linesChecked.includes(line)) {
|
||||
continue;
|
||||
}
|
||||
const timesInNewLines = newLines.filter((l) => l === line).length;
|
||||
const timesInOldLines = oldLines.filter((l) => l === line).length;
|
||||
const deletions = Math.max(0, timesInOldLines - timesInNewLines);
|
||||
totalDeletions += deletions;
|
||||
linesChecked.push(line);
|
||||
}
|
||||
return totalDeletions;
|
||||
};
|
||||
const findAdditions = ({ oldLines, newLines, }) => {
|
||||
const linesChecked = [];
|
||||
let totalAdditions = 0;
|
||||
for (const line of newLines) {
|
||||
if (linesChecked.includes(line)) {
|
||||
continue;
|
||||
}
|
||||
const timesInNewLines = newLines.filter((l) => l === line).length;
|
||||
const timesInOldLines = oldLines.filter((l) => l === line).length;
|
||||
const additions = Math.max(0, timesInNewLines - timesInOldLines);
|
||||
totalAdditions += additions;
|
||||
linesChecked.push(line);
|
||||
}
|
||||
return totalAdditions;
|
||||
};
|
||||
const simpleDiff = ({ oldLines, newLines, }) => {
|
||||
const deletions = findDeletions({ oldLines, newLines });
|
||||
const additions = findAdditions({ oldLines, newLines });
|
||||
return { deletions, additions };
|
||||
};
|
||||
exports.simpleDiff = simpleDiff;
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
import { type EnumPath } from '@remotion/studio-shared';
|
||||
export declare const updateDefaultProps: ({ input, compositionId, newDefaultProps, enumPaths, }: {
|
||||
input: string;
|
||||
compositionId: string;
|
||||
newDefaultProps: Record<string, unknown>;
|
||||
enumPaths: EnumPath[];
|
||||
}) => Promise<Promise<Promise<Promise<string>>>>;
|
||||
Generated
Vendored
+142
@@ -0,0 +1,142 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (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 () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.updateDefaultProps = void 0;
|
||||
const studio_shared_1 = require("@remotion/studio-shared");
|
||||
const recast = __importStar(require("recast"));
|
||||
const parse_ast_1 = require("./parse-ast");
|
||||
const updateDefaultProps = async ({ input, compositionId, newDefaultProps, enumPaths, }) => {
|
||||
const ast = (0, parse_ast_1.parseAst)(input);
|
||||
recast.types.visit(ast, {
|
||||
visitJSXElement(path) {
|
||||
var _a, _b;
|
||||
const { openingElement } = path.node;
|
||||
// 1: ensure its the element we're looking for
|
||||
const openingName = openingElement.name;
|
||||
if (openingName.type !== 'JSXIdentifier' &&
|
||||
openingName.type !== 'JSXNamespacedName') {
|
||||
this.traverse(path); // Continue traversing the AST
|
||||
return;
|
||||
}
|
||||
if (openingName.name !== 'Composition' && openingName.name !== 'Still') {
|
||||
this.traverse(path); // Continue traversing the AST
|
||||
return;
|
||||
}
|
||||
if (!((_a = openingElement.attributes) === null || _a === void 0 ? void 0 : _a.some((attr) => {
|
||||
if (attr.type === 'JSXSpreadAttribute') {
|
||||
return;
|
||||
}
|
||||
if (!attr.value) {
|
||||
return;
|
||||
}
|
||||
if (attr.value.type === 'JSXElement') {
|
||||
return;
|
||||
}
|
||||
if (attr.value.type === 'JSXExpressionContainer') {
|
||||
return;
|
||||
}
|
||||
if (attr.value.type === 'JSXFragment') {
|
||||
return;
|
||||
}
|
||||
return attr.name.name === 'id' && attr.value.value === compositionId;
|
||||
}))) {
|
||||
this.traverse(path); // Continue traversing the AST
|
||||
return;
|
||||
}
|
||||
// 2: Find the defaultProps attribute and handle related errors
|
||||
const defaultPropsAttr = openingElement.attributes.find((attr) => {
|
||||
if (attr.type === 'JSXSpreadAttribute') {
|
||||
this.traverse(path); // Continue traversing the AST
|
||||
return;
|
||||
}
|
||||
return attr.name.name === 'defaultProps';
|
||||
});
|
||||
if (!defaultPropsAttr) {
|
||||
throw new Error(`No \`defaultProps\` prop found in the <Composition/> tag with the ID "${compositionId}".`);
|
||||
}
|
||||
if (defaultPropsAttr.type === 'JSXSpreadAttribute') {
|
||||
this.traverse(path); // Continue traversing the AST
|
||||
return;
|
||||
}
|
||||
// 3: ensure only hardcoded values are provided
|
||||
if (!defaultPropsAttr.value ||
|
||||
defaultPropsAttr.value.type === 'JSXElement' ||
|
||||
defaultPropsAttr.value.type === 'JSXText' ||
|
||||
defaultPropsAttr.value.type === 'StringLiteral' ||
|
||||
defaultPropsAttr.value.type === 'NumericLiteral' ||
|
||||
defaultPropsAttr.value.type === 'BigIntLiteral' ||
|
||||
defaultPropsAttr.value.type === 'DecimalLiteral' ||
|
||||
defaultPropsAttr.value.type === 'NullLiteral' ||
|
||||
defaultPropsAttr.value.type === 'BooleanLiteral' ||
|
||||
defaultPropsAttr.value.type === 'RegExpLiteral' ||
|
||||
defaultPropsAttr.value.type === 'JSXFragment' ||
|
||||
defaultPropsAttr.value.type === 'Literal') {
|
||||
throw new Error(`\`defaultProps\` prop must be a hardcoded value in the <Composition/> tag, but it is a ${(_b = defaultPropsAttr.value) === null || _b === void 0 ? void 0 : _b.type}".`);
|
||||
}
|
||||
const defaultPropsValue = defaultPropsAttr.value.expression;
|
||||
if (defaultPropsValue.type !== 'ObjectExpression' &&
|
||||
defaultPropsValue.type !== 'TSAsExpression') {
|
||||
throw new Error(`\`defaultProps\` prop must be a hardcoded value in the <Composition/> tag with the ID "${compositionId}".`);
|
||||
}
|
||||
defaultPropsAttr.value.expression = recast.types.builders.identifier((0, studio_shared_1.stringifyDefaultProps)({ props: newDefaultProps, enumPaths }));
|
||||
this.traverse(path); // Continue traversing the AST
|
||||
},
|
||||
});
|
||||
let prettier = null;
|
||||
try {
|
||||
prettier = await Promise.resolve().then(() => __importStar(require('prettier')));
|
||||
}
|
||||
catch (_a) {
|
||||
throw new Error('Prettier cannot be found in the current project.');
|
||||
}
|
||||
const { format, resolveConfig, resolveConfigFile } = prettier;
|
||||
const configFilePath = await resolveConfigFile();
|
||||
if (!configFilePath) {
|
||||
throw new Error('The Prettier config file was not found');
|
||||
}
|
||||
const prettierConfig = await resolveConfig(configFilePath);
|
||||
if (!prettierConfig) {
|
||||
throw new Error('The Prettier config file was not found. For this feature, the "prettier" package must be installed and a .prettierrc file must exist.');
|
||||
}
|
||||
const finalfile = (0, parse_ast_1.serializeAst)(ast);
|
||||
const prettified = await format(finalfile, {
|
||||
...prettierConfig,
|
||||
filepath: 'test.tsx',
|
||||
plugins: [],
|
||||
endOfLine: 'auto',
|
||||
});
|
||||
return prettified;
|
||||
};
|
||||
exports.updateDefaultProps = updateDefaultProps;
|
||||
Reference in New Issue
Block a user