⚡ Developing native mobile apps just got a whole lot more awesome ⚡
6 |
7 | ---
8 |
9 | ## CLI Documentation
10 |
11 | ---
12 |
13 | ### General Usage
14 |
15 | Usage | Synopsis
16 | ------|-------
17 | General | `native [Command Parameters] [--command ]`
18 | Alias | `nativeloop [Command Parameters] [--command ]`
19 |
20 | ### Project Development Commands
21 | Command | Description
22 | ---|---
23 | [create](create.md) | Creates a new project for native mobile development with {nativeloop}.
24 | [init]() |  Initializes an existing Appcelerator mobile project for development with {nativeloop}.
25 |
26 | ### Global Options
27 | Option | Description
28 | -------|---------
29 | --help, -h, /? | Prints help about the selected command in the console.
30 | --path `` | Specifies the directory that contains the project. If not set, the project is searched for in the current directory and all directories above it.
31 | --version | Prints the client version.
32 |
33 |
--------------------------------------------------------------------------------
/docs/create.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
⚡ Developing native mobile apps just got a whole lot more awesome ⚡
6 |
7 | ---
8 |
9 | ## create
10 |
11 | ---
12 |
13 | ### Description
14 |
15 | Creates a new project for native mobile development with {nativeloop}.
16 |
17 | ### General Usage
18 |
19 | Usage | Description
20 | ---|---
21 | Create from default template | `native create [--path ] [--id ]`
22 | Create from custom template | `native create [--path ] [--appid ] --template `
23 |
24 | ### Options
25 |
26 | - `--path` - Specifies the directory where you want to create the project, if different from the current directory. The directory must be empty.
27 | - `--id` - [optional] Sets the application identifier for your project. If `--id` is not set, the App ID is created based on the name of the app.
28 | - `--template` - [optional] Specifies a local directory or valid npm package which you want to use to create your project. If `--template` is not set, the {nativeloop} CLI creates the project from the default template `@nativeloop/template-default`
29 | - `--name` - Specifies the name of your project. This is alternative to passing the app name as the first parameter.
30 | - `--url` - [optional] Specifies the url for your organization.
31 | - `--publisher` - [optional] Specifies the publisher for this app.
32 | - `--copyright` - [optional] Specifies the copyright for this app.
33 | - `--description` - [optional] Specifies the description for this app.
34 | - `--guid` - [optional] Specifies the unique GUID for this app.
35 |
36 |
37 | ### Parameters
38 |
39 | - `` is an existing directory or a valid npm package which you want to use as template for your app. You can specify the package by name in the npm registry or by local path or GitHub URL to a directory or .tar.gz containing a package.json file. The contents of the package will be copied to the directory of your project.
40 |
41 |
42 | ### Related Commands
43 |
44 | Command | Description
45 | ----------|----------
46 | [init]() |  Initializes an existing {nativeloop} or Appcelerator mobile project for development with {nativeloop}. The command prompts you to provide your project configuration interactively and uses the information to create a new package.json file or update the existing one.
47 |
48 |
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
⚡ Developing native mobile apps just got a whole lot more awesome ⚡
6 |
7 | ---
8 |
9 |
10 | ```javascript
11 | const status = "Pre-Production Beta!";
12 | const warning = "Breaking changes may be introduced before 1.0.0 release";
13 |
14 | developer.read(warning)
15 | .then((⚡) => { return developer.code(⚡); })
16 | .then((code) => { return developer.😀 });
17 | .then((app) => { return users.❤️ });
18 |
19 | ```
20 |
21 | ---
22 |
23 | # ⚡[`{nativeloop} cli`](#nativeloop)⚡
24 |
25 | [](https://badge.fury.io/js/nativeloop)
26 | []()
27 |
28 |
29 |
30 | - [Overview](#overview)
31 | - [What is [`{nativeloop}`][]?](#what-is-nativeloop)
32 | - [Features](#features)
33 | - [Quick Start](#quick-start)
34 | - [Install `{nativeloop}`](#install-nativeloop)
35 | - [Option 1: Install Globally](#option-1--install-globally)
36 | - [Option 2: Install Locally](#option-2--install-locally)
37 | - [Option 3: Install using gitTio](#option-3--install-using-gittio)
38 | - [Install Prerequisites/Dependencies](#install-prerequisitesdependencies)
39 | - [Need Help?](#need-help)
40 | - [License](#license)
41 | - [Legal](#legal)
42 |
43 |
44 |
45 | ## Overview
46 |
47 | This is the command line tool for creating and working with existing {nativeloop} mobile applications.
48 |
49 | > **:soon: Only a few commands have been implemented at this time.
50 | Feel free to test out the functionality that exists right now and stay tuned
51 | as more features are added soon!**
52 |
53 |
54 | ### What is [`{nativeloop}`][]?
55 |
56 | [`{nativeloop}`] is a framework for building awesome native apps using node.js style javascript.
57 | It provides developers with access to an extremely rapid development process
58 | without compromising on the delivered product.
59 |
60 | [`{nativeloop}`][] is open-source (MIT) and is built upon the open-source version of [`appcelerator`][]
61 | and other open-source products. If you like what you see, contribute to this and other open-source projects!
62 |
63 | ### Features
64 |
65 | - [x] ECMAScript 2015/ES6 support (using babel transformations)
66 | - [x] Supports Node.js global object: `Promise` (using bluebird but can be easily replaced with your own)
67 | - [x] Supports Node.js core module: `fs` (not complete coverage)
68 | - [x] Supports Node.js core module: `path`
69 | - [ ] Supports Node.js core module: `url`
70 | - [ ] Supports Node.js core module: `querystring`
71 | - [x] Supports relative path usage to workaround https://jira.appcelerator.org/browse/TIMOB-24170
72 | - [x] Uses the latest version of lodash, instead of older version of underscore.js
73 | - [x] Supports installation of modules for your app using [`npm`][]
74 | - [x] Does not require replacing Alloy (globally or per build of appcelerator)
75 | - [x] Several free [`{nativeloop}`][] plugins developed by MobileHero are included and available now
76 | - [x] Build and use your own [`{nativeloop}`][] plugins easily!
77 | - [x] Customize which [`{nativeloop}`][] plugins run per project, platform or deployment type (dev,test,prod)!
78 | - [x] Works great with Appcelerator LiveView! (🎉 _yay!!_ 🎉)
79 | - [x] Supports for camelcase syntax in your Alloy xml views (i.e. `` instead of `` )
80 | - [x] Supports lowercase-dashed syntax in your Alloy views (i.e. `` instead of `` )
81 |
82 |
83 | ## Quick Start
84 |
85 | ### Install `{nativeloop}`
86 |
87 | #### Option 1: Install Globally
88 |
89 | >This is your quickest and easiest way to get started with `{nativeloop}`. Installing globally will
90 | allow it to be accessed by any our your mobile projects.
91 |
92 | ```bash
93 | npm install -g nativeloop
94 | ```
95 |
96 | #### Option 2: Install Locally
97 |
98 | >Just as quick and easy, but this will allow you to use a specific version `{nativeloop}` for your mobile project. Simply run this in the root of your mobile project!
99 |
100 | ```bash
101 | npm install --save nativeloop
102 | ```
103 |
104 | #### Option 3: Install using gitTio
105 |
106 | > **:soon: Not available yet, but coming very soon!!**
107 |
108 | >Install this as a widget using gitTio (http://gitt.io). We hope to have this option available soon!
109 |
110 | ```bash
111 | gittio install nativeloop
112 | ```
113 |
114 | #### Install Prerequisites/Dependencies
115 |
116 | >_Our goal is to provide as much automation as possible to make the mobile development
117 | experience as awesome as possible. Currently there are some prerequisites/dependencies that
118 | need to installed manually but we hope to automate some of these in the near future!_
119 |
120 |
121 | - [OSX] Install latest Xcode from App Store _(7.3.1 as of the time of writing)_
122 | - Install Appcelerator Titanium and Alloy
123 |
124 | ```bash
125 | npm install -g alloy
126 | npm install -g titanium
127 | ```
128 |
129 | - [OSX] Install [homebrew](http://brew.sh) _(optional, but highly recommended)_
130 |
131 | ```bash
132 | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
133 | ```
134 |
135 | - Install IDE of your choice _(We highly recommend [Microsoft Visual Studio Code](https://code.visualstudio.com), as it is free, fast and works great!)_
136 | - Install Android SDK and NDK
137 |
138 | >OSX
139 |
140 | ```bash
141 | brew install android-sdk
142 | brew install android-ndk
143 | ```
144 |
145 | >Windows
146 |
147 | :soon: Instructions for installing on Windows coming soon!
148 |
149 | - There might be a few more items to install... Stay tuned for more detailed instructions
150 |
151 | ***New mobile project**
152 |
153 | *See documentation for create for more details: https://nativeloop.github.io/nativeloop/create
154 |
155 | ```bash
156 | native create my-cool-app
157 | ```
158 |
159 | :book: [see documentation for `create`](docs/create.md)
160 |
161 | **Upgrading existing Appcelerator mobile project**
162 |
163 | > **:soon: Not available yet, but coming very soon!!**
164 |
165 | ```bash
166 | native init
167 | ```
168 |
169 | ## Need Help?
170 |
171 | Please [submit an issue](https://github.com/nativeloop/nativeloop/issues) on GitHub and
172 | provide information about your setup.
173 |
174 |
175 | ## License
176 |
177 | []()
178 |
179 | Except for otherwise noted, this project is licensed under the terms of the MIT license. This means you have full access to the
180 | source code and can modify it to fit your own needs.
181 | See the [license.md](https://github.com/nativeloop/nativeloop-cli/blob/master/license.md) file.
182 |
183 | This project uses other third party open-source tools.
184 | Please see the [third-party.md](https://github.com/nativeloop/nativeloop-cli/blob/master/license.md) file for more information and licenses.
185 |
186 | ## Legal
187 |
188 | Nativeloop is developed by Superhero Studios and the community and is Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
189 |
190 | _Superhero Studios Incorporated and this project are in no way affiliated with any of the following companies:_
191 |
192 | - _Appcelerator, Inc_
193 | - _Axway Inc_
194 | - _Apple Inc_
195 | - _Google Inc_
196 |
197 | Alloy is developed by Appcelerator and the community and is Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
198 |
199 | Alloy is made available under the Apache Public License, version 2. See their [license](https://github.com/appcelerator/alloy/blob/master/LICENSE) file for more information.
200 |
201 | [alloy]: https://github.com/appcelerator/alloy "alloy"
202 | [npm]: https://www.npmjs.com/ "npm"
203 | [`nativeloop`]: https://github.com/nativeloop/nativeloop-mobile "nativeloop"
204 | [`{nativeloop}`]: https://github.com/nativeloop/nativeloop-mobile "nativeloop"
205 | [`Appcelerator`]: http://www.appcelerator.com/mobile-app-development-products/ "appcelerator"
--------------------------------------------------------------------------------
/docs/mobile.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
⚡ Developing native mobile apps just got a whole lot more awesome ⚡
6 |
7 | ---
8 |
9 |
10 | ```javascript
11 | const status = "Pre-Production Beta!";
12 | const warning = "Breaking changes may be introduced before 1.0.0 release";
13 |
14 | developer.read(warning)
15 | .then((⚡) => { return developer.code(⚡); })
16 | .then((code) => { return developer.😀 });
17 | .then((app) => { return users.❤️ });
18 |
19 | ```
20 |
21 | ---
22 |
23 | # ⚡[`{nativeloop}`](#nativeloop)⚡
24 |
25 | [](https://badge.fury.io/js/%40nativeloop%2Fmobile)
26 | []()
27 |
28 |
29 |
30 | - [Overview](#overview)
31 | - [What is [`{nativeloop}`][]?](#what-is-nativeloop)
32 | - [So what makes [`{nativeloop}`][] so awesome?](#so-what-makes-nativeloop-so-awesome)
33 | - [Quick(est) Start](#quickest-start)
34 | - [Quick Start](#quick-start)
35 | - [Usage](#usage)
36 | - [{nativeloop} Plugins](#nativeloop-plugins)
37 | - [Need Help?](#need-help)
38 | - [License](#license)
39 | - [Legal](#legal)
40 |
41 |
42 |
43 | ## Overview
44 |
45 | ### What is [`{nativeloop}`][]?
46 |
47 | [`{nativeloop}`] is a framework for building awesome native apps using node.js style javascript.
48 | It provides developers with access to an extremely rapid development process
49 | without compromising on the delivered product.
50 |
51 | [`{nativeloop}`][] is open-source (MIT) and is built upon the open-source version of [`appcelerator`][]
52 | and other open-source products. If you like what you see, contribute to this and other open-source projects!
53 |
54 | ### So what makes [`{nativeloop}`][] so awesome?
55 |
56 | [`{nativeloop}`][] enables all features available through use of the Appcelerator Titantium product
57 | and adds many other cool features (and some undocumented hidden gems)!
58 |
59 |
60 | - [x] ES2015/ES6 support (using babel transformations)
61 | - [ ] Supports Javascript promises (using bluebird but can be replaced with your own)
62 | - [x] Uses the latest version of lodash, instead of older version of underscore.js
63 | - [x] Supports installation of modules for your app using [`npm`][]
64 | - [x] Does not require replacing Alloy (globally or per build of appcelerator)
65 | - [x] Several free [`{nativeloop}`][] plugins developed by MobileHero are included and available now
66 | - [x] Build and use your own [`{nativeloop}`][] plugins easily!
67 | - [x] Customize which [`{nativeloop}`][] plugins run per project, platform or deployment type (dev,test,prod)!
68 | - [x] Works great with Appcelerator LiveView! (🎉 _yay!!_ 🎉)
69 | - [x] Support for lowercase-dashed syntax in your Alloy views
70 |
71 |
72 | ## Quick(est) Start
73 |
74 | > **:soon: Not available yet, but coming very soon!!**
75 |
76 | Using [`{nativeloop}`][] cli from npm. [](https://badge.fury.io/js/nativeloop)
77 |
78 | **New mobile project**
79 |
80 | ```bash
81 | npm install -g nativeloop
82 | native create app --id my.demo --name demo
83 | ```
84 |
85 | **Existing mobile project**
86 |
87 | ```bash
88 | npm install -g nativeloop
89 | native init
90 | ```
91 |
92 |
93 | ## Quick Start
94 |
95 | > _These scripts should be run in the root directory of your [`{nativeloop}`][] mobile project
96 | (the directory containing `tiapp.xml`)._
97 |
98 | This is a temporary work-around until the [`{nativeloop}`][] command-line tool is available.
99 |
100 | **New mobile project**
101 |
102 | ```bash
103 |
104 | npm install -g alloy
105 | npm install -g titanium
106 | ti create --type app -p all --wordspace-dir . --url http://nativeloop.com --id my.demo --name demo
107 | alloy new demo
108 | cd demo
109 | npm init --force
110 | npm install --save @nativeloop/mobile
111 | npm install --save alloy-widget-nativeloop
112 | ```
113 |
114 | **Existing mobile project**
115 |
116 | ```bash
117 |
118 | cd
119 | npm install --save @nativeloop/mobile
120 | npm install --save alloy-widget-nativeloop
121 | ```
122 |
123 | ## Usage
124 |
125 | > **:soon: Coming Soon!**
126 |
127 | ## {nativeloop} Plugins
128 |
129 | > **:soon: Coming Soon!**
130 |
131 |
132 | ## Need Help?
133 |
134 | Please [submit an issue](https://github.com/nativeloop/nativeloop-mobile/issues) on GitHub and
135 | provide information about your setup.
136 |
137 |
138 | ## License
139 |
140 | []()
141 |
142 | This project is licensed under the terms of the MIT license. This means you have full access to the
143 | source code and can modify it to fit your own needs.
144 | See the [license.md](https://github.com/nativeloop/nativeloop-mobile/blob/master/license.md) file.
145 |
146 | ## Legal
147 |
148 | Nativeloop is developed by Superhero Studios and the community and is Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
149 |
150 | _Superhero Studios Incorporated and this project are in no way affiliated with any of the following companies:_
151 |
152 | - _Appcelerator, Inc_
153 | - _Axway Inc_
154 | - _Apple Inc_
155 | - _Google Inc_
156 |
157 | Alloy is developed by Appcelerator and the community and is Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
158 |
159 | Alloy is made available under the Apache Public License, version 2. See their [LICENSE](https://github.com/appcelerator/alloy/blob/master/LICENSE) file for more information.
160 |
161 | [alloy]: https://github.com/appcelerator/alloy "alloy"
162 | [npm]: https://www.npmjs.com/ "npm"
163 | [`nativeloop`]: https://github.com/nativeloop/nativeloop-mobile "nativeloop"
164 | [`{nativeloop}`]: https://github.com/nativeloop/nativeloop-mobile "nativeloop"
165 | [`Appcelerator`]: http://www.appcelerator.com/mobile-app-development-products/ "appcelerator"
--------------------------------------------------------------------------------
/docs/old.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
⚡ Developing native apps just got a whole lot more awesome ⚡
6 |
7 | ---
8 |
9 |
10 | ```javascript
11 | const status = "Pre-Production Beta!";
12 | const warning = "Breaking changes may be introduced before 1.0.0 release";
13 |
14 | developer.read(warning)
15 | .then(developer.code)
16 | .then(developer.😀);
17 |
18 | ```
19 |
20 | ---
21 |
22 | # ⚡ nativeloop ⚡
23 |
24 | [](https://badge.fury.io/js/nativeloop) ➖
25 | []()
26 |
27 |
28 |
29 | - [Overview](#overview)
30 | - [What is nativeloop?](#what-is-nativeloop)
31 | - [Features](#features)
32 | - [How is this different than Adamantium?](#how-is-this-different-than-adamantium)
33 | - [So what makes nativeloop so awesome?](#so-what-makes-nativeloop-so-awesome)
34 | - [Quick Start](#quick-start)
35 | - [Usage](#usage)
36 | - [Templated Parameters](#templated-parameters)
37 | - [Alloy+ Plugins](#alloy-plugins)
38 | - [Need Help?](#need-help)
39 | - [License](#license)
40 | - [Legal](#legal)
41 |
42 |
43 |
44 | ## Overview
45 |
46 | ### What is nativeloop?
47 |
48 | [`nativeloop`][] is a framework for building awesome native apps using node.js style javascript.
49 | It provides developers with access to an extremely rapid development process
50 | without comprimising on the delivered product.
51 |
52 |
53 | ####Features
54 |
55 | - Support for lowercase-dashed syntax in your Alloy views
56 | -
57 |
58 |
59 | [`nativeloop`][] is an entire framework built around
60 | [Appcelerator Mobile](http://www.appcelerator.com/mobile-app-development-products/) and their [Alloy][] product.
61 | The idea for this framework was built upon the concepts of [MobileHero Adamantium](https://github.com/mobilehero/adamantium)
62 | and a desire to customize and extend Appcelerator Alloy for developers. How much faster or stronger all depends on YOU, the developer.
63 |
64 | There will be an assortment of alloy+ plugins (available as npm modules) that you can install
65 | in your project to help you take your existing development tools furthur
66 | than possible today. You can choose which modules are executed in your `config.json` file
67 | (which is part of your Alloy project). You can also easily create your own plugins by simply
68 | creating a npm module that follows a simple convention.
69 |
70 | ### How is this different than Adamantium?
71 |
72 | [Adamantium](https://github.com/mobilehero/adamantium) is a custom build of [Appcelerator Alloy](https://github.com/appcelerator/alloy).
73 | This was our first _(well, maybe not the first...)_ attempt to add features and capabilities to Alloy that were not necessarily on Appcelerator's
74 | Roadmap for the product. Keeping Adamantium up-to-date was, however, was becoming more difficult with merges and was not a sustainable model.
75 |
76 | [Alloy+][] is a framework for modifying your app and code during the Alloy build process.
77 | Both accomplish getting new features and capabilities into your app.
78 | When using alloy+, builds may take slightly longer and we are also limited
79 | to working within the available build hooks made available by Appcelerator.
80 |
81 | ### So what makes nativeloop so awesome?
82 |
83 | Alloy+ has many features that couldn't be implemented easily using Adamantium!
84 |
85 | * Does not require replacing Alloy (globally or per build of appcelerator)
86 | * Several free Alloy+ plugin developed by MobileHero and available now
87 | * Build and use your own Alloy+ plugin easily!
88 | * Customize which Alloy+ plugins run per project, platform or deployment type (dev,test,prod)!
89 | * Works great with Appcelerator LiveView! (🎉 _yay!!_ 🎉)
90 |
91 |
92 | ## Quick Start
93 |
94 | > _All modules should be installed in the root directory of your Appcelerator mobile project (the directory containing `tiapp.xml`)._
95 |
96 | [](https://badge.fury.io/js/nativeloop)
97 |
98 | ```bash
99 | npm install --save nativeloop
100 | ```
101 |
102 | ## Usage
103 |
104 | To use plugins in your app, add entries for your plugins to your app's `config.json` file:
105 |
106 | ```json
107 | {
108 | "tasks": [
109 | "@aplus/npm",
110 | "@aplus/underscore",
111 | "@aplus/babel",
112 | "@aplus/node",
113 | {
114 | "module": "some-other-aplus-plugin",
115 | "dirname": "${event.dir.lib}",
116 | "args": ["these", "are", "my", "args"]
117 | }
118 | ],
119 | }
120 | ```
121 |
122 | ## Templated Parameters
123 |
124 | You can use templated parameters in your variables (if supported by your plugin).
125 | The following parameters are passed to every plugin and can be used in templating:
126 |
127 |
128 | | property | description |
129 | |--- |--- |
130 | | `event` | The `event` object provides a set of objects and values which may be useful for building tasks. The object comes from the [`alloy.jmk` build task](https://wiki.appcelerator.org/pages/viewpage.action?pageId=35620079). **NOTE:** There is an additional property not found in the original event object -- `event.dir.resourcesPlatform`. This property is the platorm specific directory under the Alloy project's `Resource` directory (i.e. /Resources/iphone).|
131 | | `config` | The `config` object is the result of the [`config.json` file](https://wiki.appcelerator.org/pages/viewpage.action?pageId=35620077) after it has been processed by Alloy (to handle themes/platforms/etc). |
132 | | `logger` | The `logger` object provides a reference to the logger. See the [Appcelerator alloy.jmk wiki page](https://wiki.appcelerator.org/pages/viewpage.action?pageId=35620079) for a list of methods and properties. |
133 | | `code` | The `code` object is the source code of an module before it is parsed by uglifyjs in Alloy. This is only available in the alloy+ *exclusive* event: `preparse`. |
134 |
135 |
136 | ## Alloy+ Plugins
137 |
138 | > **Coming Soon! :mega:**
139 |
140 | - [`npm`][]: Execute npm during the Alloy build process
141 | - [`babel`][]: Run babel transformations on your code during the build process
142 | - [`es6`][]: Use ES6/ES2015 code in your apps via babel transformations!
143 | - [`node`][]: Make `require` statements in your app support nodejs packages installed via npm
144 | - [`underscore`][]: Fix some issues with the usage of underscore in Alloy and allow upgrading to lodash
145 |
146 |
147 | ## Need Help?
148 |
149 | Please [submit an issue](https://github.com/mobilehero/aplus-core/issues) on GitHub and provide information about your setup.
150 |
151 |
152 | ## License
153 |
154 | []()
155 |
156 | This project is licensed under the terms of the MIT license. This means you have full access to the source code and can modify it to fit your own needs.
157 | See the [license.md](https://github.com/mobilehero/aplus-core/blob/master/license.md) file.
158 |
159 | ## Legal
160 |
161 | _Superhero Studios Incorporated and this project are in no way affiliated with any of the following companies:_
162 |
163 | - _Appcelerator, Inc_
164 | - _Axway Inc_
165 | - _Apple Inc_
166 | - _Google Inc_
167 |
168 | Alloy is developed by Appcelerator and the community and is Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
169 | Alloy is made available under the Apache Public License, version 2. See their [LICENSE](https://github.com/appcelerator/alloy/blob/master/LICENSE) file for more information.
170 |
171 | [alloy]: https://github.com/appcelerator/alloy "alloy"
172 | [npm]: https://www.npmjs.com/ "npm"
173 | [`nativeloop`]: https://github.com/mobilehero/nativeloop "Nativeloop"
174 | [`node`]: https://github.com/mobilehero/aplus-node "node"
175 | [`babel`]: https://github.com/mobilehero/aplus-babel "babel"
176 | [`es6`]: https://github.com/mobilehero/aplus-es6 "es6"
177 | [`underscore`]: https://github.com/mobilehero/aplus-underscore "underscore"
178 | [`npm`]: https://github.com/mobilehero/aplus-npm "npm"
179 |
--------------------------------------------------------------------------------
/fix-config.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file {nativeloop} plugin for adding nativeloop widget to config.json
12 | * @module fix-config
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | const _ = require( 'lodash' );
20 |
21 | /**
22 | * Adds nativeloop widget to config.json
23 | * @function addWidget
24 | * @param {object} params - The parameters for adding widget
25 | * @param {object} params.input - The parsed json of the config.json
26 | * @param {object} params.logger - The nativeloop logger
27 | * @since 1.0.0
28 | * @returns {object} - The modified input object
29 | */
30 | exports.addWidgets = function( params ) {
31 | let logger = params.logger;
32 | logger.trace( 'Adding nativeloop widget to config.json' );
33 | params.logger.error( "adding widgets" );
34 | if( params.input.widgets && params.input.dependencies ) {
35 | _.defaults( params.input.dependencies, params.input.widgets );
36 | }
37 |
38 | return params.input;
39 | }
--------------------------------------------------------------------------------
/lib/apm.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file
12 | * Wraps the Appcelerator Performance Module. Adds console output, if in development mode
13 | * and the debug property is set to true.
14 | * @module nativeloop/apm
15 | * @see {@link http://docs.appcelerator.com/platform/latest/#!/api/Modules.Performance|Appcelerator Performance Module API Documentation}
16 | * @author Brenton House
17 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
18 | * @license Licensed under the terms of the MIT License (MIT)
19 | * @version 1.0.0
20 | * @since 1.0.0
21 | */
22 |
23 | // property to store apm instance, if enabled.
24 | var apm;
25 |
26 | /**
27 | * @property {string} appid - APM appid. Defaults to property com-appcelerator-apm-id.
28 | * @property {string} username - Name used to differentiate user metadata for crash reports.
29 | * @property {boolean} optOutStatus - Has user opted out of sending information.
30 | * @property {object} metadata - Additional information about the user.
31 | * @property {string} userUUID - Unique id of the user.
32 | * @property {boolean} didCrash - Did the app crash on last load. Not used without APM.
33 | * @property {boolean} debug - Specifies whether the app should output to console, in addition to APM.
34 | * @property {boolean} shouldCollectLogcat - Should app collect logcat data on Android devices.
35 | */
36 | const wrapper = {
37 | appid: Ti.App.Properties.getString( 'com-appcelerator-apm-id' ) || 'unknown',
38 | username: 'anonymous',
39 | optOutStatus: false,
40 | metadata: {},
41 | userUUID: Ti.App.guid,
42 | didCrash: false,
43 | debug: false,
44 | shouldCollectLogcat: false,
45 | }
46 |
47 | /**
48 | * Returns true if the application crashed on the previous session else returns false.
49 | * @function didCrashOnLastAppLoad
50 | * @returns {boolean}
51 | * @since 1.0.0
52 | */
53 | wrapper.didCrashOnLastAppLoad = function () {
54 | if ( apm ) {
55 | return apm.didCrashOnLastAppLoad();
56 | }
57 | return wrapper.didCrash;
58 | };
59 |
60 | /**
61 | * Returns true if the user opt out to send information else returns false.
62 | * @function getOptOutStatus
63 | * @returns {boolean}
64 | * @since 1.0.0
65 | */
66 | wrapper.getOptOutStatus = function () {
67 | if ( apm ) {
68 | return apm.getOptOutStatus();
69 | }
70 | return wrapper.optOutStatus;
71 | };
72 |
73 | /**
74 | * Returns a string consisting of the UUID generated by Crittercism for user identification.
75 | * @function getUserUUID
76 | * @returns {string}
77 | * @since 1.0.0
78 | */
79 | wrapper.getUserUUID = function () {
80 | if ( apm ) {
81 | return apm.getUserUUID();
82 | }
83 | return wraper.userUUID;
84 | };
85 |
86 | /**
87 | * On the Android platform, you can optionally pass in initialization parameters.
88 | * @summary Initializes the module.
89 | * @function init
90 | * @param {string} [appid] - APM App ID found in the tiapp.xml file or the Appcelerator Performance dashboard.
By default, if this parameter is not specified, the module uses the value stored as the com-appcelerator-apm-id key in the tiapp.xml file to initialize the module.
91 | * @param {object} [config] - Android-specific initialization parameters.
92 | * @param {string} [config.notificationTitle] - This parameter determines the title shown on notification alerts sent from Crittercism.
93 | * @param {boolean} [config.shouldCollectLogcat=false] - If true, enables collecting logcat data on Android devices running Google API Level 16 (Jelly Bean) and higher.
94 | * @since 1.0.0
95 | */
96 | wrapper.init = function ( appid, config ) {
97 |
98 | wrapper.appid = appid || Ti.App.Properties.getString( 'com-appcelerator-apm-id' ) || wrapper.appid;
99 | config = config || {};
100 |
101 | if ( !_.isUndefined( config.shouldCollectLogcat ) ) {
102 | wrapper.shouldCollectLogcat = config.shouldCollectLogcat;
103 | }
104 |
105 | // Attempt to load the APM module and initialize.
106 | try {
107 | apm = require( 'com.appcelerator.apm' );
108 | apm.init( wrapper.appid, config );
109 | } catch ( error ) {
110 | Ti.API.warn( 'com.appcelerator.apm module is not available' );
111 | }
112 |
113 | };
114 |
115 | /**
116 | * These breadcrumbs are collected and passed to the Performance service.
117 | * The most recent 100 breadcrumbs before the crash occurred are displayed on the Performance Dashboard.
118 | * @summary Leaves a breadcrumb trail in your code to get a playback of events leading up to a crash.
119 | * @function leaveBreadcrumb
120 | * @param {string} breadcrumb - Up to 140 characters to identify the event or application state.
121 | * @since 1.0.0
122 | */
123 | wrapper.leaveBreadcrumb = function ( breadcrumb ) {
124 | ENV_DEVELOPMENT && wrapper.debug && Ti.API.trace( '[APM] breadcrumb → ' + breadcrumb );
125 | apm && apm.leaveBreadcrumb( breadcrumb );
126 | };
127 |
128 | /**
129 | * Crittercism limits the logging of handled errors to one per minute.
130 | * Up to five errors are buffered and are subsequently sent after the one minute limit.
131 | * @summary Used to track handled errors.
132 | * @function logHandledException
133 | * @param {Error} error - Error to log.
134 | * @since 1.0.0
135 | */
136 | wrapper.logHandledException = function ( error ) {
137 | ENV_DEVELOPMENT && Ti.API.error( '[APM] exception → ' + JSON.stringify( error, null, 2 ) );
138 | try {
139 | apm && apm.logHandledException( error );
140 | } catch ( ex ) {
141 | Ti.API.error( '[APM] Error calling apm.logHandledException() → ' + ex );
142 | }
143 | };
144 |
145 | /**
146 | * The data is stored in a dictionary and displayed on the developer portal when viewing a user profile.
147 | * @summary Used to set a single pair of arbitrary user metadata.
148 | * @function setMetadata
149 | * @params {string} key - Metadata key.
150 | * @params {string|number} value - Metadata value. Can be either an integer or string.
151 | * @since 1.0.0
152 | */
153 | wrapper.setMetadata = function ( key, value ) {
154 | wrapper.metadata[ key ] = value;
155 | ENV_DEVELOPMENT && Ti.API.info( '[APM] metadata → key: ' + JSON.stringify( key, null, 2 ) + ' value: ' + JSON.stringify( value, null, 2 ) );
156 | apm && wrapper.apm.setMetadata( key, value );
157 | };
158 |
159 | /**
160 | * Sets the users opt-out status from sending any and all information to the Performance service.
161 | * @function setOptOutStatus
162 | * @params {boolean} optOutStatus - If set to true, data is not sent to the Performance service.
163 | * @since 1.0.0
164 | */
165 | wrapper.setOptOutStatus = function ( optOutStatus ) {
166 | wrapper.optOutStatus = optOutStatus;
167 | ENV_DEVELOPMENT && Ti.API.info( '[APM] Setting optOutStatus to ' + optOutStatus );
168 | apm && apm.setOptOutStatus( optOutStatus );
169 | };
170 |
171 | /**
172 | * Updates only if there has been a change to the username from previous settings.
173 | * @summary Sets a username to differentiate user metadata for crash reports.
174 | * @function setUsername
175 | * @params {string} username - Up to 32 characters to set to identify a user.
176 | * @since 1.0.0
177 | */
178 | wrapper.setUsername = function ( username ) {
179 | wrapper.username = username;
180 | ENV_DEVELOPMENT && Ti.API.info( '[APM] Setting username to ' + username );
181 | apm && apm.setUsername( username );
182 | };
183 |
184 | module.exports = wrapper;
--------------------------------------------------------------------------------
/lib/baseController.js:
--------------------------------------------------------------------------------
1 |
2 | const base = function($){
3 | $.nav = _.get($,'args.params.navigator');
4 | };
5 | module.exports = base;
6 |
7 |
--------------------------------------------------------------------------------
/lib/device.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file This module is used to display information known about the device it is running on.
12 | * @module nativeloop/device
13 | * @author Brenton House
14 | * @version 1.0.0
15 | * @since 1.0.0
16 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
17 | * @license Licensed under the terms of the MIT License (MIT)
18 | *
19 | */
20 |
21 | /**
22 | * Define exports for this module
23 | */
24 | var device = {};
25 | module.exports = device;
26 |
27 | /**
28 | * Declare variables needed for this module
29 | */
30 | console.log( 'inside device.js' );
31 | device.width = null;
32 | const events = require( 'events' );
33 |
34 | /**
35 | * @function calculatePercentWidth
36 | * @summary summary
37 | * @param {number} relative - description
38 | * @param {number} plus - description
39 | * @since 1.0.0
40 | * @returns {number} - description
41 | */
42 | var calculatePercentWidth = function( relative, plus ) {
43 |
44 | relative = relative || 100;
45 | plus = plus || 0;
46 |
47 | switch( device.platform ) {
48 | case "mobileweb":
49 | return device.platformWidth;
50 |
51 | case "iPhone OS":
52 | return device.platformWidth;
53 |
54 | default:
55 | //var pointDp = measurement.pointPXToDP(relative);
56 | var px = device.platformWidth * ( relative / 100 );
57 | var calcDp = Math.round( px / ( device.dpi / 160 ) );
58 | return( calcDp + parseInt( plus ) );
59 | break;
60 | }
61 |
62 | };
63 |
64 | /**
65 | * @function calculatePercentHeight
66 | * @summary summary
67 | * @param {number} relative - description
68 | * @param {number} plus - description
69 | * @since 1.0.0
70 | * @returns {number} - description
71 | */
72 | var calculatePercentHeight = function( relative, plus ) {
73 |
74 | relative = relative || 100;
75 | plus = plus || 0;
76 |
77 | switch( device.platform ) {
78 | case "mobileweb":
79 | return device.platformHeight;
80 |
81 | case "iPhone OS":
82 | return device.platformHeight;
83 |
84 | default:
85 | //var pointDp = measurement.pointPXToDP(relative);
86 | var px = device.platformHeight * ( relative / 100 );
87 | var calcDp = Math.round( px / ( device.dpi / 160 ) );
88 | return( calcDp + parseInt( plus ) );
89 | break;
90 | }
91 |
92 | };
93 |
94 | /**
95 | * @function isIos7Plus
96 | * @summary Function to test if device is iOS 7 or later
97 | * @since 1.0.0
98 | * @returns {bool} - Returns true if iOS 7+ otherwise false
99 | */
100 | var isIos7Plus = function() {
101 | //TODO: Cache this call
102 | // iOS-specific test
103 | if( OS_IOS ) {
104 | //var version = Titanium.Platform.version.split(".");
105 | var version = device.version.split( "." );
106 | var major = parseInt( version[ 0 ], 10 );
107 |
108 | // Can only test this support on a 3.2+ device
109 | if( major >= 7 ) {
110 | return true;
111 | }
112 | }
113 | return false;
114 | }
115 |
116 | /**
117 | * @function isIos8Plus
118 | * @summary Function to test if device is iOS 8 or later
119 | * @since 1.0.0
120 | * @returns {bool} - Returns true if iOS 8+ otherwise false
121 | */
122 | var isIos8Plus = function() {
123 | //TODO: Cache this call
124 | // iOS-specific test
125 | if( OS_IOS ) {
126 | //var version = Titanium.Platform.version.split(".");
127 | var version = device.version.split( "." );
128 | var major = parseInt( version[ 0 ], 10 );
129 |
130 | // Can only test this support on a 3.2+ device
131 | if( major >= 8 ) {
132 | return true;
133 | }
134 | }
135 | return false;
136 | }
137 |
138 | /**
139 | * Fire orientationchange event
140 | */
141 | device.onOrientationChange = function( value ) {
142 | events.emit( 'nativeloop.orientationchange' );
143 | }
144 |
145 | /**
146 | * @function recalculate
147 | * @summary Calculate properties of the device when it is initialized or when device orientation is changed.
148 | * @since 1.0.0
149 | */
150 | device.recalculate = function() {
151 | var platformWidth = Ti.Platform.displayCaps.platformWidth;
152 | var platformHeight = Ti.Platform.displayCaps.platformHeight;
153 | // var deviceWidth = OS_IOS ? Ti.Platform.displayCaps.platformWidth : Math.round( Ti.Platform.displayCaps.platformWidth / ( Ti.Platform.displayCaps.dpi / 160 ) );
154 |
155 | var orientation = Ti.Gesture.orientation;
156 | device.isLandscape = orientation === ( Ti.UI.LANDSCAPE_LEFT || orientation === Ti.UI.LANDSCAPE_RIGHT );
157 | device.isPortrait = !device.isLandscape;
158 |
159 | device.platformWidth = device.isPortrait && platformWidth > platformHeight ? platformHeight : platformWidth;
160 | device.platformHeight = device.isPortrait && platformWidth > platformHeight ? platformWidth : platformHeight;
161 |
162 | device.actualHeight = calculatePercentHeight();
163 | device.height = isIos7Plus() ? device.actualHeight - 20 : device.actualHeight;
164 | device.width = calculatePercentWidth();
165 | //console.log(device);
166 |
167 | };
168 |
169 | /**
170 | * @function destroy
171 | * @summary Cleanup when destroying module.
172 | * @since 1.0.0
173 | * @returns {object} - description
174 | */
175 | device.destroy = function() {
176 |
177 | events.off( 'hero.orientationchange', device.recalculate );
178 | Ti.Gesture.removeEventListener( "orientationchange", device.onOrientationChange );
179 |
180 | }
181 |
182 | /**
183 | * @function getFriendlyOsNameAndVersion
184 | * @summary summary
185 | * @since 1.0.0
186 | * @returns {string} - description
187 | */
188 | var getFriendlyOsNameAndVersion = function() {
189 | var os = device.isIos ? "iOS" : device.os;
190 | return os + " " + os.version;
191 | }
192 |
193 | /**
194 | * @function OsName
195 | * @summary Get friendly OS name
196 | * @param {string} original - OS name
197 | * @since 1.0.0
198 | * @returns {string} - Friendly OS name
199 | */
200 | var OsName = function( original ) {
201 |
202 | switch( original ) {
203 |
204 | case "iphone":
205 | case "ipad":
206 | {
207 | return "iOS";
208 | }
209 |
210 | default:
211 | {
212 | return original;
213 | }
214 | }
215 | }
216 |
217 | /**
218 | * @function getFriendlyModel
219 | * @summary Get friendly device model name
220 | * @param {string} original - Original device model name
221 | * @since 1.0.0
222 | * @returns {string} - description
223 | */
224 | device.getFriendlyModel = function( original ) {
225 |
226 | original = original || device.model;
227 |
228 | switch( original ) {
229 |
230 | case "iPhone9,2":
231 | case "iPhone9,4":
232 | {
233 | return "iPhone 7 Plus";
234 | }
235 |
236 | case "iPhone9,1":
237 | case "iPhone9,3":
238 | {
239 | return "iPhone 7";
240 | }
241 |
242 | case "iPhone8,4":
243 | {
244 | return "iPhone SE";
245 | }
246 |
247 | case "iPhone8,2":
248 | {
249 | return "iPhone 6s Plus";
250 | }
251 |
252 | case "iPhone8,1":
253 | {
254 | return " iPhone 6s";
255 | }
256 | case "iPhone7,2":
257 | {
258 | return "iPhone 6";
259 | }
260 | case "iPhone7,1":
261 | {
262 | return "iPhone 6 Plus";
263 | }
264 | case "iPhone6,2":
265 | {
266 | return "iPhone 5s (A1457/A1518/A1530)";
267 | }
268 | case "iPhone6,1":
269 | {
270 | return "iPhone 5s (A1433/A1453)";
271 | }
272 | case "iPhone5,4":
273 | {
274 | return "iPhone 5c (A1507/A1516/A1529)";
275 | }
276 | case "iPhone5,3":
277 | {
278 | return "iPhone 5c (A1456/A1532)";
279 | }
280 | case "iPhone5,2":
281 | {
282 | return "iPhone 5 (A1429)";
283 | }
284 | case "iPhone5,1":
285 | {
286 | return "iPhone 5 (A1428)";
287 | }
288 | case "iPhone4,1":
289 | {
290 | return "iPhone 4S";
291 | }
292 | case "iPhone3,3":
293 | {
294 | return "iPhone 4 (CDMA)";
295 | }
296 | case "iPhone3,1":
297 | {
298 | return "iPhone 4 (GSM)";
299 | }
300 | case "iPhone2,1":
301 | {
302 | return "iPhone 3GS";
303 | }
304 | case "iPhone1,2":
305 | {
306 | return "iPhone 3G";
307 | }
308 | case "iPhone1,1":
309 | {
310 | return "iPhone";
311 | }
312 | case "iPad6,8":
313 | {
314 | return "iPad Pro (Wi-Fi+LTE)";
315 | }
316 | case "iPad6,7":
317 | {
318 | return "iPad Pro (Wi-Fi)";
319 | }
320 | case "iPad5,4":
321 | {
322 | return "iPad Air 2 (Wi-Fi+LTE)";
323 | }
324 | case "iPad5,3":
325 | {
326 | return "iPad Air 2 (Wi-Fi)";
327 | }
328 | case "iPad5,2":
329 | {
330 | return "iPad mini 4 (Wi-Fi+LTE)";
331 | }
332 | case "iPad5,1":
333 | {
334 | return "iPad mini 4 (Wi-Fi)";
335 | }
336 | case "iPad4,9":
337 | {
338 | return "iPad mini 3 (A1601)";
339 | }
340 | case "iPad4,8":
341 | {
342 | return "iPad mini 3 (A1600)";
343 | }
344 | case "iPad4,7":
345 | {
346 | return "iPad mini 3 (Wi-Fi)";
347 | }
348 | case "iPad4,6":
349 | {
350 | return "iPad mini 2 (Rev)";
351 | }
352 | default:
353 | {
354 | return original;
355 | }
356 | }
357 | }
358 |
359 | /**
360 | * @function init
361 | * @summary Initializes this module. Executed when module is loaded.
362 | * @since 1.0.0
363 | * @returns {object} - description
364 | */
365 | device.init = function() {
366 | device.model = Ti.Platform.model;
367 | device.friendlyModel = device.getFriendlyModel( device.model );
368 | device.version = Ti.Platform.version;
369 | device.versionMajor = parseInt( device.version.split( '.' )[ 0 ], 10 );
370 | device.versionMinor = parseInt( device.version.split( '.' )[ 1 ], 10 );
371 | device.dpi = Ti.Platform.displayCaps.dpi;
372 | device.os = Ti.Platform.osname;
373 | device.platform = Ti.Platform.name;
374 | device.isIos = device.platform === 'iPhone OS';
375 | device.isMobileWeb = device.os === 'mobileweb';
376 | device.isAndroid = device.os === 'android';
377 | device.isIphone = device.os === 'iphone';
378 | device.isIpad = device.os === 'ipad';
379 | device.isTizen = device.os === 'tizen';
380 | device.isSimulator = device.model === 'Simulator' || device.model.indexOf( 'sdk' ) !== -1;
381 | device.id = Ti.Platform.id;
382 | device.isIos7Plus = isIos7Plus() ? true : false;
383 | device.isIos8Plus = isIos8Plus() ? true : false;
384 |
385 | device.recalculate();
386 |
387 | events.on( 'nativeloop.orientationchange', device.recalculate );
388 | Ti.Gesture.addEventListener( "orientationchange", device.onOrientationChange );
389 |
390 | }();
--------------------------------------------------------------------------------
/lib/events.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file This is the core class for nativeloop event management.
12 | * @module nativeloop/events
13 | * @author Brenton House
14 | * @version 1.0.0
15 | * @since 1.0.0
16 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
17 | * @license Licensed under the terms of the MIT License (MIT)
18 | *
19 | */
20 |
21 | var EventEmitter = require( 'nativeloop/eventemitter2' );
22 |
23 | //TODO: make delimiter configurable
24 |
25 | var events = new EventEmitter( {
26 | wildcard: true,
27 | newListener: false,
28 | delimiter: '::',
29 | maxListeners: 20
30 | } );
31 |
32 | events.trigger = events.emit;
33 | events.fire = events.emit;
34 |
35 | module.exports = events;
--------------------------------------------------------------------------------
/lib/fonts/mobilewin8.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobilehero-archive/nativeloop/9043d7e314ec5db64dbe429379f640dda527e314/lib/fonts/mobilewin8.ttf
--------------------------------------------------------------------------------
/lib/iconfonts.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file This is the core class for managing iconfonts used by nativeloop.
12 | * @module nativeloop/iconsfonts
13 | * @author Brenton House
14 | * @version 1.0.0
15 | * @since 1.0.0
16 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
17 | * @license Licensed under the terms of the MIT License (MIT)
18 | *
19 | */
20 |
21 | var iconfonts = {};
22 | module.exports = iconfonts;
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file This is the core class for nativeloop funcationality.
12 | * @module nativeloop
13 | * @author Brenton House
14 | * @version 1.0.0
15 | * @since 1.0.0
16 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
17 | * @license Licensed under the terms of the MIT License (MIT)
18 | *
19 | */
20 |
21 | const events = require( 'events' );
22 | const apm = require( 'nativeloop/apm' );
23 |
24 | var ux = {};
25 | module.exports = ux;
26 |
27 |
28 | ux.createfontIcon = params => {
29 | console.debug( "creating nativeloop.fontIcon" );
30 | fixFontAttributes( params );
31 | }
32 |
33 | ux.createImageIcon = params => {
34 | console.debug( "creating nativeloop.imageIcon" );
35 | fixFontAttributes( params );
36 | }
37 |
38 | ux.createText = ux.createLabel = function( params ) {
39 | console.debug( "creating nativeloop.label" );
40 | // console.error( 'params: ' + JSON.stringify( params, null, 2 ) );
41 | params = createDefaultParams( params );
42 | fixFontAttributes( params );
43 | fixLines( params );
44 | var view = Ti.UI.createLabel( params );
45 | ux.addEventListeners( params, view );
46 | return view;
47 | }
48 |
49 | ux.createImage = ux.createImageView = function( params ) {
50 | console.debug( "creating nativeloop.ImageView" );
51 | params = createDefaultParams( params );
52 | if( params.src ) {
53 | params.image = params.src;
54 | }
55 | var view = Ti.UI.createImageView( params );
56 | ux.addEventListeners( params, view );
57 | return view;
58 | }
59 |
60 | ux.createFlex = function( params ) {
61 | console.debug( "creating nativeloop.flex" );
62 | params = createDefaultParams( params );
63 | var controller = Alloy.createWidget( 'nativeloop', 'flex', params );
64 | var view = controller.getView();
65 | ux.addEventListeners( params, view );
66 | return view;
67 |
68 | }
69 |
70 | ux.createTile = function( params ) {
71 | console.debug( "creating nativeloop.tile" );
72 | params = createDefaultParams( params );
73 | var controller = Alloy.createWidget( 'nativeloop', 'tile', params );
74 | var view = controller.getView();
75 | console.error( 'params.click: ' + utils.stringify( params.click, null, 2 ) );
76 | ux.addEventListeners( params, view );
77 | return view;
78 | }
79 |
80 |
81 | ux.createView = function( params ) {
82 | params = createDefaultParams( params );
83 | var view = Ti.UI.createView( params );
84 | ux.addEventListeners( params, view );
85 | return view;
86 | }
87 |
88 | ux.createTextField = function( params ) {
89 | params = createDefaultParams( params );
90 | var view = Ti.UI.createTextField( params );
91 | ux.addEventListeners( params, view );
92 | return view;
93 | }
94 |
95 | var fixFontAttributes = function( params ) {
96 | // find any font attributes and create proper font object
97 | if( params && ( params.fontSize || params.fontStyle || params.fontFamily || params.fontWeight || params.textStyle ) ) {
98 |
99 | params.font = params.font || {};
100 | params.font.fontSize = params.fontSize || params.font.fontSize;
101 | params.font.fontStyle = params.fontStyle || params.font.fontStyle; // iOS only: 'italic' or 'normal'
102 | params.font.fontFamily = params.fontFamily || params.font.fontFamily;
103 | params.font.fontWeight = params.fontWeight || params.font.fontWeight;
104 | params.font.textStyle = params.textStyle || params.font.textStyle;
105 |
106 | delete params[ 'fontSize' ];
107 | delete params[ 'fontStyle' ];
108 | delete params[ 'fontFamily' ];
109 | delete params[ 'fontWeight' ];
110 | delete params[ 'textStyle' ];
111 | }
112 | }
113 |
114 | /**
115 | * @function fixLines
116 | * @summary Add support for lines property on iOS
117 | * @param {object} params - description
118 | * @since 1.0.0
119 | * @returns {object} - description
120 | */
121 | var fixLines = function( params ) {
122 | if( OS_IOS ) {
123 | if( params.lines ) {
124 | _.defaults( params.font, {
125 | fontSize: "15sp"
126 | } );
127 | if( !!parseInt( params.font.fontSize ) ) {
128 | params.height = ( Math.floor( parseInt( params.lines ) ) * Math.floor( parseInt( params.font.fontSize ) ) * 1.333 ) + 1;
129 | // console.trace("setting height height to: " + params.height);
130 | }
131 | }
132 | }
133 |
134 | return params;
135 | }
136 |
137 |
138 | var createDefaultParams = function( params ) {
139 | params = _.defaults( params, {} );
140 | return params;
141 | }
142 |
143 | var known_events = [ "click", "dblclick", "doubletap", "focus", "keypressed", "longclick", "longpress", "pinch", "postlayout", "singletap", "swipe", "touchcancel", "touchend", "touchmove", "touchstart", "twofingertap", "return", "change", "blur", "focus" ];
144 |
145 |
146 | /**
147 | * @function addEventListeners
148 | * @summary Add event listeners based on event shortcut names defined in xml or config
149 | * @param {object} params - Parameters used to create view
150 | * @param {object} view - Ti.UI.View that will trigger events
151 | * @since 1.0.0
152 | */
153 | ux.addEventListeners = function( params, view ) {
154 |
155 | var found = _.intersection( _.keys( params ), known_events );
156 | _.forEach( found, function( event ) {
157 | if( params[ event ] ) {
158 | var actions = params[ event ].split( "||" );
159 | var eventHandler;
160 | if( params.__navigatorId ) {
161 | eventHandler = Alloy.Navigators[ params.__navigatorId ] || events;
162 | } else {
163 | eventHandler = events;
164 | }
165 | _.forEach( actions, function( action ) {
166 | Ti.API.trace( "Adding Event Listener -- " + event + ":" + action );
167 | view.addEventListener( event, function( e ) {
168 | Ti.API.trace( "Triggering event action -- " + action );
169 | eventHandler.emit( action, e );
170 | } );
171 |
172 | } );
173 | }
174 | } );
175 |
176 | return view;
177 |
178 | }
179 |
180 |
181 |
182 | _.once( () => Alloy.createController = ( name, args ) => {
183 | var __prefix = "Alloy.createController: ";
184 | apm.leaveBreadcrumb( __prefix + "entering" );
185 | var controller = new( require( "alloy/controllers/" + name ) )( args );
186 | // controller.nav = _.get( args, 'params.navigator' );[]
187 | // controller.nav = _.get( args, 'navigator' );
188 | apm.leaveBreadcrumb( __prefix + "exiting" );
189 | return controller;
190 | } )();
191 |
192 | _.once( () => Alloy.createWidget = ( id, name, args ) => {
193 | var __prefix = "Alloy.createWidget: ";
194 | apm.leaveBreadcrumb( __prefix + "entering" );
195 | if( "undefined" != typeof name && null !== name && _.isObject( name ) && !_.isString( name ) ) {
196 | args = name;
197 | name = DEFAULT_WIDGET;
198 | }
199 |
200 | // if( args ) {
201 | // if( args.navigator ) {
202 | // args.params = args.params || {};
203 | // args.params.navigator = args.navigator;
204 | // delete args.navigator;
205 | // }
206 | // }
207 |
208 | var controller = new( require( "alloy/widgets/" + id + "/controllers/" + ( name || DEFAULT_WIDGET ) ) )( args );
209 | // controller.nav = _.get( args, 'navigator' );
210 | apm.leaveBreadcrumb( __prefix + "exiting" );
211 | return controller;
212 |
213 | } )();
--------------------------------------------------------------------------------
/lib/navigation.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file This is the core class for nativeloop naviation.
12 | * @module nativeloop/navigation
13 | * @author Brenton House
14 | * @version 1.0.0
15 | * @since 1.0.0
16 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
17 | * @license Licensed under the terms of the MIT License (MIT)
18 | *
19 | */
20 |
21 | const __modulename = __filename;
22 | const apm = require( 'nativeloop/apm' );
23 |
24 | var Navigation = {};
25 |
26 | // Similar to API used by react-native-navigation (https://github.com/wix/react-native-navigation/wiki/Top-Level-API)
27 |
28 | /**
29 | * @function createTabBasedWindow
30 | * @summary create a window with bottom-tab control
31 | * @param {object} params
32 | * @param {object} params.tabsStyle
33 | * @param {object} [params.passProps] - simple serializable object that will pass as props to all top screens (optional)
34 | * @param {object} [params.drawer] - side menu drawer in your app
35 | * @param {object} [params.drawer.left] - left side drawer properties
36 | * @param {object} [params.drawer.right] - right side drawer properties
37 | * @param {string} [params.animationType] - add transition animation to root change: 'none', 'slide-down', 'fade' (optional)
38 | * @param {object[]} params.tabs - tabs definitions
39 | * @param {string} [params.tabs[].label] - tab label as appears under the icon (optional)
40 | * @param {string|object} params.tabs[].screen - unique ID registered with Navigation.registerScreen
41 | * @param {string} params.tabs[].selectedIcon - local image asset for the tab icon selected state (optional)
42 | * @param {string} params.tabs[].title - title of the screen as appears in the nav bar (optional)
43 | * @param {object} params.tabs[].navigatorStyle - override the navigator style for the tab screen
44 | * @param {object} params.tabs[].navigatorButtons - override the nav buttons for the tab screen
45 | * @param {object[]} params.tabs[].navigatorButtons.leftButtons - override the left nav buttons for the tab screen
46 | * @param {object[]} params.tabs[].navigatorButtons.leftButtons[].title - title for the left nav button
47 | * @param {string} params.tabs[].navigatorButtons.leftButtons[].id - id for this button
48 | * @param {boolean} [params.tabs[].navigatorButtons.leftButtons[].disabled=false] - used to disable the button (optional)
49 | * @param {string} [params.tabs[].navigatorButtons.leftButtons[].image] - local image asset name to use for button (optional)
50 | * @param {string} [params.tabs[].navigatorButtons.leftButtons[].icon] - local icon name to use for button (optional)
51 | * @param {object[]} params.tabs[].navigatorButtons.rightButtons - override the right nav buttons for the tab screen
52 | * @param {object[]} params.tabs[].navigatorButtons.rightButtons[].title - title for the right nav button
53 | * @param {string} params.tabs[].navigatorButtons.rightButtons[].id - id for this button
54 | * @param {boolean} [params.tabs[].navigatorButtons.rightButtons[].disabled=false] - used to disable the button (optional)
55 | * @param {string} [params.tabs[].navigatorButtons.rightButtons[].image] - local image asset name to use for button (optional)
56 | * @param {string} [params.tabs[].navigatorButtons.rightButtons[].icon] - local icon name to use for button (optional)
57 | * @since 1.0.0
58 | */
59 | Navigation.createTabBasedWindow = ( params = {} ) => {
60 | // create widget controller for tab
61 | // create navigator for tab (passing in widget controller for tab)
62 | // navigate to first screen
63 | // pass window from widget controller for tab to constructor for widget controller for tabbed window
64 | // open widget controller window for tabbed window
65 |
66 | let controller = Alloy.createWidget( 'nativeloop', 'tabbedWindow', params );
67 | let window = controller.getView();
68 | // window.open();
69 | return window;
70 | };
71 |
72 | /**
73 | * @function createNavBasedWindow
74 | * @summary create a window with a top navigation bar
75 | * @param {object} params
76 | * @param {object} params.screen - screen parameters
77 | * @param {string} params.screen.title - title of the screen as appears in the nav bar (optional)
78 | * @param {object} params.screen.navigatorStyle - override the navigator style for the tab screen
79 | * @param {object} params.screen.navigatorButtons - override the nav buttons for the tab screen
80 | * @param {object[]} params.screen.navigatorButtons.leftButtons - override the left nav buttons for the tab screen
81 | * @param {string} params.screen.navigatorButtons.leftButtons[].title - title for the left nav button
82 | * @param {string} params.screen.navigatorButtons.leftButtons[].id - id for this button
83 | * @param {boolean} [params.screen.navigatorButtons.leftButtons[].disabled=false] - used to disable the button (optional)
84 | * @param {string} [params.screen.navigatorButtons.leftButtons[].image] - local image asset name to use for button (optional)
85 | * @param {string} [params.screen.navigatorButtons.leftButtons[].icon] - local icon name to use for button (optional)
86 | * @param {object[]} params.screen.navigatorButtons.rightButtons - override the right nav buttons for the tab screen
87 | * @param {object[]} params.screen.navigatorButtons.rightButtons[].title - title for the right nav button
88 | * @param {string} params.screen.navigatorButtons.rightButtons[].id - id for this button
89 | * @param {boolean} [params.screen.navigatorButtons.rightButtons[].disabled=false] - used to disable the button (optional)
90 | * @param {string} [params.screen.navigatorButtons.rightButtons[].image] - local image asset name to use for button (optional)
91 | * @param {string} [params.screen.navigatorButtons.rightButtons[].icon] - local icon name to use for button (optional)
92 | * @param {object} [params.passProps] - simple serializable object that will pass as props to all top screens (optional)
93 | * @param {object} [params.drawer] - side menu drawer in your app
94 | * @param {object} [params.drawer.left] - left side drawer properties
95 | * @param {object} [params.drawer.right] - right side drawer properties
96 | * @param {string} [params.animationType] - add transition animation to root change: 'none', 'slide-down', 'fade' (optional)
97 | * @since 1.0.0
98 | */
99 | Navigation.createNavBasedWindow = ( params = {} ) => {
100 | var __prefix = __modulename + '.push: ';
101 | apm.leaveBreadcrumb( __prefix + 'entering' );
102 |
103 | // create widget controller
104 | // create navigator (passing in widget controller)
105 | // navigate to first screen
106 | // open widget controller window
107 |
108 | //TODO: Check for required values
109 |
110 | var Navigator = require( 'nativeloop/navigator' );
111 | let navigator = new Navigator();
112 |
113 | // if( _.isString( params ) ) {
114 | // params = { screen: { name: params } }
115 | // } else if( _.isString( params.screen ) ) {
116 | // params.screen = { name: params }
117 | // }
118 |
119 | // let screen = _.cloneDeep( params.screen );
120 | // screen.passProps = _.cloneDeep( params.passProps || {} );
121 | navigator.push( params );
122 |
123 | let window = navigator.controller.getView();
124 | // window.open();
125 |
126 | apm.leaveBreadcrumb( __prefix + '.exiting' );
127 | __prefix = null;
128 |
129 | return window;
130 | };
131 |
132 | Navigation.showModal = ( params = {} ) => {};
133 | Navigation.dismissModal = ( params = {} ) => {};
134 | Navigation.dismissAllModals = ( params = {} ) => {};
135 | Navigation.showLightBox = ( params = {} ) => {};
136 | Navigation.dismissLightBox = ( params = {} ) => {};
137 | Navigation.registerScreen = ( screenID, generator ) => {};
138 | Navigation.registerComponent = ( screenID, generator, store = undefined, Provider = undefined ) => {};
139 |
140 | module.exports = Navigation;
141 |
142 | // module.exports = {
143 | // Navigation,
144 | // }
145 |
146 | // Screen API: https://github.com/wix/react-native-navigation/wiki/Screen-API
147 |
148 | // Add: popToTop() // from ex-navigation
--------------------------------------------------------------------------------
/lib/process.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | function noop() {}
4 |
5 | var process = module.exports = {};
6 |
7 | process.nextTick = function() {
8 | var canSetImmediate = "undefined" != typeof window && window.setImmediate;
9 | var canMutationObserver = "undefined" != typeof window && window.MutationObserver;
10 | var canPost = "undefined" != typeof window && window.postMessage && window.addEventListener;
11 | if( canSetImmediate ) return function( f ) {
12 | return window.setImmediate( f );
13 | };
14 | var queue = [];
15 | if( canMutationObserver ) {
16 | var hiddenDiv = document.createElement( "div" );
17 | var observer = new MutationObserver( function() {
18 | var queueList = queue.slice();
19 | queue.length = 0;
20 | queueList.forEach( function( fn ) {
21 | fn();
22 | } );
23 | } );
24 | observer.observe( hiddenDiv, {
25 | attributes: true
26 | } );
27 | return function( fn ) {
28 | queue.length || hiddenDiv.setAttribute( "yes", "no" );
29 | queue.push( fn );
30 | };
31 | }
32 | if( canPost ) {
33 | window.addEventListener( "message", function( ev ) {
34 | var source = ev.source;
35 | if( ( source === window || null === source ) && "process-tick" === ev.data ) {
36 | ev.stopPropagation();
37 | if( queue.length > 0 ) {
38 | var fn = queue.shift();
39 | fn();
40 | }
41 | }
42 | }, true );
43 | return function( fn ) {
44 | queue.push( fn );
45 | window.postMessage( "process-tick", "*" );
46 | };
47 | }
48 | return function( fn ) {
49 | setTimeout( fn, 0 );
50 | };
51 | }();
52 |
53 | process.title = "browser";
54 |
55 | process.browser = true;
56 |
57 | process.env = {};
58 |
59 | process.argv = [];
60 |
61 | process.on = noop;
62 |
63 | process.addListener = noop;
64 |
65 | process.once = noop;
66 |
67 | process.off = noop;
68 |
69 | process.removeListener = noop;
70 |
71 | process.removeAllListeners = noop;
72 |
73 | process.emit = noop;
74 |
75 | process.binding = function() {
76 | throw new Error( "process.binding is not supported" );
77 | };
78 |
79 | process.cwd = function() {
80 | return "/";
81 | };
82 |
83 | process.chdir = function() {
84 | throw new Error( "process.chdir is not supported" );
85 | };
--------------------------------------------------------------------------------
/lib/resolver.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file This is the core class for resolving modules in nativeloop.
12 | * @module nativeloop/resolver
13 | * @author Brenton House
14 | * @version 1.0.0
15 | * @since 1.0.0
16 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
17 | * @license Licensed under the terms of the MIT License (MIT)
18 | *
19 | */
20 |
21 | var logger = console;
22 | const _ = require( "./lodash" );
23 | const path = require( "path" );
24 | var registry = {
25 | files: [],
26 | directories: [],
27 | core: [],
28 | fallback: [],
29 | alias: []
30 | };
31 |
32 |
33 |
34 | //Add backwards compatibility to lodash
35 | _.contains ? _.includes || _.mixin( {
36 | includes: _.contains
37 | } ) : _.mixin( {
38 | contains: _.includes
39 | } );
40 |
41 |
42 | function convert_to_alloy_path( resolved_path ) {
43 | var parsed_path = path.posix.parse( resolved_path );
44 | return path.posix.join( parsed_path.dir, parsed_path.name );
45 | }
46 |
47 | function check_for_alias( request ) {
48 | var alias_module = load_alias_modules( request );
49 | if( alias_module ) {
50 | logger.debug( "alias_module: " + convert_to_alloy_path( alias_module ) );
51 | return convert_to_alloy_path( alias_module );
52 | }
53 | return convert_to_alloy_path( request );
54 | }
55 |
56 | function _resolve( request, basepath, physical_file ) {
57 | logger.debug( "resolve request: " + request );
58 | logger.debug( "resolve basepath: " + basepath );
59 | basepath = basepath || path.posix.sep;
60 | if( !physical_file ) {
61 | var core_module = load_core_modules( request );
62 | if( core_module ) {
63 | logger.debug( "core_module: " + check_for_alias( core_module ) );
64 | return check_for_alias( core_module );
65 | }
66 | }
67 | var start = request.substring( 0, 1 );
68 | if( "." === start || "/" === start ) {
69 | var file_module = load_as_file( request, basepath );
70 | if( file_module ) {
71 | logger.debug( "file_module: " + file_module );
72 | return physical_file ? file_module : check_for_alias( file_module );
73 | }
74 | var directory_module = load_as_directory( request, basepath );
75 | if( directory_module ) {
76 | logger.debug( "directory_module: " + directory_module );
77 | return physical_file ? directory_module : check_for_alias( directory_module );
78 | }
79 | }
80 | var node_module = load_node_modules( request, basepath );
81 | if( node_module ) {
82 | logger.debug( "node_module: " + node_module );
83 | console.error( "physical_file: " + JSON.stringify( physical_file, null, 2 ) );
84 | return physical_file ? node_module : check_for_alias( node_module );
85 | }
86 | var alloy_file_module = load_as_file( request, "/" );
87 | if( alloy_file_module ) {
88 | logger.debug( "alloy_file_module: " + alloy_file_module );
89 | return physical_file ? alloy_file_module : check_for_alias( alloy_file_module );
90 | }
91 | var fallback_module = load_fallback_modules( request );
92 | if( fallback_module ) {
93 | logger.debug( "fallback_module: " + fallback_module );
94 | return physical_file ? fallback_module : check_for_alias( fallback_module );
95 | }
96 | logger.trace( "Cannot find file. Returning request: " + request );
97 | return request;
98 | }
99 |
100 | function load_core_modules( request ) {
101 | var module_path = _.find( registry.core, function( item ) {
102 | return item.id === request;
103 | } );
104 | if( module_path ) return module_path.path;
105 | }
106 |
107 | function load_fallback_modules( request ) {
108 | var module_path = _.find( registry.fallback, function( item ) {
109 | return item.id === request;
110 | } );
111 | if( module_path ) return module_path.path;
112 | }
113 |
114 | function load_alias_modules( request ) {
115 | var module_path = _.find( registry.alias, function( item ) {
116 | return item.id === request;
117 | } );
118 | if( module_path ) return module_path.path;
119 | logger.debug( "alias not found: " + request );
120 | }
121 |
122 | function load_as_file( request, startpath ) {
123 | var module_path;
124 | var resolved_path = path.posix.resolve( startpath, request );
125 | logger.debug( "resolved_path: " + resolved_path );
126 | _.includes( registry.files, resolved_path ) && ( module_path = resolved_path );
127 | if( module_path ) return module_path;
128 | var extension = path.extname( request );
129 | if( !extension ) {
130 | var exts = [ ".js", ".json" ];
131 | _.forEach( exts, function( ext ) {
132 | resolved_path = path.posix.resolve( startpath, request + ext );
133 | logger.debug( "resolved_path: " + resolved_path );
134 | _.includes( registry.files, resolved_path ) && ( module_path = resolved_path );
135 | if( !module_path ) return !module_path;
136 | } );
137 | }
138 | return module_path;
139 | }
140 |
141 | function load_as_directory( request, startpath ) {
142 | var resolved_path = path.posix.resolve( startpath, request );
143 | var module_path = _.find( registry.directories, function( item ) {
144 | return item.id === resolved_path;
145 | } );
146 | if( module_path ) return module_path.path;
147 | }
148 |
149 | function load_node_modules( request, startpath ) {
150 | var resolved_path;
151 | var nodepaths = node_modules_paths( startpath );
152 | _.forEach( nodepaths, function( nodepath ) {
153 | resolved_path = load_as_file( request, nodepath );
154 | return !resolved_path;
155 | } );
156 | if( resolved_path ) return resolved_path;
157 | _.forEach( nodepaths, function( nodepath ) {
158 | resolved_path = load_as_directory( request, nodepath );
159 | return !resolved_path;
160 | } );
161 | return resolved_path;
162 | }
163 |
164 | function node_modules_paths( from ) {
165 | from = path.posix.resolve( from );
166 | var paths = [];
167 | var parts = from.split( splitRe );
168 | for( var tip = parts.length - 1; tip >= 0; tip-- ) {
169 | if( "node_modules" === parts[ tip ] ) continue;
170 | var dir = parts.slice( 0, tip + 1 ).concat( "node_modules" ).join( path.posix.sep );
171 | paths.push( dir );
172 | }
173 | return paths;
174 | }
175 |
176 |
177 | var ensureCore = function( key, value ) {
178 | _.find( registry.core, function( item ) {
179 | return item.id === key;
180 | } ) || registry.core.push( {
181 | id: key,
182 | path: value
183 | } );
184 | };
185 |
186 | var ensureAlias = function( key, value ) {
187 | _.find( registry.alias, function( item ) {
188 | return item.id === key;
189 | } ) || registry.alias.push( {
190 | id: key,
191 | path: value
192 | } );
193 | };
194 |
195 | var ensureFallback = function( key, value ) {
196 | _.find( registry.fallback, function( item ) {
197 | return item.id === key;
198 | } ) || registry.fallback.push( {
199 | id: key,
200 | path: value
201 | } );
202 | };
203 |
204 | var resolver = function( _registry, _logger, building ) {
205 | _registry && ( registry = _.defaults( _registry, registry ) );
206 | _logger && ( logger = _logger );
207 | logger.error( "-----------------------------------------------------------" );
208 | if( building ) {
209 | ensureCore( "path", "nativeloop/path" );
210 | ensureCore( "alloy", "/alloy" );
211 | ensureCore( "nativeloop", "/nativeloop" );
212 | ensureCore( "resolver", "nativeloop/resolver" );
213 | ensureCore( "process", "nativeloop/process" );
214 | ensureCore( "util", "nativeloop/util" );
215 | ensureAlias( "alloy/underscore", "nativeloop/lodash" );
216 | ensureFallback( "lodash", "nativeloop/lodash" );
217 | ensureFallback( "events", "nativeloop/events" );
218 | ensureFallback( "bluebird", "nativeloop/bluebird" );
219 | _.forEach( registry.fallback, function( fallback ) {
220 | fallback.path = _resolve( fallback.path, "/" );
221 | } );
222 | _.forEach( registry.alias, function( alias ) {
223 | alias.id = _resolve( alias.id, "/", true );
224 | alias.path = _resolve( alias.path, "/" );
225 | } );
226 | _.forEach( registry.core, function( core ) {
227 | core.path = _resolve( core.path, "/" );
228 | } );
229 | }
230 | Object.defineProperty( this, "registry", {
231 | get: function() {
232 | return _.clone( registry );
233 | },
234 | enumerable: true,
235 | configurable: false
236 | } );
237 | };
238 |
239 | module.exports = resolver;
240 |
241 | resolver.prototype.resolve = _.memoize( _resolve, function( request, basepath ) {
242 | return request + "::" + basepath;
243 | } );
244 |
245 | var splitRe = /\//;
--------------------------------------------------------------------------------
/lib/util.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | // Copyright Node.js contributors. All rights reserved.
3 |
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to
6 | // deal in the Software without restriction, including without limitation the
7 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 | // sell copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 |
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 |
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 | // IN THE SOFTWARE.
21 |
22 |
23 | /**
24 | * Inherit the prototype methods from one constructor into another.
25 | *
26 | * The Function.prototype.inherits from lang.js rewritten as a standalone
27 | * function (not on Function.prototype). NOTE: If this file is to be loaded
28 | * during bootstrapping this function needs to be rewritten using some native
29 | * functions as prototype setup using normal JavaScript does not work as
30 | * expected during bootstrapping (see mirror.js in r114903).
31 | *
32 | * @param {function} ctor Constructor function which needs to inherit the
33 | * prototype.
34 | * @param {function} superCtor Constructor function to inherit prototype from.
35 | * @throws {TypeError} Will error if either constructor is null, or if
36 | * the super constructor lacks a prototype.
37 | */
38 | exports.inherits = function( ctor, superCtor ) {
39 |
40 | if( ctor === undefined || ctor === null )
41 | throw new TypeError( 'The constructor to "inherits" must not be ' +
42 | 'null or undefined' );
43 |
44 | if( superCtor === undefined || superCtor === null )
45 | throw new TypeError( 'The super constructor to "inherits" must not ' +
46 | 'be null or undefined' );
47 |
48 | if( superCtor.prototype === undefined )
49 | throw new TypeError( 'The super constructor to "inherits" must ' +
50 | 'have a prototype' );
51 |
52 | ctor.super_ = superCtor;
53 | Object.setPrototypeOf( ctor.prototype, superCtor.prototype );
54 | };
--------------------------------------------------------------------------------
/lib/utils.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file This is the core class for functionality enabled by the MobileHero platform.
12 | * @module nativeloop/utils
13 | * @author Brenton House
14 | * @version 1.0.0
15 | * @since 1.0.0
16 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
17 | * @license Licensed under the terms of the MIT License (MIT)
18 | *
19 | */
20 |
21 | var utils = {};
22 | module.exports = utils;
23 |
24 | /**
25 | * @function createUrlHash
26 | * @param {string} url - Url to be hashed
27 | * @since 1.0.0
28 | * @returns {string} Hash of normalized url
29 | */
30 | utils.createUrlHash = url => {
31 | //TODO: Normalize url
32 |
33 | return Ti.Utils.md5HexDigest( url );
34 | };
35 |
36 | /**
37 | * @function openURL
38 | * @param {string} url - Url to be opened
39 | * @since 1.0.0
40 | * @returns {boolean} Success of opening URL
41 | */
42 | utils.openURL = function( url ) {
43 | if( _.isArray( url ) ) {
44 | url = url[ 0 ];
45 | }
46 | if( !Ti.Platform.canOpenURL( url ) ) {
47 | console.warn( 'Not able to open url: ' + url );
48 | return false;
49 | }
50 | var success = false;
51 | try {
52 | success = Ti.Platform.openURL( url );
53 | } catch( ex ) {
54 | console.error( 'Failed to open url: ' + url );
55 | Alloy.Globals.apm.logHandledException( err );
56 | return false;
57 | }
58 |
59 | return success;
60 | };
61 |
62 | /**
63 | * Parse a percentage of a given whole or device width (if whole is undefined)
64 | * @function parsePercentage
65 | * @param {string} input - value to be parsed for a percentage and then converted to number
66 | * @param {number} [whole] - value of entire width (defaults to device width)
67 | * @since 1.0.0
68 | * @returns {number}
69 | */
70 | utils.parsePercentage = function( input, whole ) {
71 | if( !input || input === Ti.UI.SIZE || input === Ti.UI.FILL ) {
72 | return input;
73 | }
74 | whole = whole || require( 'nativeloop/device' ).width;
75 | if( _.isString( input ) ) {
76 | var test = input.slice( -1 );
77 | if( test === '%' ) {
78 | var percentage = input.slice( 0, -1 );
79 | var percentageInt = _.parseInt( percentage );
80 | if( percentageInt > 0 ) {
81 | return whole * ( percentageInt / 100 );
82 | }
83 | } else {
84 | var parsedInput = _.parseInt( input );
85 | return _.isFinite( parsedInput ) ? parsedInput : input;
86 | }
87 | }
88 |
89 | return input;
90 | };
91 |
92 | /**
93 | * Parse input in CSS style padding format
94 | * @function parsePadding
95 | * @param {string|object} paddingInput
96 | * @param {number} totalWidth
97 | * @since 1.0.0
98 | * @returns {object} padding object
99 | */
100 | utils.parsePadding = function( paddingInput, totalWidth ) {
101 | // console.error( 'paddingInput: ' + JSON.stringify( paddingInput, null, 2 ) );
102 | var padding = {};
103 |
104 | if( _.isNil( paddingInput ) ) {
105 | // return padding;
106 | padding.exists = false;
107 | paddingInput = 0;
108 | } else {
109 | padding.exists = true;
110 | }
111 |
112 | if( _.isNumber( paddingInput ) ) {
113 | paddingInput = paddingInput.toString();
114 | // console.error( 'paddingInput: ' + JSON.stringify( paddingInput, null, 2 ) );
115 | } else if( _.isString( paddingInput ) ) {
116 | if( paddingInput.indexOf( ' ' ) > 0 ) {
117 | //paddingInput = _.map(paddingInput.split(' '), function (value) { return parseInt(value); });
118 | paddingInput = paddingInput.split( ' ' );
119 | }
120 | }
121 | if( _.isObject( paddingInput ) ) {
122 | if( _.isArray( paddingInput ) ) {
123 | var ln = paddingInput.length;
124 |
125 | if( ln === 1 ) {
126 | padding.top = paddingInput[ 0 ];
127 | padding.right = padding.top;
128 | padding.bottom = padding.top;
129 | padding.left = padding.top;
130 | } else if( ln === 2 ) {
131 | padding.top = paddingInput[ 0 ];
132 | padding.right = paddingInput[ 1 ];
133 | padding.bottom = padding.top;
134 | padding.left = padding.right;
135 | } else if( ln === 3 ) {
136 | padding.top = paddingInput[ 0 ];
137 | padding.right = paddingInput[ 1 ];
138 | padding.bottom = paddingInput[ 2 ];
139 | padding.left = padding.right;
140 | } else {
141 | padding.top = paddingInput[ 0 ];
142 | padding.right = paddingInput[ 1 ];
143 | padding.bottom = paddingInput[ 2 ];
144 | padding.left = paddingInput[ 3 ];
145 | }
146 | } else {
147 | padding.top = paddingInput.top || 0;
148 | padding.right = paddingInput.right || 0;
149 | padding.bottom = paddingInput.bottom || 0;
150 | padding.left = paddingInput.left || 0;
151 | }
152 | } else {
153 | padding.top = paddingInput;
154 | padding.right = paddingInput;
155 | padding.bottom = paddingInput;
156 | padding.left = paddingInput;
157 | }
158 |
159 | padding.top = utils.parsePercentage( padding.top, totalWidth );
160 | padding.right = utils.parsePercentage( padding.right, totalWidth );
161 | padding.bottom = utils.parsePercentage( padding.bottom, totalWidth );
162 | padding.left = utils.parsePercentage( padding.left, totalWidth );
163 |
164 | // console.error( 'padding: ' + JSON.stringify( padding, null, 2 ) );
165 |
166 | return padding;
167 | };
168 |
169 | /**
170 | * @function tryParseInt
171 | * @summary Converts the string representation of a number to an integer
172 | * @param {string} intput - A string representing a number to convert.
173 | * @param {object} [defaultValue] - Default value to be used if conversion fails
174 | * @since 1.0.0
175 | * @returns {int} - The float equivalent to the numeric value contained in input
176 | */
177 | utils.tryParseInt = function( input, defaultValue ) {
178 | var retValue = parseInt( input );
179 | if( isNaN( retValue ) ) {
180 | retValue = defaultValue;
181 | }
182 |
183 | return retValue;
184 | };
185 |
186 | /**
187 | * @function tryParseFloat
188 | * @summary Converts the string representation of a number to a float
189 | * @param {string} str - A string representing a number to convert.
190 | * @param {object} [defaultValue] - Default value to be used if conversion fails
191 | * @since 1.0.0
192 | * @returns {object} - The float equivalent to the numeric value contained in input
193 | */
194 | utils.tryParseFloat = function( str, defaultValue ) {
195 | var retValue = parseFloat( str );
196 | if( isNaN( retValue ) ) {
197 | retValue = defaultValue;
198 | }
199 |
200 | return retValue;
201 | };
202 |
203 | /**
204 | * @function isFloat
205 | * @summary Checks to see if a value is float
206 | * @param {*} input - The value to check to see if it is a float
207 | * @since 1.0.0
208 | * @returns {bool} - true if input is float otherwise false
209 | */
210 | utils.isFloat = function( v ) {
211 | return Number( input ) === input && input % 1 !== 0;
212 | };
213 |
214 |
215 | utils.decimalPlaces = function( num ) {
216 | var match = ( '' + num ).match( /(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/ );
217 | if( !match ) {
218 | return 0;
219 | }
220 | return Math.max(
221 | 0,
222 | // Number of digits right of decimal point.
223 | ( match[ 1 ] ? match[ 1 ].length : 0 ) -
224 | // Adjust for scientific notation.
225 | ( match[ 2 ] ? +match[ 2 ] : 0 )
226 | );
227 | };
228 |
229 | /**
230 | * @function stringify
231 | * @summary Converts an object to a string in a safe way (skipping circular values)
232 | * @param {object} input - Object to be converted to string
233 | * @since 1.0.0
234 | * @returns {string} - String value of input
235 | */
236 | utils.stringify = input => {
237 | var cache = [];
238 | return JSON.stringify(
239 | input,
240 | function( key, value ) {
241 | if( typeof value === 'object' && value !== null ) {
242 | if( cache.indexOf( value ) !== -1 ) {
243 | // Circular reference found, discard key
244 | return;
245 | }
246 | // Store value in our collection
247 | cache.push( value );
248 | }
249 | return value;
250 | },
251 | 2
252 | );
253 | };
254 |
255 | /**
256 | * @function saveIconAsFile
257 | * @summary Saves a font icon character as an image file
258 | * @param {object} params - Parameters used to create image
259 | * @param {string} params.name - Font and character to use in format: fontname.character*
260 | * @param {string} [params.color] - Foreground color of the icon (defaults to black)
261 | * @param {boolean} [params.force] - Force generation of image file (defaults to black)
262 | * @since 1.0.0
263 | * @returns {string} - Path of newly created object
264 | */
265 | utils.saveIconAsFile = function( params ) {
266 | //TODO: take color and size into consideration
267 | params.color = params.color || 'black';
268 |
269 | let iconNormal = Titanium.Filesystem.getFile(
270 | Titanium.Filesystem.getTempDirectory(),
271 | `${params.name}_${params.height}_${params.color}.png`
272 | );
273 | if( params.force || !iconNormal.exists() ) {
274 | params.retina = false;
275 | let blob = utils.getIconAsBlob( params );
276 | iconNormal.write( blob );
277 | // console.error( 'normal.blob.height: ' + JSON.stringify( blob.height, null, 2 ) );
278 | // console.error( 'normal.blob.width: ' + JSON.stringify( blob.width, null, 2 ) );
279 | }
280 |
281 | //TODO: Not sure why retina sized icons are showing twice the size on
282 | // a retina device, but commenting out for now.
283 |
284 | // if( OS_IOS ) {
285 | // let iconRetina = Titanium.Filesystem.getFile(
286 | // Titanium.Filesystem.getTempDirectory(),
287 | // `${params.name}_${params.color}@2x.png`
288 | // );
289 |
290 | // if( params.force || !iconRetina.exists() ) {
291 | // params.retina = true;
292 | // let blob = utils.getIconAsBlob( params );
293 | // iconRetina.write( blob );
294 | // console.error( 'retina.blob.height: ' + JSON.stringify( blob.height, null, 2 ) );
295 | // console.error( 'retina.blob.width: ' + JSON.stringify( blob.width, null, 2 ) );
296 | // }
297 | // }
298 |
299 | return iconNormal.nativePath;
300 | };
301 |
302 | /**
303 | * @function getIconAsBlob
304 | * @summary Generates an image blob for a specified icon font character
305 | * @param {object} params - Parameters used to create image
306 | * @since 1.0.0
307 | * @returns {object} - Image blog representing icon font character
308 | */
309 | utils.getIconAsBlob = function( params ) {
310 | return utils.getIconAsLabel( params ).toImage( null, !!params.retina );
311 | };
312 |
313 | /**
314 | * @function getIconAsLabel
315 | * @summary Creates a label from an icon font character
316 | * @param {object} params - parameters for creating label
317 | * @since 1.0.0
318 | * @returns {object} - Titanium Label
319 | */
320 | utils.getIconAsLabel = function( params ) {
321 | //TODO: Check for required parameters
322 |
323 | if( params.height ) {
324 | // if( params.retina ) {
325 | // params.height = params.height * 2;
326 | // }
327 |
328 | // params.fontSize = (params.height * 0.75) + "sp";
329 | params.fontSize = params.height * 0.9;
330 | }
331 |
332 | let split = params.name.split( '.' );
333 |
334 | params.fontFamily = params.fontFamily || split[ 0 ];
335 | params.text = typeof params.name === 'string' ?
336 | _.get( require( '/nativeloop/iconfonts' ), params.name ) :
337 | String.fromCharCode( params.name );
338 |
339 | // console.error( 'getIconAsLabel.params: ' + JSON.stringify( params, null, 2 ) );
340 |
341 | let label = Ti.UI.createLabel( {
342 | height: Ti.UI.SIZE,
343 | // height: params.height,
344 | width: Ti.UI.SIZE,
345 |
346 | font: {
347 | fontFamily: params.fontFamily,
348 | fontSize: params.fontSize,
349 | },
350 | text: params.text,
351 | textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
352 | color: params.color || 'black',
353 | } );
354 |
355 | return label;
356 | };
357 |
358 | /**
359 | * @function createGuid
360 | * @summary create a guid
361 | * @since 1.0.0
362 | * @returns {string} - guid
363 | */
364 | utils.createGuid = function() {
365 | var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace( /[xy]/g, function( c ) {
366 | var r = Math.random() * 16 | 0,
367 | v = c == 'x' ? r : r & 0x3 | 0x8;
368 | return v.toString( 16 );
369 | } );
370 | return guid;
371 | };
372 |
373 | Alloy.stringify = utils.stringify;
--------------------------------------------------------------------------------
/lib/ux.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobilehero-archive/nativeloop/9043d7e314ec5db64dbe429379f640dda527e314/lib/ux.js
--------------------------------------------------------------------------------
/license.md:
--------------------------------------------------------------------------------
1 | # The MIT License (MIT)
2 |
3 | > Copyright (c) 2017 Superhero Studios Incorporated
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/npm-scripts/_postinstall.js:
--------------------------------------------------------------------------------
1 | var fs = require( "fs-extra" );
2 | var path = require( "path" );
3 | var tiappDir = require( "tiapp-dir" );
4 | var pathExists = require( 'path-exists' );
5 |
6 | var root = tiappDir.sync( process.env.PWD );
7 |
8 | if( !root ) {
9 | console.error( "tiapp.xml does not exist: " + process.env.PWD );
10 | return;
11 | }
12 |
13 | var target = path.join( root, "app", "alloy.jmk" );
14 | console.error( "target: " + target );
15 | var source = path.join( __dirname, "..", "template", "alloy.jmk" );
16 | if( pathExists.sync( source ) ) {
17 | if( pathExists.sync( target ) ) {
18 | // check to see if the alloy.jmk is one provided by nativeloop
19 | var original = fs.readFileSync( target, 'utf8' );
20 | var test = /\/\/NATIVELOOP: ALLOY\.JMK/.test( original );
21 | console.info( "nativeloop alloy.jmk in place: " + test );
22 | if( !test ) {
23 | console.info( "Renaming alloy.jmk to alloy.bakup.jmk" );
24 | fs.renameSync( path.join( root, "app", "alloy.jmk" ), path.join( root, "app", "alloy.bakup.jmk" ) )
25 | }
26 | }
27 |
28 | console.info( "Copying alloy.jmk to " + target );
29 | fs.copySync( path.join( __dirname, "..", "template", "alloy.jmk" ), target, { clobber: true, dereference: true } );
30 | } else {
31 | console.error( "source file does not exist: " + source );
32 | }
--------------------------------------------------------------------------------
/npm-scripts/version.js:
--------------------------------------------------------------------------------
1 | var _ = require( "lodash" );
2 | var semver = require( "semver" );
3 | var spawn = require( 'child_process' ).spawn;
4 |
5 | // Process any arguments
6 | var args = process.argv.slice( 2 );
7 | var message;
8 | if( args.length === 0 ) {
9 | message = "Uh, everything is under control. Situation normal.";
10 | } else {
11 | message = args.join( " " );
12 | }
13 |
14 | if( !_.includes( message, "{{" ) ) {
15 | message = ":checkered_flag: v{{version}} :heavy_minus_sign: " + message;
16 | }
17 |
18 | // Load current version
19 | var package = require( "../package" );
20 | console.log( "package.version: " + package.version );
21 |
22 | // Create new version
23 | var new_version = semver.inc( package.version, 'prerelease', '' );
24 | console.log( "new_version: " + new_version );
25 |
26 | // Format commit message
27 | _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
28 | var formatted_message = _.template( message )( { version: new_version } );
29 | console.log( "formatted_message: " + formatted_message );
30 |
31 | var git_cmd = "git";
32 | if( process.platform === 'win32' ) {
33 | var npm_cmd = 'npm.cmd'
34 | } else {
35 | var npm_cmd = 'npm'
36 | }
37 |
38 | //kick off npm process
39 | var npm = spawn( npm_cmd, [ '--no-git-tag-version', 'version', new_version ] );
40 | var git;
41 |
42 | //spit stdout to screen
43 | npm.stdout.on( 'data', function( data ) { process.stdout.write( data.toString() ); } );
44 |
45 | //spit stderr to screen
46 | npm.stderr.on( 'data', function( data ) { process.stdout.write( data.toString() ); } );
47 |
48 | npm.on( 'close', function( code ) {
49 |
50 | //kick off git_cmd process
51 | git = spawn( git_cmd, [ 'commit', '-am', formatted_message ] );
52 |
53 | //spit stdout to screen
54 | git.stdout.on( 'data', function( data ) { process.stdout.write( data.toString() ); } );
55 |
56 | //spit stderr to screen
57 | git.stderr.on( 'data', function( data ) { process.stdout.write( data.toString() ); } );
58 |
59 | git.on( 'close', function( code ) {
60 | console.log( "Finished: " + code );
61 | console.log( "-----------------------------------------------------------" );
62 |
63 | //kick off git_cmd process
64 | git = spawn( git_cmd, [ 'tag', 'v' + new_version ] );
65 |
66 | //spit stdout to screen
67 | git.stdout.on( 'data', function( data ) {
68 | process.stdout.write( data.toString() );
69 | } );
70 |
71 | //spit stderr to screen
72 | git.stderr.on( 'data', function( data ) {
73 | process.stdout.write( data.toString() );
74 | } );
75 |
76 | git.on( 'close', function( code ) {
77 | console.log( "Finished: " + code );
78 | console.log( "-----------------------------------------------------------" );
79 |
80 | } );
81 | } );
82 | console.log( "Finished: " + code );
83 | console.log( "-----------------------------------------------------------" );
84 | } );
--------------------------------------------------------------------------------
/npm-scripts/version_old.js:
--------------------------------------------------------------------------------
1 | var _ = require( "lodash" );
2 | var semver = require( "semver" );
3 | // var tiapp = require("tiapp.xml").load('./tiapp.xml');
4 | // var initial_version = tiapp.version;
5 |
6 | var package = require( "../package" );
7 | var initial_version = package.version;
8 |
9 | var versions = initial_version.split( '.' );
10 | var major = _.parseInt( versions[ 0 ] ) || 1;
11 | var minor = _.parseInt( versions[ 1 ] ) || 0;
12 | var build = _.parseInt( versions[ 2 ] ) || 0;
13 | var revision = _.parseInt( versions[ 3 ] ) || 0;
14 |
15 | // revision++;
16 |
17 | // tiapp.version = major + "." + minor + "." + build + "." + revision;
18 | // tiapp.write();
19 |
20 | var spawn = require( 'child_process' ).spawn;
21 | console.log( "initial_version: " + initial_version );
22 |
23 | // var new_version = major + "." + minor + ".beta-" + build + "." + revision;
24 |
25 | var new_version = semver.inc( initial_version, 'prerelease', 'beta' );
26 | console.log( "new_version: " + new_version );
27 |
28 | var git_cmd = "git";
29 | if( process.platform === 'win32' ) {
30 | var npm_cmd = 'npm.cmd'
31 | } else {
32 | var npm_cmd = 'npm'
33 | }
34 |
35 | //kick off process
36 | var npm = spawn( npm_cmd, [ '--no-git-tag-version', 'version', new_version ] );
37 | var git;
38 |
39 | //spit stdout to screen
40 | npm.stdout.on( 'data', function( data ) { process.stdout.write( data.toString() ); } );
41 |
42 | // //spit stderr to screen
43 | npm.stderr.on( 'data', function( data ) { process.stdout.write( data.toString() ); } );
44 |
45 | npm.on( 'close', function( code ) {
46 | git = spawn( git_cmd, [ 'commit', '-am', ":checkered_flag: updating code for version " + new_version ] );
47 |
48 | //spit stdout to screen
49 | git.stdout.on( 'data', function( data ) { process.stdout.write( data.toString() ); } );
50 |
51 | // //spit stderr to screen
52 | git.stderr.on( 'data', function( data ) { process.stdout.write( data.toString() ); } );
53 |
54 | git.on( 'close', function( code ) {
55 | console.log( "Finished: " + code );
56 | console.log( "-----------------------------------------------------------" );
57 | } );
58 |
59 | console.log( "Finished: " + code );
60 | console.log( "-----------------------------------------------------------" );
61 | } );
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nativeloop",
3 | "version": "1.0.39",
4 | "description": "⭐ Axway Amplify module for using nativeloop with Appcelerator Titanium SDK Framework",
5 | "keywords": [
6 | "axway",
7 | "appcelerator",
8 | "titanium",
9 | "mobile",
10 | "turbo",
11 | "sdk",
12 | "plugin",
13 | "amplify",
14 | "api-builder",
15 | "appcelerator-titanium",
16 | "titanium-sdk",
17 | "titanium-mobile",
18 | "titanium-module",
19 | "axway-sdk",
20 | "axway-amplify",
21 | "brenton-house"
22 | ],
23 | "homepage": "https://brenton.house/saying-goodbye-to-axway-amplify-titanium-31a44f3671de",
24 | "bugs": {
25 | "url": "https://github.com/mobilehero-archive/nativeloop/issues"
26 | },
27 | "license": "MIT",
28 | "author": {
29 | "name": "Brenton House",
30 | "email": "brenton.house@gmail.com",
31 | "url": "https://github.com/brentonhouse"
32 | },
33 | "main": "./core.js",
34 | "scripts": {
35 | "lint": "eslint . --fix",
36 | "list": "npm pack && tar -xvzf *.tgz && rm -rf package *.tgz",
37 | "prep": "npm install --ignore-scripts",
38 | "test": "npm run prep",
39 | "prepublishOnly": "git pull && npm test && bump insane",
40 | "prepublishOnly2": "git pull && npm test && npm audit fix && bump insane"
41 | },
42 | "repository": {
43 | "type": "git",
44 | "url": "git://github.com/mobilehero-archive/nativeloop-cli.git"
45 | },
46 | "devDependencies": {
47 | "semver": "^7.3.6"
48 | },
49 | "engines": {
50 | "node": ">=0.10"
51 | },
52 | "dependencies": {
53 | "@geek/cache": "^1.0.2",
54 | "@geek/config": "^1.0.1",
55 | "@geek/dotenv": "^0.0.9",
56 | "@geek/eslint-config": "^1.0.3",
57 | "@geek/jsonc": "^1.0.8",
58 | "@geek/jwt": "^1.0.1",
59 | "@geek/logger": "^1.0.19",
60 | "@geek/npm": "0.0.3",
61 | "@geek/retry": "^1.0.0",
62 | "@geek/spawn": "^1.0.2",
63 | "@geek/spinner": "^1.0.2",
64 | "@geek/tld": "^2.0.1-1",
65 | "@titanium/appcelerator": "^6.0.43",
66 | "@titanium/bluebird": "^3.7.47",
67 | "@titanium/errors": "^1.0.46",
68 | "@titanium/essentials": "^1.0.75",
69 | "@titanium/events": "^1.0.53",
70 | "@titanium/eventsource": "^1.0.48",
71 | "@titanium/jwt": "^1.0.45",
72 | "@titanium/module-copier": "^1.0.50",
73 | "@titanium/please": "^1.0.53",
74 | "@titanium/polyfill": "^1.0.51",
75 | "@titanium/querystring": "^1.0.43",
76 | "@titanium/tiapp-xml": "^1.0.53",
77 | "@titanium/titanium": "^5.4.52",
78 | "@titanium/turbo": "^2.2.70",
79 | "babel-core": "^6.26.3",
80 | "babel-preset-es2015": "^6.22.0",
81 | "bluebird": "^3.7.2",
82 | "chalk": "^5.0.1",
83 | "conf": "^10.1.2",
84 | "debug": "^4.3.4",
85 | "env-paths": "^3.0.0",
86 | "figures": "^4.0.1",
87 | "findit": "^2.0.0",
88 | "fs-extra": "^10.0.1",
89 | "global-paths": "^1.0.0",
90 | "hjson": "^3.2.2",
91 | "lodash": "^4.17.21",
92 | "path-exists": "^5.0.0",
93 | "resolve": "^1.22.0",
94 | "temp": "^0.9.4",
95 | "yargs": "^17.4.1"
96 | },
97 | "bin": {
98 | "native": "cli.js",
99 | "nativeloop": "cli.js"
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/plugins/babeljs.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file {nativeloop} plugin for running babel transformations on your mobile code
12 | * @module nativeloop/plugins/babeljs
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | var path = require( 'path' );
20 | var fs = require( 'fs-extra' );
21 | // var wrench = require('wrench');
22 | var _ = require( 'lodash' );
23 | var logger;
24 | var babel = require( 'babel-core' );
25 | var minimatch = require( 'minimatch' );
26 |
27 | /**
28 | * Run babel tranformations on mobile source code
29 | * @function plugin
30 | * @param {object} params - parameters available for executing of Alloy+ plugin.
31 | * @param {object} params.event - Provides a set of objects and values which may be useful for building tasks:
32 | * @param {object} params.event.alloyConfig - Contains Alloy compiler configuration information.
33 | * @param {string} params.event.alloyConfig.platform - either android, ios, mobileweb or windows.
34 | * @param {string} [params.event.alloyConfig.file] - file to target for selective compilation.
35 | * @param {string} params.event.alloyConfig.deploytype - compilation environment type: either development, test or production.
36 | * @param {string} params.event.alloyConfig.beautify - if set to true, the output from UglifyJS will be beautified.
37 | * @param {string} params.event.autoStyle - If set to true, autostyle is enabled for the entire project.
38 | * @param {object} params.event.dependencies - If set to true, autostyle is enabled for the entire project.
39 | * @param {object} params.event.dir - Contains directory paths to various resources.
40 | * @param {string} params.event.dir.home - absolute path to the Alloy project's app directory.
41 | * @param {string} params.event.dir.project - absolute path to the Alloy project's root directory.
42 | * @param {string} params.event.dir.resources - absolute path to the Alloy project's Resource directory.
43 | * @param {string} params.event.dir.resourcesAlloy - absolute path to the Alloy project's Resource/alloy directory.
44 | * @param {string} params.event.dir.resourcesPlatform - absolute path to the Alloy project's Resource/{platform} directory. (i.e. /Resources/iphone)
45 | * @param {string} params.event.dir.assets - absolute path to the Alloy project's assets.
46 | * @param {string} params.event.dir.config - absolute path to the Alloy project's config.
47 | * @param {string} params.event.dir.controllers - absolute path to the Alloy project's controllers.
48 | * @param {string} params.event.dir.migrations - absolute path to the Alloy project's migrations.
49 | * @param {string} params.event.dir.models - absolute path to the Alloy project's models.
50 | * @param {string} params.event.dir.styles - absolute path to the Alloy project's styles.
51 | * @param {string} params.event.dir.themes - absolute path to the Alloy project's themes.
52 | * @param {string} params.event.dir.views - absolute path to the Alloy project's views.
53 | * @param {string} params.event.dir.widgets - absolute path to the Alloy project's widgets.
54 | * @param {string} params.event.dir.builtins - absolute path to the Alloy project's builtins.
55 | * @param {string} params.event.dir.template - absolute path to the Alloy project's template.
56 | * @param {string} params.event.sourcemap - If true, generates the source mapping files for use with the Studio debugger and other functions.
57 | These files maps the generated Titanium files in the Resources directory to the ones in the app directory.
58 | * @param {string} params.event.theme - Name of the theme being used.
59 | * @param {string} [params.event.code] - Only present for the appjs build hook. Contains the contents of the app.js file.
60 | * @param {string} [params.event.appJSFile] - Only present for the appjs build hook. Contains the the absolute path to the app.js file.
61 | * @param {object} params.logger - Alloy logger object
62 | * @param {string[]} [params.includes] - Array of glob patterns to match files to be included in transformation
63 | * @param {string} [params.code]
64 | * @param {object} params.options - babel configuration object (see http://babeljs.io/docs/usage/options/)
65 | * @param {string[]} [params.options.presets=[]] - List of presets (a set of plugins) to load and use..
66 | * @param {string[]} [options.plugins=[]] - List of plugins to load and use.
67 | * @param {boolean} [params.options.babelrc=true] - Specify whether or not to use .babelrc and .babelignore files.
68 | * @param {boolean} [params.options.ast=true] - Include the AST in the returned object
69 | * @param {boolean} [params.options.minified=true] - Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping () from new when safe)
70 | * @param {boolean} [params.options.comments=true] - Output comments in generated output.
71 | * @param {object} [params.options.env={}] - This is an object of keys that represent different environments. For example, you may have: { env: { production: { someOption: true } } } which will use those options when the enviroment variable BABEL_ENV is set to "production". If BABEL_ENV isn’t set then NODE_ENV will be used, if it’s not set then it defaults to "development"
72 | * @param {string} [params.options.extends=null] - A path to an .babelrc file to extend
73 | */
74 | function plugin( params ) {
75 |
76 | logger = params.logger;
77 | params.dirname = params.dirname ? _.template( params.dirname )( params ) : params.event.dir.resourcesPlatform;
78 |
79 | _.defaults( params, {
80 | options: {},
81 | includes: [ '**/*.js', '!backbone.js', '!**/alloy/lodash.js' ]
82 | } );
83 |
84 | if( params.code ) {
85 | // logger.trace(params.code);
86 | logger.trace( "running babel on code" );
87 | params.code = transformCode( params.code, params.options );
88 | } else {
89 | logger.trace( "running babel in directory: " + params.dirname );
90 | var files = findFiles( params.dirname, params.includes );
91 | _.forEach( files, function( file ) {
92 | transformFile( path.join( params.dirname, file ), params.options );
93 | } );
94 | }
95 | }
96 |
97 | /**
98 | * Replace backslashes for cross-platform usage
99 | * Adapted from https://github.com/sindresorhus/slash
100 | * @function replaceBackSlashes
101 | * @param {string} intput - value needing to have backslashes replaced in.
102 | * @returns {string}
103 | */
104 | function replaceBackSlashes( input ) {
105 | var isExtendedLengthPath = /^\\\\\?\\/.test( input );
106 | var hasNonAscii = /[^\x00-\x80]+/.test( input );
107 |
108 | if( isExtendedLengthPath || hasNonAscii ) {
109 | return input;
110 | }
111 |
112 | return input.replace( /\\/g, '/' );
113 | };
114 |
115 | /**
116 | * Find all files that match extension criteria
117 | * @function findFiles
118 | * @param {string} rootpath - Absolute path of the directory from which file search will begin
119 | * @param {string[]|string} [patterns="**"] - Pattern(s) to be used when attempting to match files found
120 | * @returns {string[]} - Matched file paths
121 | */
122 | function findFiles( rootpath, patterns ) {
123 | var patterns = patterns || [ '**' ];
124 | if( _.isString( patterns ) ) {
125 | patterns = [ patterns ];
126 | }
127 | var files = _.map( fs.readdirSyncRecursive( rootpath ), function( filename ) {
128 | return path.posix.sep + replaceBackSlashes( filename );
129 | } );
130 | var matchedFiles = match( files, patterns, {
131 | nocase: true,
132 | matchBase: true,
133 | dot: true,
134 | } );
135 | return _.filter( matchedFiles, function( file ) {
136 | return !fs.statSync( path.join( rootpath, file ) ).isDirectory();
137 | } ) || [];
138 |
139 | };
140 |
141 | /**
142 | * Find items in array that match a set of patterns
143 | * Adapted from https://github.com/sindresorhus/multimatch
144 | * @function match
145 | * @param {string[]} list
146 | * @param {string[]|string} patterns
147 | * @param {object} options
148 | * @returns {string[]}
149 | */
150 | function match( list, patterns, options ) {
151 | list = list || [];
152 | patterns = patterns || [];
153 | if( _.isString( patterns ) ) {
154 | patterns = [ patterns ];
155 | }
156 |
157 | if( list.length === 0 || patterns.length === 0 ) {
158 | return [];
159 | }
160 |
161 | options = options || {};
162 | return patterns.reduce( function( ret, pattern ) {
163 | var process = _.union
164 | if( pattern[ 0 ] === '!' ) {
165 | pattern = pattern.slice( 1 );
166 | process = _.difference;
167 | }
168 | return process( ret, minimatch.match( list, pattern, options ) );
169 | }, [] );
170 | };
171 |
172 |
173 | /**
174 | * Transform a file with babeljs using babel config
175 | * @function transformFile
176 | * @param {string} filepath - absolute path of the file to be transformed
177 | * @param {object} options - babel configuration object (see http://babeljs.io/docs/usage/options/)
178 | * @param {string[]} [options.presets=[]] - List of presets (a set of plugins) to load and use..
179 | * @param {string[]} [options.plugins=[]] - List of plugins to load and use.
180 | * @param {boolean} [options.babelrc=true] - Specify whether or not to use .babelrc and .babelignore files.
181 | * @param {boolean} [options.ast=true] - Include the AST in the returned object
182 | * @param {boolean} [options.minified=true] - Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping () from new when safe)
183 | * @param {boolean} [options.comments=true] - Output comments in generated output.
184 | * @param {object} [options.env={}] - This is an object of keys that represent different environments. For example, you may have: { env: { production: { someOption: true } } } which will use those options when the enviroment variable BABEL_ENV is set to "production". If BABEL_ENV isn’t set then NODE_ENV will be used, if it’s not set then it defaults to "development"
185 | * @param {string} [options.extends=null] - A path to an .babelrc file to extend
186 | */
187 | function transformFile( filepath, options ) {
188 | logger.trace( "transforming file - " + filepath );
189 | var content = fs.readFileSync( filepath, 'utf8' );
190 | var result = transformCode( content, options );
191 | fs.writeFileSync( filepath, result );
192 | }
193 |
194 | /**
195 | * Transform the code with bablejs using babel config.
196 | * @function transformCode
197 | * @param {string} code - code to transform using babeljs
198 | * @param {object} options - babel configuration object (see http://babeljs.io/docs/usage/options/)
199 | * @param {string[]} [options.presets=[]] - List of presets (a set of plugins) to load and use..
200 | * @param {string[]} [options.plugins=[]] - List of plugins to load and use.
201 | * @param {boolean} [options.babelrc=true] - Specify whether or not to use .babelrc and .babelignore files.
202 | * @param {boolean} [options.ast=true] - Include the AST in the returned object
203 | * @param {boolean} [options.minified=true] - Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping () from new when safe)
204 | * @param {boolean} [options.comments=true] - Output comments in generated output.
205 | * @param {object} [options.env={}] - This is an object of keys that represent different environments. For example, you may have: { env: { production: { someOption: true } } } which will use those options when the enviroment variable BABEL_ENV is set to "production". If BABEL_ENV isn’t set then NODE_ENV will be used, if it’s not set then it defaults to "development"
206 | * @param {string} [options.extends=null] - A path to an .babelrc file to extend
207 | */
208 | function transformCode( code, options ) {
209 | var result = babel.transform( code, options );
210 | var modified = result.code;
211 | return modified;
212 | }
213 |
214 | module.exports.execute = plugin;
215 | module.exports.tasks = [];
--------------------------------------------------------------------------------
/plugins/backbone-fix.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file {nativeloop} plugin for fixing backbone.js usage issues in Alloy
12 | * @module nativeloop/plugins/nodejs
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | var path = require( "path" );
20 | var _ = require( 'lodash' );
21 | var fs = require( 'fs' );
22 | var logger;
23 |
24 | /**
25 | * Fix certain usages of backbone.js in Alloy source code
26 | *
27 | * @param {object} params
28 | */
29 | function plugin( params ) {
30 | logger = params.logger;
31 | params.dirname = params.dirname ? _.template( params.dirname )( params ) : params.event.dir.resourcesPlatform;
32 | logger.trace( "fixing backbone usage in directory: " + params.dirname );
33 | injectCode( params );
34 |
35 | }
36 |
37 | /**
38 | * Inject necessary code into the file app.js
39 | */
40 | function injectCode( params ) {
41 |
42 | var fullpath = path.join( params.dirname, "app.js" );
43 | var source = fs.readFileSync( fullpath, 'utf8' );
44 | var test = /\/\/NATIVELOOP: BACKBONE-FIX/.test( source );
45 | logger.trace( "NATIVELOOP: BACKBONE-FIX -- CODE INJECTED ALREADY: " + test );
46 | if( !test ) {
47 | source = source.replace( /(var\s+Alloy[^;]+;)/g, "$1\n//NATIVELOOP: BACKBONE-FIX\nAlloy.Backbone.Events.addEventListener = Backbone.Events.on;\nAlloy.Backbone.Events.removeEventListener = Backbone.Events.off;\n\n" );
48 | fs.writeFileSync( fullpath, source );
49 | }
50 | }
51 |
52 | module.exports.execute = plugin;
53 | module.exports.tasks = [
54 | {
55 | "module": module.id,
56 | "events": "postcompile"
57 | }
58 | ]
--------------------------------------------------------------------------------
/plugins/es2015.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file {nativeloop} plugin for transforming ES6/ES2015 code to ES5 code
12 | * @module nativeloop/plugins/nodejs
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | module.exports.tasks = [ {
20 | 'module': module.id,
21 | 'options': {
22 | 'presets': [
23 | 'es2015'
24 | ]
25 | },
26 | 'includes': [ '**/*.js', '!backbone2.js', '!**/alloy/lodash.js' ],
27 | 'events': [ 'preload', 'preparse' ]
28 | } ]
--------------------------------------------------------------------------------
/plugins/nodejs.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file nativeloop} plugin for making alloy code use the nodejs style module resolution
12 | * @module nativeloop/plugins/nodejs
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | var path = require( "path" );
20 | var _ = require( 'lodash' );
21 | var logger;
22 |
23 | function plugin( params ) {
24 |
25 | logger = params.logger;
26 | params.dirname = params.dirname || params.event.dir.resourcesPlatform;
27 |
28 | _.defaults( params.config, {
29 | modules: {}
30 | } );
31 |
32 | logger.debug( "fixing alloy require in directory: " + params.dirname );
33 | // logger.trace("nodejs params: " + JSON.stringify(params.config, null, 2));
34 | var r = require( './resolver/resolve-fix' );
35 | var resolveFix = new r( params.dirname, params.modules, params.includes, logger );
36 | var registry = JSON.stringify( resolveFix.registry, null, 4 );
37 | //console.warn(registry);
38 | }
39 |
40 | module.exports.execute = plugin;
41 | module.exports.tasks = [
42 | {
43 | "module": module.id,
44 | "events": "postcompile"
45 | }
46 | ]
--------------------------------------------------------------------------------
/plugins/npm.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file {nativeloop} plugin for executing npm during build process
12 | * @module nativeloop/plugins/npm
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | var _ = require( 'lodash' );
20 |
21 | function plugin( params ) {
22 |
23 | params.dirname = params.dirname ? _.template( params.dirname )( params ) : params.event.dir.lib;
24 | params.args = params.args ? _.map( params.args, function( arg ) {
25 | return _.template( arg )( params );
26 | } ) : [ "install" ];
27 |
28 | params.logger.trace( "running npm in directory: " + params.dirname );
29 | params.logger.trace( "npm " + params.args.join( " " ) );
30 |
31 | return require( "@geek/spawn" ).spawnSync( "npm", params.args, {
32 | cwd: params.dirname
33 | } );
34 |
35 | }
36 |
37 | module.exports.execute = plugin;
38 | module.exports.tasks = [
39 | {
40 | "module": module.id,
41 | "dirname": "${event.dir.lib}",
42 | "args": [ "install" ],
43 | "events": "preload"
44 | }
45 | ]
--------------------------------------------------------------------------------
/plugins/promises.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file {nativeloop} plugin for adding support for promises to Alloy
12 | * @module nativeloop/plugins/promises
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | var path = require('path');
20 | var _ = require('lodash');
21 | var fs = require('fs-extra');
22 | var logger;
23 |
24 | /**
25 | * Add support for promises
26 | * @function plugin
27 | * @param {object} params
28 | */
29 | function plugin(params) {
30 | logger = params.logger;
31 | params.dirname = params.dirname ? _.template(params.dirname)(params) : params.event.dir.resourcesPlatform;
32 | logger.trace('Adding promise support: ' + params.dirname);
33 | injectCode(params);
34 |
35 | }
36 |
37 | /**
38 | * Inject necessary code into the file app.js
39 | * @function injectCode
40 | * @param params {object}
41 | */
42 | function injectCode(params) {
43 |
44 | var fullpath = path.join(params.dirname, 'app.js');
45 | var source = fs.readFileSync(fullpath, 'utf8');
46 | var test = /\/\/NATIVELOOP: PROMISES/.test(source);
47 | logger.trace('NATIVELOOP: PROMISES -- CODE INJECTED ALREADY: ' + test);
48 | if(!test) {
49 | source = source.replace(/(var\s+Alloy[^;]+;)/g, "$1\n//NATIVELOOP: PROMISES\nvar Promise = require('bluebird');\n\n");
50 | fs.writeFileSync(fullpath, source);
51 | }
52 | }
53 |
54 | module.exports.execute = plugin;
55 | module.exports.tasks = [
56 | {
57 | 'module': module.id,
58 | 'events': 'postcompile'
59 | }
60 | ]
--------------------------------------------------------------------------------
/plugins/remove-invalid-header.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file {nativeloop} plugin for removing invalid http header in Alloy
12 | * @module nativeloop/plugins/remove-invalid-header
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | var path = require( 'path' );
20 | var _ = require( 'lodash' );
21 | var fs = require( 'fs' );
22 | var logger;
23 |
24 | /**
25 | * Remove invalid http headers from being inserted
26 | * @function replace_content
27 | * @param {string} fullpath
28 | */
29 | function replace_content( fullpath ) {
30 | var source = fs.readFileSync( fullpath, 'utf8' );
31 | var regex = /(this._xhr.setRequestHeader\('X-Titanium-Id', App.guid\);)/g
32 | var test = regex.test( source );
33 | if( test ) {
34 | logger.trace( 'Fixing file: ' + fullpath );
35 | source = source.replace( regex, "" );
36 | fs.writeFileSync( fullpath, source );
37 | }
38 | }
39 |
40 | /**
41 | * Fixes CORS issues with MobileWeb by removing invalid HTTP headers
42 | * @function plugin
43 | * @param {object} params
44 | */
45 | function plugin( params ) {
46 | logger = params.logger;
47 | params.dirname = params.dirname ? _.template( params.dirname )( params ) : path.join( params.event.dir.project, 'build', 'mobileweb', 'titanium', 'Ti', 'Network' );
48 | logger.trace( 'removing invalid http headers in directory: ' + params.dirname );
49 | //replace_content(path.join(params.dirname, "HTTPClient.js"));
50 | }
51 |
52 | module.exports.execute = plugin;
53 | module.exports.tasks = [
54 | {
55 | 'module': module.id,
56 | 'events': 'postcompile'
57 | }
58 | ]
--------------------------------------------------------------------------------
/plugins/resolver/resolve-fix.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file Fix resolve issues by replacing functionality
12 | * @module @nativeloop/mobile/plugins/resolver/resolver/resolve-fix
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | var _ = require( 'lodash' );
20 | // var wrench = require( 'wrench' );
21 | var path = require( 'path' );
22 | var fs = require( 'fs-extra' );
23 | var minimatch = require( 'minimatch' );
24 |
25 | /**
26 | *
27 | * @param {string} rootpath - Directory path to start searching for files
28 | * @param {object} registry - Object used to store files/modules found
29 | * @param {string[]} registry.files - Files found in search
30 | * @param {string[]} registry.directories - Directories found in search
31 | * @param {object[]} registry.core - Core modules to use in app
32 | * @param {object[]} registry.fallback - Modules to use in case of reference to missing module
33 | * @param {string[]} [params.includes] - Array of glob patterns to match files to be included in search
34 | * @param {object} [logger=console] - Alloy logger object
35 | */
36 | module.exports = function( rootpath, registry, includes, logger ) {
37 |
38 | registry = registry || {};
39 |
40 | _.defaults( registry, {
41 | files: [],
42 | directories: [],
43 | core: [],
44 | fallback: [],
45 | alias: [],
46 | } );
47 | logger = logger || console;
48 |
49 | // logger.debug("includes: " + JSON.stringify(includes, null, 2));
50 | includes = includes || [ '**/*.js', '**/*.json', '!resolver.js' ];
51 |
52 | /**
53 | * Inject necessary code into the file app.js
54 | * @function injectCode
55 | */
56 | function injectCode() {
57 |
58 | var fullpath = path.join( rootpath, "app.js" );
59 | var source = fs.readFileSync( fullpath, 'utf8' );
60 | var test = /\/\/ALLOY-RESOLVER/.test( source );
61 | logger.trace( "CODE INJECTED ALREADY: " + test );
62 | if( !test ) {
63 | source = source.replace( /(var\s+Alloy[^;]+;)/g, "$1\n//ALLOY-RESOLVER\nvar process=require('process');\nAlloy.resolve=new (require('nativeloop/resolver'))().resolve;\n" );
64 | fs.writeFileSync( fullpath, source );
65 | }
66 | }
67 |
68 |
69 | function fixFile( file ) {
70 | var fullpath = path.join( rootpath, file );
71 | var basepath = path.posix.dirname( file );
72 | var basefile = path.posix.resolve( file );
73 | var source = fs.readFileSync( fullpath, 'utf8' );
74 | logger.trace( 'fixing file: ' + fullpath );
75 |
76 | var requireRegex = /(require)\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g;
77 | var staticRequireRegex = /(require)(?:\(\s*['"])([^'"]+)(?:['"]\s*\))/g;
78 | var alloyDynamicRegex = /require\(\s*['"]alloy\//g
79 | var alloyResolveRegex = /require\(\s*Alloy\.resolve\(/g
80 |
81 |
82 | source = source.replace( requireRegex, function( entireText, requireText, requestedModule ) {
83 | // logger.error('entireText: ' + entireText);
84 |
85 | var isStaticRequire = staticRequireRegex.test( entireText );
86 | var isDynamicAlloyRequire = alloyDynamicRegex.test( entireText );
87 | var isAlloyResolve = alloyResolveRegex.test( entireText );
88 | // logger.trace('isStaticRequire: ' + isStaticRequire);
89 | // logger.trace('isDynamicAlloyRequire: ' + isDynamicAlloyRequire);
90 | // logger.trace('isAlloyResolve: ' + isAlloyResolve);
91 | if( isStaticRequire ) {
92 | var revisedText = entireText.replace( staticRequireRegex, function( $1, $2, $3 ) {
93 | var resolved_path = resolver.resolve( $3, basepath );
94 | return 'require("' + resolved_path + '")';
95 | } );
96 | // logger.debug('returning: ' + revisedText);
97 | return revisedText;
98 | } else if( isDynamicAlloyRequire ) {
99 | // logger.trace('fixFiles: found dynamic alloy require');
100 | // logger.debug('returning: ' + entireText);
101 | return entireText;
102 | } else if( isAlloyResolve ) {
103 | // logger.trace('fixFiles: found Alloy.resolve require');
104 | // logger.debug('returning: ' + entireText);
105 | return entireText;
106 | } else {
107 | // logger.trace("isDynamicAlloyRequire: " + isDynamicAlloyRequire);
108 | // logger.trace("fixFiles: found dynamic non-alloy require");
109 | // logger.debug("returning: " + 'require(Alloy.resolve(' + requestedModule + ', "' + basepath + '"))');
110 | return 'require(Alloy.resolve(' + requestedModule + ', "' + basepath + '"))';
111 | }
112 | } );
113 |
114 | fs.writeFileSync( fullpath, source, {
115 | mode: 0o755
116 | } );
117 | }
118 |
119 |
120 | /**
121 | * Fix module resolution in all found javascript files
122 | * @function fixFiles
123 | */
124 | function fixFiles() {
125 | logger.trace( 'inside fixFiles()' );
126 |
127 | var filepaths = match( registry.files, includes.concat( [ '!**/*.json' ] ), {
128 | nocase: true,
129 | matchBase: true,
130 | dot: true,
131 | } );
132 |
133 | _.each( filepaths, fixFile );
134 |
135 | }
136 |
137 |
138 | /**
139 | * Replace backslashes for cross-platform usage
140 | * Adapted from https://github.com/sindresorhus/slash
141 | * @function replaceBackSlashes
142 | * @param {string} input - value needing to have backslashes replaced in.
143 | * @returns {string}
144 | */
145 | function replaceBackSlashes( input ) {
146 | var isExtendedLengthPath = /^\\\\\?\\/.test( input );
147 | var hasNonAscii = /[^\x00-\x80]+/.test( input );
148 |
149 | if( isExtendedLengthPath || hasNonAscii ) {
150 | return input;
151 | }
152 |
153 | return input.replace( /\\/g, '/' );
154 | };
155 |
156 | /**
157 | * Find all files that match extension criteria
158 | * @function findFiles
159 | * @param {string} rootpath - Absolute path of the directory from which file search will begin
160 | * @param {string[]|string} [patterns='**'] - Pattern(s) to be used when attempting to match files found
161 | * @returns {string[]} - Matched file paths
162 | */
163 | function findFiles( rootpath, patterns ) {
164 | // logger.trace('inside findFiles()');
165 | var patterns = patterns || [ '**' ];
166 | if( _.isString( patterns ) ) {
167 | patterns = [ patterns ];
168 | }
169 | var files = _.map( fs.readdirSyncRecursive( rootpath ), function( filename ) {
170 | return path.posix.sep + replaceBackSlashes( filename );
171 | } );
172 | var matchedFiles = match( files, patterns, {
173 | nocase: true,
174 | matchBase: true,
175 | dot: true,
176 | } );
177 | return _.filter( matchedFiles, function( file ) {
178 | return !fs.statSync( path.join( rootpath, file ) ).isDirectory();
179 | } ) || [];
180 |
181 | };
182 |
183 | /**
184 | * Find items in array that match a set of patterns
185 | * Adapted from https://github.com/sindresorhus/multimatch
186 | * @function match
187 | * @param {string[]} [list=[]]
188 | * @param {string[]|string} [patterns=[]]
189 | * @param {object} [options={}]
190 | * @returns {string[]}
191 | */
192 | function match( list, patterns, options ) {
193 | list = list || [];
194 | patterns = patterns || [];
195 | if( _.isString( patterns ) ) {
196 | patterns = [ patterns ];
197 | }
198 |
199 | if( list.length === 0 || patterns.length === 0 ) {
200 | return [];
201 | }
202 |
203 | options = options || {};
204 | return patterns.reduce( function( ret, pattern ) {
205 | var process = _.union
206 | if( pattern[ 0 ] === '!' ) {
207 | pattern = pattern.slice( 1 );
208 | process = _.difference;
209 | }
210 | return process( ret, minimatch.match( list, pattern, options ) );
211 | }, [] );
212 | };
213 |
214 | /**
215 | * Find and process all files
216 | * @function loadFiles
217 | */
218 | function loadFiles() {
219 | // logger.trace('inside loadFiles()');
220 | var allfiles = findFiles( rootpath, [ '**/*.js', '**/*.json' ] );
221 | // logger.debug(JSON.stringify(allfiles, null, 2));
222 |
223 | _.forEach( allfiles, function( filepath ) {
224 | registry.files.push( filepath );
225 | } );
226 |
227 | var packagepaths = _.filter( allfiles, function( filepath ) {
228 | return( /.+(package\.json)/.test( filepath ) );
229 | } );
230 | _.forEach( packagepaths, function( filepath ) {
231 | var content = fs.readFileSync( path.posix.join( rootpath, filepath ), 'utf8' );
232 | var json = JSON.parse( content );
233 | if( json.main ) {
234 | registry.directories.push( {
235 | id: path.posix.dirname( filepath ),
236 | path: path.posix.resolve( path.posix.join( path.posix.dirname( filepath ), json.main ) )
237 | } );
238 | }
239 | } );
240 |
241 | var indexpaths = _.filter( allfiles, function( filepath ) {
242 | return( /.+(index\.js)/.test( filepath ) );
243 | } );
244 |
245 | _.forEach( indexpaths, function( filepath ) {
246 | var existingdir = _.find( registry.directories, function( dir ) {
247 | return dir.id === path.posix.dirname( filepath );
248 | } );
249 | if( !existingdir ) {
250 | registry.directories.push( {
251 | id: path.posix.dirname( filepath ),
252 | path: filepath
253 | } );
254 | }
255 | } );
256 |
257 | return registry;
258 | };
259 |
260 |
261 | /**
262 | * Write registry file to resolver.js
263 | * @function writeRegistry
264 | */
265 | function writeRegistry() {
266 | logger.trace( 'inside writeRegistry()' );
267 | var filepath = path.join( rootpath, resolver.resolve( 'resolver' ) ) + '.js';
268 | var content = fs.readFileSync( filepath, 'utf8' );
269 | var regex = /(var\s+registry\s+=\s+)[^;]*(;)/g;
270 | var modified = content.replace( regex, '$1' + JSON.stringify( registry ) + '$2' );
271 | fs.writeFileSync( filepath, modified );
272 | }
273 |
274 | //fs.copySync(path.join(__dirname, 'lib', 'resolver.js'), path.join(rootpath, 'resolver.js'));
275 | // fs.copySync(path.join(__dirname, 'lib', 'path.js'), path.join(rootpath, 'path.js'));
276 | // fs.copySync(path.join(__dirname, 'lib', 'process.js'), path.join(rootpath, 'process.js'));
277 | //fs.copySync(path.join(__dirname, 'lib', 'alloy', 'lodash.js'), path.join(rootpath, 'alloy', 'lodash.js'));
278 |
279 | loadFiles();
280 |
281 | // var r = require( '../../lib/node_modules/resolver' );
282 | var r = require( '../../lib/resolver' );
283 | var resolver = new r( registry, logger, true );
284 | var registry = resolver.registry;
285 |
286 | injectCode();
287 | fixFiles();
288 |
289 | console.error( 'registry: ' + JSON.stringify( registry, null, 2 ) );
290 |
291 |
292 | writeRegistry();
293 | // fixFile('/node_modules/nativeloop/resolver.js');
294 | fixFile( '/nativeloop/resolver.js' );
295 |
296 | console.error( 'registry: ' + JSON.stringify( registry, null, 2 ) );
297 |
298 | Object.defineProperty( this, 'registry', {
299 | get: function() {
300 | return _.clone( registry );
301 | },
302 | enumerable: true,
303 | configurable: false
304 | } );
305 | }
--------------------------------------------------------------------------------
/plugins/underscore-fix.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file {nativeloop} plugin for fixing underscore.js usage issues in Alloy
12 | * @module nativeloop/plugins/underscore-fix
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | var path = require( 'path' );
20 | var _ = require( 'lodash' );
21 | var fs = require( 'fs-extra' );
22 | var logger;
23 |
24 | /**
25 | * Remove invalid underscore calls from a file
26 | * @function replace_content
27 | * @param {string} fullpath
28 | */
29 | function replace_content( fullpath ) {
30 | var source = fs.readFileSync( fullpath, 'utf8' );
31 | var regex = /(require\s*\(\s*['"].*alloy\/underscore['"]\s*\))._/g
32 | var test = regex.test( source );
33 | if( test ) {
34 | logger.trace( 'Fixing file: ' + fullpath );
35 | source = source.replace( regex, '$1' );
36 | fs.writeFileSync( fullpath, source );
37 | }
38 | }
39 |
40 | /**
41 | * Fix certain usages of underscore.js in Alloy source code
42 | * @function plugin
43 | * @param {object} params
44 | */
45 | function plugin( params ) {
46 | logger = params.logger;
47 | params.dirname = params.dirname ? _.template( params.dirname )( params ) : params.event.dir.resourcesPlatform;
48 | logger.trace( "fixing underscore in directory: " + params.dirname );
49 |
50 | replace_content( path.join( params.dirname, 'alloy.js' ) );
51 | replace_content( path.join( params.dirname, 'alloy', 'sync', 'properties.js' ) );
52 | replace_content( path.join( params.dirname, 'alloy', 'sync', 'sql.js' ) );
53 | replace_content( path.join( params.dirname, 'alloy', 'constants.js' ) );
54 |
55 | injectCode( params );
56 |
57 | }
58 |
59 | /**
60 | * Inject necessary code into the file app.js
61 | * @function injectCode
62 | * @param params {object}
63 | */
64 | function injectCode( params ) {
65 |
66 | var fullpath = path.join( params.dirname, 'app.js' );
67 | var source = fs.readFileSync( fullpath, 'utf8' );
68 | var test = /\/\/NATIVELOOP: UNDERSCORE-FIX/.test( source );
69 | logger.trace( 'NATIVELOOP: UNDERSCORE-FIX -- CODE INJECTED ALREADY: ' + test );
70 | if( !test ) {
71 | source = source.replace( /(var\s+Alloy[^;]+;)/g, "$1\n//NATIVELOOP: UNDERSCORE-FIX\nif(_.VERSION !== \"1.6.0\") {\r\n\tconsole.info(\"Wrapping _.template()\");\r\n\t_.mixin({\r\n\t\ttemplate: _.wrap(_.template, function(func, text, data, options) {\r\n\t\t\tif(options) {\r\n\t\t\t\t\/\/ If a third parameter was passed in, we hope that the older version of template was expected here.\r\n\t\t\t\treturn func(text, options)(data);\r\n\t\t\t} else {\r\n\t\t\t\t\/\/ Here we hope they intended to use the updated version of template...\r\n\t\t\t\treturn func(text, data);\r\n\t\t\t}\r\n\t\t})\r\n\t});\r\n}" );
72 | fs.writeFileSync( fullpath, source );
73 | }
74 | }
75 |
76 | module.exports.execute = plugin;
77 | module.exports.tasks = [
78 | {
79 | 'module': module.id,
80 | 'events': 'postcompile'
81 | }
82 | ]
--------------------------------------------------------------------------------
/plugins/widgets-add.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file {nativeloop} plugin for fixing underscore.js usage issues in Alloy
12 | * @module nativeloop/plugins/widgets-add
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | var path = require( 'path' );
20 | var _ = require( 'lodash' );
21 | var fs = require( 'fs' );
22 | var logger;
23 | var config
24 | var config_location;
25 |
26 | function addWidget( name, version ) {
27 | logger.trace( "Adding widget to config.json file: " + name + "(" + version + ")" );
28 | config.dependencies = config.dependencies || {};
29 | config.dependencies[ name ] = version;
30 | fs.writeFileSync( config_location, JSON.stringify( config, null, 2 ) );
31 | }
32 |
33 |
34 | /**
35 | * Ensure that widgets are configured in alloy config.json
36 | *
37 | * @param {object} params
38 | */
39 | function plugin( params ) {
40 | logger = params.logger;
41 | logger.trace( "ensuring widget is configured in config.json file: " + params.event.dir.config );
42 | config_location = params.event.dir.config + ".json";
43 | config = require( config_location );
44 | // logger.warn("config: " + JSON.stringify(config, null, 2));
45 |
46 | _.defaults( config, {
47 | "widgets": {},
48 | "dependencies": {},
49 | } );
50 |
51 | _.defaults( config.widgets, {
52 | "nativeloop": "*",
53 | } );
54 |
55 |
56 | // _.defaults( config.dependencies, config.widgets );
57 |
58 | fs.writeFileSync( config_location, JSON.stringify( config, null, 2 ) );
59 |
60 | // _.forEach(_.keys(config.widgets), (widget) => {
61 |
62 | // });
63 |
64 | // var n = _.get( config, "dependencies.nativeloop" );
65 | // !n && addWidget( "nativeloop", "*" );
66 | }
67 |
68 |
69 | module.exports.execute = plugin;
70 | module.exports.tasks = [ {
71 | "module": module.id,
72 | "events": "preload"
73 | } ]
--------------------------------------------------------------------------------
/plugins/widgets-remove.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /***
3 | * __ _ __ __
4 | * ____ ___ ____ / /_ (_)/ /___ / /_ ___ _____ ____
5 | * / __ `__ \ / __ \ / __ \ / // // _ \ / __ \ / _ \ / ___// __ \
6 | * / / / / / // /_/ // /_/ // // // __// / / // __// / / /_/ /
7 | * /_/ /_/ /_/ \____//_.___//_//_/ \___//_/ /_/ \___//_/ \____/
8 | *
9 | * mobile solutions for everyday heroes
10 | *
11 | * @file {nativeloop} plugin for fixing underscore.js usage issues in Alloy
12 | * @module nativeloop/plugins/widgets-remove
13 | * @author Brenton House
14 | * @copyright Copyright (c) 2017 by Superhero Studios Incorporated. All Rights Reserved.
15 | * @license Licensed under the terms of the MIT License (MIT)
16 | *
17 | */
18 |
19 | var path = require( "path" );
20 | var _ = require( 'lodash' );
21 | var fs = require( 'fs' );
22 | var logger;
23 | var config
24 | var config_location;
25 |
26 |
27 | /**
28 | * Ensure that widgets are configured in alloy config.json
29 | *
30 | * @param {object} params
31 | */
32 | function plugin( params ) {
33 | logger = params.logger;
34 | logger.trace( "ensuring widget is configured in config.json file: " + params.event.dir.config );
35 | config_location = params.event.dir.config + ".json";
36 | config = require( config_location );
37 | // logger.warn("config: " + JSON.stringify(config, null, 2));
38 |
39 | _.defaults( config, {
40 | "widgets": {},
41 | "dependencies": {},
42 | } );
43 |
44 | delete config.dependencies.nativeloop;
45 |
46 | _.forEach( _.keys( config.widgets ), ( widget ) => {
47 | if( config.dependencies[ widget ] && config.dependencies[ widget ] === config.widgets[ widget ] ) {
48 | delete config.dependencies[ widget ];
49 | }
50 | } );
51 |
52 | fs.writeFileSync( config_location, JSON.stringify( config, null, 2 ) );
53 | }
54 |
55 |
56 | module.exports.execute = plugin;
57 | module.exports.tasks = [ {
58 | "module": module.id,
59 | "events": "postcompile"
60 | } ]
--------------------------------------------------------------------------------
/references/alloy.d.ts:
--------------------------------------------------------------------------------
1 | declare module Alloy {
2 | export var CFG : any;
3 | export var Collections : any;
4 | export var Globals : any;
5 | export var Models : any;
6 | export var isHandheld : boolean;
7 | export var isTablet : boolean;
8 | export function createCollection (name: string, args?: any) : Backbone.Collection;
9 | export function createController (name: string, args?: any) : Alloy.Controller;
10 | export function createModel (name: string, args?: any) : Backbone.Model;
11 | export function createWidget (id: string, name?: string, args?: any) : Alloy.Controller;
12 | export module Controller {
13 | export function addClass (proxy: any, classes: Array/String, opts?: Dictionary