beever-create 0.1.2 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/index.js +10 -0
  2. package/dist/index.js.map +1 -1
  3. package/package.json +2 -1
  4. package/templates/common/assets/README.md +60 -0
  5. package/templates/common/assets/fonts/Figtree/Figtree-Italic-VariableFont_wght.ttf +0 -0
  6. package/templates/common/assets/fonts/Figtree/Figtree-VariableFont_wght.ttf +0 -0
  7. package/templates/common/assets/fonts/Figtree/OFL.txt +93 -0
  8. package/templates/common/assets/fonts/Figtree/README.txt +77 -0
  9. package/templates/common/assets/fonts/Figtree/index.ts +27 -0
  10. package/templates/common/assets/fonts/Figtree/static/Figtree-Black.ttf +0 -0
  11. package/templates/common/assets/fonts/Figtree/static/Figtree-BlackItalic.ttf +0 -0
  12. package/templates/common/assets/fonts/Figtree/static/Figtree-Bold.ttf +0 -0
  13. package/templates/common/assets/fonts/Figtree/static/Figtree-BoldItalic.ttf +0 -0
  14. package/templates/common/assets/fonts/Figtree/static/Figtree-ExtraBold.ttf +0 -0
  15. package/templates/common/assets/fonts/Figtree/static/Figtree-ExtraBoldItalic.ttf +0 -0
  16. package/templates/common/assets/fonts/Figtree/static/Figtree-Italic.ttf +0 -0
  17. package/templates/common/assets/fonts/Figtree/static/Figtree-Light.ttf +0 -0
  18. package/templates/common/assets/fonts/Figtree/static/Figtree-LightItalic.ttf +0 -0
  19. package/templates/common/assets/fonts/Figtree/static/Figtree-Medium.ttf +0 -0
  20. package/templates/common/assets/fonts/Figtree/static/Figtree-MediumItalic.ttf +0 -0
  21. package/templates/common/assets/fonts/Figtree/static/Figtree-Regular.ttf +0 -0
  22. package/templates/common/assets/fonts/Figtree/static/Figtree-SemiBold.ttf +0 -0
  23. package/templates/common/assets/fonts/Figtree/static/Figtree-SemiBoldItalic.ttf +0 -0
  24. package/templates/common/assets/fonts/index.ts +1 -0
  25. package/templates/common/assets/icons/index.ts +0 -0
  26. package/templates/common/assets/images/index.ts +0 -0
  27. package/templates/common/assets/index.ts +1 -0
  28. package/templates/common/features/welcome/screens/WelcomeScreen.tsx +8 -2
  29. package/templates/common/web/main.tsx +2 -0
  30. package/templates/common/web/styles.css +21 -0
  31. package/templates/expo/package.json +2 -1
  32. package/templates/standalone/index.js +1 -5
  33. package/templates/standalone/package.json +9 -3
  34. package/templates/standalone/react-native.config.js +3 -0
  35. package/templates/standalone/scripts/android.js +574 -0
  36. package/templates/tsconfig.json +11 -0
  37. /package/templates/standalone/{tsconfig.json → tsconfig.json.template} +0 -0
