Lines 113-176javascript
115 createCommand.push('--verbose');
118 return createCommand;
121function checkHcaptchaLinked() {
122 return false; // https://stackoverflow.com/a/47403470/902217
125// Main function that takes parsed arguments and runs the necessary setup
126function main({ cliName, projectRelativeProjectPath, projectName, projectTemplate, packageManager, frameworkVersion, verbose, skipBuild }) {
127 console.warn(`Warning! Example project will be generated in '${path.dirname(process.cwd())}'`);
129 // Build the command to initialize the project
130 const createCommand = buildCreateCommand({ cliName, projectRelativeProjectPath, projectName, projectTemplate, packageManager, frameworkVersion });
132 // Run the project initialization command
133 console.log(`Running command: ${createCommand}`);
134 execSync(createCommand.join(' '), { stdio: 'inherit', shell: true, env: { ...process.env, PATH: cleanPathEnv() } });
136 const projectPath = path.join(process.cwd(), projectRelativeProjectPath);
137 const packageManagerOptions = { stdio: 'inherit', cwd: projectPath };
140 fs.unlinkSync(path.join(projectPath, 'App.tsx'));
141 fs.copyFileSync('Example.App.js', path.join(projectPath, 'App.js'));
142 fs.copyFileSync('Example.jest.config.js', path.join(projectPath, 'jest.config.js'));
143 fs.copyFileSync('Example.jest.setup.js', path.join(projectPath, 'jest.setup.js'));
145 // Install dependencies
146 const isHcaptchaLinked = checkHcaptchaLinked();
147 const mainPackage = '@hcaptcha/react-native-hcaptcha';
148 const libRoot = process.cwd();
149 const libPathFromProject = path.relative(projectPath, libRoot);
150 const projectPackage = JSON.parse(fs.readFileSync(path.join(projectPath, 'package.json'), 'utf8'));
151 const reactNativeVersion = projectPackage.dependencies['react-native'];
152 const peerPackages = 'react-native-webview';
153 const devPackages = `typescript @react-native/jest-preset@${reactNativeVersion}`;
155 console.warn('Installing dependencies...');
156 if (packageManager === 'yarn') {
157 execSync(`yarn add @hcaptcha/react-native-hcaptcha@file:${libPathFromProject}`, packageManagerOptions);
158 execSync(`yarn add --dev ${devPackages}`, packageManagerOptions);
HighRuntime Package Install
Package source invokes a package manager install command at runtime.
__scripts__/generate-example.jsView on unpkg · L156 159 execSync(`yarn add ${peerPackages}`, packageManagerOptions);
161 // https://github.com/facebook/react-native/issues/29977 - react-native doesn't work with symlinks so `cp` instead
162 const destLibDir = path.join(projectPath, 'react-native-hcaptcha');
163 const excludes = ['__e2e__/host', '__tests__', '__mocks__', 'node_modules', '.git', 'output', '.reassure'].map(e => `--exclude=${e}`).join(' ');
164 execSync(`rsync -a ${excludes} ${libRoot}/ ${destLibDir}/`, { stdio: 'inherit' });
165 execSync('npm i --save file:./react-native-hcaptcha', packageManagerOptions);
166 execSync(`npm i --save-dev ${devPackages}`, packageManagerOptions);
167 execSync(`npm i --save ${peerPackages}`, packageManagerOptions);
170 if (isHcaptchaLinked) {
171 execSync(`${packageManager} link ${mainPackage}`, packageManagerOptions);
176 if (platform() === 'darwin') {