diff --git a/index.js b/index.js index ad499f1..251d84e 100644 --- a/index.js +++ b/index.js @@ -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); \ No newline at end of file +console.log(params); +console.log("Got commands:"); +console.log(getAllCommands(params)); + +const pipeline = CreatePipeline(params); + +console.log("Running commands!"); +await pipeline.run(); \ No newline at end of file diff --git a/package.json b/package.json index 5bfa5cd..2134541 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "license": "ISC", "author": "", - "type": "commonjs", + "type": "module", "main": "index.js", "scripts": { "pipeline": "node index.js" diff --git a/src/command-config.js b/src/command-config.js new file mode 100644 index 0000000..acebf82 --- /dev/null +++ b/src/command-config.js @@ -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, + } +]; \ No newline at end of file diff --git a/src/commands/extract-to-se.js b/src/commands/extract-to-se.js new file mode 100644 index 0000000..f509533 --- /dev/null +++ b/src/commands/extract-to-se.js @@ -0,0 +1,3 @@ +export async function extractToEpisodeNumber(inputDir, inputFile, outputDir, options) { + console.log("Mapping!"); +} \ No newline at end of file diff --git a/src/commands/finalize-filenames.js b/src/commands/finalize-filenames.js new file mode 100644 index 0000000..b5771bf --- /dev/null +++ b/src/commands/finalize-filenames.js @@ -0,0 +1,3 @@ +export async function finalizeFileNames(inputDir, inputFile, outputDir, { ShowName }) { + console.log(`Outputting as ${outputDir}/${ShowName} ${inputFile}`); +} \ No newline at end of file diff --git a/src/parsing/parse-commands.js b/src/parsing/parse-commands.js new file mode 100644 index 0000000..b19ec89 --- /dev/null +++ b/src/parsing/parse-commands.js @@ -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; +} \ No newline at end of file diff --git a/src/pipeline.js b/src/pipeline.js new file mode 100644 index 0000000..7aefd4c --- /dev/null +++ b/src/pipeline.js @@ -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/* + }, + }; +} \ No newline at end of file