package/dist/index.js CHANGED
@@ -202,6 +202,16 @@ async function main() {
202
202
  fs.cpSync(selectedTemplatePath, projectPath, {
203
203
  recursive: true
204
204
  });
205
+ if (mobileProjectType === "standalone") {
206
+ const templateTsconfigPath = path.join(
207
+ projectPath,
208
+ "tsconfig.json.template"
209
+ );
210
+ const projectTsconfigPath = path.join(projectPath, "tsconfig.json");
211
+ if (fs.existsSync(templateTsconfigPath)) {
212
+ fs.renameSync(templateTsconfigPath, projectTsconfigPath);
213
+ }
214
+ }
205
215
  replaceTemplatePlaceholders(projectPath);
206
216
  if (mobileProjectType === "standalone") {
207
217
  renameStandaloneNativeDirectories();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import fs from \"node:fs\";\r\nimport path from \"node:path\";\r\nimport { spawnSync } from \"node:child_process\";\r\nimport { fileURLToPath } from \"node:url\";\r\nimport { createInterface } from \"node:readline/promises\";\r\nimport { stdin, stdout } from \"node:process\";\r\n\r\ntype MobileProjectType = \"standalone\" | \"expo\";\r\n\r\nconst projectName = process.argv[2];\r\n\r\nif (!projectName) {\r\n console.log(\"Please provide a project name.\");\r\n console.log(\"Usage: npx beever-create <project-name>\");\r\n process.exit(1);\r\n}\r\n\r\n// Validate the project name before creating anything.\r\nconst validProjectName = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(projectName);\r\n\r\nif (!validProjectName) {\r\n console.error(\r\n \"Invalid project name. Start with a letter or number and use only letters, numbers, hyphens, and underscores.\",\r\n );\r\n process.exit(1);\r\n}\r\n\r\nconst projectPath = path.resolve(process.cwd(), projectName);\r\n\r\nif (fs.existsSync(projectPath)) {\r\n console.error(`A folder named \"${projectName}\" already exists.`);\r\n process.exit(1);\r\n}\r\n\r\n// Resolve template directories.\r\nconst currentDirectory = path.dirname(fileURLToPath(import.meta.url));\r\nconst templatesPath = path.resolve(currentDirectory, \"../templates\");\r\n\r\nconst commonTemplatePath = path.join(templatesPath, \"common\");\r\nconst expoTemplatePath = path.join(templatesPath, \"expo\");\r\nconst standaloneTemplatePath = path.join(templatesPath, \"standalone\");\r\n\r\n// Generate project identifiers.\r\nconst packageName = projectName.toLowerCase().replace(/_/g, \"-\");\r\n\r\nconst displayName = projectName.replace(/[-_]+/g, \" \").trim();\r\n\r\nconst appNameParts = projectName.split(/[-_]+/).filter(Boolean);\r\n\r\nlet appName = appNameParts\r\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\r\n .join(\"\");\r\n\r\nif (!appName || /^[0-9]/.test(appName)) {\r\n appName = `App${appName}`;\r\n}\r\n\r\nconst nativePackageName = projectName.toLowerCase().replace(/[^a-z0-9]/g, \"\");\r\n\r\nconst safeNativePackageName = /^[a-z]/.test(nativePackageName)\r\n ? nativePackageName\r\n : `app${nativePackageName}`;\r\n\r\nconst androidPackage = `com.beever.${safeNativePackageName}`;\r\nconst iosBundleIdentifier = `com.beever.${safeNativePackageName}`;\r\n\r\n// Only these files are processed as text.\r\n// Binary assets are deliberately excluded.\r\nconst textFileExtensions = new Set([\r\n \".json\",\r\n \".js\",\r\n \".jsx\",\r\n \".ts\",\r\n \".tsx\",\r\n \".gradle\",\r\n \".properties\",\r\n \".kt\",\r\n \".swift\",\r\n \".plist\",\r\n \".storyboard\",\r\n \".xcprivacy\",\r\n \".pbxproj\",\r\n \".xcscheme\",\r\n \".xml\",\r\n \".md\",\r\n \".txt\",\r\n \".html\",\r\n \".css\",\r\n \".scss\",\r\n \".yml\",\r\n \".yaml\",\r\n \".toml\",\r\n]);\r\n\r\nconst placeholderValues: Record<string, string> = {\r\n \"{{projectName}}\": packageName,\r\n \"{{packageName}}\": packageName,\r\n \"{{displayName}}\": displayName,\r\n \"{{appName}}\": appName,\r\n \"{{androidPackage}}\": androidPackage,\r\n \"{{iosBundleIdentifier}}\": iosBundleIdentifier,\r\n};\r\n\r\nfunction replaceTemplatePlaceholders(directory: string) {\r\n const entries = fs.readdirSync(directory, {\r\n withFileTypes: true,\r\n });\r\n\r\n for (const entry of entries) {\r\n const entryPath = path.join(directory, entry.name);\r\n\r\n if (entry.isDirectory()) {\r\n replaceTemplatePlaceholders(entryPath);\r\n continue;\r\n }\r\n\r\n const extension = path.extname(entry.name).toLowerCase();\r\n\r\n const isPodfile = entry.name === \"Podfile\";\r\n const isTextFile = isPodfile || textFileExtensions.has(extension);\r\n\r\n if (!isTextFile) {\r\n continue;\r\n }\r\n\r\n let content = fs.readFileSync(entryPath, \"utf8\");\r\n\r\n for (const [placeholder, value] of Object.entries(placeholderValues)) {\r\n content = content.split(placeholder).join(value);\r\n }\r\n\r\n fs.writeFileSync(entryPath, content, \"utf8\");\r\n }\r\n}\r\n\r\nfunction renameStandaloneNativeDirectories() {\r\n const androidPackageDirectory = path.join(\r\n projectPath,\r\n \"android\",\r\n \"app\",\r\n \"src\",\r\n \"main\",\r\n \"java\",\r\n \"com\",\r\n \"beevernativetemplatetest\",\r\n );\r\n\r\n const androidPackageParent = path.dirname(androidPackageDirectory);\r\n\r\n const androidPackageTarget = path.join(\r\n androidPackageParent,\r\n \"beever\",\r\n safeNativePackageName,\r\n );\r\n\r\n if (fs.existsSync(androidPackageDirectory)) {\r\n fs.mkdirSync(path.dirname(androidPackageTarget), {\r\n recursive: true,\r\n });\r\n\r\n fs.renameSync(androidPackageDirectory, androidPackageTarget);\r\n }\r\n\r\n const iosDirectory = path.join(projectPath, \"ios\");\r\n\r\n const oldIosAppDirectory = path.join(\r\n iosDirectory,\r\n \"BeeverNativeTemplateTest\",\r\n );\r\n\r\n const newIosAppDirectory = path.join(iosDirectory, appName);\r\n\r\n if (fs.existsSync(oldIosAppDirectory)) {\r\n fs.renameSync(oldIosAppDirectory, newIosAppDirectory);\r\n }\r\n\r\n const oldXcodeProjectDirectory = path.join(\r\n iosDirectory,\r\n \"BeeverNativeTemplateTest.xcodeproj\",\r\n );\r\n\r\n const newXcodeProjectDirectory = path.join(\r\n iosDirectory,\r\n `${appName}.xcodeproj`,\r\n );\r\n\r\n if (fs.existsSync(oldXcodeProjectDirectory)) {\r\n fs.renameSync(oldXcodeProjectDirectory, newXcodeProjectDirectory);\r\n }\r\n\r\n const oldSchemeFile = path.join(\r\n newXcodeProjectDirectory,\r\n \"xcshareddata\",\r\n \"xcschemes\",\r\n \"BeeverNativeTemplateTest.xcscheme\",\r\n );\r\n\r\n const newSchemeFile = path.join(\r\n newXcodeProjectDirectory,\r\n \"xcshareddata\",\r\n \"xcschemes\",\r\n `${appName}.xcscheme`,\r\n );\r\n\r\n if (fs.existsSync(oldSchemeFile)) {\r\n fs.renameSync(oldSchemeFile, newSchemeFile);\r\n }\r\n}\r\n\r\nasync function selectMobileProjectType(): Promise<MobileProjectType> {\r\n const rl = createInterface({\r\n input: stdin,\r\n output: stdout,\r\n });\r\n\r\n try {\r\n console.log(\"\\nWhich mobile setup would you like?\\n\");\r\n console.log(\" 1. React Native Standalone\");\r\n console.log(\" 2. React Native with Expo\\n\");\r\n\r\n const answer = (await rl.question(\"Choose an option (1 or 2): \")).trim();\r\n\r\n if (answer === \"1\") {\r\n return \"standalone\";\r\n }\r\n\r\n if (answer === \"2\") {\r\n return \"expo\";\r\n }\r\n\r\n throw new Error(\"Invalid selection. Please choose 1 or 2.\");\r\n } finally {\r\n rl.close();\r\n }\r\n}\r\n\r\nasync function main() {\r\n let mobileProjectType: MobileProjectType;\r\n\r\n try {\r\n mobileProjectType = await selectMobileProjectType();\r\n } catch (error) {\r\n console.error(error instanceof Error ? error.message : error);\r\n process.exit(1);\r\n }\r\n\r\n const selectedTemplatePath =\r\n mobileProjectType === \"standalone\"\r\n ? standaloneTemplatePath\r\n : expoTemplatePath;\r\n\r\n try {\r\n // Verify the required template directories.\r\n if (!fs.existsSync(commonTemplatePath)) {\r\n throw new Error(\"Common project template not found.\");\r\n }\r\n\r\n if (!fs.existsSync(selectedTemplatePath)) {\r\n throw new Error(\r\n `The ${mobileProjectType} project template was not found.`,\r\n );\r\n }\r\n\r\n // Create the project directory.\r\n fs.mkdirSync(projectPath);\r\n\r\n // Copy shared application code first.\r\n fs.cpSync(commonTemplatePath, projectPath, {\r\n recursive: true,\r\n });\r\n\r\n // Overlay the selected mobile project template.\r\n fs.cpSync(selectedTemplatePath, projectPath, {\r\n recursive: true,\r\n });\r\n\r\n // Replace template placeholders in text files.\r\n replaceTemplatePlaceholders(projectPath);\r\n\r\n // Rename native project directories for Standalone.\r\n if (mobileProjectType === \"standalone\") {\r\n renameStandaloneNativeDirectories();\r\n }\r\n } catch (error) {\r\n console.error(\"\\nFailed to create Beever project.\");\r\n\r\n if (fs.existsSync(projectPath)) {\r\n fs.rmSync(projectPath, {\r\n recursive: true,\r\n force: true,\r\n });\r\n }\r\n\r\n console.error(error);\r\n process.exit(1);\r\n }\r\n\r\n // Automatically install project dependencies.\r\n console.log(\"\\nInstalling project dependencies...\\n\");\r\n\r\n const installOptions = {\r\n cwd: projectPath,\r\n stdio: \"inherit\" as const,\r\n };\r\n\r\n const installResult =\r\n process.platform === \"win32\"\r\n ? spawnSync(\r\n process.env.ComSpec || \"cmd.exe\",\r\n [\"/d\", \"/s\", \"/c\", \"npm install\"],\r\n installOptions,\r\n )\r\n : spawnSync(\"npm\", [\"install\"], installOptions);\r\n\r\n if (installResult.error || installResult.status !== 0) {\r\n console.error(\"\\nDependency installation failed.\");\r\n console.error(`Your project was created at: ${projectPath}`);\r\n console.error(\"You can retry by running 'npm install' inside the project.\");\r\n process.exit(1);\r\n }\r\n\r\n // Display the appropriate success message.\r\n console.log(\"\\nBeever project created successfully!\\n\");\r\n console.log(\"Your Beever project is ready for:\");\r\n console.log(\" - Web\");\r\n\r\n if (mobileProjectType === \"standalone\") {\r\n console.log(\" - React Native Standalone\");\r\n } else {\r\n console.log(\" - React Native with Expo\");\r\n }\r\n\r\n console.log(\"\\nDependencies installed successfully!\");\r\n}\r\n\r\nawait main();\r\n"],"mappings":";;;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,OAAO,cAAc;AAI9B,IAAM,cAAc,QAAQ,KAAK,CAAC;AAElC,IAAI,CAAC,aAAa;AAChB,UAAQ,IAAI,gCAAgC;AAC5C,UAAQ,IAAI,yCAAyC;AACrD,UAAQ,KAAK,CAAC;AAChB;AAGA,IAAM,mBAAmB,8BAA8B,KAAK,WAAW;AAEvE,IAAI,CAAC,kBAAkB;AACrB,UAAQ;AAAA,IACN;AAAA,EACF;AACA,UAAQ,KAAK,CAAC;AAChB;AAEA,IAAM,cAAc,KAAK,QAAQ,QAAQ,IAAI,GAAG,WAAW;AAE3D,IAAI,GAAG,WAAW,WAAW,GAAG;AAC9B,UAAQ,MAAM,mBAAmB,WAAW,mBAAmB;AAC/D,UAAQ,KAAK,CAAC;AAChB;AAGA,IAAM,mBAAmB,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AACpE,IAAM,gBAAgB,KAAK,QAAQ,kBAAkB,cAAc;AAEnE,IAAM,qBAAqB,KAAK,KAAK,eAAe,QAAQ;AAC5D,IAAM,mBAAmB,KAAK,KAAK,eAAe,MAAM;AACxD,IAAM,yBAAyB,KAAK,KAAK,eAAe,YAAY;AAGpE,IAAM,cAAc,YAAY,YAAY,EAAE,QAAQ,MAAM,GAAG;AAE/D,IAAM,cAAc,YAAY,QAAQ,UAAU,GAAG,EAAE,KAAK;AAE5D,IAAM,eAAe,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CAA4B,WAAW;AAGvC,QAAI,sBAAsB,cAAc;AACtC,wCAAkC;AAAA,IACpC;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,oCAAoC;AAElD,QAAI,GAAG,WAAW,WAAW,GAAG;AAC9B,SAAG,OAAO,aAAa;AAAA,QACrB,WAAW;AAAA,QACX,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AAEA,YAAQ,MAAM,KAAK;AACnB,YAAQ,KAAK,CAAC;AAAA,EAChB;AAGA,UAAQ,IAAI,wCAAwC;AAEpD,QAAM,iBAAiB;AAAA,IACrB,KAAK;AAAA,IACL,OAAO;AAAA,EACT;AAEA,QAAM,gBACJ,QAAQ,aAAa,UACjB;AAAA,IACE,QAAQ,IAAI,WAAW;AAAA,IACvB,CAAC,MAAM,MAAM,MAAM,aAAa;AAAA,IAChC;AAAA,EACF,IACA,UAAU,OAAO,CAAC,SAAS,GAAG,cAAc;AAElD,MAAI,cAAc,SAAS,cAAc,WAAW,GAAG;AACrD,YAAQ,MAAM,mCAAmC;AACjD,YAAQ,MAAM,gCAAgC,WAAW,EAAE;AAC3D,YAAQ,MAAM,4DAA4D;AAC1E,YAAQ,KAAK,CAAC;AAAA,EAChB;AAGA,UAAQ,IAAI,0CAA0C;AACtD,UAAQ,IAAI,mCAAmC;AAC/C,UAAQ,IAAI,SAAS;AAErB,MAAI,sBAAsB,cAAc;AACtC,YAAQ,IAAI,6BAA6B;AAAA,EAC3C,OAAO;AACL,YAAQ,IAAI,4BAA4B;AAAA,EAC1C;AAEA,UAAQ,IAAI,wCAAwC;AACtD;AAEA,MAAM,KAAK;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import fs from \"node:fs\";\r\nimport path from \"node:path\";\r\nimport { spawnSync } from \"node:child_process\";\r\nimport { fileURLToPath } from \"node:url\";\r\nimport { createInterface } from \"node:readline/promises\";\r\nimport { stdin, stdout } from \"node:process\";\r\n\r\ntype MobileProjectType = \"standalone\" | \"expo\";\r\n\r\nconst projectName = process.argv[2];\r\n\r\nif (!projectName) {\r\n console.log(\"Please provide a project name.\");\r\n console.log(\"Usage: npx beever-create <project-name>\");\r\n process.exit(1);\r\n}\r\n\r\n// Validate the project name before creating anything.\r\nconst validProjectName = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(projectName);\r\n\r\nif (!validProjectName) {\r\n console.error(\r\n \"Invalid project name. Start with a letter or number and use only letters, numbers, hyphens, and underscores.\",\r\n );\r\n process.exit(1);\r\n}\r\n\r\nconst projectPath = path.resolve(process.cwd(), projectName);\r\n\r\nif (fs.existsSync(projectPath)) {\r\n console.error(`A folder named \"${projectName}\" already exists.`);\r\n process.exit(1);\r\n}\r\n\r\n// Resolve template directories.\r\nconst currentDirectory = path.dirname(fileURLToPath(import.meta.url));\r\nconst templatesPath = path.resolve(currentDirectory, \"../templates\");\r\n\r\nconst commonTemplatePath = path.join(templatesPath, \"common\");\r\nconst expoTemplatePath = path.join(templatesPath, \"expo\");\r\nconst standaloneTemplatePath = path.join(templatesPath, \"standalone\");\r\n\r\n// Generate project identifiers.\r\nconst packageName = projectName.toLowerCase().replace(/_/g, \"-\");\r\n\r\nconst displayName = projectName.replace(/[-_]+/g, \" \").trim();\r\n\r\nconst appNameParts = projectName.split(/[-_]+/).filter(Boolean);\r\n\r\nlet appName = appNameParts\r\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\r\n .join(\"\");\r\n\r\nif (!appName || /^[0-9]/.test(appName)) {\r\n appName = `App${appName}`;\r\n}\r\n\r\nconst nativePackageName = projectName.toLowerCase().replace(/[^a-z0-9]/g, \"\");\r\n\r\nconst safeNativePackageName = /^[a-z]/.test(nativePackageName)\r\n ? nativePackageName\r\n : `app${nativePackageName}`;\r\n\r\nconst androidPackage = `com.beever.${safeNativePackageName}`;\r\nconst iosBundleIdentifier = `com.beever.${safeNativePackageName}`;\r\n\r\n// Only these files are processed as text.\r\n// Binary assets are deliberately excluded.\r\nconst textFileExtensions = new Set([\r\n \".json\",\r\n \".js\",\r\n \".jsx\",\r\n \".ts\",\r\n \".tsx\",\r\n \".gradle\",\r\n \".properties\",\r\n \".kt\",\r\n \".swift\",\r\n \".plist\",\r\n \".storyboard\",\r\n \".xcprivacy\",\r\n \".pbxproj\",\r\n \".xcscheme\",\r\n \".xml\",\r\n \".md\",\r\n \".txt\",\r\n \".html\",\r\n \".css\",\r\n \".scss\",\r\n \".yml\",\r\n \".yaml\",\r\n \".toml\",\r\n]);\r\n\r\nconst placeholderValues: Record<string, string> = {\r\n \"{{projectName}}\": packageName,\r\n \"{{packageName}}\": packageName,\r\n \"{{displayName}}\": displayName,\r\n \"{{appName}}\": appName,\r\n \"{{androidPackage}}\": androidPackage,\r\n \"{{iosBundleIdentifier}}\": iosBundleIdentifier,\r\n};\r\n\r\nfunction replaceTemplatePlaceholders(directory: string) {\r\n const entries = fs.readdirSync(directory, {\r\n withFileTypes: true,\r\n });\r\n\r\n for (const entry of entries) {\r\n const entryPath = path.join(directory, entry.name);\r\n\r\n if (entry.isDirectory()) {\r\n replaceTemplatePlaceholders(entryPath);\r\n continue;\r\n }\r\n\r\n const extension = path.extname(entry.name).toLowerCase();\r\n\r\n const isPodfile = entry.name === \"Podfile\";\r\n const isTextFile = isPodfile || textFileExtensions.has(extension);\r\n\r\n if (!isTextFile) {\r\n continue;\r\n }\r\n\r\n let content = fs.readFileSync(entryPath, \"utf8\");\r\n\r\n for (const [placeholder, value] of Object.entries(placeholderValues)) {\r\n content = content.split(placeholder).join(value);\r\n }\r\n\r\n fs.writeFileSync(entryPath, content, \"utf8\");\r\n }\r\n}\r\n\r\nfunction renameStandaloneNativeDirectories() {\r\n const androidPackageDirectory = path.join(\r\n projectPath,\r\n \"android\",\r\n \"app\",\r\n \"src\",\r\n \"main\",\r\n \"java\",\r\n \"com\",\r\n \"beevernativetemplatetest\",\r\n );\r\n\r\n const androidPackageParent = path.dirname(androidPackageDirectory);\r\n\r\n const androidPackageTarget = path.join(\r\n androidPackageParent,\r\n \"beever\",\r\n safeNativePackageName,\r\n );\r\n\r\n if (fs.existsSync(androidPackageDirectory)) {\r\n fs.mkdirSync(path.dirname(androidPackageTarget), {\r\n recursive: true,\r\n });\r\n\r\n fs.renameSync(androidPackageDirectory, androidPackageTarget);\r\n }\r\n\r\n const iosDirectory = path.join(projectPath, \"ios\");\r\n\r\n const oldIosAppDirectory = path.join(\r\n iosDirectory,\r\n \"BeeverNativeTemplateTest\",\r\n );\r\n\r\n const newIosAppDirectory = path.join(iosDirectory, appName);\r\n\r\n if (fs.existsSync(oldIosAppDirectory)) {\r\n fs.renameSync(oldIosAppDirectory, newIosAppDirectory);\r\n }\r\n\r\n const oldXcodeProjectDirectory = path.join(\r\n iosDirectory,\r\n \"BeeverNativeTemplateTest.xcodeproj\",\r\n );\r\n\r\n const newXcodeProjectDirectory = path.join(\r\n iosDirectory,\r\n `${appName}.xcodeproj`,\r\n );\r\n\r\n if (fs.existsSync(oldXcodeProjectDirectory)) {\r\n fs.renameSync(oldXcodeProjectDirectory, newXcodeProjectDirectory);\r\n }\r\n\r\n const oldSchemeFile = path.join(\r\n newXcodeProjectDirectory,\r\n \"xcshareddata\",\r\n \"xcschemes\",\r\n \"BeeverNativeTemplateTest.xcscheme\",\r\n );\r\n\r\n const newSchemeFile = path.join(\r\n newXcodeProjectDirectory,\r\n \"xcshareddata\",\r\n \"xcschemes\",\r\n `${appName}.xcscheme`,\r\n );\r\n\r\n if (fs.existsSync(oldSchemeFile)) {\r\n fs.renameSync(oldSchemeFile, newSchemeFile);\r\n }\r\n}\r\n\r\nasync function selectMobileProjectType(): Promise<MobileProjectType> {\r\n const rl = createInterface({\r\n input: stdin,\r\n output: stdout,\r\n });\r\n\r\n try {\r\n console.log(\"\\nWhich mobile setup would you like?\\n\");\r\n console.log(\" 1. React Native Standalone\");\r\n console.log(\" 2. React Native with Expo\\n\");\r\n\r\n const answer = (await rl.question(\"Choose an option (1 or 2): \")).trim();\r\n\r\n if (answer === \"1\") {\r\n return \"standalone\";\r\n }\r\n\r\n if (answer === \"2\") {\r\n return \"expo\";\r\n }\r\n\r\n throw new Error(\"Invalid selection. Please choose 1 or 2.\");\r\n } finally {\r\n rl.close();\r\n }\r\n}\r\n\r\nasync function main() {\r\n let mobileProjectType: MobileProjectType;\r\n\r\n try {\r\n mobileProjectType = await selectMobileProjectType();\r\n } catch (error) {\r\n console.error(error instanceof Error ? error.message : error);\r\n process.exit(1);\r\n }\r\n\r\n const selectedTemplatePath =\r\n mobileProjectType === \"standalone\"\r\n ? standaloneTemplatePath\r\n : expoTemplatePath;\r\n\r\n try {\r\n // Verify the required template directories.\r\n if (!fs.existsSync(commonTemplatePath)) {\r\n throw new Error(\"Common project template not found.\");\r\n }\r\n\r\n if (!fs.existsSync(selectedTemplatePath)) {\r\n throw new Error(\r\n `The ${mobileProjectType} project template was not found.`,\r\n );\r\n }\r\n\r\n // Create the project directory.\r\n fs.mkdirSync(projectPath);\r\n\r\n // Copy shared application code first.\r\n fs.cpSync(commonTemplatePath, projectPath, {\r\n recursive: true,\r\n });\r\n\r\n // Overlay the selected mobile project template.\r\n fs.cpSync(selectedTemplatePath, projectPath, {\r\n recursive: true,\r\n });\r\n\r\n // Restore the TypeScript configuration filename for Standalone projects.\r\n if (mobileProjectType === \"standalone\") {\r\n const templateTsconfigPath = path.join(\r\n projectPath,\r\n \"tsconfig.json.template\",\r\n );\r\n\r\n const projectTsconfigPath = path.join(projectPath, \"tsconfig.json\");\r\n\r\n if (fs.existsSync(templateTsconfigPath)) {\r\n fs.renameSync(templateTsconfigPath, projectTsconfigPath);\r\n }\r\n }\r\n\r\n // Replace template placeholders in text files.\r\n replaceTemplatePlaceholders(projectPath);\r\n\r\n // Rename native project directories for Standalone.\r\n if (mobileProjectType === \"standalone\") {\r\n renameStandaloneNativeDirectories();\r\n }\r\n } catch (error) {\r\n console.error(\"\\nFailed to create Beever project.\");\r\n\r\n if (fs.existsSync(projectPath)) {\r\n fs.rmSync(projectPath, {\r\n recursive: true,\r\n force: true,\r\n });\r\n }\r\n\r\n console.error(error);\r\n process.exit(1);\r\n }\r\n\r\n // Automatically install project dependencies.\r\n console.log(\"\\nInstalling project dependencies...\\n\");\r\n\r\n const installOptions = {\r\n cwd: projectPath,\r\n stdio: \"inherit\" as const,\r\n };\r\n\r\n const installResult =\r\n process.platform === \"win32\"\r\n ? spawnSync(\r\n process.env.ComSpec || \"cmd.exe\",\r\n [\"/d\", \"/s\", \"/c\", \"npm install\"],\r\n installOptions,\r\n )\r\n : spawnSync(\"npm\", [\"install\"], installOptions);\r\n\r\n if (installResult.error || installResult.status !== 0) {\r\n console.error(\"\\nDependency installation failed.\");\r\n console.error(`Your project was created at: ${projectPath}`);\r\n console.error(\"You can retry by running 'npm install' inside the project.\");\r\n process.exit(1);\r\n }\r\n\r\n // Display the appropriate success message.\r\n console.log(\"\\nBeever project created successfully!\\n\");\r\n console.log(\"Your Beever project is ready for:\");\r\n console.log(\" - Web\");\r\n\r\n if (mobileProjectType === \"standalone\") {\r\n console.log(\" - React Native Standalone\");\r\n } else {\r\n console.log(\" - React Native with Expo\");\r\n }\r\n\r\n console.log(\"\\nDependencies installed successfully!\");\r\n}\r\n\r\nawait main();\r\n"],"mappings":";;;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,OAAO,cAAc;AAI9B,IAAM,cAAc,QAAQ,KAAK,CAAC;AAElC,IAAI,CAAC,aAAa;AAChB,UAAQ,IAAI,gCAAgC;AAC5C,UAAQ,IAAI,yCAAyC;AACrD,UAAQ,KAAK,CAAC;AAChB;AAGA,IAAM,mBAAmB,8BAA8B,KAAK,WAAW;AAEvE,IAAI,CAAC,kBAAkB;AACrB,UAAQ;AAAA,IACN;AAAA,EACF;AACA,UAAQ,KAAK,CAAC;AAChB;AAEA,IAAM,cAAc,KAAK,QAAQ,QAAQ,IAAI,GAAG,WAAW;AAE3D,IAAI,GAAG,WAAW,WA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AAO,CAAC,SAAS,GAAG,cAAc;AAElD,MAAI,cAAc,SAAS,cAAc,WAAW,GAAG;AACrD,YAAQ,MAAM,mCAAmC;AACjD,YAAQ,MAAM,gCAAgC,WAAW,EAAE;AAC3D,YAAQ,MAAM,4DAA4D;AAC1E,YAAQ,KAAK,CAAC;AAAA,EAChB;AAGA,UAAQ,IAAI,0CAA0C;AACtD,UAAQ,IAAI,mCAAmC;AAC/C,UAAQ,IAAI,SAAS;AAErB,MAAI,sBAAsB,cAAc;AACtC,YAAQ,IAAI,6BAA6B;AAAA,EAC3C,OAAO;AACL,YAAQ,IAAI,4BAA4B;AAAA,EAC1C;AAEA,UAAQ,IAAI,wCAAwC;AACtD;AAEA,MAAM,KAAK;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beever-create",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "description": "CLI tool for creating Beever projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,6 +15,7 @@
