Add command parsing structure and calling structure

This commit is contained in:
walcutt 2025-06-23 18:46:38 -04:00
parent 926fb02654
commit 322808f90f
7 changed files with 108 additions and 3 deletions

View File

@ -1,3 +1,15 @@
const params = process.argv;
import { getAllCommands } from "./src/parsing/parse-commands.js";
import { CreatePipeline } from "./src/pipeline.js";
console.log("Raw params:");
console.log(process);
const params = process.argv.slice(2);
console.log("Executed with params:");
console.log(params);
console.log(params);
console.log("Got commands:");
console.log(getAllCommands(params));
const pipeline = CreatePipeline(params);
console.log("Running commands!");
await pipeline.run();

View File

@ -8,7 +8,7 @@
},
"license": "ISC",
"author": "",
"type": "commonjs",
"type": "module",
"main": "index.js",
"scripts": {
"pipeline": "node index.js"

17
src/command-config.js Normal file
View File

@ -0,0 +1,17 @@
import { extractToEpisodeNumber } from "./commands/extract-to-se.js";
import { finalizeFileNames } from "./commands/finalize-filenames.js";
export const CommandConfig = [
{
name: 'ExtractToEpisodeNumber',
commands: ['-x'],
params: [],
func: extractToEpisodeNumber,
},
{
name: 'FinalizeFileNames',
commands: ['-o'],
params: ['ShowName'],
func: finalizeFileNames,
}
];

View File

@ -0,0 +1,3 @@
export async function extractToEpisodeNumber(inputDir, inputFile, outputDir, options) {
console.log("Mapping!");
}

View File

@ -0,0 +1,3 @@
export async function finalizeFileNames(inputDir, inputFile, outputDir, { ShowName }) {
console.log(`Outputting as ${outputDir}/${ShowName} ${inputFile}`);
}

View File

@ -0,0 +1,40 @@
import { CommandConfig } from "../command-config.js";
export function getAllCommands(inputTokens) {
const tokens = inputTokens;
const commandArray = [];
for(let i = 0; i < tokens.length; i++) {
const command = getMatchingCommand(tokens[i]);
if(command) {
const isValid = ((i + command.params.length) < tokens.length);
if(isValid) {
const parameters = {};
for(let k = 0; k < command.params.length; k++) {
const name = command.params[k];
const value = tokens[i + k + 1];
parameters[name] = value;
}
const commandObject = {
command: command.name,
parameters: parameters,
func: command.func,
};
commandArray.push(commandObject);
i += command.params.length;
}
}
}
return commandArray;
}
function getMatchingCommand(token) {
const match = CommandConfig.find(
(el) => el?.commands?.includes(token)
);
return match;
}

30
src/pipeline.js Normal file
View File

@ -0,0 +1,30 @@
import { getAllCommands } from "./parsing/parse-commands.js";
export function CreatePipeline(inputParams) {
const commands = getAllCommands(inputParams);
return {
commands: commands,
async run() {
// Create /temp/Step-0
// Copy /input/* -> /temp/Step-0
for(let i = 0; i < this.commands.length; i++) {
const inputDir = `/temp/Step-${i}`;
const outputDir = `/temp/Step-${i+1}`;
const files = ['S01E01.mkv', 'S01E02.mkv']; // Get from file system
const func = this.commands[i].func;
const params = this.commands[i].parameters;
for(let k = 0; k < files.length; k++) {
const result = await func(inputDir, files[k], outputDir, params);
}
}
// Copy /temp/Step-L/* -> /output
// remove /temp/*
},
};
}