(fpath: string)
| 115 | } |
| 116 | |
| 117 | export async function parseInfoFile(fpath: string) { |
| 118 | const config = getConfig(); |
| 119 | const { importPathPrefix } = config; |
| 120 | |
| 121 | let _importPathPrefix: string; |
| 122 | |
| 123 | switch (config.mode) { |
| 124 | case "qwikcity": |
| 125 | _importPathPrefix = importPathPrefix || "~/routes"; |
| 126 | break; |
| 127 | default: |
| 128 | _importPathPrefix = importPathPrefix || "@/app"; |
| 129 | break; |
| 130 | } |
| 131 | |
| 132 | const newPath: RouteInfo = { |
| 133 | importPath: `${_importPathPrefix}/${fpath}`.replace(/.ts$/, ""), |
| 134 | infoPath: `/${fpath}`, |
| 135 | importKey: "", |
| 136 | verbs: [], |
| 137 | pathTemplate: "" |
| 138 | }; |
| 139 | |
| 140 | const code: string = fs |
| 141 | .readFileSync(absoluteFilePath(config, fpath)) |
| 142 | .toString(); |
| 143 | const mod = parseModule(code); |
| 144 | newPath.importKey = newPath.importKey || mod.exports.Route?.name || "tempKey"; |
| 145 | |
| 146 | for (const verb of ["GET", "POST", "DELETE", "PUT"]) { |
| 147 | if (mod.exports[verb]) { |
| 148 | newPath.verbs.push(verb); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | newPath.pathTemplate = `/${path.parse(fpath).dir.split(path.sep).join("/")}`; |
| 153 | |
| 154 | paths[fpath] = newPath; |
| 155 | |
| 156 | return newPath.verbs.length || 1; |
| 157 | } |
| 158 | |
| 159 | async function createInfoFile(config: Config, fpath: string) { |
| 160 | let infoFile: string; |
no test coverage detected