MCPcopy
hub / github.com/infinitered/ignite / generate

Function generate

src/commands/generate.ts:19–143  ·  view source on GitHub ↗
(toolbox: GluegunToolbox)

Source from the content-addressed store, hash-verified

17}
18
19async function generate(toolbox: GluegunToolbox) {
20 const { parameters, strings, filesystem, prompt } = toolbox
21
22 // what generator are we running?
23 const generator = parameters.first.toLowerCase()
24
25 // check if we should override front matter dir or default dir
26 let dir = parameters.options.dir ?? parameters.third
27
28 // we need a name for this component
29 let name = parameters.second
30 if (!name) {
31 warning(`⚠️ Please specify a name for your ${generator}:`)
32 p()
33 command(`npx ignite-cli g ${generator} MyName`)
34 return
35 }
36
37 // parse any subdirectories from the specified name
38 let subdirectory = ""
39 if (name.indexOf(SUB_DIR_DELIMITER) > -1) {
40 const lastSlashIndex = name.lastIndexOf(SUB_DIR_DELIMITER)
41 subdirectory = name.substring(0, lastSlashIndex + 1)
42 name = name.substring(lastSlashIndex + 1)
43 }
44
45 // avoid the my-component-component phenomenon
46 const pascalGenerator = strings.pascalCase(generator)
47 let pascalName = strings.pascalCase(name)
48 if (pascalName.endsWith(pascalGenerator)) {
49 p(`Stripping ${pascalGenerator} from end of name`)
50 p(
51 `Note that you don't need to add ${pascalGenerator} to the end of the name -- we'll do it for you!`,
52 )
53 pascalName = pascalName.slice(0, -1 * pascalGenerator.length)
54 command(`npx ignite-cli generate ${generator} ${pascalName}`)
55 }
56 /**
57 * Check if the project uses Expo Router as a dependency in package.json,
58 * denoting an Expo Router app.
59 */
60 if (generator === "route") {
61 const packageJson = filesystem.read("package.json", "json")
62 const isExpoRouterApp = !!packageJson?.dependencies?.["expo-router"]
63
64 const isSrcAppStructure = filesystem.exists("src/app") === "dir"
65 const isAppStructure = filesystem.exists("app") === "dir"
66 const defaultRouterDir = isSrcAppStructure ? "src/app" : isAppStructure ? "app" : null
67
68 if (isExpoRouterApp) {
69 const directoryDirSetInFrontMatter = frontMatterDirectoryDir("route")
70 p(directoryDirSetInFrontMatter)
71
72 if (directoryDirSetInFrontMatter || dir) {
73 heading(
74 `It looks like you're working in a project using Expo Router, determined directory for route from ${dir ? "override" : "template front matter"}`,
75 )
76 dir = dir || directoryDirSetInFrontMatter

Callers

nothing calls this directly

Calls 7

warningFunction · 0.90
pFunction · 0.90
commandFunction · 0.90
frontMatterDirectoryDirFunction · 0.90
headingFunction · 0.90
boolFlagFunction · 0.90
generateFromTemplateFunction · 0.90

Tested by

no test coverage detected