import { BudgieUtilities } from "../../BudgieUtilities" ; import { FileMetadata } from "../FileMetadata" ; import { CaseStyle } from "../Languages/Casing/CaseStyle" ; import { LineResults } from "../LineResults" ; import { CommandNames } from "../Names/CommandNames" ; import { Command } from "./Command" ; import { CommandResult } from "./CommandResult" ; import { CommandMetadata } from "./Metadata/CommandMetadata" ; import { RepeatingParameters } from "./Metadata/Parameters/RepeatingParameters" ; import { SingleParameter } from "./Metadata/Parameters/SingleParameter" ; /**
 * Starts a file.
 */ export class FileStartCommand extends Command { /**
     * Metadata on the command.
     */ private static metadata : CommandMetadata = new CommandMetadata ( CommandNames . FileStart ) . withDescription ( "Starts a file" ) . withIndentation ( [ 1 ] ) . withParameters ( [ new RepeatingParameters ( "Directories leading to the file" , [ new SingleParameter ( "directory" , "Directory leading to the file" , false ) , ] ) , new SingleParameter ( "fileStart" , "The name of the file." , true ) , ] ) ; returns public getMetadata ( ) { return FileStartCommand . metadata ; } param parameters returns public render ( parameters ) { const output = [ ] ; const source = this . language . syntax . files . startLines ; const packagePathAndFileName = parameters . slice ( 1 ) ; const packagePath = packagePathAndFileName . slice ( 0 , packagePathAndFileName . length - 1 ) ; const packagePathJoined = this . context . convertArrayToCase ( packagePath , this . language . syntax . files . startCase ) ; const fileName = this . context . convertStringToCase ( packagePathAndFileName [ packagePathAndFileName . length - 1 ] , CaseStyle . PascalCase ) ; for ( let line of source ) { line = BudgieUtilities . stringReplaceAll ( line , "{0}" , fileName ) ; line = BudgieUtilities . stringReplaceAll ( line , "{1}" , packagePathJoined ) ; output . push ( new CommandResult ( line , 0 ) ) ; } if ( output . length !== 0 ) { output [ output . length - 1 ] . indentation = this . language . syntax . files . indentation ; } this . context . setFileMetadata ( new FileMetadata ( fileName , packagePath ) ) ; return new LineResults ( output ) ; } }