15
15
  "build": "tsup"
16
16
  },
17
17
  "devDependencies": {
18
+ "@react-native/typescript-config": "0.88.1",
18
19
  "@types/node": "^20.19.0",
19
20
  "tsup": "^9.0.0",
20
21
  "typescript": "^6.0.3"
@@ -0,0 +1,60 @@
1
+ # Assets
2
+
3
+ This folder contains the application's shared assets, including fonts, images, and icons.
4
+
5
+ Assets are organized by type so they can be reused across the Web and Mobile applications.
6
+
7
+ ## Folder Structure
8
+
9
+ ```text
10
+ assets/
11
+ ├── fonts/
12
+ │ ├── Figtree/
13
+ │ └── index.ts
14
+ ├── images/
15
+ ├── icons/
16
+ └── index.ts
17
+ ```
18
+
19
+ ## Fonts
20
+
21
+ Place font files inside `fonts/`, organized by font family.
22
+
23
+ Example:
24
+
25
+ ```text
26
+ fonts/
27
+ └── Figtree/
28
+ ├── Figtree-VariableFont_wght.ttf
29
+ ├── Figtree-Italic-VariableFont_wght.ttf
30
+ ├── static/
31
+ └── index.ts
32
+ ```
33
+
34
+ Font references can be exported through the font family's `index.ts` and accessed from the assets entry point.
35
+
36
+ ```ts
37
+ import { Figtree } from "./assets";
38
+
39
+ const regularFont = Figtree.variable.normal;
40
+ const italicFont = Figtree.variable.italic;
41
+ ```
42
+
43
+ Web and Mobile may require different font-loading and registration procedures. The same font files can be shared where supported.
44
+
45
+ ## Images
46
+
47
+ Place application images inside `images/`. Organize them into subfolders when needed.
48
+
49
+ ## Icons
50
+
51
+ Place application icon assets inside `icons/`. Organize them by category or purpose when needed.
52
+
53
+ ## Guidelines
54
+
55
+ - Keep shared assets inside this folder.
56
+ - Organize assets by type and font family.
57
+ - Use descriptive filenames.
58
+ - Avoid duplicating the same asset unnecessarily.
59
+ - Keep font license files alongside their font files.
60
+ - Use platform-specific asset loading where required.
@@ -0,0 +1,93 @@
1
+ Copyright 2022 The Figtree Project Authors (https://github.com/erikdkennedy/figtree)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://openfontlicense.org
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,77 @@
1
+ Figtree Variable Font
2
+ =====================
3
+
4
+ This download contains Figtree as both variable fonts and static fonts.
5
+
6
+ Figtree is a variable font with this axis:
7
+ wght
8
+
9
+ This means all the styles are contained in these files:
10
+ Figtree/Figtree-VariableFont_wght.ttf
11
+ Figtree/Figtree-Italic-VariableFont_wght.ttf
12
+
13
+ If your app fully supports variable fonts, you can now pick intermediate styles
14
+ that aren’t available as static fonts. Not all apps support variable fonts, and
15
+ in those cases you can use the static font files for Figtree:
16
+ Figtree/static/Figtree-Light.ttf
17
+ Figtree/static/Figtree-Regular.ttf
18
+ Figtree/static/Figtree-Medium.ttf
19
+ Figtree/static/Figtree-SemiBold.ttf
20
+ Figtree/static/Figtree-Bold.ttf
21
+ Figtree/static/Figtree-ExtraBold.ttf
22
+ Figtree/static/Figtree-Black.ttf
23
+ Figtree/static/Figtree-LightItalic.ttf
24
+ Figtree/static/Figtree-Italic.ttf
25
+ Figtree/static/Figtree-MediumItalic.ttf
26
+ Figtree/static/Figtree-SemiBoldItalic.ttf
27
+ Figtree/static/Figtree-BoldItalic.ttf
28
+ Figtree/static/Figtree-ExtraBoldItalic.ttf
29
+ Figtree/static/Figtree-BlackItalic.ttf
30
+
31
+ Get started
32
+ -----------
33
+
34
+ 1. Install the font files you want to use
35
+
36
+ 2. Use your app's font picker to view the font family and all the
37
+ available styles
38
+
39
+ Learn more about variable fonts
40
+ -------------------------------
41
+
42
+ https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts
43
+ https://variablefonts.typenetwork.com
44
+ https://medium.com/variable-fonts
45
+
46
+ In desktop apps
47
+
48
+ https://theblog.adobe.com/can-variable-fonts-illustrator-cc
49
+ https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts
50
+
51
+ Online
52
+
53
+ https://developers.google.com/fonts/docs/getting_started
54
+ https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide
55
+ https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts
56
+
57
+ Installing fonts
58
+
59
+ MacOS: https://support.apple.com/en-us/HT201749
60
+ Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux
61
+ Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows
62
+
63
+ Android Apps
64
+
65
+ https://developers.google.com/fonts/docs/android
66
+ https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts
67
+
68
+ License
69
+ -------
70
+ Please read the full license text (OFL.txt) to understand the permissions,
71
+ restrictions and requirements for usage, redistribution, and modification.
72
+
73
+ You can use them in your products & projects – print or digital,
74
+ commercial or otherwise.
75
+
76
+ This isn't legal advice, please consider consulting a lawyer and see the full
77
+ license for all details.
@@ -0,0 +1,27 @@
1
+ export const Figtree = {
2
+ family: "Figtree",
3
+
4
+ variable: {
5
+ normal: "./assets/fonts/Figtree/Figtree-VariableFont_wght.ttf",
6
+ italic: "./assets/fonts/Figtree/Figtree-Italic-VariableFont_wght.ttf",
7
+ },
8
+
9
+ static: {
10
+ light: "./assets/fonts/Figtree/static/Figtree-Light.ttf",
11
+ regular: "./assets/fonts/Figtree/static/Figtree-Regular.ttf",
12
+ medium: "./assets/fonts/Figtree/static/Figtree-Medium.ttf",
13
+ semibold: "./assets/fonts/Figtree/static/Figtree-SemiBold.ttf",
14
+ bold: "./assets/fonts/Figtree/static/Figtree-Bold.ttf",
15
+ extrabold: "./assets/fonts/Figtree/static/Figtree-ExtraBold.ttf",
16
+ black: "./assets/fonts/Figtree/static/Figtree-Black.ttf",
17
+
18
+ lightItalic: "./assets/fonts/Figtree/static/Figtree-LightItalic.ttf",
19
+ italic: "./assets/fonts/Figtree/static/Figtree-Italic.ttf",
20
+ mediumItalic: "./assets/fonts/Figtree/static/Figtree-MediumItalic.ttf",
21
+ semiboldItalic: "./assets/fonts/Figtree/static/Figtree-SemiBoldItalic.ttf",
22
+ boldItalic: "./assets/fonts/Figtree/static/Figtree-BoldItalic.ttf",
23
+ extraboldItalic:
24
+ "./assets/fonts/Figtree/static/Figtree-ExtraBoldItalic.ttf",
25
+ blackItalic: "./assets/fonts/Figtree/static/Figtree-BlackItalic.ttf",
26
+ },
27
+ } as const;
@@ -0,0 +1 @@
1
+ export * from "./Figtree";
File without changes
File without changes
@@ -0,0 +1 @@
1
+ export * from "./fonts";
@@ -4,7 +4,9 @@ export function WelcomeScreen() {
4
4
  return (
5
5
  <View style={styles.container}>
6
6
  <Text style={styles.title}>Welcome to Beever!</Text>
7
- <Text>Your cross-platform project starts here.</Text>
7
+ <Text style={styles.subtitle}>
8
+ Your cross-platform project starts here.
9
+ </Text>
8
10
  </View>
9
11
  );
10
12
  }
@@ -17,8 +19,12 @@ const styles = StyleSheet.create({
17
19
  padding: 24,
18
20
  },
19
21
  title: {
22
+ fontFamily: "Figtree-Bold",
20
23
  fontSize: 24,
21
- fontWeight: "bold",
22
24
  marginBottom: 8,
23
25
  },
26
+ subtitle: {
27
+ fontFamily: "Figtree-Regular",
28
+ fontSize: 16,
29
+ },
24
30
  });
@@ -1,6 +1,8 @@
1
1
  import { createRoot } from "react-dom/client";
2
2
  import { WelcomePage } from "../features/welcome/pages/WelcomePage";
3
3
 
4
+ import "./styles.css";
5
+
4
6
  const rootElement = document.getElementById("root");
5
7
 
6
8
  if (!rootElement) {
@@ -0,0 +1,21 @@
1
+ @font-face {
2
+ font-family: "Figtree";
3
+ src: url("../assets/fonts/Figtree/Figtree-VariableFont_wght.ttf")
4
+ format("truetype");
5
+ font-weight: 300 900;
6
+ font-style: normal;
7
+ font-display: swap;
8
+ }
9
+
10
+ @font-face {
11
+ font-family: "Figtree";
12
+ src: url("../assets/fonts/Figtree/Figtree-Italic-VariableFont_wght.ttf")
13
+ format("truetype");
14
+ font-weight: 300 900;
15
+ font-style: italic;
16
+ font-display: swap;
17
+ }
18
+
19
+ body {
20
+ font-family: "Figtree", sans-serif;
21
+ }
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "@beever/web": "0.1.0",
13
- "@beever/mobile": "0.1.0",
13
+ "@beever/mobile": "0.1.1",
14
14
  "expo": "~58.0.26",
15
15
  "expo-dev-client": "~58.0.21",
16
16
  "react": "19.3.0",
@@ -24,3 +24,4 @@
24
24
  "vite": "^7.3.8"
25
25
  }
26
26
  }
