amis-rpc-design/node_modules/@react-native-community/cli/build/commands/init/editTemplate.js.map

1 line
15 KiB
Plaintext
Raw Normal View History

2023-10-07 19:42:30 +08:00
{"version":3,"names":["DEFAULT_TITLE_PLACEHOLDER","validatePackageName","packageName","packageNameParts","split","packageNameRegex","length","test","replaceNameInUTF8File","filePath","projectName","templateName","logger","debug","fileContent","fs","readFile","replacedFileContent","replace","RegExp","toLowerCase","writeFile","renameFile","oldName","newName","newFileName","path","join","dirname","basename","rename","shouldRenameFile","nameToReplace","includes","shouldIgnoreFile","match","isIosFile","UNDERSCORED_DOTFILES","processDotfiles","dotfile","find","e","undefined","createAndroidPackagePaths","pathParts","slice","pathToFolders","segmentsList","initialDir","process","cwd","chdir","rmdir","segment","mkdirSync","replacePlaceholderWithPackageName","placeholderName","placeholderTitle","cleanPackageName","walk","reverse","iosFile","stat","isDirectory","fileName","error","CLIError","changePlaceholderInTemplate","projectTitle","message"],"sources":["../../../src/commands/init/editTemplate.ts"],"sourcesContent":["import path from 'path';\nimport {CLIError, logger} from '@react-native-community/cli-tools';\nimport walk from '../../tools/walk';\n\n// We need `graceful-fs` behavior around async file renames on Win32.\n// `gracefulify` does not support patching `fs.promises`. Use `fs-extra`, which\n// exposes its own promise-based interface over `graceful-fs`.\nimport fs from 'fs-extra';\n\ninterface PlaceholderConfig {\n projectName: string;\n placeholderName: string;\n placeholderTitle?: string;\n projectTitle?: string;\n packageName?: string;\n}\n\n/**\n TODO: This is a default placeholder for title in react-native template.\n We should get rid of this once custom templates adapt `placeholderTitle` in their configurations.\n*/\nconst DEFAULT_TITLE_PLACEHOLDER = 'Hello App Display Name';\n\nexport function validatePackageName(packageName: string) {\n const packageNameParts = packageName.split('.');\n const packageNameRegex = /^([a-zA-Z]([a-zA-Z0-9_])*\\.)+[a-zA-Z]([a-zA-Z0-9_])*$/u;\n\n if (packageNameParts.length < 2) {\n throw `The package name ${packageName} is invalid. It should contain at least two segments, e.g. com.app`;\n }\n\n if (!packageNameRegex.test(packageName)) {\n throw `The ${packageName} package name is not valid. It can contain only alphanumeric characters and dots.`;\n }\n}\n\nexport async function replaceNameInUTF8File(\n filePath: string,\n projectName: string,\n templateName: string,\n) {\n logger.debug(`Replacing in ${filePath}`);\n const fileContent = await fs.readFile(filePath, 'utf8');\n const replacedFileContent = fileContent\n .replace(new RegExp(templateName, 'g'), projectName)\n .replace(\n new RegExp(templateName.toLowerCase(), 'g'),\n projectName.toLowerCase(),\n );\n\n if (fileContent !== replacedFileContent) {\n await fs.writeFile(filePath, replacedFileContent, 'utf8');\n }\n}\n\nasync function renameFile(filePath: string, oldName: string, newName: string) {\n const newFileName = path.join(\n path.dirname(filePath),\n path.basename(filePath).replace(new RegExp(oldName, 'g'), newName),\n );\n\n logger.debug(`Renaming ${filePath} -> file:${newFileName}`);\n\n await fs.rename(filePath, newFileName);\n}\n\nfunction shouldRenameFile(filePath: string, nameToReplace: string) {\n return path.basename(filePath).includes(nameToReplace);\n}\n\nfunction shouldIgnoreFile(filePath: string) {\n return filePath.match(/node_modules|yarn.lock|package-lock.json/g);\n}\n\nfunction isIosFile(filePath: string) {\n return filePath.includes('ios');\n}\n\nconst UNDERSCORED_DOTFILES = [\n 'buckconfig',\n 'eslintrc.js',\n 'flowconfig',\n 'gitattributes',\n 'gitignore',\n 'prettierrc.js',\n 'watchmanconfig',\n 'editorconfig',\n 'bundle',\n 'ruby-version',\n 'node-version',\n 'xcode.env',\n];\n\nasync function processDotfiles(filePath: string) {\n const dotfile = UNDERSCORED_DOTFILES.find((e) => filePath.includes(`_${e}`));\n\n if (dotfile === undefined) {\n return;\n }\n\n await renameFile(filePath, `_${dotfile}`, `.${dotfile}`);\n}\n\nasyn