From 8b3642f8f43018307bdb0a152f3dcc652c978a04 Mon Sep 17 00:00:00 2001 From: Yauhen Date: Thu, 29 Aug 2019 13:25:42 +0300 Subject: [PATCH] refactor(framework): install-templates functionality return * refactor(framework): install-templates functionality return Authored-By: Artur Yorsh <10753921+artyorsh@users.noreply.github.com> --- README.md | 28 ++------ .../getting-started/where-to-start.md | 7 +- docs/src/articles/guides/install-existing.md | 37 ++++++++++ docs/src/articles/guides/install-new.md | 30 ++++++++ docs/src/articles/guides/install.md | 54 -------------- docs/src/structure.ts | 15 +++- .../template-ui-kitten-typescript/App.tsx | 39 ++++++++++ .../_tsconfig.json | 15 ++++ .../dependencies.json | 4 ++ .../devDependencies.json | 7 ++ .../template-ui-kitten-typescript/install.js | 72 +++++++++++++++++++ .../jest.config.js | 4 ++ .../package.json | 22 ++++++ src/templates/template-ui-kitten/App.js | 39 ++++++++++ .../template-ui-kitten/dependencies.json | 4 ++ src/templates/template-ui-kitten/package.json | 18 +++++ tsconfig.dev.json | 1 - 17 files changed, 314 insertions(+), 82 deletions(-) create mode 100644 docs/src/articles/guides/install-existing.md create mode 100644 docs/src/articles/guides/install-new.md delete mode 100644 docs/src/articles/guides/install.md create mode 100644 src/templates/template-ui-kitten-typescript/App.tsx create mode 100644 src/templates/template-ui-kitten-typescript/_tsconfig.json create mode 100644 src/templates/template-ui-kitten-typescript/dependencies.json create mode 100644 src/templates/template-ui-kitten-typescript/devDependencies.json create mode 100644 src/templates/template-ui-kitten-typescript/install.js create mode 100644 src/templates/template-ui-kitten-typescript/jest.config.js create mode 100644 src/templates/template-ui-kitten-typescript/package.json create mode 100644 src/templates/template-ui-kitten/App.js create mode 100644 src/templates/template-ui-kitten/dependencies.json create mode 100644 src/templates/template-ui-kitten/package.json diff --git a/README.md b/README.md index e50834a06..cf89c012e 100644 --- a/README.md +++ b/README.md @@ -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 = () => ( - - - -); - -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: @@ -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 diff --git a/docs/src/articles/getting-started/where-to-start.md b/docs/src/articles/getting-started/where-to-start.md index c7d2766fc..47ebe4690 100644 --- a/docs/src/articles/getting-started/where-to-start.md +++ b/docs/src/articles/getting-started/where-to-start.md @@ -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. +
## I'm new to React Native or mobile development diff --git a/docs/src/articles/guides/install-existing.md b/docs/src/articles/guides/install-existing.md new file mode 100644 index 000000000..cd44c2af0 --- /dev/null +++ b/docs/src/articles/guides/install-existing.md @@ -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. + +
+ +## Install UI Kitten and Eva Design System + +```bash +npm i react-native-ui-kitten @eva-design/eva +``` + +
+ +## 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 = () => ( + + + +); + +export default App; +``` + +That's it. UI Kitten is ready now. diff --git a/docs/src/articles/guides/install-new.md b/docs/src/articles/guides/install-new.md new file mode 100644 index 000000000..782458341 --- /dev/null +++ b/docs/src/articles/guides/install-new.md @@ -0,0 +1,30 @@ +# Starting a new App + +If you don't have any code yet, please consider checking React Native Getting Started documentation for help creating your app. + +
+ +## Installation + +First of all, you should have React Native CLI installed. + +```bash +npm i -g react-native-cli +``` + +
+ +## 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. diff --git a/docs/src/articles/guides/install.md b/docs/src/articles/guides/install.md deleted file mode 100644 index 678221eb3..000000000 --- a/docs/src/articles/guides/install.md +++ /dev/null @@ -1,54 +0,0 @@ -# Install UI Kitten - -If you don't have any code yet, please consider checking React Native Getting Started documentation for help creating your app. - -
- -## Installation - -We recommend to develop React Native with expo-cli, you can install it with the following command. - -```bash -npm i -g expo-cli -``` - -
- -## Create a New Project - -A new project can be created using Expo CLI tools. - -```bash -expo init PROJECT-NAME -``` -
- -## Install UI Kitten and Eva Design System - -```bash -npm i react-native-ui-kitten @eva-design/eva -``` - -
- -## Configure Application Root - -At this step you have everything in place, let's configure UI Kitten to be used in your app. - -```js -import * as React from 'react'; -import { mapping, light as lightTheme } from '@eva-design/eva'; -import { ApplicationProvider, Layout } from 'react-native-ui-kitten'; - -const App = () => ( - - - -); - -export default App; -``` - -That's it. UI Kitten is ready now. diff --git a/docs/src/structure.ts b/docs/src/structure.ts index 6616fb224..b1178dd0f 100644 --- a/docs/src/structure.ts +++ b/docs/src/structure.ts @@ -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', }, ], }, diff --git a/src/templates/template-ui-kitten-typescript/App.tsx b/src/templates/template-ui-kitten-typescript/App.tsx new file mode 100644 index 000000000..6c6d0ebc5 --- /dev/null +++ b/src/templates/template-ui-kitten-typescript/App.tsx @@ -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 = () => ( + + + + Welcome to UI Kitten 😻 + + + Start with editing App.tsx to configure your App + + + For example, try changing theme to Dark by simply changing an import + + + +); + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + }, + text: { + textAlign: 'center', + }, +}); + +export default App; diff --git a/src/templates/template-ui-kitten-typescript/_tsconfig.json b/src/templates/template-ui-kitten-typescript/_tsconfig.json new file mode 100644 index 000000000..1bfc717a7 --- /dev/null +++ b/src/templates/template-ui-kitten-typescript/_tsconfig.json @@ -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"] +} diff --git a/src/templates/template-ui-kitten-typescript/dependencies.json b/src/templates/template-ui-kitten-typescript/dependencies.json new file mode 100644 index 000000000..0fbfce8a2 --- /dev/null +++ b/src/templates/template-ui-kitten-typescript/dependencies.json @@ -0,0 +1,4 @@ +{ + "@eva-design/eva": "^1.0.1", + "react-native-ui-kitten": "^4.1.0" +} diff --git a/src/templates/template-ui-kitten-typescript/devDependencies.json b/src/templates/template-ui-kitten-typescript/devDependencies.json new file mode 100644 index 000000000..4846c5445 --- /dev/null +++ b/src/templates/template-ui-kitten-typescript/devDependencies.json @@ -0,0 +1,7 @@ +{ + "@types/jest": "latest", + "@types/react-native": "latest", + "@types/react-test-renderer": "latest", + "@types/react": "latest", + "typescript": "latest" +} diff --git a/src/templates/template-ui-kitten-typescript/install.js b/src/templates/template-ui-kitten-typescript/install.js new file mode 100644 index 000000000..7b166cdc6 --- /dev/null +++ b/src/templates/template-ui-kitten-typescript/install.js @@ -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); diff --git a/src/templates/template-ui-kitten-typescript/jest.config.js b/src/templates/template-ui-kitten-typescript/jest.config.js new file mode 100644 index 000000000..4ee5f1683 --- /dev/null +++ b/src/templates/template-ui-kitten-typescript/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + preset: 'react-native', + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], +}; diff --git a/src/templates/template-ui-kitten-typescript/package.json b/src/templates/template-ui-kitten-typescript/package.json new file mode 100644 index 000000000..7dedf86e9 --- /dev/null +++ b/src/templates/template-ui-kitten-typescript/package.json @@ -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 ", + "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" + } +} diff --git a/src/templates/template-ui-kitten/App.js b/src/templates/template-ui-kitten/App.js new file mode 100644 index 000000000..152e0ebfb --- /dev/null +++ b/src/templates/template-ui-kitten/App.js @@ -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 = () => ( + + + + Welcome to UI Kitten 😻 + + + Start with editing App.js to configure your App + + + For example, try changing theme to Dark by simply changing an import + + + +); + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + }, + text: { + textAlign: 'center', + }, +}); + +export default App; diff --git a/src/templates/template-ui-kitten/dependencies.json b/src/templates/template-ui-kitten/dependencies.json new file mode 100644 index 000000000..0fbfce8a2 --- /dev/null +++ b/src/templates/template-ui-kitten/dependencies.json @@ -0,0 +1,4 @@ +{ + "@eva-design/eva": "^1.0.1", + "react-native-ui-kitten": "^4.1.0" +} diff --git a/src/templates/template-ui-kitten/package.json b/src/templates/template-ui-kitten/package.json new file mode 100644 index 000000000..210b72e1a --- /dev/null +++ b/src/templates/template-ui-kitten/package.json @@ -0,0 +1,18 @@ +{ + "name": "react-native-template-ui-kitten", + "description": "React Native template with UI Kitten", + "version": "4.1.0", + "license": "MIT", + "author": "akveo ", + "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", + "template", + "boilerplate" + ] +} diff --git a/tsconfig.dev.json b/tsconfig.dev.json index 7d790e923..352a2bcf5 100644 --- a/tsconfig.dev.json +++ b/tsconfig.dev.json @@ -5,7 +5,6 @@ "jsx": "react-native", "target": "es2015", "lib": [ - "dom", "es2018" ] },