process :: FilePath -> FilePath -> IO ()
process inputWrapperPath outputDirectoryPath = do
  putStrLn "Processing the binder..."
  let inputBinderPath =
        fromString $ inputWrapperPath ++ "/"
                     ++ (IO.takeBaseName inputWrapperPath) ++ ".scrivx"
  inputBinder <- XML.readFile XML.def inputBinderPath
  let labels =
       Map.fromList
         $ fromDocument inputBinder
         $/ element "LabelSettings"
         &/ element "Labels"
         &/ element "Label"
         &| (\itemCursor ->
               let key = T.concat $ attribute "ID" itemCursor
                   name = T.concat $ itemCursor $/ content
               in (key, name))
      statuses =
       Map.fromList
         $ fromDocument inputBinder
         $/ element "StatusSettings"
         &/ element "StatusItems"
         &/ element "Status"
         &| (\itemCursor ->
               let key = attribute "ID" itemCursor
                   name = T.concat $ itemCursor $/ content
               in (key, name))
  binder <-
    mapM (\(index, binderItem) -> do
             collectBinderItem labels binderItem
                               [(index, binderItemTitle binderItem)])
         (zip [1 ..] $ (fromDocument inputBinder)
                     $/ element "Binder"
                     &/ element "BinderItem"
                     &| node)
  draft <- case computeDraft binder of
             Nothing -> do
               putStrLn $ "Draft not found by that name in the binder."
               IO.exitFailure
             Just draft -> getOutputDraft inputWrapperPath draft
           >>= return . (\draft -> computeFlattenedOutput
                                     (outputSectionID draft)
                                     (outputSectionID draft)
                                     Nothing
                                     Nothing
                                     draft)
  return $!! draft
  putStrLn "Writing output..."
  IO.createDirectory outputDirectoryPath
  LBS.writeFile (outputDirectoryPath ++ "/content.json")
                (JSON.encode
                  $ JSON.object
                    ["toc" JSON..= (JSON.String $ fst $ head draft),
                     "sections" JSON..=
                       (JSON.object $ map (uncurry (JSON..=)) draft)])
  mapM_ (\dataFileInputName -> do
           dataFileInputPath <- Paths.getDataFileName dataFileInputName
           data' <- BS.readFile dataFileInputPath
           let dataFileOutputPath =
                 outputDirectoryPath ++ "/"
                 ++ IO.takeFileName dataFileInputName
           BS.writeFile dataFileOutputPath data')
        ["Data/handlebars.js",
         "Data/index.css",
         "Data/index.html",
         "Data/index.js"]
process :: FilePath -> FilePath -> IO ()
process inputWrapperPath outputDirectoryPath = do
  putStrLn "Processing the binder..."
  let inputBinderPath =
        fromString $ inputWrapperPath ++ "/"
                     ++ (IO.takeBaseName inputWrapperPath) ++ ".scrivx"
  inputBinder <- XML.readFile XML.def inputBinderPath
  let labels =
       Map.fromList
         $ fromDocument inputBinder
         $/ element "LabelSettings"
         &/ element "Labels"
         &/ element "Label"
         &| (\itemCursor ->
               let key = T.concat $ attribute "ID" itemCursor
                   name = T.concat $ itemCursor $/ content
               in (key, name))
      statuses =
       Map.fromList
         $ fromDocument inputBinder
         $/ element "StatusSettings"
         &/ element "StatusItems"
         &/ element "Status"
         &| (\itemCursor ->
               let key = attribute "ID" itemCursor
                   name = T.concat $ itemCursor $/ content
               in (key, name))
  binder <-
    mapM (\(index, binderItem) -> do
             collectBinderItem labels binderItem
                               [(index, binderItemTitle binderItem)])
         (zip [1 ..] $ (fromDocument inputBinder)
                     $/ element "Binder"
                     &/ element "BinderItem"
                     &| node)
  draft <- case computeDraft binder of
             Nothing -> do
               putStrLn $ "Draft not found by that name in the binder."
               IO.exitFailure
             Just draft -> getOutputDraft inputWrapperPath draft
           >>= return . (\draft -> computeFlattenedOutput
                                     (outputSectionID draft)
                                     (outputSectionID draft)
                                     Nothing
                                     Nothing
                                     draft)
  return $!! draft
  putStrLn "Writing output..."
  IO.createDirectory outputDirectoryPath
  LBS.writeFile (outputDirectoryPath ++ "/content.json")
                (JSON.encode
                  $ JSON.object
                    ["toc" JSON..= (JSON.String $ fst $ head draft),
                     "sections" JSON..=
                       (JSON.object $ map (uncurry (JSON..=)) draft)])
  mapM_ (\dataFileInputName -> do
           dataFileInputPath <- Paths.getDataFileName dataFileInputName
           data' <- BS.readFile dataFileInputPath
           let dataFileOutputPath =
                 outputDirectoryPath ++ "/"
                 ++ IO.takeFileName dataFileInputName
           BS.writeFile dataFileOutputPath data')
        ["Data/handlebars.js",
         "Data/index.css",
         "Data/index.html",
         "Data/index.js"]
process inputWrapperPath outputDirectoryPath = do
  putStrLn "Processing the binder..."
  let inputBinderPath =
        fromString $ inputWrapperPath ++ "/"
                     ++ (IO.takeBaseName inputWrapperPath) ++ ".scrivx"
  inputBinder <- XML.readFile XML.def inputBinderPath
  let labels =
       Map.fromList
         $ fromDocument inputBinder
         $/ element "LabelSettings"
         &/ element "Labels"
         &/ element "Label"
         &| (\itemCursor ->
               let key = T.concat $ attribute "ID" itemCursor
                   name = T.concat $ itemCursor $/ content
               in (key, name))
      statuses =
       Map.fromList
         $ fromDocument inputBinder
         $/ element "StatusSettings"
         &/ element "StatusItems"
         &/ element "Status"
         &| (\itemCursor ->
               let key = attribute "ID" itemCursor
                   name = T.concat $ itemCursor $/ content
               in (key, name))
  binder <-
    mapM (\(index, binderItem) -> do
             collectBinderItem labels binderItem
                               [(index, binderItemTitle binderItem)])
         (zip [1 ..] $ (fromDocument inputBinder)
                     $/ element "Binder"
                     &/ element "BinderItem"
                     &| node)
  draft <- case computeDraft binder of
             Nothing -> do
               putStrLn $ "Draft not found by that name in the binder."
               IO.exitFailure
             Just draft -> getOutputDraft inputWrapperPath draft
           >>= return . (\draft -> computeFlattenedOutput
                                     (outputSectionID draft)
                                     (outputSectionID draft)
                                     Nothing
                                     Nothing
                                     draft)
  return $!! draft
  putStrLn "Writing output..."
  IO.createDirectory outputDirectoryPath
  LBS.writeFile (outputDirectoryPath ++ "/content.json")
                (JSON.encode
                  $ JSON.object
                    ["toc" JSON..= (JSON.String $ fst $ head draft),
                     "sections" JSON..=
                       (JSON.object $ map (uncurry (JSON..=)) draft)])
  mapM_ (\dataFileInputName -> do
           dataFileInputPath <- Paths.getDataFileName dataFileInputName
           data' <- BS.readFile dataFileInputPath
           let dataFileOutputPath =
                 outputDirectoryPath ++ "/"
                 ++ IO.takeFileName dataFileInputName
           BS.writeFile dataFileOutputPath data')
        ["Data/handlebars.js",
         "Data/index.css",
         "Data/index.html",
         "Data/index.js"]