Skip to content

Commit

Permalink
fix: maybe fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hkonsti committed Mar 18, 2024
1 parent 4cf5550 commit 49cb38d
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions packages/vite-plugin/src/partials/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,39 @@ function getHotModuleReplacementCode(metaFilePaths: string[]) {
return code;
}

async function getMetaFileNamePath(
filePath: string,
indexOfMakeScene: number,
fileContent: string,
) {
// Extract the comment before the index
const comment = extractCommentBeforeIndex(fileContent, indexOfMakeScene);

/**
* If there is no comment, or no file is specified, we check if
* there is a meta file with the same name as the typescript file.
*/
if (comment) {
const file = comment.split('meta=')[1].replace(/\s/g, '').slice(0, -2);
if (file) {
return file.trim();
}
}

// If no file is specified, we try the typescript file name
const path = filePath.split('.');
path.pop();
const guessedPath = path.join('.') + '.meta';

// Check if the file exists
try {
await fs.access(guessedPath);
return guessedPath;
} catch (e) {
throw new Error(`No meta file found for ${filePath}.`);
}
}

export function scenesPlugin(): Plugin {
return {
name: 'revideo:scene',
Expand Down Expand Up @@ -146,23 +179,12 @@ export function scenesPlugin(): Plugin {
continue;
}

// Extract the comment before the index
const comment = extractCommentBeforeIndex(content, index);

// TODO: add support for this
if (!comment) {
throw new Error(`${id}: TODO: needs comment`);
}

const file = comment.split('meta=')[1].replace(/\s/g, '').slice(0, -2);
if (!file) {
throw new Error(`${id}: TODO: needs meta file`);
}
const path = await getMetaFileNamePath(id, index, content);

calls.push({
startIndex: index,
endIndex: end,
metaFile: file.trim(),
metaFile: path,
});
}

Expand Down

0 comments on commit 49cb38d

Please sign in to comment.