zaf_react 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b7e2722c17c6ad651a3d5011fb2f3372c13011c134509edd3067df7693e13240
4
+ data.tar.gz: e21e51748596d4e5379abf6ac197bbd0f0f84098cb9c0d1947cea6ef99535ab3
5
+ SHA512:
6
+ metadata.gz: c58bfd1552542a03c1d53a31882e16e64c9e6f93b2da43237ca56f722c47d56745e70a0b5487cc871f817811ccc2791ec4d792bc3aca78cb4462c0951bb73bab
7
+ data.tar.gz: b1c5191ffa5b5b6f7566202b8e49273c3e280d044a5b5ae7cacf60113890a4d5c8b33181e843d2fdf9267cd2b21fe25aa4729ae0c5b0e60cbca9627e574263f9
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # ZAFReact
2
+
3
+ React for Zendesk App Framework V2.0
4
+
5
+ ## Requirements
6
+
7
+ NPM: Direct from [NPM](https://www.npmjs.com/get-npm) or install with [Homebrew](https://brew.sh)
8
+
9
+ $ brew install node
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'zaf_react'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install zaf_react
26
+
27
+ ## Usage
28
+
29
+ #### Initialize a new ZAF React App
30
+
31
+ $ zafr init
32
+
33
+ This will generate a very basic React app with an example component "src/components/item-list/item-list.js".
34
+
35
+ ---
36
+
37
+ #### Start the React server for local testing
38
+
39
+ $ zafr start
40
+
41
+ This will run the React server on [localhost:3000](http://localhost:3000).
42
+
43
+ ---
44
+
45
+ #### Compile a production build for React
46
+
47
+ $ zafr build
48
+
49
+ This will compile the React app into a production ready build. This will not run if uploaded to Zendesk. See below.
50
+
51
+ ---
52
+
53
+ #### Start the ZAT Server
54
+
55
+ $ zafr server
56
+
57
+ This will run the previous ```zafr build``` command, then start the ZAT Server for local testing in Zendesk. See Zendesk's docs here for using the ZAT server [here](https://developer.zendesk.com/apps/docs/developer-guide/zat#server).
58
+
59
+ ---
60
+
61
+ #### Validation
62
+
63
+ $ zafr validate
64
+
65
+ This will run the ```zat validate``` command in the ```/build``` directory to validate the ZAF V2.0 App.
66
+
67
+ ---
68
+
69
+ #### Package the full app for uploading to Zendesk
70
+
71
+ $ zafr package
72
+
73
+ This will run the above ```zafr build``` command, then flatten the React assets directory structure, and finally compile the entire app into a ZAF V2.0 app ready for upload to Zendesk. The uploadable .zip file can be found at ```/build/tmp/app-{timstamp}.zip```.
74
+
75
+ ---
76
+
77
+ ## ZAFClient
78
+
79
+ Zendesk's ZAFClient is not available outside of Zendesk. In order to allow local testing, without any need for Zendesk, use the file ```/source/src/zendesk/helpers/zaf_test_client.js```. There you can build methods to simulate the ZAFClient functionality away from the Zendesk environment. The ZAF Test Client will not be used when uploaded to Zendesk or when using the ZAT Server.
80
+
81
+ ## Notes
82
+
83
+ During the ```zafr package``` command, all React style and js assets will be flattened and moved from ```/build/assets/static/*``` to ```/build/assets/*``` as ZAF V2.0 does not allow a nested file structure.
84
+
85
+ ## Contributing
86
+
87
+ Bug reports and pull requests are welcome on GitHub at https://github.com/onlyexcellence/zaf_react.
data/bin/zafr ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require 'zaf_react'
3
+
4
+
5
+ # CLI
6
+ require "zaf_react/cli"
7
+
8
+
9
+ # Start CLI
10
+ ZAFReact::CLI.start(ARGV)
data/lib/boot.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Application Root
2
+ APP_ROOT = File.expand_path("../",__dir__)
@@ -0,0 +1,19 @@
1
+ module ZAFReact
2
+ class CLI < Thor
3
+
4
+
5
+ include Thor::Actions
6
+
7
+
8
+ desc "build", "Build React App"
9
+ # ========================================================
10
+ def build
11
+ remove_dir 'build'
12
+ directory 'zendesk', 'build'
13
+ raise Error, "React build failed".light_red if !system("npm run build --prefix source")
14
+ directory 'source/build', 'build/assets'
15
+ end
16
+
17
+
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ module ZAFReact
2
+ class CLI < Thor
3
+
4
+
5
+ include Thor::Actions
6
+
7
+
8
+ desc "init", "Initialize a new React App with ZAFClient"
9
+ # ========================================================
10
+ def init# _git = false
11
+ if Dir.exists?("source/src")
12
+ exit if ask("Are you sure you want to create a fresh app? This will remove all current work. Type ".light_cyan << "yes".light_yellow << " to continue.".light_cyan).downcase != "yes"
13
+ end
14
+ # remove_dir ".git" if _git
15
+ remove_dir "source"
16
+ remove_dir "zendesk"
17
+ remove_dir "build"
18
+ raise Error, "npm create failed".light_red if !system("create-react-app source")
19
+ remove_dir "source/.git"
20
+ copy_file "#{APP_ROOT}/lib/zaf_react/source/react/public/index.html", "source/public/index.html", force: true
21
+ remove_dir "source/src"
22
+ directory "#{APP_ROOT}/lib/zaf_react/source/react/src", "source/src"
23
+ directory "#{APP_ROOT}/lib/zaf_react/source/zendesk", "zendesk"
24
+ remove_file "source/.gitignore"
25
+ copy_file "#{APP_ROOT}/lib/zaf_react/ignore", ".gitignore"
26
+ # system "git init" if _git
27
+ end
28
+
29
+
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ module ZAFReact
2
+ class CLI < Thor
3
+
4
+
5
+ include Thor::Actions
6
+
7
+
8
+ desc "package", "ZAT Package"
9
+ # ========================================================
10
+ def package
11
+ build
12
+
13
+ directory "build/assets/static/js", "build/assets" if Dir.exists?("build/assets/static/js")
14
+ directory "build/assets/static/css", "build/assets" if Dir.exists?("build/assets/static/css")
15
+
16
+ remove_dir "build/assets/static"
17
+
18
+ Dir.glob([
19
+ "build/assets/*.js",
20
+ "build/assets/*.css",
21
+ "build/assets/*.json",
22
+ "build/assets/*.map",
23
+ "build/assets/*.html"
24
+ ]) do |filename|
25
+ gsub_file filename, /(\"\/static\/(js|css)\/)|(\"static\/(js|css)\/)/i, '"'
26
+ end
27
+
28
+ system "zat package --path=build"
29
+ end
30
+
31
+
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module ZAFReact
2
+ class CLI < Thor
3
+
4
+
5
+ include Thor::Actions
6
+
7
+
8
+ desc "server", "Start ZAT Server"
9
+ # ========================================================
10
+ def server
11
+ build
12
+ raise Error, "ZAT build failed".light_red if !system("zat server --path=build")
13
+ end
14
+
15
+
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module ZAFReact
2
+ class CLI < Thor
3
+
4
+
5
+ include Thor::Actions
6
+
7
+
8
+ desc "start", "Start local server"
9
+ # ========================================================
10
+ def start
11
+ system "npm start --prefix source"
12
+ end
13
+
14
+
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module ZAFReact
2
+ class CLI < Thor
3
+
4
+
5
+ include Thor::Actions
6
+
7
+
8
+ desc "validate", "ZAT Validate"
9
+ # ========================================================
10
+ def validate
11
+ system "zat validate --path=build"
12
+ end
13
+
14
+
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require "thor"
2
+
3
+
4
+ Dir["#{APP_ROOT}/lib/zaf_react/cli/*.rb"].each { |file| require file }
5
+
6
+
7
+ module ZAFReact
8
+ class CLI < Thor
9
+ end
10
+ end
11
+
12
+
13
+ ZAFReact::CLI.source_root("./")
@@ -0,0 +1,31 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ /source/node_modules
5
+ /source/.pnp
6
+ /source/.pnp.js
7
+
8
+ # testing
9
+ /source/coverage
10
+
11
+ # production
12
+ /source/build
13
+
14
+ # misc
15
+ /source/.DS_Store
16
+ /source/.env
17
+ /source/.env.development
18
+ /source/.env.local
19
+ /source/.env.development.local
20
+ /source/.env.test.local
21
+ /source/.env.production.local
22
+
23
+ /source/npm-debug.log*
24
+ /source/yarn-debug.log*
25
+ /source/yarn-error.log*
26
+
27
+ # Zendesk Test Environment
28
+ /build
29
+
30
+ # Ruby Environment
31
+ Gemfile.lock
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="theme-color" content="#000000" />
8
+ <meta
9
+ name="description"
10
+ content="Web site created using create-react-app"
11
+ />
12
+ <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13
+ <!--
14
+ manifest.json provides metadata used when your web app is installed on a
15
+ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16
+ -->
17
+ <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18
+ <!--
19
+ Notice the use of %PUBLIC_URL% in the tags above.
20
+ It will be replaced with the URL of the `public` folder during the build.
21
+ Only files inside the `public` folder can be referenced from the HTML.
22
+
23
+ Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24
+ work correctly both with client-side routing and a non-root public URL.
25
+ Learn how to configure a non-root public URL by running `npm run build`.
26
+ -->
27
+ <script src="https://static.zdassets.com/zendesk_app_framework_sdk/2.0/zaf_sdk.min.js"></script>
28
+ <title>React App</title>
29
+ </head>
30
+ <body>
31
+ <div id="root"></div>
32
+ <!-- <script src="https://static.zdassets.com/zendesk_app_framework_sdk/2.0/zaf_sdk.min.js"></script> -->
33
+ <!--
34
+ This HTML file is a template.
35
+ If you open it directly in the browser, you will see an empty page.
36
+
37
+ You can add webfonts, meta tags, or analytics to this file.
38
+ The build step will place the bundled scripts into the <body> tag.
39
+
40
+ To begin the development, run `npm start` or `yarn start`.
41
+ To create a production bundle, use `npm run build` or `yarn build`.
42
+ -->
43
+ </body>
44
+ </html>
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import ItemList from './components/item-list/item-list'
3
+
4
+ function App() {
5
+ return (
6
+ <div>
7
+ <ItemList />
8
+ </div>
9
+ );
10
+ }
11
+
12
+ export default App;
@@ -0,0 +1,39 @@
1
+ import React, { Component } from 'react';
2
+ import CLIENT from '../../zendesk/zaf_client';
3
+
4
+
5
+ class List extends Component {
6
+
7
+
8
+ constructor(){
9
+ super()
10
+ this.state = {
11
+ item_list: []
12
+ }
13
+ }
14
+
15
+
16
+ componentDidMount(){
17
+ CLIENT.metadata().then(metadata => {
18
+ this.setState({ item_list: JSON.parse(metadata['settings']['item_list'])} );
19
+ });
20
+ }
21
+
22
+
23
+ render(){
24
+ return (
25
+ <ul>
26
+ {
27
+ this.state.item_list.map((item, key) => {
28
+ return <li key={key}>{item}</li>
29
+ })
30
+ }
31
+ </ul>
32
+ )
33
+ }
34
+
35
+
36
+ }
37
+
38
+
39
+ export default List;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import App from './app.js'
4
+
5
+ ReactDOM.render(<App />, document.getElementById('root'));
@@ -0,0 +1,23 @@
1
+ // Simulates the ZAFClient functionality for local testing
2
+
3
+
4
+ class ZAFTestClient {
5
+
6
+ static init() { return new this(); }
7
+
8
+ invoke(_type, _params){}
9
+
10
+ metadata(){
11
+ return new Promise((resolve, reject) => {
12
+ resolve({
13
+ settings: {
14
+ item_list: JSON.stringify(["One", "Two", "Three", "Four"])
15
+ }
16
+ });
17
+ });
18
+ }
19
+
20
+ }
21
+
22
+
23
+ export default ZAFTestClient;
@@ -0,0 +1,11 @@
1
+ let client;
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ client = ZAFClient.init(); // eslint-disable-line no-undef
5
+ } else {
6
+ client = require('./helpers/zaf_test_client').default.init();
7
+ }
8
+
9
+ client.invoke('resize', { width: '340px', height: '400px' });
10
+
11
+ export default client;
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
3
+ viewBox="0 0 18 18" style="enable-background:new 0 0 18 18;" xml:space="preserve">
4
+ <path id="Fill-3" d="M1.5,6.1C1.3,5.9,1,6,1,6.4l0,7c0,0.3,0.2,0.7,0.5,0.9l6,3.6C7.8,18.1,8,18,8,17.6l0-7.1c0-0.3-0.2-0.7-0.5-0.9
5
+ L1.5,6.1z"/>
6
+ <path id="Fill-5" d="M10.5,17.9c-0.3,0.2-0.5,0-0.5-0.3l0-7c0-0.3,0.2-0.7,0.5-0.9l6-3.6C16.8,5.9,17,6,17,6.4l0,7.1
7
+ c0,0.3-0.2,0.7-0.5,0.9L10.5,17.9z"/>
8
+ <path id="Fill-1" d="M2.2,3.7c-0.3,0.2-0.3,0.4,0,0.6l6.2,3.6C8.7,8,9.2,8,9.4,7.9l6.3-3.6c0.3-0.2,0.3-0.4,0-0.6L9.5,0.1
9
+ C9.2,0,8.8,0,8.5,0.1L2.2,3.7z"/>
10
+ </svg>
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "",
3
+ "author": {
4
+ "name": "",
5
+ "email": "",
6
+ "url": ""
7
+ },
8
+ "defaultLocale": "en",
9
+ "private": true,
10
+ "location": {
11
+ "support": {
12
+ "top_bar": "assets/index.html"
13
+ }
14
+ },
15
+ "parameters": [
16
+ {
17
+ "name": "item_list",
18
+ "type": "text",
19
+ "required": false,
20
+ "secure": false,
21
+ "default": "[\"A\", \"B\", \"C\"]"
22
+ }
23
+ ],
24
+ "version": "0.1",
25
+ "frameworkVersion": "2.0"
26
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "app": {
3
+ "name": "Zen Tunes",
4
+ "short_description": "Play the famous zen tunes in your help desk.",
5
+ "long_description": "Play the famous zen tunes in your help desk and \n listen to the beats it has to offer.",
6
+ "installation_instructions": "Simply click install."
7
+ }
8
+ }
@@ -0,0 +1,3 @@
1
+ module ZAFReact
2
+ VERSION = "0.1.3"
3
+ end
data/lib/zaf_react.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "zaf_react/version"
2
+ require "awesome_print"
3
+ require "colorize"
4
+ require "boot"
5
+
6
+ module ZAFReact
7
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zaf_react
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - onlyexcellence
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: awesome_print
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: zendesk_apps_tools
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.8.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.8.0
69
+ description:
70
+ email:
71
+ - will@wambl.com
72
+ executables:
73
+ - zafr
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - README.md
78
+ - bin/zafr
79
+ - lib/boot.rb
80
+ - lib/zaf_react.rb
81
+ - lib/zaf_react/cli.rb
82
+ - lib/zaf_react/cli/build.rb
83
+ - lib/zaf_react/cli/init.rb
84
+ - lib/zaf_react/cli/package.rb
85
+ - lib/zaf_react/cli/server.rb
86
+ - lib/zaf_react/cli/start.rb
87
+ - lib/zaf_react/cli/validate.rb
88
+ - lib/zaf_react/ignore
89
+ - lib/zaf_react/source/react/public/index.html
90
+ - lib/zaf_react/source/react/src/app.js
91
+ - lib/zaf_react/source/react/src/components/item-list/item-list.js
92
+ - lib/zaf_react/source/react/src/index.js
93
+ - lib/zaf_react/source/react/src/zendesk/helpers/zaf_test_client.js
94
+ - lib/zaf_react/source/react/src/zendesk/zaf_client.js
95
+ - lib/zaf_react/source/zendesk/assets/logo-small.png
96
+ - lib/zaf_react/source/zendesk/assets/logo.png
97
+ - lib/zaf_react/source/zendesk/assets/logo.svg
98
+ - lib/zaf_react/source/zendesk/manifest.json
99
+ - lib/zaf_react/source/zendesk/translations/en.json
100
+ - lib/zaf_react/version.rb
101
+ homepage: https://github.com/onlyexcellence/zaf_react
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ homepage_uri: https://github.com/onlyexcellence/zaf_react
106
+ source_code_uri: https://github.com/onlyexcellence/zaf_react
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.0.6
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Zendesk App Framework with React
126
+ test_files: []