27
+
@@ -1,9 +1,5 @@
1
- /**
2
- * @format
3
- */
4
-
5
1
  import { AppRegistry } from 'react-native';
6
- import App from './App';
2
+ import App from './mobile/App';
7
3
  import { name as appName } from './app.json';
8
4
 
9
5
  AppRegistry.registerComponent(appName, () => App);
@@ -3,9 +3,13 @@
3
3
  "version": "1.0.0",
4
4
  "private": true,
5
5
  "scripts": {
6
+ "postinstall": "react-native-asset",
6
7
  "web": "vite web --config web/vite.config.ts",
7
8
  "build:web": "vite build web --config web/vite.config.ts",
8
- "android": "react-native run-android",
9
+ "install:android:emulator": "node scripts/android.js install:emulator",
10
+ "install:android:device": "node scripts/android.js install:device",
11
+ "android:emulator": "node scripts/android.js emulator",
12
+ "android:device": "node scripts/android.js device",
9
13
  "ios": "react-native run-ios",
10
14
  "lint": "eslint .",
11
15
  "start": "react-native start",
@@ -13,7 +17,7 @@
13
17
  },
14
18
  "dependencies": {
15
19
  "@beever/web": "0.1.0",
16
- "@beever/mobile": "0.1.0",
20
+ "@beever/mobile": "0.1.1",
17
21
  "react": "19.3.0",
18
22
  "react-dom": "19.3.0",
19
23
  "react-native": "0.88.1"
@@ -39,9 +43,11 @@
39
43
  "prettier": "2.8.8",
40
44
  "react-test-renderer": "19.3.0",
41
45
  "typescript": "^6.0.3",
42
- "vite": "^7.3.8"
46
+ "vite": "^7.3.8",
47
+ "react-native-asset": "^2.3.0"
43
48
  },
