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

Function createInfoFile

src/shared/build-tools.ts:159–210  ·  view source on GitHub ↗
(config: Config, fpath: string)

Source from the content-addressed store, hash-verified

157}
158
159async function createInfoFile(config: Config, fpath: string) {
160 let infoFile: string;
161
162 switch (config.mode) {
163 case "qwikcity":
164 infoFile = path.join(path.dirname(fpath), "routeInfo.ts");
165 break;
166 default:
167 infoFile = fpath.replace(/\.(js|jsx|ts|tsx)$/, ".info.ts");
168 break;
169 }
170
171 const absPath = absoluteFilePath(config, infoFile);
172 const pathElements = path
173 .parse(infoFile)
174 .dir.split(path.sep)
175 .filter((v) => v.length);
176
177 let name = "Home";
178 if (pathElements.length) {
179 name = pathElements.map((p) => upperFirst(jsClean(p))).join("");
180 }
181
182 const params: string[] = [];
183 for (const elem of pathElements) {
184 if (elem.startsWith("[[...") && elem.endsWith("]]")) {
185 params.push(`${jsClean(elem)}: z.string().array().optional()`);
186 } else if (elem.startsWith("[...") && elem.endsWith("]")) {
187 params.push(`${jsClean(elem)}: z.string().array()`);
188 } else if (elem.startsWith("[") && elem.endsWith("]")) {
189 params.push(`${jsClean(elem)}: z.string()`);
190 }
191 }
192
193 const code: string = fs
194 .readFileSync(absoluteFilePath(config, fpath))
195 .toString();
196
197 // TODO: Use AST to parse the code and find the verbs, magicast doesn't work for exported functions
198 const verbs: string[] = [];
199 for (const verb of Object.keys(VERB_KEYS)) {
200 if (code.includes(`function ${verb}(`)) {
201 verbs.push(verb);
202 }
203 }
204
205 await buildFileFromTemplate("shared/info.ts.template", absPath, {
206 name,
207 params,
208 verbs: verbs.map((verb) => ({ verb, keys: VERB_KEYS[verb] }))
209 });
210}
211
212export async function checkRouteFile(path: string) {
213 const config = getConfig();

Callers 1

checkRouteFileFunction · 0.85

Calls 4

absoluteFilePathFunction · 0.90
upperFirstFunction · 0.90
jsCleanFunction · 0.90
buildFileFromTemplateFunction · 0.90

Tested by

no test coverage detected