コード例 #1
0
ファイル: create.py プロジェクト: getsiphon/siphon-cli
def create(app_name, app_path):
    auth = Auth()

    # Create the app server-side
    siphon = Siphon(auth.auth_token)
    obj = siphon.create(app_name)
    app_id = obj['id']  # server gives us back our internal app ID

    # Populate our new directory with template files
    copy_app_template(app_name, app_path)

    # Write out a .siphon configuration to the new direcotry
    conf = Config(directory=app_name)
    conf.app_id = app_id

    # Copy our .siphonignore file over
    siphon_ignore = os.path.join(CLI_RESOURCES, '.siphonignore')
    shutil.copyfile(siphon_ignore, os.path.join(app_path, '.siphonignore'))
    puts(colored.green('Siphon app created at %s' % app_path))

    # Register Mixpanel event
    username = auth.username
    mixpanel_event(MIXPANEL_EVENT_CREATE, username, {'app_id': app_id,
                                                     'existing_app': False})

    # Write out the Siphonfile
    with open(os.path.join(app_name, SIPHON_USER_CONFIG), 'w') as fp:
        json.dump({'base_version': obj['base_version']}, fp, indent=2)

    # Implicitly do a push too
    with cd(app_path):
        from siphon.cli.commands.push import push
        push(track_event=False)
    puts(colored.green('Done.'))
コード例 #2
0
ファイル: create.py プロジェクト: getsiphon/siphon-cli
def init():
    auth = Auth()
    # Create the app server-side
    siphon = Siphon(auth.auth_token)
    print('Please enter a name for your Siphon app.')

    try:
        name_valid = False
        while not name_valid:
            app_name = get_input('App name: ')
            name_valid = app_name_valid(app_name)
            if not name_valid:
                print('Siphon app names may only contain letters, numbers, ' \
                      'underscores and hyphens.')
    except KeyboardInterrupt:
        sys.exit(1)

    obj = siphon.create(app_name)
    app_id = obj['id']  # server gives us back our internal app ID

    # Write out a .siphon configuration to the new directory
    conf = Config()
    conf.app_id = app_id

    # Copy our .siphonignore file over
    siphon_ignore = os.path.join(CLI_RESOURCES, '.siphonignore')
    shutil.copyfile(siphon_ignore, '.siphonignore')

    puts(colored.green('Siphon app created.'))

    # Register Mixpanel event
    username = auth.username
    mixpanel_event(MIXPANEL_EVENT_CREATE, username, {'app_id': app_id,
                                                     'existing_app': True})

    # Write out the Siphonfile
    with open(SIPHON_USER_CONFIG, 'w') as fp:
        json.dump({'base_version': obj['base_version']}, fp, indent=2)

    # Implicitly do a push too
    from siphon.cli.commands.push import push
    push(track_event=False)
    puts(colored.green('Done.'))

    # Print warning about mismatched React Native versions
    project_rn_version = node_module_version('node_modules/react-native')
    siphon_rn_version = obj['react_native_version']
    if project_rn_version != siphon_rn_version:
        puts(colored.yellow('Note: Siphon app is using React Native %s but ' \
            'existing project is using React Native %s.\n'\
            'Please visit https://getsiphon.com/docs/base-version/ to learn ' \
            'more about base versions.\n' %
                            (siphon_rn_version, project_rn_version)))

    if os.path.isfile('index.js'):
        print('You must register your component with the name \'App\'' \
              'in your index.js file to use Siphon.\n')
        if os.path.isfile('index.js'):
            print_app_registry_message('index.js')
    else:
        print('You must register your component with the name \'App\'' \
              'in your index.ios.js and index.android.js files ' \
              ' to use Siphon.\n')
        if os.path.isfile('index.ios.js'):
            print_app_registry_message('index.ios.js')
        if os.path.isfile('index.android.js'):
            print_app_registry_message('index.android.js')