{"version":3,"names":["installTemplatePackage","templateName","root","packageManager","logger","debug","PackageManager","init","silent","getYarnVersionIfAvailable","executeCommand","install","getTemplateConfig","templateSourceDir","configFilePath","path","resolve","fs","existsSync","CLIError","chalk","underline","dim","require","copyTemplate","templateDir","templatePath","regexStr","copyFiles","process","cwd","exclude","RegExp","replacePathSepForRegex","executePostInitScript","postInitScript","scriptPath","execa","stdio"],"sources":["../../../src/commands/init/template.ts"],"sourcesContent":["import execa from 'execa';\nimport path from 'path';\nimport {logger, CLIError} from '@react-native-community/cli-tools';\nimport * as PackageManager from '../../tools/packageManager';\nimport copyFiles from '../../tools/copyFiles';\nimport replacePathSepForRegex from '../../tools/replacePathSepForRegex';\nimport fs from 'fs';\nimport chalk from 'chalk';\nimport {getYarnVersionIfAvailable} from '../../tools/yarn';\nimport {executeCommand} from '../../tools/packageManager';\n\nexport type TemplateConfig = {\n placeholderName: string;\n templateDir: string;\n postInitScript?: string;\n titlePlaceholder?: string;\n};\n\nexport async function installTemplatePackage(\n templateName: string,\n root: string,\n packageManager: PackageManager.PackageManager,\n) {\n logger.debug(`Installing template from ${templateName}`);\n\n await PackageManager.init({\n packageManager,\n silent: true,\n root,\n });\n\n // React Native doesn't support PnP, so we need to set nodeLinker to node-modules. Read more here: https://github.com/react-native-community/cli/issues/27#issuecomment-1772626767\n\n if (packageManager === 'yarn' && getYarnVersionIfAvailable() !== null) {\n executeCommand('yarn', ['config', 'set', 'nodeLinker', 'node-modules'], {\n root,\n silent: true,\n });\n }\n\n return PackageManager.install([templateName], {\n packageManager,\n silent: true,\n root,\n });\n}\n\nexport function getTemplateConfig(\n templateName: string,\n templateSourceDir: string,\n): TemplateConfig {\n const configFilePath = path.resolve(\n templateSourceDir,\n 'node_modules',\n templateName,\n 'template.config.js',\n );\n\n logger.debug(`Getting config from ${configFilePath}`);\n if (!fs.existsSync(configFilePath)) {\n throw new CLIError(\n `Couldn't find the \"${configFilePath} file inside \"${templateName}\" template. Please make sure the template is valid.\n Read more: ${chalk.underline.dim(\n 'https://github.com/react-native-community/cli/blob/main/docs/init.md#creating-custom-template',\n )}`,\n );\n }\n return require(configFilePath);\n}\n\nexport async function copyTemplate(\n templateName: string,\n templateDir: string,\n templateSourceDir: string,\n) {\n const templatePath = path.resolve(\n templateSourceDir,\n 'node_modules',\n templateName,\n templateDir,\n );\n\n logger.debug(`Copying template from ${templatePath}`);\n let regexStr = path.resolve(templatePath, 'node_modules');\n await copyFiles(templatePath, process.cwd(), {\n exclude: [new RegExp(replacePathSepForRegex(regexStr))],\n });\n}\n\nexport function executePostInitScript(\n templateName: string,\n postInitScript: string,\n templateSourceDir: string,\n) {\n const scriptPath = path.resolve(\n templateSourceDir,\n 'node_modules',\n templateName,\n postInitScript,\n );\n\n logger.debug(`Executing post init script located ${scriptPath}`);\n\n return execa(scriptPath, {stdio: 'inherit'});\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;AACA;AACA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;AAA2D;AAAA;AAAA;AAUpD,eAAeA,sBAAsB,CAC1CC,YAAoB,EACpBC,IAAY,EACZC,cAA6C,EAC7C;EACAC,kBAAM,CAACC,KAAK,CAAE,4BAA2BJ,YAAa,EAAC,CAAC;EAExD,MAAMK,cAAc,CAACC,IAAI,CAAC;IACxBJ,cAAc;IACdK,MAAM,EAAE,IAAI;IACZN;EACF,CAAC,CAAC;;EAEF;;EAEA,IAAIC,cAAc,KAAK,MAAM,IAAI,IAAAM,+BAAyB,GAAE,KAAK,IAAI,EAAE;IACrE,IAAAC,6BAAc,EAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,cAAc,CAAC,EAAE;MACtER,IAAI;MACJM,MAAM,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