(rawInput: string)
| 18 | * - dir/app => ["app", "dir/app"] |
| 19 | */ |
| 20 | export const parseNameAndPath = (rawInput: string) => { |
| 21 | const input = removeTrailingSlash(rawInput); |
| 22 | |
| 23 | const paths = input.split("/"); |
| 24 | |
| 25 | let appName = paths[paths.length - 1]!; |
| 26 | |
| 27 | // If the user ran `npx create-t3-app .` or similar, the appName should be the current directory |
| 28 | if (appName === ".") { |
| 29 | const parsedCwd = pathModule.resolve(process.cwd()); |
| 30 | appName = pathModule.basename(parsedCwd); |
| 31 | } |
| 32 | |
| 33 | // If the first part is a @, it's a scoped package |
| 34 | const indexOfDelimiter = paths.findIndex((p) => p.startsWith("@")); |
| 35 | if (paths.findIndex((p) => p.startsWith("@")) !== -1) { |
| 36 | appName = paths.slice(indexOfDelimiter).join("/"); |
| 37 | } |
| 38 | |
| 39 | const path = paths.filter((p) => !p.startsWith("@")).join("/"); |
| 40 | |
| 41 | return [appName, path] as const; |
| 42 | }; |
no test coverage detected