Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

feat(templates): Add Android template #73

Merged
merged 10 commits into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
618 changes: 618 additions & 0 deletions scripts/__snapshots__/e2e-templates.test.js.snap

Large diffs are not rendered by default.

41 changes: 23 additions & 18 deletions scripts/e2e-templates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,29 @@ describe('Templates', () => {
});

test('File content', () => {
generatedFiles.forEach(filePath => {
if (['.png', '.ico', '.jpg'].includes(filePath.slice(-4))) {
const image = fs.readFileSync(`${templatePath}/${filePath}`);

expect(image).toMatchImageSnapshot({
customSnapshotIdentifier: `e2e-installs-${
templateConfig.templateName
}-${path.basename(filePath)}`,
});
} else {
const fileContent = fs
.readFileSync(`${appPath}/${filePath}`)
.toString()
.trim();

expect(fileContent).toMatchSnapshot(filePath);
}
});
generatedFiles
.filter(filePath => !['.jar'].includes(filePath.slice(-4)))
.forEach(filePath => {
if (['.png', '.ico', '.jpg'].includes(filePath.slice(-4))) {
const image = fs.readFileSync(`${templatePath}/${filePath}`);

expect(image).toMatchImageSnapshot({
customSnapshotsDir: path.resolve(
`./scripts/__image_snapshots__/${
templateConfig.templateName
}/${path.dirname(filePath)}`
),
customSnapshotIdentifier: path.basename(filePath),
});
} else {
const fileContent = fs
.readFileSync(`${appPath}/${filePath}`)
.toString()
.trim();

expect(fileContent).toMatchSnapshot(filePath);
}
});
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/api/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Options with unknown template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch iOS, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;
exports[`Options with unknown template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch Android, InstantSearch iOS, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;

exports[`Options with unvalid name throws 1`] = `
"Could not create a project called \\"./WrongNpmName\\" because of npm naming restrictions.
- name cannot start with a period
- name can only contain URL-friendly characters"
`;

exports[`Options with wrong template path throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch iOS, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;
exports[`Options with wrong template path throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch Android, InstantSearch iOS, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;

exports[`Options without path throws 1`] = `"The option \`path\` is required."`;

exports[`Options without template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch iOS, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;
exports[`Options without template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch Android, InstantSearch iOS, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;
19 changes: 19 additions & 0 deletions src/tasks/android/teardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const chalk = require('chalk');

module.exports = function teardown(config) {
if (!config.silent) {
console.log();
console.log(
`🎉 Created ${chalk.bold.cyan(config.name)} at ${chalk.green(
config.path
)}.`
);
console.log();

console.log('Begin by opening the new project.');
console.log();
console.log('⚡️ Start building something awesome!');
}

return Promise.resolve();
};
19 changes: 12 additions & 7 deletions src/tasks/common/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@ module.exports = function build(config) {
// Add the `.hbs` extension to any templating files that need
// their placeholders to get filled with `metalsmith-in-place`
rename([
// `npx` renames `.gitignore` files to `.npmignore`
// See https://github.com/algolia/create-instantsearch-app/issues/48
['.gitignore.template', '.gitignore'],
[/\.md$/, '.md.hbs'],
[/\.json$/, '.json.hbs'],
// For the web
[/\.webmanifest$/, '.webmanifest.hbs'],
[/\.html$/, '.html.hbs'],
[/\.css$/, '.css.hbs'],
[/\.js$/, '.js.hbs'],
[/\.ts$/, '.ts.hbs'],
[/\.vue$/, '.vue.hbs'],
[/\.swift$/, '.swift.hbs'],
[/\.md$/, '.md.hbs'],
[/\.json$/, '.json.hbs'],
[/\.webmanifest$/, '.webmanifest.hbs'],
// Use `.babelrc.template` as name to not trigger babel
// when requiring the file `.template.js` in end-to-end tests
// and rename it `.babelrc` afterwards
['.babelrc.template', '.babelrc'],
// `npx` renames `.gitignore` files to `.npmignore`
// See https://github.com/algolia/create-instantsearch-app/issues/48
['.gitignore.template', '.gitignore'],
['.eslintrc.js.hbs', '.eslintrc.js'],
// For iOS
[/\.swift$/, '.swift.hbs'],
// For Android
[/\.java$/, '.java.hbs'],
[/\.xml$/, '.xml.hbs'],
])
)
.use(inPlace())
Expand Down
17 changes: 17 additions & 0 deletions src/templates/InstantSearch Android/.gitignore.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# IDE Files
*.iml
.idea/*
projectFilesBackup

# Build
.gradle
/.idea/workspace.xml
/.idea/libraries
/build
/captures

# Local setup
/local.properties

# OS Files
.DS_Store
11 changes: 11 additions & 0 deletions src/templates/InstantSearch Android/.template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const setup = require('../../tasks/ios/setup');
const install = require('../../tasks/ios/install');
const teardown = require('../../tasks/android/teardown');

module.exports = {
templateName: 'instantsearch-android',
appName: 'instantsearch-android-app',
tasks: {
teardown,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions src/templates/InstantSearch Android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apply plugin: 'com.android.application'

android {
dataBinding.enabled true
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.instantsearch.app"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.example:instantsearch-android:1.12.0'
testImplementation 'junit:junit:4.12'
}
25 changes: 25 additions & 0 deletions src/templates/InstantSearch Android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/pln/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.instantsearch.app;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.example.instantsearch.app", appContext.getPackageName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.instantsearch.app"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.instantsearch.app;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.example.instantsearch.helpers.Searcher;
import com.example.instantsearch.helpers.InstantSearch;

public class MainActivity extends AppCompatActivity {
private static final String ALGOLIA_APP_ID = "{{appId}}";
private static final String ALGOLIA_SEARCH_API_KEY = "{{apiKey}}";
private static final String ALGOLIA_INDEX_NAME = "{{indexName}}";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Searcher searcher = Searcher.create(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY, ALGOLIA_INDEX_NAME);
final InstantSearch helper = new InstantSearch(this, searcher);
helper.search(); // First empty search to display default results
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.instantsearch.app;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.example.instantsearch.helpers.Searcher;
import com.example.instantsearch.helpers.InstantSearch;

public class MainActivity extends AppCompatActivity {
private static final String ALGOLIA_APP_ID = "latency";
private static final String ALGOLIA_SEARCH_API_KEY = "3d9875e51fbd20c7754e65422f7ce5e1";
private static final String ALGOLIA_INDEX_NAME = "bestbuy";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Searcher searcher = Searcher.create(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY, ALGOLIA_INDEX_NAME);
final InstantSearch helper = new InstantSearch(this, searcher);
helper.search(); // First empty search to display default results
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/activity_main"
xmlns:algolia="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.instantsearch.app.MainActivity">

<com.example.instantsearch.ui.views.SearchBox
android:id="@+id/search_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"/>

<com.example.instantsearch.ui.views.Hits
android:id="@+id/hits"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/search_box"
algolia:itemLayout="@layout/hits_item"/>
</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:algolia="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/{{mainAttribute}}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="{{mainAttribute}}"
android:textSize="20sp"
algolia:attribute='@{"{{mainAttribute}}"}'
algolia:highlightColor="@color/colorAccent"
algolia:highlighted="@{true}"/>
</LinearLayout>
</layout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">{{name}}</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
Loading