infinitered / ignite

Infinite Red's battle-tested React Native project boilerplate, along with a CLI, component/model generators, and more! 9 years of continuous development and counting.
MIT License
17.71k stars 1.4k forks source link

Feature request: Support for --package option for ignite new command #1044

Closed rostislav-simonik closed 2 years ago

rostislav-simonik commented 7 years ago

Hello, I'd like ask you for --package=<package> support in ignite new command, which should result in react-native init <name> --package=<package> Thanks,

jamonholmgren commented 7 years ago

Agree, thanks @rostislav-simonik .

jamonholmgren commented 5 years ago

Still planning to add this (2 years later). :-)

rostislav-simonik commented 5 years ago

@jamonholmgren nevermind, we created bash script for time being.

jamonholmgren commented 5 years ago

What we need is the ability to pass through the --package CLI command to react-native init.

ignite new MyApp --package "com.infinitered.jamonapp"

This would run:

react-native init MyApp --package "com.infinitered.jamonapp"
rostislav-simonik commented 5 years ago

@jamonholmgren I think that command line option for react-native is not supported anymore. I've created shell scripts a time ago, but to be platform independent would be great to rewrite them into js.

#!/bin/bash
if [[ -z $1 || -z $2 ]]; then
    echo -e "missig package prefix"
    echo -e "usage: $0 <package_prefix> <destination>"
    echo -e "example: $0 com.company.group ./folder"
    echo -e "produces: com.company.group.project package & bundle id"
    exit 1
fi
package_prefix=$1
destination=$2
pushd $destination

TMP_FILE=`mktemp /tmp/sedfile.XXXXXXXXXX`

safe_recursive_sed () {
    search_pattern=$1
    sed_patern=$2
    path=$3

    for i in $(grep $search_pattern -Rl $path); do
        sed $sed_patern $i > $TMP_FILE
        mv $TMP_FILE $i
    done
}

# ios project
echo -e "\nchanging bundle id for ios project..."
echo -e "\torg.reactjs.native.example.<name> -> $package_prefix.<name>"
ios_pattern='org.reactjs.native.example.$(PRODUCT_NAME:'
safe_recursive_sed $ios_pattern 's/'$ios_pattern'/'$package_prefix'.$(PRODUCT_NAME:lower:/g' ios

# android project
echo -e "\nchanging package for android project..."
echo -e "\tcom.<name> -> $package_prefix.<name>\n"
name=$(sed -n 's/.*package="com.\(.*\)".*/\1/p'  android/app/src/main/AndroidManifest.xml)
package_prefix_path=$(echo $package_prefix | sed 's/\./\//g')
original_package='com.'$name
package=$package_prefix'.'$name

mkdir -p android/app/src/main/java/$package_prefix_path
if [ -d android/app/src/main/java/com ]; then
    mv android/app/src/main/java/com/* android/app/src/main/java/$package_prefix_path/
    safe_recursive_sed $original_package "s/$original_package/$package/g" android
    rm -rf android/app/src/main/java/com
fi
popd

and added to own boilerplate version like this

 const packagePrefix = parameters.options['package-prefix']

  if (packagePrefix) {
    spinner.text = `▸ setting up package prefix ${highlight(packagePrefix)}.${name.toLowerCase()}`
    spinner.start()
    await system.spawn(`${ignite.ignitePluginPath()}/scripts/change-package-name.sh ${packagePrefix} ${process.cwd()}`, { stdio: 'ignore' })
    spinner.stop()
    spinner.succeed(`package prefix ${highlight(packagePrefix)}.${name.toLowerCase()} set`)
  }
jamonholmgren commented 5 years ago

That's very interesting. I didn't know the react-native-cli doesn't support a custom package name.

archansel commented 4 years ago

Any update on this?

frankcalise commented 2 years ago

Package names are properly handled in the latest version of Ignite.

Closing as this is solved now, in both Vanilla and Expo