From 2c44c703947e238434e42cef9431abc8cea06701 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 12 Mar 2021 18:04:28 +0100 Subject: [PATCH] Remove unused code --- create-dependency/index.js | 133 ------------------------------------- 1 file changed, 133 deletions(-) diff --git a/create-dependency/index.js b/create-dependency/index.js index ef564774..674487bd 100644 --- a/create-dependency/index.js +++ b/create-dependency/index.js @@ -78,141 +78,8 @@ async function createFile([elmJson, docsJson]) { await exec('npx elm-format --yes ' + relativeFilePath); console.log("File created! You can find it at:\n ", relativeFilePath); }); - return; - - const moduleName = packageName - .replace("/", "-") - .split("-") - .map(capitalize) - .join(""); - - return `module Review.Test.Dependencies.${moduleName} exposing (dependency) - -import Elm.Docs -import Elm.Project -import Elm.Type -import Json.Decode as Decode -import Review.Project.Dependency as Dependency exposing (Dependency) - - -dependency : Dependency -dependency = - Dependency.create - "${packageName}" - (createElmJsonProject elmJson) - dependencyModules - - -createElmJsonProject : String -> Elm.Project.Project -createElmJsonProject rawElmJson = - case Decode.decodeString Elm.Project.decoder rawElmJson of - Ok project -> - project - - Err error -> - Debug.todo ("Failed to decode elm.json for ${packageName}: " ++ Debug.toString error) - - -elmJson : String -elmJson = - """${JSON.stringify(elmJson, null, 4)} -""" - - -dependencyModules : List Elm.Docs.Module -dependencyModules = - [ ${docsJson.map(formatModule).join("\n , ")} - ] - - -decodeType : String -> Elm.Type.Type -decodeType type_ = - case Decode.decodeString Elm.Type.decoder type_ of - Ok resultType -> - resultType - Err _ -> - Elm.Type.Var "unknown" -` -} - -function capitalize(str) { - return str[0].toUpperCase() + str.slice(1); -} - -function formatModule(moduleDoc) { - return `{ name = "${moduleDoc.name}" - , comment = ${formatComment(moduleDoc.comment)} - , unions = [ ${moduleDoc.unions.map(formatUnion).join("\n , ")} ] - , aliases = [ ${moduleDoc.aliases.map(formatAlias).filter(Boolean).join("\n , ")} ] - , values = [ ${moduleDoc.values.map(formatValue).filter(Boolean).join("\n , ")} ] - , binops = [ ${moduleDoc.binops.map(formatBinop).filter(Boolean).join("\n , ")} ] - }` - // if (JSON.stringify(moduleDoc).includes("initialize 4")) { - // console.log(JSON.stringify(moduleDoc).slice(2470, 2530)) - // } - - return JSON.stringify(JSON.stringify(moduleDoc)); - // .split("\\n") - // .join("\\\\n"); -} - -function formatUnion(union) { - return `{ name = "${union.name}" - , comment = ${formatComment(union.comment)} - , args = ${JSON.stringify(union.args)} - , tags = [ ${union.cases.map( - (([name, types]) => - `( "${name}", [ ${types.map(formatType).join(", ")} ] )`) - ).join("\n , ")} ] - }` -} - -function formatType(type) { - return `decodeType "${type}"`; -} - -function formatComment(comment) { - const withEscapedTripleQuotes = comment - .split(`"""`).join(`\\"\\"\\"`) - .split("\\").join("\\\\"); - return `"""${withEscapedTripleQuotes}"""` -} - -function formatAlias(alias) { - return `{ name = "${alias.name}" - , comment = ${formatComment(alias.comment)} - , args = ${JSON.stringify(alias.args)} - , tipe = ${formatType(alias.type)} - }` -} - -function formatValue(value) { - return `{ name = "${value.name}" - , comment = ${formatComment(value.comment)} - , tipe = ${formatType(value.type)} - }` -} - - -function formatBinop(binop) { - return `{ name = "${binop.name}" - , comment = ${formatComment(binop.comment)} - , tipe = ${formatType(binop.type)} - , associativity = ${formatAssociativity(binop.associativity)} - , precedence = ${binop.precedence} - }` -} - -function formatAssociativity(associativity) { - switch (associativity) { - case "left": return "Elm.Docs.Left" - case "right": return "Elm.Docs.Right" - case "non": return "Elm.Docs.None" - default: return "unknown" - } } downloadFiles() .then(createFile) - // .then(console.log) .catch(console.error); \ No newline at end of file