create-react-native-library
Advanced tools
Comparing version 0.38.0-next.1 to 0.38.0
@@ -494,6 +494,6 @@ "use strict"; | ||
if (reactNativeVersion != null) { | ||
if (example === 'expo') { | ||
console.warn(`${_kleur.default.yellow('⚠')} Ignoring --react-native-version for Expo example`); | ||
if (example === 'vanilla') { | ||
console.log(`${_kleur.default.blue('ℹ')} Using ${_kleur.default.cyan(`react-native@${reactNativeVersion}`)} for the example`); | ||
} else { | ||
console.log(`${_kleur.default.blue('ℹ')} Using ${_kleur.default.cyan(`react-native@${reactNativeVersion}`)} for the example`); | ||
console.warn(`${_kleur.default.yellow('⚠')} Ignoring --react-native-version for unsupported example type: ${_kleur.default.cyan(example)}`); | ||
} | ||
@@ -507,5 +507,4 @@ } | ||
dest: folder, | ||
slug: options.project.slug, | ||
projectName: options.project.name, | ||
arch, | ||
project: options.project, | ||
reactNativeVersion | ||
@@ -556,12 +555,21 @@ }); | ||
} | ||
const rootPackageJson = await _fsExtra.default.readJson(_path.default.join(folder, 'package.json')); | ||
if (example !== 'none') { | ||
// Set `react` and `react-native` versions of root `package.json` from example `package.json` | ||
const examplePackageJson = await _fsExtra.default.readJSON(_path.default.join(folder, 'example', 'package.json')); | ||
const rootPackageJson = await _fsExtra.default.readJSON(_path.default.join(folder, 'package.json')); | ||
rootPackageJson.devDependencies.react = examplePackageJson.dependencies.react; | ||
rootPackageJson.devDependencies['react-native'] = examplePackageJson.dependencies['react-native']; | ||
await _fsExtra.default.writeJSON(_path.default.join(folder, 'package.json'), rootPackageJson, { | ||
spaces: 2 | ||
}); | ||
if (examplePackageJson.dependencies?.react && examplePackageJson.dependencies?.['react-native']) { | ||
rootPackageJson.devDependencies = rootPackageJson.devDependencies || {}; | ||
rootPackageJson.devDependencies.react = examplePackageJson.dependencies.react; | ||
rootPackageJson.devDependencies['react-native'] = examplePackageJson.dependencies['react-native']; | ||
} | ||
} | ||
// Some of the passed args can already be derived from the generated package.json file. | ||
const ignoredAnswers = ['name', 'slug', 'description', 'authorName', 'authorEmail', 'authorUrl', 'repoUrl', 'example', 'reactNativeVersion', 'local']; | ||
const libraryMetadata = Object.fromEntries(Object.entries(answers).filter(([answer]) => !ignoredAnswers.includes(answer))); | ||
libraryMetadata.version = _package.version; | ||
rootPackageJson['create-react-native-library'] = libraryMetadata; | ||
await _fsExtra.default.writeJson(_path.default.join(folder, 'package.json'), rootPackageJson, { | ||
spaces: 2 | ||
}); | ||
if (!local) { | ||
@@ -593,12 +601,2 @@ let isInGitRepo = false; | ||
} | ||
// Some of the passed args can already be derived from the generated package.json file. | ||
const ignoredAnswers = ['name', 'slug', 'description', 'authorName', 'authorEmail', 'authorUrl', 'repoUrl', 'example', 'reactNativeVersion', 'local']; | ||
const libraryMetadata = Object.fromEntries(Object.entries(answers).filter(([answer]) => !ignoredAnswers.includes(answer))); | ||
libraryMetadata.version = _package.version; | ||
const libraryPackageJson = await _fsExtra.default.readJson(_path.default.join(folder, 'package.json')); | ||
libraryPackageJson['create-react-native-library'] = libraryMetadata; | ||
await _fsExtra.default.writeJson(_path.default.join(folder, 'package.json'), libraryPackageJson, { | ||
spaces: 2 | ||
}); | ||
spinner.succeed(`Project created successfully at ${_kleur.default.yellow(_path.default.relative(process.cwd(), folder))}!\n`); | ||
@@ -605,0 +603,0 @@ if (local) { |
@@ -25,5 +25,4 @@ "use strict"; | ||
dest, | ||
slug, | ||
projectName, | ||
arch, | ||
project, | ||
reactNativeVersion = 'latest' | ||
@@ -34,6 +33,6 @@ }) { | ||
// `npx --package react-native-test-app@latest init --name ${projectName}Example --destination example --version ${reactNativeVersion}` | ||
const testAppArgs = ['--package', `react-native-test-app@latest`, 'init', '--name', `${projectName}Example`, `--destination`, directory, ...(reactNativeVersion !== 'latest' ? ['--version', reactNativeVersion] : []), '--platform', 'ios', '--platform', 'android']; | ||
const testAppArgs = ['--package', `react-native-test-app@latest`, 'init', '--name', `${project.name}Example`, `--destination`, directory, ...(reactNativeVersion !== 'latest' ? ['--version', reactNativeVersion] : []), '--platform', 'ios', '--platform', 'android']; | ||
// `npx react-native init <projectName> --directory example --skip-install` | ||
const vanillaArgs = [`react-native@${reactNativeVersion}`, 'init', `${projectName}Example`, '--directory', directory, '--version', reactNativeVersion, '--skip-install', '--npm']; | ||
const vanillaArgs = [`react-native@${reactNativeVersion}`, 'init', `${project.name}Example`, '--package-name', `${project.package}.example`, '--directory', directory, '--version', reactNativeVersion, '--skip-install', '--npm']; | ||
@@ -67,4 +66,4 @@ // `npx create-expo-app example --no-install --template blank` | ||
// Patch the example app's package.json | ||
const pkg = JSON.parse(await _fsExtra.default.readFile(_path.default.join(directory, 'package.json'), 'utf8')); | ||
pkg.name = `${slug}-example`; | ||
const pkg = await _fsExtra.default.readJSON(_path.default.join(directory, 'package.json')); | ||
pkg.name = `${project.slug}-example`; | ||
@@ -82,6 +81,24 @@ // Remove Jest config for now | ||
'build:android': 'react-native build-android --extra-params "--no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a"', | ||
'build:ios': `react-native build-ios --scheme ${projectName}Example --mode Debug --extra-params "-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO"` | ||
'build:ios': `react-native build-ios --scheme ${project.name}Example --mode Debug --extra-params "-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO"` | ||
}; | ||
if (type !== 'expo') { | ||
if (type === 'vanilla') { | ||
Object.assign(scripts, SCRIPTS_TO_ADD); | ||
} else if (type === 'test-app') { | ||
// `react-native-test-app` doesn't bundle application by default in 'Release' mode and also `bundle` command doesn't create a directory. | ||
// `mkdist` script should be removed after stable React Native major contains this fix: https://github.com/facebook/react-native/pull/45182. | ||
const androidBuild = ['npm run mkdist', 'react-native bundle --entry-file index.js --platform android --dev true --bundle-output dist/main.android.jsbundle --assets-dest dist', SCRIPTS_TO_ADD['build:android']].join(' && '); | ||
const iosBuild = ['npm run mkdist', 'react-native bundle --entry-file index.js --platform ios --dev true --bundle-output dist/main.ios.jsbundle --assets-dest dist', SCRIPTS_TO_ADD['build:android']].join(' && '); | ||
Object.assign(scripts, { | ||
'build:android': androidBuild, | ||
'build:ios': iosBuild | ||
}); | ||
const app = await _fsExtra.default.readJSON(_path.default.join(directory, 'app.json')); | ||
app.android = app.android || {}; | ||
app.android.package = `${project.package}.example`; | ||
app.ios = app.ios || {}; | ||
app.ios.bundleIdentifier = `${project.package}.example`; | ||
await _fsExtra.default.writeJSON(_path.default.join(directory, 'app.json'), app, { | ||
spaces: 2 | ||
}); | ||
} | ||
@@ -117,2 +134,10 @@ PACKAGES_TO_REMOVE.forEach(name => { | ||
scripts.web = 'expo start --web'; | ||
const app = await _fsExtra.default.readJSON(_path.default.join(directory, 'app.json')); | ||
app.expo.android = app.expo.android || {}; | ||
app.expo.android.package = `${project.package}.example`; | ||
app.expo.ios = app.expo.ios || {}; | ||
app.expo.ios.bundleIdentifier = `${project.package}.example`; | ||
await _fsExtra.default.writeJSON(_path.default.join(directory, 'app.json'), app, { | ||
spaces: 2 | ||
}); | ||
} | ||
@@ -119,0 +144,0 @@ await _fsExtra.default.writeJSON(_path.default.join(directory, 'package.json'), pkg, { |
{ | ||
"name": "create-react-native-library", | ||
"version": "0.38.0-next.1", | ||
"version": "0.38.0", | ||
"description": "CLI to scaffold React Native libraries", | ||
@@ -68,3 +68,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "1f98de6342f68958a465c34b6997b3aab5eae08c" | ||
"gitHead": "a1bc1bae766336e4e0473a50d44f90cbc0c59b77" | ||
} |
@@ -170,3 +170,3 @@ { | ||
{ | ||
"esm": true, | ||
"esm": true | ||
} | ||
@@ -176,3 +176,3 @@ ], | ||
{ | ||
"esm": true, | ||
"esm": true | ||
} | ||
@@ -179,0 +179,0 @@ ], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3547161
15395