Skip to content

Commit

Permalink
refactor(framework): install-templates functionality return
Browse files Browse the repository at this point in the history
* refactor(framework): install-templates functionality return

Authored-By: Artur Yorsh <10753921+artyorsh@users.noreply.github.com>
  • Loading branch information
32penkin committed Aug 29, 2019
1 parent 573d76c commit 8b3642f
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 82 deletions.
28 changes: 5 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,14 @@ There is a huge variety of customizable layouts, use “as is” or add new bloc

## Quick Start

Install UI Kitten and Eva Design System packages via npm:
Start a new app with UI Kitten template from a scratch:

```bash
npm i react-native-ui-kitten @eva-design/eva
react-native init AwesomeApp --template ui-kitten
```

Modify your application root:

```jsx
import React from 'react';
import { mapping, light as lightTheme } from '@eva-design/eva';
import { ApplicationProvider, Layout } from 'react-native-ui-kitten';

const App = () => (
<ApplicationProvider
mapping={mapping}
theme={lightTheme}>
<Layout style={{flex: 1}}/>
</ApplicationProvider>
);

export default App;
```

The code above will configure your application component to apply Eva Design System styling magic.
Read the [Design System guide][link:doc-theme-system] for more details.
This will setup a new React Native application configured with UI Kitten.
Refer to the [Documentation][link:doc-where-start] for more options to start.

## How can I support the developers?
- Star our GitHub repo :star:
Expand All @@ -83,7 +65,7 @@ We're always happy to receive your feedback!
[link:travis]: https://travis-ci.com/akveo/react-native-ui-kitten
[link:coveralls]: https://coveralls.io/github/akveo/react-native-ui-kitten?branch=master
[link:doc-homepage]: https://akveo.github.io/react-native-ui-kitten
[link:doc-theme-system]: https://akveo.github.io/react-native-ui-kitten/docs/design-system/eva-design-system-intro
[link:doc-where-start]: https://akveo.github.io/react-native-ui-kitten/docs/getting-started/where-to-start
[link:kitten-tricks]: https://github.com/akveo/kittenTricks
[link:eva-icons]: https://github.com/akveo/eva-icons
[link:akveo-homepage]: https://akveo.com
Expand Down
7 changes: 5 additions & 2 deletions docs/src/articles/getting-started/where-to-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ UI Kitten is a framework of UI components powered by Eva Design System for your

## Quick start tutorials

**[Install UI Kitten](guides/install-ui-kitten)**
- **[Start a new App](guides/start-a-new-app)**

This tutorial explains how to setup React Native app with UI Kitten.
This tutorial explains how to setup React Native app with UI Kitten from a scratch.

- **[Install into existing App](guides/install-into-existing-app)**

Please consider creating an issue on GitHub if your use case is not described above. But we kindly ask to always look through the documentation and the list of existing issues first.


<hr>

## I'm new to React Native or mobile development
Expand Down
37 changes: 37 additions & 0 deletions docs/src/articles/guides/install-existing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Add into existing project

If you already have an existing code base, you're able to give UI Kitten a try as simple as `npm install`. Please refer to [Start a new App Guide](guides/start-a-new-app) if you don't have any code yet.

<hr>

## Install UI Kitten and Eva Design System

```bash
npm i react-native-ui-kitten @eva-design/eva
```

<hr>

## Configure Application Root

At this step you have everything in place, let's configure UI Kitten to be used in your app.
In your **App.js**:

```js
import React from 'react';
import { mapping, light as lightTheme } from '@eva-design/eva';
import { ApplicationProvider } from 'react-native-ui-kitten';
import { RootComponent } from '../path-to/root.component'; // <-- Import your application entry point

const App = () => (
<ApplicationProvider
mapping={mapping}
theme={lightTheme}>
<RootComponent />
</ApplicationProvider>
);

export default App;
```

That's it. UI Kitten is ready now.
30 changes: 30 additions & 0 deletions docs/src/articles/guides/install-new.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Starting a new App

If you don't have any code yet, please consider checking <a href="https://facebook.github.io/react-native/docs/getting-started" target="_blank">React Native Getting Started</a> documentation for help creating your app.

<hr>

## Installation

First of all, you should have React Native CLI installed.

```bash
npm i -g react-native-cli
```

<hr>

## Create a New Project

A new project can be created using React Native CLI tools ant UI Kitten template.

```bash
react-native init AwesomeApp --template ui-kitten
```

Or, if you want to init with TypeScript:
```bash
react-native init --template ui-kitten-typescript
```

That's it. UI Kitten is ready now. For the next steps, simply follow command line instructions.
54 changes: 0 additions & 54 deletions docs/src/articles/guides/install.md