44
49
  "engines": {
45
50
  "node": ">= 22.11.0"
46
51
  }
47
52
  }
53
+
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ assets: ['./assets/fonts'],
3
+ };
@@ -0,0 +1,574 @@
1
+ const fs = require('node:fs');
2
+ const path = require('node:path');
3
+ const os = require('node:os');
4
+ const http = require('node:http');
5
+ const net = require('node:net');
6
+ const readline = require('node:readline/promises');
7
+ const { spawn, spawnSync } = require('node:child_process');
8
+
9
+ const projectRoot = path.resolve(__dirname, '..');
10
+ const androidDirectory = path.join(projectRoot, 'android');
11
+
12
+ const applicationId = '{{androidPackage}}';
13
+ const metroPort = 8081;
14
+
15
+ // --------------------------------------------------
16
+ // ADB
17
+ // --------------------------------------------------
18
+
19
+ function getAdbPath() {
20
+ const sdkPaths = [
21
+ process.env.ANDROID_HOME,
22
+ process.env.ANDROID_SDK_ROOT,
23
+ process.env.LOCALAPPDATA
24
+ ? path.join(process.env.LOCALAPPDATA, 'Android', 'Sdk')
25
+ : null,
26
+ ].filter(Boolean);
27
+
28
+ for (const sdkPath of sdkPaths) {
29
+ const adbPath = path.join(
30
+ sdkPath,
31
+ 'platform-tools',
32
+ process.platform === 'win32' ? 'adb.exe' : 'adb',
33
+ );
34
+
35
+ if (fs.existsSync(adbPath)) {
36
+ return adbPath;
37
+ }
38
+ }
39
+
40
+ throw new Error(
41
+ 'Android SDK not found. Install Android SDK or configure ANDROID_HOME.',
42
+ );
43
+ }
44
+
45
+ function runAdb(args) {
46
+ const result = spawnSync(getAdbPath(), args, {
47
+ encoding: 'utf8',
48
+ windowsHide: true,
49
+ });
50
+
51
+ if (result.error) {
52
+ throw result.error;
53
+ }
54
+
55
+ if (result.status !== 0) {
56
+ throw new Error(result.stderr || result.stdout || 'ADB command failed.');
57
+ }
58
+
59
+ return result.stdout.trim();
60
+ }
61
+
62
+ // --------------------------------------------------
63
+ // Android device detection
64
+ // --------------------------------------------------
65
+
66
+ function getAndroidDevices() {
67
+ let adbPath;
68
+
69
+ try {
70
+ adbPath = getAdbPath();
71
+ } catch {
72
+ return null;
73
+ }
74
+
75
+ const result = spawnSync(adbPath, ['devices', '-l'], {
76
+ encoding: 'utf8',
77
+ windowsHide: true,
78
+ });
79
+
80
+ if (result.error) {
81
+ throw result.error;
82
+ }
83
+
84
+ if (result.status !== 0) {
85
+ throw new Error(result.stderr || 'Unable to detect Android devices.');
86
+ }
87
+
88
+ const devices = result.stdout
89
+ .split(/\r?\n/)
90
+ .slice(1)
91
+ .filter(line => line.trim())
92
+ .map(line => {
93
+ const parts = line.trim().split(/\s+/);
94
+ const serial = parts[0];
95
+ const state = parts[1];
96
+ const model = parts.find(part => part.startsWith('model:'))?.slice(6);
97
+
98
+ return {
99
+ serial,
100
+ state,
101
+ model: model || serial,
102
+ type: serial.startsWith('emulator-') ? 'emulator' : 'device',
103
+ };
104
+ });
105
+
106
+ // Remove duplicate connections to the same physical device.
107
+ // Prefer the direct IP connection over the mDNS connection.
108
+ const uniqueDevices = new Map();
109
+
110
+ for (const device of devices) {
111
+ if (!device.model || device.state !== 'device') {
112
+ uniqueDevices.set(device.serial, device);
113
+ continue;
114
+ }
115
+
116
+ const existing = uniqueDevices.get(device.model);
117
+
118
+ if (!existing) {
119
+ uniqueDevices.set(device.model, device);
120
+ continue;
121
+ }
122
+
123
+ const existingIsDirect = /^\d{1,3}(?:\.\d{1,3}){3}:\d+$/.test(
124
+ existing.serial,
125
+ );
126
+
127
+ const currentIsDirect = /^\d{1,3}(?:\.\d{1,3}){3}:\d+$/.test(device.serial);
128
+
129
+ if (currentIsDirect && !existingIsDirect) {
130
+ uniqueDevices.set(device.model, device);
131
+ }
132
+ }
133
+
134
+ return [...uniqueDevices.values()];
135
+ }
136
+
137
+ async function selectAndroidTarget(type, allowMissing = false) {
138
+ const devices = getAndroidDevices();
139
+
140
+ if (devices === null) {
141
+ if (allowMissing) {
142
+ return null;
143
+ }
144
+
145
+ throw new Error(
146
+ 'Android SDK or ADB not found. Install Android SDK and configure ANDROID_HOME.',
147
+ );
148
+ }
149
+
150
+ const targets = devices.filter(
151
+ device => device.type === type && device.state === 'device',
152
+ );
153
+
154
+ if (targets.length === 0) {
155
+ const unavailable = devices.filter(device => device.type === type);
156
+
157
+ if (unavailable.length > 0) {
158
+ console.error(`\nFound an Android ${type}, but it isn't ready:`);
159
+
160
+ unavailable.forEach(device => {
161
+ console.error(` ${device.serial}: ${device.state}`);
162
+ });
163
+
164
+ throw new Error(
165
+ 'Check the device connection and USB debugging authorization.',
166
+ );
167
+ }
168
+
169
+ if (allowMissing) {
170
+ return null;
171
+ }
172
+
173
+ throw new Error(
174
+ type === 'emulator'
175
+ ? 'No Android emulator found. Start an emulator first.'
176
+ : 'No Android phone found. Connect your phone using USB or wireless debugging.',
177
+ );
178
+ }
179
+
180
+ if (targets.length === 1) {
181
+ return targets[0];
182
+ }
183
+
184
+ console.log(`\nMultiple Android ${type}s found:\n`);
185
+
186
+ targets.forEach((device, index) => {
187
+ console.log(` ${index + 1}. ${device.model} (${device.serial})`);
188
+ });
189
+
190
+ const rl = readline.createInterface({
191
+ input: process.stdin,
192
+ output: process.stdout,
193
+ });
194
+
195
+ try {
196
+ const answer = await rl.question('\nSelect a device: ');
197
+ const index = Number(answer) - 1;
198
+
199
+ if (!Number.isInteger(index) || !targets[index]) {
200
+ throw new Error('Invalid device selection.');
201
+ }
202
+
203
+ return targets[index];
204
+ } finally {
205
+ rl.close();
206
+ }
207
+ }
208
+
209
+ // --------------------------------------------------
210
+ // Android APK building and installation
211
+ // --------------------------------------------------
212
+
213
+ function buildAndroidApk() {
214
+ const gradleWrapper = path.join(
215
+ androidDirectory,
216
+ process.platform === 'win32' ? 'gradlew.bat' : 'gradlew',
217
+ );
218
+
219
+ if (!fs.existsSync(gradleWrapper)) {
220
+ throw new Error('Android Gradle wrapper not found.');
221
+ }
222
+
223
+ console.log('\nBuilding Android debug APK...\n');
224
+
225
+ const result =
226
+ process.platform === 'win32'
227
+ ? spawnSync('cmd.exe', ['/d', '/c', 'gradlew.bat app:assembleDebug'], {
228
+ cwd: androidDirectory,
229
+ stdio: 'inherit',
230
+ windowsHide: true,
231
+ })
232
+ : spawnSync(gradleWrapper, ['app:assembleDebug'], {
233
+ cwd: androidDirectory,
234
+ stdio: 'inherit',
235
+ });
236
+
237
+ if (result.error) {
238
+ throw result.error;
239
+ }
240
+
241
+ if (result.status !== 0) {
242
+ throw new Error('Android APK build failed.');
243
+ }
244
+
245
+ return path.join(
246
+ androidDirectory,
247
+ 'app',
248
+ 'build',
249
+ 'outputs',
250
+ 'apk',
251
+ 'debug',
252
+ 'app-debug.apk',
253
+ );
254
+ }
255
+
256
+ function installApk(device, apkPath) {
257
+ console.log(`\nInstalling APK on ${device.model}...\n`);
258
+
259
+ const output = runAdb(['-s', device.serial, 'install', '-r', apkPath]);
260
+
261
+ console.log(output);
262
+ }
263
+
264
+ // --------------------------------------------------
265
+ // App launching
266
+ // --------------------------------------------------
267
+
268
+ function launchApp(device) {
269
+ console.log(`\nLaunching Beever app on ${device.model}...\n`);
270
+
271
+ const output = runAdb([
272
+ '-s',
273
+ device.serial,
274
+ 'shell',
275
+ 'monkey',
276
+ '-p',
277
+ applicationId,
278
+ '-c',
279
+ 'android.intent.category.LAUNCHER',
280
+ '1',
281
+ ]);
282
+
283
+ console.log(output);
284
+ }
285
+
286
+ // --------------------------------------------------
287
+ // Metro detection
288
+ // --------------------------------------------------
289
+
290
+ function isMetroRunning(port) {
291
+ return new Promise(resolve => {
292
+ const request = http.get(`http://127.0.0.1:${port}/status`, response => {
293
+ let body = '';
294
+
295
+ response.on('data', chunk => {
296
+ body += chunk;
297
+ });
298
+
299
+ response.on('end', () => {
300
+ resolve(
301
+ response.statusCode === 200 &&
302
+ body.includes('packager-status:running'),
303
+ );
304
+ });
305
+ });
306
+
307
+ request.setTimeout(2000, () => {
308
+ request.destroy();
309
+ resolve(false);
310
+ });
311
+
312
+ request.on('error', () => resolve(false));
313
+ });
314
+ }
315
+
316
+ function isPortAvailable(port) {
317
+ return new Promise(resolve => {
318
+ const server = net.createServer();
319
+
320
+ server.once('error', () => resolve(false));
321
+
322
+ server.once('listening', () => {
323
+ server.close(() => resolve(true));
324
+ });
325
+
326
+ server.listen(port, '127.0.0.1');
327
+ });
328
+ }
329
+
330
+ async function waitForMetro(child) {
331
+ const startedAt = Date.now();
332
+
333
+ while (Date.now() - startedAt < 60000) {
334
+ if (child.exitCode !== null || child.signalCode !== null) {
335
+ throw new Error('Metro stopped before it became ready.');
336
+ }
337
+
338
+ if (await isMetroRunning(metroPort)) {
339
+ return;
340
+ }
341
+
342
+ await new Promise(resolve => setTimeout(resolve, 500));
343
+ }
344
+
345
+ throw new Error('Metro did not start within 60 seconds.');
346
+ }
347
+
348
+ async function startMetro() {
349
+ if (await isMetroRunning(metroPort)) {
350
+ console.log(`\nMetro is already running on port ${metroPort}.`);
351
+ console.log('Reusing the existing Metro server.');
352
+ return;
353
+ }
354
+
355
+ if (!(await isPortAvailable(metroPort))) {
356
+ throw new Error(
357
+ `Port ${metroPort} is occupied by another application. ` +
358
+ 'Close that application before starting Beever.',
359
+ );
360
+ }
361
+
362
+ const cliPath = path.join(
363
+ projectRoot,
364
+ 'node_modules',
365
+ 'react-native',
366
+ 'cli.js',
367
+ );
368
+
369
+ if (!fs.existsSync(cliPath)) {
370
+ throw new Error('React Native CLI not found. Run npm install first.');
371
+ }
372
+
373
+ console.log(`\nStarting Metro on port ${metroPort}...\n`);
374
+
375
+ const child = spawn(
376
+ process.execPath,
377
+ [cliPath, 'start', '--port', String(metroPort), '--host', '0.0.0.0'],
378
+ {
379
+ cwd: projectRoot,
380
+ stdio: 'inherit',
381
+ windowsHide: true,
382
+ },
383
+ );
384
+
385
+ let spawnError = null;
386
+
387
+ child.on('error', error => {
388
+ spawnError = error;
389
+ });
390
+
391
+ try {
392
+ await waitForMetro(child);
393
+ } catch (error) {
394
+ if (spawnError) {
395
+ throw spawnError;
396
+ }
397
+
398
+ throw error;
399
+ }
400
+
401
+ console.log('\nMetro is ready!');
402
+ }
403
+
404
+ // --------------------------------------------------
405
+ // Local network detection
406
+ // --------------------------------------------------
407
+
408
+ function getLocalIPv4Addresses() {
409
+ const interfaces = os.networkInterfaces();
410
+ const addresses = [];
411
+
412
+ for (const entries of Object.values(interfaces)) {
413
+ for (const entry of entries || []) {
414
+ const isIPv4 = entry.family === 'IPv4' || entry.family === 4;
415
+
416
+ if (!isIPv4 || entry.internal) {
417
+ continue;
418
+ }
419
+
420
+ const address = entry.address;
421
+
422
+ const isPrivate =
423
+ /^10\./.test(address) ||
424
+ /^192\.168\./.test(address) ||
425
+ /^172\.(1[6-9]|2\d|3[01])\./.test(address);
426
+
427
+ if (isPrivate && !addresses.includes(address)) {
428
+ addresses.push(address);
429
+ }
430
+ }
431
+ }
432
+
433
+ return addresses;
434
+ }
435
+
436
+ function showWifiInstructions() {
437
+ const addresses = getLocalIPv4Addresses();
438
+
439
+ console.log('\n--------------------------------------------');
440
+ console.log(' BEEVER WI-FI DEVELOPMENT');
441
+ console.log('--------------------------------------------');
442
+
443
+ console.log('\nNo ADB-connected phone was detected.');
444
+ console.log('Metro is running and ready for a Wi-Fi connection.');
445
+
446
+ if (addresses.length === 0) {
447
+ console.log('\nCould not automatically detect your local IPv4 address.');
448
+ console.log('Run ipconfig on Windows to find your Wi-Fi IPv4 address.');
449
+ } else {
450
+ console.log('\nAvailable Metro addresses:\n');
451
+
452
+ addresses.forEach(address => {
453
+ console.log(` ${address}:${metroPort}`);
454
+ });
455
+ }
456
+
457
+ console.log('\nOn your Android phone:');
458
+ console.log(' 1. Connect to the same Wi-Fi network as your computer.');
459
+ console.log(' 2. Open your installed Beever app.');
460
+ console.log(' 3. Open the React Native Developer Menu.');
461
+ console.log(' 4. Select Settings.');
462
+ console.log(' 5. Open Debug server host & port for device.');
463
+ console.log(' 6. Enter your computer IP address and port.');
464
+ console.log(` Example: 192.168.1.52:${metroPort}`);
465
+ console.log(' 7. Return to the app and reload it.');
466
+
467
+ console.log('\nKeep this terminal open while developing.');
468
+ console.log(
469
+ 'Make sure your firewall allows Node.js on your private network.',
470
+ );
471
+ console.log('--------------------------------------------\n');
472
+ }
473
+
474
+ // --------------------------------------------------
475
+ // Device-to-Metro connection
476
+ // --------------------------------------------------
477
+
478
+ function connectDeviceToMetro(device) {
479
+ console.log(`\nConnecting ${device.model} to Metro...\n`);
480
+
481
+ runAdb([
482
+ '-s',
483
+ device.serial,
484
+ 'reverse',
485
+ `tcp:${metroPort}`,
486
+ `tcp:${metroPort}`,
487
+ ]);
488
+
489
+ console.log(`Device connected to Metro on port ${metroPort}.`);
490
+ }
491
+
492
+ // --------------------------------------------------
493
+ // Install commands
494
+ // --------------------------------------------------
495
+
496
+ async function installEmulator() {
497
+ const device = await selectAndroidTarget('emulator');
498
+ const apkPath = buildAndroidApk();
499
+
500
+ installApk(device, apkPath);
501
+
502
+ console.log('\nBeever app successfully installed on the emulator!');
503
+ }
504
+
505
+ async function installDevice() {
506
+ const device = await selectAndroidTarget('device');
507
+ const apkPath = buildAndroidApk();
508
+
509
+ installApk(device, apkPath);
510
+
511
+ console.log('\nBeever app successfully installed on the phone!');
512
+ }
513
+
514
+ // --------------------------------------------------
515
+ // Development commands
516
+ // --------------------------------------------------
517
+
518
+ async function developEmulator() {
519
+ const device = await selectAndroidTarget('emulator');
520
+
521
+ await startMetro();
522
+
523
+ connectDeviceToMetro(device);
524
+ launchApp(device);
525
+
526
+ console.log('\nBeever is running on the emulator!');
527
+ }
528
+
529
+ async function developDevice() {
530
+ const device = await selectAndroidTarget('device', true);
531
+
532
+ await startMetro();
533
+
534
+ if (!device) {
535
+ showWifiInstructions();
536
+ return;
537
+ }
538
+
539
+ connectDeviceToMetro(device);
540
+ launchApp(device);
541
+
542
+ console.log('\nBeever is running on the phone!');
543
+ }
544
+
545
+ // --------------------------------------------------
546
+ // Command registration
547
+ // --------------------------------------------------
548
+
549
+ const commands = {
550
+ 'install:emulator': installEmulator,
551
+ 'install:device': installDevice,
552
+ emulator: developEmulator,
553
+ device: developDevice,
554
+ };
555
+
556
+ const command = process.argv[2];
557
+
558
+ if (!command || !commands[command]) {
559
+ console.error(
560
+ '\nUnknown Android command.\n\n' +
561
+ 'Available commands:\n' +
562
+ ' install:emulator\n' +
563
+ ' install:device\n' +
564
+ ' emulator\n' +
565
+ ' device\n',
566
+ );
567
+
568
+ process.exit(1);
569
+ }
570
+
571
+ commands[command]().catch(error => {
572
+ console.error(`\nAndroid error: ${error.message}`);
573
+ process.exit(1);
574
+ });
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "jsx": "react-jsx",
7
+ "noEmit": true,
8
+ "noCheck": true
9
+ },
10
+ "include": ["**/*.ts", "**/*.tsx"]
11
+ }