MCPcopy Index your code
hub / github.com/ProNextJS/declarative-routing / parseInfoFile

Function parseInfoFile

src/shared/build-tools.ts:117–157  ·  view source on GitHub ↗
(fpath: string)

Source from the content-addressed store, hash-verified

115}
116
117export 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
159async function createInfoFile(config: Config, fpath: string) {
160 let infoFile: string;

Callers 2

processFileFunction · 0.90
buildFilesFunction · 0.85

Calls 2

getConfigFunction · 0.90
absoluteFilePathFunction · 0.90

Tested by

no test coverage detected