This file was deleted.

15 changes: 13 additions & 2 deletions docs/src/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@ export const structure = [
children: [
{
type: 'page',
name: 'Install UI Kitten',
name: 'Start a new App',
children: [
{
type: 'block',
block: 'markdown',
source: 'guides/install.md',
source: 'guides/install-new.md',
},
],
},
{
type: 'page',
name: 'Install into existing App',
children: [
{
type: 'block',
block: 'markdown',
source: 'guides/install-existing.md',
},
],
},
Expand Down
39 changes: 39 additions & 0 deletions src/templates/template-ui-kitten-typescript/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @license
* Copyright Akveo. All Rights Reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import React from 'react';
import { StyleSheet } from 'react-native';
import { ApplicationProvider, Layout, Text } from 'react-native-ui-kitten';
import { mapping, light as theme } from '@eva-design/eva';

const App = () => (
<ApplicationProvider mapping={mapping} theme={theme}>
<Layout style={styles.container}>
<Text style={styles.text} category='h1'>
Welcome to UI Kitten 😻
</Text>
<Text style={styles.text} category='s1'>
Start with editing App.tsx to configure your App
</Text>
<Text style={styles.text} appearance='hint'>
For example, try changing theme to Dark by simply changing an import
</Text>
</Layout>
</ApplicationProvider>
);

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
text: {
textAlign: 'center',
},
});

export default App;
15 changes: 15 additions & 0 deletions src/templates/template-ui-kitten-typescript/_tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react",
"lib": ["es6"],
"moduleResolution": "node",
"noEmit": true,
"strict": true,
"target": "esnext"
},
"exclude": ["node_modules", "babel.config.js", "metro.config.js", "jest.config.js"]
}
4 changes: 4 additions & 0 deletions src/templates/template-ui-kitten-typescript/dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"@eva-design/eva": "^1.0.1",
"react-native-ui-kitten": "^4.1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"@types/jest": "latest",
"@types/react-native": "latest",
"@types/react-test-renderer": "latest",
"@types/react": "latest",
"typescript": "latest"
}
72 changes: 72 additions & 0 deletions src/templates/template-ui-kitten-typescript/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* @license
* Copyright Akveo. All Rights Reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

/**
* Additional scripts needed to correctly setup a project.
* Based on https://github.com/react-native-community/react-native-template-typescript.
*
* Runs as install script on `npm install` and replaces self after everything is done.
*
* - Replaces useless .js files
* - Adds tsconfig.json
*/

const fs = require('fs');
const path = require('path');

if (fs.existsSync(path.join(__dirname, '.travis.yml'))) {
process.exit()
}

const projectFilesToDelete = [
'.flowconfig',
'App.js',
'__tests__/App-test.js',
];

const templateFilesToAdd = [
'_tsconfig.json',
];

const templateFilesToDelete = [
'install.js',
'_tsconfig.json',
];

const deleteFile = (filePath) => {
if (!fs.existsSync(filePath)) {
return
}

fs.unlinkSync(filePath)
};

const projectPath = path.join(__dirname, '..', '..');

const projectFilePath = (fileName) => {
return path.join(projectPath, fileName);
};

const templateFilePath = (fileName) => {
return path.join(__dirname, fileName);
};

const replaceTemplateFile = (fileName) => {
const newName = fileName.replace('_', '');
fs.copyFileSync(templateFilePath(fileName), templateFilePath(newName));
};

const deleteProjectFile = (fileName) => {
deleteFile(projectFilePath(fileName));
};

const deleteTemplateFile = (fileName) => {
deleteFile(templateFilePath(fileName));
};

templateFilesToAdd.forEach(replaceTemplateFile);
projectFilesToDelete.forEach(deleteProjectFile);
templateFilesToDelete.forEach(deleteTemplateFile);
4 changes: 4 additions & 0 deletions src/templates/template-ui-kitten-typescript/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'react-native',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
};
22 changes: 22 additions & 0 deletions src/templates/template-ui-kitten-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "react-native-template-ui-kitten-typescript",
"description": "React Native template with UI Kitten and TypeScript",
"version": "4.1.0",
"license": "MIT",
"author": "akveo <contact@akveo.com>",
"homepage": "https://github.com/akveo/react-native-ui-kitten#readme",
"repository": "git+https://github.com/akveo/react-native-ui-kitten.git",
"bugs": {
"url": "https://github.com/akveo/react-native-ui-kitten/issues"
},
"keywords": [
"react-native",
"ui-kitten",
"typescript",
"template",
"boilerplate"
],
"scripts": {
"install": "node install.js"
}
}

0 comments on commit 8b3642f

Please sign in to comment.