Ignite: Feature request: Support for --package option for ignite new command

Created on 22 May 2017  Â·  7Comments  Â·  Source: infinitered/ignite

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,

Hacktoberfest enhancement help wanted

All 7 comments

Agree, thanks @rostislav-simonik .

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

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

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"

@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`)
  }

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

Any update on this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GantMan picture GantMan  Â·  3Comments

GantMan picture GantMan  Â·  3Comments

tayfunyasar picture tayfunyasar  Â·  3Comments

lichao0817 picture lichao0817  Â·  3Comments

GantMan picture GantMan  Â·  3Comments