├── .gitignore
├── .jshintignore
├── .jshintrc
├── .npmignore
├── .travis.yml
├── Gruntfile.js
├── LICENSE
├── README.md
├── bin
├── install-titaniumifier-plugin
└── titaniumifier
├── index.js
├── lib
├── builtins
│ └── index.js
├── globals
│ ├── global.js
│ ├── index.js
│ ├── process.js
│ └── timers.js
├── manifest.js
├── packer-build.js
├── packer-pack.js
├── packer.js
├── scripts
│ └── prepublish.js
├── titaniumifier.js
└── util
│ ├── fs.js
│ └── prelude.js
├── logo.svg
├── manifest.js
├── package.json
├── packer.js
├── plugin
└── 1.0.0
│ └── hook.js
├── test
├── manifest
│ ├── expected
│ │ ├── manifest.01
│ │ ├── manifest.02
│ │ ├── manifest.03
│ │ ├── manifest.04
│ │ ├── manifest.05
│ │ ├── manifest.06
│ │ ├── manifest.07
│ │ ├── manifest.08
│ │ ├── manifest.09
│ │ └── manifest.10
│ ├── fixtures
│ │ ├── package.01.json
│ │ ├── package.02.json
│ │ ├── package.03.json
│ │ ├── package.04.json
│ │ ├── package.05.json
│ │ ├── package.06.json
│ │ ├── package.07.json
│ │ ├── package.08.json
│ │ ├── package.09.json
│ │ ├── package.10.json
│ │ ├── package.INVALID.1.json
│ │ ├── package.INVALID.2.json
│ │ ├── package.INVALID.3.json
│ │ ├── package.INVALID.4.json
│ │ └── package.INVALID.5.json
│ └── index.js
├── packer
│ ├── fake-module-1
│ │ ├── index-titanium.js
│ │ ├── index.js
│ │ ├── package.json
│ │ └── setup-global-var.js
│ ├── fake-module-2
│ │ ├── index-titanium.js
│ │ ├── index.js
│ │ └── package.json
│ ├── index.js
│ ├── module-1
│ │ ├── docs
│ │ │ └── index.md
│ │ ├── example
│ │ │ └── app.js
│ │ ├── index.js
│ │ ├── node_modules
│ │ │ ├── example
│ │ │ │ ├── index.js
│ │ │ │ └── package.json
│ │ │ └── insert-global
│ │ │ │ └── index.js
│ │ ├── package.json
│ │ └── titanium.js
│ └── module-2
│ │ ├── index.js
│ │ └── package.json
└── runtime
│ ├── app
│ └── app.js
│ ├── module-a
│ ├── index.js
│ ├── node_modules
│ │ └── module-b
│ │ │ ├── index.js
│ │ │ ├── package.json
│ │ │ ├── the-answer.js
│ │ │ └── the-real-answer.js
│ └── package.json
│ ├── module-c
│ ├── index.js
│ └── package.json
│ └── tiapp.xml
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | lib/util/_prelude.js
2 | node_modules
3 | test/packer/build
4 | test/runtime/build
5 | tmp
6 | !test/**/node_modules
7 |
--------------------------------------------------------------------------------
/.jshintignore:
--------------------------------------------------------------------------------
1 | lib/util/_prelude.js
2 | lib/util/prelude.js
3 | **/build/**
4 | **/node_modules/**
5 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "node": true,
3 |
4 | "curly": false,
5 | "indent": 2,
6 | "trailing": true,
7 |
8 | "boss": true,
9 | "latedef": false,
10 | "eqeqeq": true,
11 | "eqnull": true,
12 | "expr": true,
13 | "undef": true,
14 |
15 | "globals": {
16 | "TODO": true,
17 | "describe": true,
18 | "it": true,
19 | "before": true,
20 | "Titanium": true,
21 | "Promise": true
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | test
2 | tmp
3 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "5"
4 | - "4"
5 | - "0.12"
6 | - "0.10"
7 | before_script:
8 | - npm install --global grunt-cli
9 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var Promise = require('bluebird');
4 | var path = require('path');
5 | var packer = require('./packer');
6 |
7 | module.exports = function (grunt) {
8 |
9 | grunt.initConfig({
10 |
11 | pkg: grunt.file.readJSON('package.json'),
12 |
13 | jshint: {
14 | options: {
15 | jshintrc: true
16 | },
17 | all: [ 'lib/**/*.js', 'test/**/*.js' ]
18 | },
19 |
20 | mochaTest: {
21 | packer: {
22 | src: [ 'test/packer' ]
23 | },
24 | manifest: {
25 | src: [ 'test/manifest' ]
26 | }
27 | },
28 |
29 | clean: {
30 | all: [ 'test/*/build', 'tmp' ]
31 | },
32 |
33 | unzip: {
34 | 'module-a': {
35 | src: 'test/runtime/build/module-a-commonjs-1.2.3.zip',
36 | dest: 'test/runtime/build'
37 | },
38 | 'module-c': {
39 | src: 'test/runtime/build/module-c-commonjs-1.2.3.zip',
40 | dest: 'test/runtime/build'
41 | }
42 | },
43 |
44 | titanium_run: {
45 | options: {
46 | success: '[TESTS ALL OK]',
47 | failure: '[TESTS WITH FAILURES]'
48 | },
49 | test: {
50 | files: {
51 | 'tmp/test': [
52 | // We need to define modules
53 | 'test/runtime/tiapp.xml'
54 | ],
55 | 'tmp/test/Resources': [
56 | // Application sources
57 | 'test/runtime/app/*.js',
58 | // Browserified files
59 | require.resolve('ti-mocha/ti-mocha'),
60 | require.resolve('should/should')
61 | ],
62 | 'tmp/test/modules': [
63 | 'test/runtime/build/modules/*'
64 | ]
65 | }
66 | }
67 | }
68 |
69 | });
70 |
71 | grunt.loadNpmTasks('grunt-contrib-clean');
72 | grunt.loadNpmTasks('grunt-contrib-jshint');
73 | grunt.loadNpmTasks('grunt-mocha-test');
74 | grunt.loadNpmTasks('grunt-titanium');
75 | grunt.loadNpmTasks('grunt-zip');
76 |
77 | grunt.registerTask('build-runtime-modules', 'Build the zip to be used in runtime tests', function () {
78 | var done = this.async();
79 |
80 | grunt.file.mkdir('test/runtime/build');
81 |
82 | Promise.all([
83 | packer.build({
84 | entry: path.resolve(__dirname, 'test/runtime/module-a')
85 | }),
86 | packer.build({
87 | entry: path.resolve(__dirname, 'test/runtime/module-c')
88 | })
89 | ])
90 | .map(function (zip) {
91 | return zip.writeModule(path.resolve(__dirname, 'test/runtime/build'));
92 | })
93 | .done(function () {
94 | grunt.log.ok('Runtime module built');
95 | done(true);
96 | }, function (err) {
97 | throw err;
98 | });
99 | });
100 |
101 | grunt.registerTask('titanium', [
102 | 'clean', 'build-runtime-modules', 'unzip', 'titanium_run'
103 | ]);
104 |
105 | grunt.registerTask('test', [ 'mochaTest' ]);
106 |
107 | grunt.registerTask('default', [ 'jshint', 'test' ]);
108 | };
109 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 2.1, February 1999
3 |
4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | (This is the first released version of the Lesser GPL. It also counts
10 | as the successor of the GNU Library Public License, version 2, hence
11 | the version number 2.1.)
12 |
13 | Preamble
14 |
15 | The licenses for most software are designed to take away your
16 | freedom to share and change it. By contrast, the GNU General Public
17 | Licenses are intended to guarantee your freedom to share and change
18 | free software--to make sure the software is free for all its users.
19 |
20 | This license, the Lesser General Public License, applies to some
21 | specially designated software packages--typically libraries--of the
22 | Free Software Foundation and other authors who decide to use it. You
23 | can use it too, but we suggest you first think carefully about whether
24 | this license or the ordinary General Public License is the better
25 | strategy to use in any particular case, based on the explanations below.
26 |
27 | When we speak of free software, we are referring to freedom of use,
28 | not price. Our General Public Licenses are designed to make sure that
29 | you have the freedom to distribute copies of free software (and charge
30 | for this service if you wish); that you receive source code or can get
31 | it if you want it; that you can change the software and use pieces of
32 | it in new free programs; and that you are informed that you can do
33 | these things.
34 |
35 | To protect your rights, we need to make restrictions that forbid
36 | distributors to deny you these rights or to ask you to surrender these
37 | rights. These restrictions translate to certain responsibilities for
38 | you if you distribute copies of the library or if you modify it.
39 |
40 | For example, if you distribute copies of the library, whether gratis
41 | or for a fee, you must give the recipients all the rights that we gave
42 | you. You must make sure that they, too, receive or can get the source
43 | code. If you link other code with the library, you must provide
44 | complete object files to the recipients, so that they can relink them
45 | with the library after making changes to the library and recompiling
46 | it. And you must show them these terms so they know their rights.
47 |
48 | We protect your rights with a two-step method: (1) we copyright the
49 | library, and (2) we offer you this license, which gives you legal
50 | permission to copy, distribute and/or modify the library.
51 |
52 | To protect each distributor, we want to make it very clear that
53 | there is no warranty for the free library. Also, if the library is
54 | modified by someone else and passed on, the recipients should know
55 | that what they have is not the original version, so that the original
56 | author's reputation will not be affected by problems that might be
57 | introduced by others.
58 |
59 | Finally, software patents pose a constant threat to the existence of
60 | any free program. We wish to make sure that a company cannot
61 | effectively restrict the users of a free program by obtaining a
62 | restrictive license from a patent holder. Therefore, we insist that
63 | any patent license obtained for a version of the library must be
64 | consistent with the full freedom of use specified in this license.
65 |
66 | Most GNU software, including some libraries, is covered by the
67 | ordinary GNU General Public License. This license, the GNU Lesser
68 | General Public License, applies to certain designated libraries, and
69 | is quite different from the ordinary General Public License. We use
70 | this license for certain libraries in order to permit linking those
71 | libraries into non-free programs.
72 |
73 | When a program is linked with a library, whether statically or using
74 | a shared library, the combination of the two is legally speaking a
75 | combined work, a derivative of the original library. The ordinary
76 | General Public License therefore permits such linking only if the
77 | entire combination fits its criteria of freedom. The Lesser General
78 | Public License permits more lax criteria for linking other code with
79 | the library.
80 |
81 | We call this license the "Lesser" General Public License because it
82 | does Less to protect the user's freedom than the ordinary General
83 | Public License. It also provides other free software developers Less
84 | of an advantage over competing non-free programs. These disadvantages
85 | are the reason we use the ordinary General Public License for many
86 | libraries. However, the Lesser license provides advantages in certain
87 | special circumstances.
88 |
89 | For example, on rare occasions, there may be a special need to
90 | encourage the widest possible use of a certain library, so that it becomes
91 | a de-facto standard. To achieve this, non-free programs must be
92 | allowed to use the library. A more frequent case is that a free
93 | library does the same job as widely used non-free libraries. In this
94 | case, there is little to gain by limiting the free library to free
95 | software only, so we use the Lesser General Public License.
96 |
97 | In other cases, permission to use a particular library in non-free
98 | programs enables a greater number of people to use a large body of
99 | free software. For example, permission to use the GNU C Library in
100 | non-free programs enables many more people to use the whole GNU
101 | operating system, as well as its variant, the GNU/Linux operating
102 | system.
103 |
104 | Although the Lesser General Public License is Less protective of the
105 | users' freedom, it does ensure that the user of a program that is
106 | linked with the Library has the freedom and the wherewithal to run
107 | that program using a modified version of the Library.
108 |
109 | The precise terms and conditions for copying, distribution and
110 | modification follow. Pay close attention to the difference between a
111 | "work based on the library" and a "work that uses the library". The
112 | former contains code derived from the library, whereas the latter must
113 | be combined with the library in order to run.
114 |
115 | GNU LESSER GENERAL PUBLIC LICENSE
116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117 |
118 | 0. This License Agreement applies to any software library or other
119 | program which contains a notice placed by the copyright holder or
120 | other authorized party saying it may be distributed under the terms of
121 | this Lesser General Public License (also called "this License").
122 | Each licensee is addressed as "you".
123 |
124 | A "library" means a collection of software functions and/or data
125 | prepared so as to be conveniently linked with application programs
126 | (which use some of those functions and data) to form executables.
127 |
128 | The "Library", below, refers to any such software library or work
129 | which has been distributed under these terms. A "work based on the
130 | Library" means either the Library or any derivative work under
131 | copyright law: that is to say, a work containing the Library or a
132 | portion of it, either verbatim or with modifications and/or translated
133 | straightforwardly into another language. (Hereinafter, translation is
134 | included without limitation in the term "modification".)
135 |
136 | "Source code" for a work means the preferred form of the work for
137 | making modifications to it. For a library, complete source code means
138 | all the source code for all modules it contains, plus any associated
139 | interface definition files, plus the scripts used to control compilation
140 | and installation of the library.
141 |
142 | Activities other than copying, distribution and modification are not
143 | covered by this License; they are outside its scope. The act of
144 | running a program using the Library is not restricted, and output from
145 | such a program is covered only if its contents constitute a work based
146 | on the Library (independent of the use of the Library in a tool for
147 | writing it). Whether that is true depends on what the Library does
148 | and what the program that uses the Library does.
149 |
150 | 1. You may copy and distribute verbatim copies of the Library's
151 | complete source code as you receive it, in any medium, provided that
152 | you conspicuously and appropriately publish on each copy an
153 | appropriate copyright notice and disclaimer of warranty; keep intact
154 | all the notices that refer to this License and to the absence of any
155 | warranty; and distribute a copy of this License along with the
156 | Library.
157 |
158 | You may charge a fee for the physical act of transferring a copy,
159 | and you may at your option offer warranty protection in exchange for a
160 | fee.
161 |
162 | 2. You may modify your copy or copies of the Library or any portion
163 | of it, thus forming a work based on the Library, and copy and
164 | distribute such modifications or work under the terms of Section 1
165 | above, provided that you also meet all of these conditions:
166 |
167 | a) The modified work must itself be a software library.
168 |
169 | b) You must cause the files modified to carry prominent notices
170 | stating that you changed the files and the date of any change.
171 |
172 | c) You must cause the whole of the work to be licensed at no
173 | charge to all third parties under the terms of this License.
174 |
175 | d) If a facility in the modified Library refers to a function or a
176 | table of data to be supplied by an application program that uses
177 | the facility, other than as an argument passed when the facility
178 | is invoked, then you must make a good faith effort to ensure that,
179 | in the event an application does not supply such function or
180 | table, the facility still operates, and performs whatever part of
181 | its purpose remains meaningful.
182 |
183 | (For example, a function in a library to compute square roots has
184 | a purpose that is entirely well-defined independent of the
185 | application. Therefore, Subsection 2d requires that any
186 | application-supplied function or table used by this function must
187 | be optional: if the application does not supply it, the square
188 | root function must still compute square roots.)
189 |
190 | These requirements apply to the modified work as a whole. If
191 | identifiable sections of that work are not derived from the Library,
192 | and can be reasonably considered independent and separate works in
193 | themselves, then this License, and its terms, do not apply to those
194 | sections when you distribute them as separate works. But when you
195 | distribute the same sections as part of a whole which is a work based
196 | on the Library, the distribution of the whole must be on the terms of
197 | this License, whose permissions for other licensees extend to the
198 | entire whole, and thus to each and every part regardless of who wrote
199 | it.
200 |
201 | Thus, it is not the intent of this section to claim rights or contest
202 | your rights to work written entirely by you; rather, the intent is to
203 | exercise the right to control the distribution of derivative or
204 | collective works based on the Library.
205 |
206 | In addition, mere aggregation of another work not based on the Library
207 | with the Library (or with a work based on the Library) on a volume of
208 | a storage or distribution medium does not bring the other work under
209 | the scope of this License.
210 |
211 | 3. You may opt to apply the terms of the ordinary GNU General Public
212 | License instead of this License to a given copy of the Library. To do
213 | this, you must alter all the notices that refer to this License, so
214 | that they refer to the ordinary GNU General Public License, version 2,
215 | instead of to this License. (If a newer version than version 2 of the
216 | ordinary GNU General Public License has appeared, then you can specify
217 | that version instead if you wish.) Do not make any other change in
218 | these notices.
219 |
220 | Once this change is made in a given copy, it is irreversible for
221 | that copy, so the ordinary GNU General Public License applies to all
222 | subsequent copies and derivative works made from that copy.
223 |
224 | This option is useful when you wish to copy part of the code of
225 | the Library into a program that is not a library.
226 |
227 | 4. You may copy and distribute the Library (or a portion or
228 | derivative of it, under Section 2) in object code or executable form
229 | under the terms of Sections 1 and 2 above provided that you accompany
230 | it with the complete corresponding machine-readable source code, which
231 | must be distributed under the terms of Sections 1 and 2 above on a
232 | medium customarily used for software interchange.
233 |
234 | If distribution of object code is made by offering access to copy
235 | from a designated place, then offering equivalent access to copy the
236 | source code from the same place satisfies the requirement to
237 | distribute the source code, even though third parties are not
238 | compelled to copy the source along with the object code.
239 |
240 | 5. A program that contains no derivative of any portion of the
241 | Library, but is designed to work with the Library by being compiled or
242 | linked with it, is called a "work that uses the Library". Such a
243 | work, in isolation, is not a derivative work of the Library, and
244 | therefore falls outside the scope of this License.
245 |
246 | However, linking a "work that uses the Library" with the Library
247 | creates an executable that is a derivative of the Library (because it
248 | contains portions of the Library), rather than a "work that uses the
249 | library". The executable is therefore covered by this License.
250 | Section 6 states terms for distribution of such executables.
251 |
252 | When a "work that uses the Library" uses material from a header file
253 | that is part of the Library, the object code for the work may be a
254 | derivative work of the Library even though the source code is not.
255 | Whether this is true is especially significant if the work can be
256 | linked without the Library, or if the work is itself a library. The
257 | threshold for this to be true is not precisely defined by law.
258 |
259 | If such an object file uses only numerical parameters, data
260 | structure layouts and accessors, and small macros and small inline
261 | functions (ten lines or less in length), then the use of the object
262 | file is unrestricted, regardless of whether it is legally a derivative
263 | work. (Executables containing this object code plus portions of the
264 | Library will still fall under Section 6.)
265 |
266 | Otherwise, if the work is a derivative of the Library, you may
267 | distribute the object code for the work under the terms of Section 6.
268 | Any executables containing that work also fall under Section 6,
269 | whether or not they are linked directly with the Library itself.
270 |
271 | 6. As an exception to the Sections above, you may also combine or
272 | link a "work that uses the Library" with the Library to produce a
273 | work containing portions of the Library, and distribute that work
274 | under terms of your choice, provided that the terms permit
275 | modification of the work for the customer's own use and reverse
276 | engineering for debugging such modifications.
277 |
278 | You must give prominent notice with each copy of the work that the
279 | Library is used in it and that the Library and its use are covered by
280 | this License. You must supply a copy of this License. If the work
281 | during execution displays copyright notices, you must include the
282 | copyright notice for the Library among them, as well as a reference
283 | directing the user to the copy of this License. Also, you must do one
284 | of these things:
285 |
286 | a) Accompany the work with the complete corresponding
287 | machine-readable source code for the Library including whatever
288 | changes were used in the work (which must be distributed under
289 | Sections 1 and 2 above); and, if the work is an executable linked
290 | with the Library, with the complete machine-readable "work that
291 | uses the Library", as object code and/or source code, so that the
292 | user can modify the Library and then relink to produce a modified
293 | executable containing the modified Library. (It is understood
294 | that the user who changes the contents of definitions files in the
295 | Library will not necessarily be able to recompile the application
296 | to use the modified definitions.)
297 |
298 | b) Use a suitable shared library mechanism for linking with the
299 | Library. A suitable mechanism is one that (1) uses at run time a
300 | copy of the library already present on the user's computer system,
301 | rather than copying library functions into the executable, and (2)
302 | will operate properly with a modified version of the library, if
303 | the user installs one, as long as the modified version is
304 | interface-compatible with the version that the work was made with.
305 |
306 | c) Accompany the work with a written offer, valid for at
307 | least three years, to give the same user the materials
308 | specified in Subsection 6a, above, for a charge no more
309 | than the cost of performing this distribution.
310 |
311 | d) If distribution of the work is made by offering access to copy
312 | from a designated place, offer equivalent access to copy the above
313 | specified materials from the same place.
314 |
315 | e) Verify that the user has already received a copy of these
316 | materials or that you have already sent this user a copy.
317 |
318 | For an executable, the required form of the "work that uses the
319 | Library" must include any data and utility programs needed for
320 | reproducing the executable from it. However, as a special exception,
321 | the materials to be distributed need not include anything that is
322 | normally distributed (in either source or binary form) with the major
323 | components (compiler, kernel, and so on) of the operating system on
324 | which the executable runs, unless that component itself accompanies
325 | the executable.
326 |
327 | It may happen that this requirement contradicts the license
328 | restrictions of other proprietary libraries that do not normally
329 | accompany the operating system. Such a contradiction means you cannot
330 | use both them and the Library together in an executable that you
331 | distribute.
332 |
333 | 7. You may place library facilities that are a work based on the
334 | Library side-by-side in a single library together with other library
335 | facilities not covered by this License, and distribute such a combined
336 | library, provided that the separate distribution of the work based on
337 | the Library and of the other library facilities is otherwise
338 | permitted, and provided that you do these two things:
339 |
340 | a) Accompany the combined library with a copy of the same work
341 | based on the Library, uncombined with any other library
342 | facilities. This must be distributed under the terms of the
343 | Sections above.
344 |
345 | b) Give prominent notice with the combined library of the fact
346 | that part of it is a work based on the Library, and explaining
347 | where to find the accompanying uncombined form of the same work.
348 |
349 | 8. You may not copy, modify, sublicense, link with, or distribute
350 | the Library except as expressly provided under this License. Any
351 | attempt otherwise to copy, modify, sublicense, link with, or
352 | distribute the Library is void, and will automatically terminate your
353 | rights under this License. However, parties who have received copies,
354 | or rights, from you under this License will not have their licenses
355 | terminated so long as such parties remain in full compliance.
356 |
357 | 9. You are not required to accept this License, since you have not
358 | signed it. However, nothing else grants you permission to modify or
359 | distribute the Library or its derivative works. These actions are
360 | prohibited by law if you do not accept this License. Therefore, by
361 | modifying or distributing the Library (or any work based on the
362 | Library), you indicate your acceptance of this License to do so, and
363 | all its terms and conditions for copying, distributing or modifying
364 | the Library or works based on it.
365 |
366 | 10. Each time you redistribute the Library (or any work based on the
367 | Library), the recipient automatically receives a license from the
368 | original licensor to copy, distribute, link with or modify the Library
369 | subject to these terms and conditions. You may not impose any further
370 | restrictions on the recipients' exercise of the rights granted herein.
371 | You are not responsible for enforcing compliance by third parties with
372 | this License.
373 |
374 | 11. If, as a consequence of a court judgment or allegation of patent
375 | infringement or for any other reason (not limited to patent issues),
376 | conditions are imposed on you (whether by court order, agreement or
377 | otherwise) that contradict the conditions of this License, they do not
378 | excuse you from the conditions of this License. If you cannot
379 | distribute so as to satisfy simultaneously your obligations under this
380 | License and any other pertinent obligations, then as a consequence you
381 | may not distribute the Library at all. For example, if a patent
382 | license would not permit royalty-free redistribution of the Library by
383 | all those who receive copies directly or indirectly through you, then
384 | the only way you could satisfy both it and this License would be to
385 | refrain entirely from distribution of the Library.
386 |
387 | If any portion of this section is held invalid or unenforceable under any
388 | particular circumstance, the balance of the section is intended to apply,
389 | and the section as a whole is intended to apply in other circumstances.
390 |
391 | It is not the purpose of this section to induce you to infringe any
392 | patents or other property right claims or to contest validity of any
393 | such claims; this section has the sole purpose of protecting the
394 | integrity of the free software distribution system which is
395 | implemented by public license practices. Many people have made
396 | generous contributions to the wide range of software distributed
397 | through that system in reliance on consistent application of that
398 | system; it is up to the author/donor to decide if he or she is willing
399 | to distribute software through any other system and a licensee cannot
400 | impose that choice.
401 |
402 | This section is intended to make thoroughly clear what is believed to
403 | be a consequence of the rest of this License.
404 |
405 | 12. If the distribution and/or use of the Library is restricted in
406 | certain countries either by patents or by copyrighted interfaces, the
407 | original copyright holder who places the Library under this License may add
408 | an explicit geographical distribution limitation excluding those countries,
409 | so that distribution is permitted only in or among countries not thus
410 | excluded. In such case, this License incorporates the limitation as if
411 | written in the body of this License.
412 |
413 | 13. The Free Software Foundation may publish revised and/or new
414 | versions of the Lesser General Public License from time to time.
415 | Such new versions will be similar in spirit to the present version,
416 | but may differ in detail to address new problems or concerns.
417 |
418 | Each version is given a distinguishing version number. If the Library
419 | specifies a version number of this License which applies to it and
420 | "any later version", you have the option of following the terms and
421 | conditions either of that version or of any later version published by
422 | the Free Software Foundation. If the Library does not specify a
423 | license version number, you may choose any version ever published by
424 | the Free Software Foundation.
425 |
426 | 14. If you wish to incorporate parts of the Library into other free
427 | programs whose distribution conditions are incompatible with these,
428 | write to the author to ask for permission. For software which is
429 | copyrighted by the Free Software Foundation, write to the Free
430 | Software Foundation; we sometimes make exceptions for this. Our
431 | decision will be guided by the two goals of preserving the free status
432 | of all derivatives of our free software and of promoting the sharing
433 | and reuse of software generally.
434 |
435 | NO WARRANTY
436 |
437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
446 |
447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456 | DAMAGES.
457 |
458 | END OF TERMS AND CONDITIONS
459 |
460 | How to Apply These Terms to Your New Libraries
461 |
462 | If you develop a new library, and you want it to be of the greatest
463 | possible use to the public, we recommend making it free software that
464 | everyone can redistribute and change. You can do so by permitting
465 | redistribution under these terms (or, alternatively, under the terms of the
466 | ordinary General Public License).
467 |
468 | To apply these terms, attach the following notices to the library. It is
469 | safest to attach them to the start of each source file to most effectively
470 | convey the exclusion of warranty; and each file should have at least the
471 | "copyright" line and a pointer to where the full notice is found.
472 |
473 | {description}
474 | Copyright (C) {year} {fullname}
475 |
476 | This library is free software; you can redistribute it and/or
477 | modify it under the terms of the GNU Lesser General Public
478 | License as published by the Free Software Foundation; either
479 | version 2.1 of the License, or (at your option) any later version.
480 |
481 | This library is distributed in the hope that it will be useful,
482 | but WITHOUT ANY WARRANTY; without even the implied warranty of
483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
484 | Lesser General Public License for more details.
485 |
486 | You should have received a copy of the GNU Lesser General Public
487 | License along with this library; if not, write to the Free Software
488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
489 |
490 | Also add information on how to contact you by electronic and paper mail.
491 |
492 | You should also get your employer (if you work as a programmer) or your
493 | school, if any, to sign a "copyright disclaimer" for the library, if
494 | necessary. Here is a sample; alter the names:
495 |
496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the
497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker.
498 |
499 | {signature of Ty Coon}, 1 April 1990
500 | Ty Coon, President of Vice
501 |
502 | That's all there is to it!
503 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Titaniumifier
2 | =============
3 |
4 |
5 |
6 | [](https://travis-ci.org/smclab/titaniumifier)
7 | [](https://www.npmjs.com/package/titaniumifier) [](https://gitter.im/smclab/titaniumifier?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8 |
9 | Build your **Titanium CommonJS Modules** as they should be: as **CommonJS packages**, allowing more than one file.
10 |
11 | Developed around [substack][ss]’s [browserify][b], *titaniumifier* is a tool that can be used to build a zip file following Titanium SDK conventions with a `package.json` as its starting point.
12 |
13 | [Documentation][wiki]
14 | ---------------------
15 |
16 | The [Titaniumifier Wiki][wiki] is where you’ll find the most up to date documentation.
17 |
18 |
19 | Installation and usage
20 | ----------------------
21 |
22 | If you’re serious with it you can use the [**Grunt plugin**][gt].
23 |
24 | If you just want to test it out you can use the `titaniumifier` CLI (good for **quick tests**):
25 |
26 | # install it globally
27 | $ [sudo] npm install --global titaniumifier
28 |
29 | # move into a node package
30 | $ cd path/to/project
31 |
32 | # this will build dist/NAME-commonjs.VERSION.zip
33 | $ titaniumifier --out dist
34 |
35 | [wiki]: https://github.com/smclab/titaniumifier/wiki
36 | [ss]: https://github.com/substack
37 | [b]: https://github.com/substack/node-browserify
38 | [gt]: https://github.com/smclab/grunt-titaniumifier
39 | [ti-superagent]: https://github.com/smclab/ti-superagent
40 |
41 | - - -
42 |
43 |
44 | What is it for?
45 | ---------------
46 |
47 | You’ll want to give `titaniumifier` a try if you want to write
48 |
49 | - a Titanium CommonJS distributable module
50 | - more complex than a single file,
51 | - some `npm` dependencies;
52 | - a package that works on both Node.js and Titanium SDK;
53 | - a wrapper for an existing package existing on `npm`.
54 |
55 | Once you’re done writing your package you’ll be able to publish it on `npm` for users to
56 |
57 | - use it with Node.js;
58 | - include it as a dependency of a *titaniumified* package.
59 |
60 |
61 | What is it **not** for?
62 | -----------------------
63 |
64 | Even with `titaniumifier` you still wont be ablo to
65 |
66 | - use or depend on ‘complex’ e ‘deeply node-ish’ packages like `socket.io` without work;
67 | - install Node.js packages in your app using `npm install ...`;
68 |
69 |
70 | TODO
71 | ----
72 |
73 | - Make the built module easily debuggable from Titanium Studio (this is pretty big;)
74 | - Document and explore transpilation (this is a research mostly related to source maps/debug features;)
75 | - Make titaniumified repositories crawlable from `gitTio`;
76 | - Shim the following globals
77 | - `Buffer` with `Titanium.Buffer`
78 | - `TypedArrays`,
79 | - `set/clearImmediate`,
80 | - `process.nextTick`;
81 | - Shim the following built-ins
82 | - `http`,
83 | - `net` (with `Titanium.Network.TCPSocket`),
84 | - `stream` (and make `fs` work with it.)
85 |
86 | The shimming process could be a community effort into the development of `ti-http`, `ti-net` etc. Contact us if you’re interested in working on it. In case don’t limit yourself to pure JS, give native development a chance.
87 |
88 |
89 | Compatibility
90 | -------------
91 |
92 | ### Titanium SDK
93 |
94 | The reference packages have been tested extensively from Titanium SDK 3.2 onward. There should be no reson for titaniumified packages to not work on older SDK versions.
95 |
96 | Issues with Titanium SDK 3.x will be considered critical. With older versions we’ll try to do our best.
97 |
98 | Because it does not mangle your `Resources` folder it is compatible with Alloy and TiShadow (and similars.) Please report any issue you have.
99 |
100 | ### Node.js (in packages)
101 |
102 | Currently Node.js 0.10 environment is shimmed in the packaging process. Once Node.js 0.12 is out there will be some interesting challenge to cope with (generators, WeakMap etc.)
103 |
104 | Once that happens we’ll shim whatever is necessary.
105 |
106 | ### Node.js (build-time)
107 |
108 | This code is tested against Node.js 0.10 and 0.11.
109 |
110 |
111 | Please steal this code (aka *examples*)
112 | ---------------------------------------
113 |
114 | At the moment, you’ll use `titaniumifier` through its `grunt` plugin, [`grunt-titaniumifier`][grtt].
115 |
116 | There are 2 reference packages at the moment:
117 |
118 | - [`ti-superagent`][tisa] Which wraps @visionmedia’s `superagent`
119 | - [`liferay-connector`][lc] Which is a connector for our Portal Framework of choice, Liferay
120 |
121 | [grtt]: https://github.com/smclab/grunt-titaniumifier
122 | [tisa]: https://github.com/smclab/ti-superagent
123 | [lc]: https://github.com/smclab/liferay-connector
124 |
125 |
126 | Contributing and whishlist
127 | --------------------------
128 |
129 | If you feel like helping, we’ll accept pull requests with great joy.
130 |
131 | Here are a few ideas to help this project:
132 |
133 | - A Gulp plugin (here’s a [link to get you started][gp])
134 | - Even more unit-tests (**yes please!**)
135 |
136 | [gp]: https://github.com/gulpjs/gulp/blob/master/docs/writing-a-plugin/README.md
137 |
138 |
139 | We love feedback
140 | ----------------
141 |
142 | **Please**, don’t be afraid in opening new issues, even just for asking some help.
143 |
144 |
145 | Credits
146 | -------
147 |
148 | Humbly made by the spry ladies and gents at SMC.
149 |
150 |
151 | License
152 | -------
153 |
154 | This library, *titaniumifier*, is free software ("Licensed Software"); you can
155 | redistribute it and/or modify it under the terms of the [GNU Lesser General
156 | Public License](http://www.gnu.org/licenses/lgpl-2.1.html) as published by the
157 | Free Software Foundation; either version 2.1 of the License, or (at your
158 | option) any later version.
159 |
160 | This library is distributed in the hope that it will be useful, but WITHOUT ANY
161 | WARRANTY; including but not limited to, the implied warranty of MERCHANTABILITY,
162 | NONINFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
163 | Public License for more details.
164 |
165 | You should have received a copy of the [GNU Lesser General Public
166 | License](http://www.gnu.org/licenses/lgpl-2.1.html) along with this library; if
167 | not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
168 | Floor, Boston, MA 02110-1301 USA
169 |
--------------------------------------------------------------------------------
/bin/install-titaniumifier-plugin:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var pkg = require('../package');
4 |
5 | var logSymbols = require('log-symbols');
6 | var mkdirp = require('mkdirp');
7 | var path = require('path');
8 | var fs = require('fs');
9 | var program = require('commander');
10 | var updateNotifier = require('update-notifier');
11 |
12 | updateNotifier({ pkg: pkg }).notify();
13 |
14 | var BETA = logSymbols.warning + " BETA " + logSymbols.warning;
15 |
16 | var v = '1.0.0';
17 |
18 | program
19 | .version(pkg.version)
20 | .description(BETA + " Use npm modules in your app!")
21 | .option('--no-simulate', 'actually run the installation process')
22 | .parse(process.argv);
23 |
24 | install(resolve(program.args[0]), program.simulate);
25 |
26 | function install(entry, simulate) {
27 |
28 | console.log("");
29 | console.log(" " + BETA);
30 | console.log(" This tool is in beta! Use at your own risk!");
31 | console.log(" " + BETA);
32 |
33 | console.log("");
34 |
35 | console.log(" 1. Environment");
36 | console.log(" -----------");
37 |
38 | console.log(" %s working on '%s'", logSymbols.info, entry);
39 |
40 | var failures = 0;
41 | var warnings = 0;
42 |
43 | if (!is('file', path.resolve(entry, 'tiapp.xml'))) {
44 | console.log(" %s no tiapp.xml found in '%s'", logSymbols.error, entry);
45 | failures++;
46 | }
47 |
48 | if (!is('directory', path.resolve(entry, 'Resources'))) {
49 | console.log(" %s no Resources dir found in '%s'", logSymbols.error, entry);
50 | console.log(" %s (this plugin does NOT work yet with Alloy)", logSymbols.error);
51 | failures++;
52 | }
53 |
54 | if (!is('file', path.resolve(entry, 'package.json'))) {
55 | console.log(" %s no package.json found in '%s'", logSymbols.error, entry);
56 | console.log(" %s run `npm init` to get one!", logSymbols.error);
57 | failures++;
58 | }
59 | else {
60 | console.log(" %s found a package.json (yeah!)", logSymbols.info);
61 |
62 | try {
63 | var pkgSrc = fs.readFileSync(path.resolve(entry, 'package.json'), 'utf-8');
64 | var pkg = JSON.parse(pkgSrc);
65 |
66 | if (!pkg.main) {
67 | console.log(" %s package.json has no 'main' property", logSymbols.error);
68 | failures++;
69 | }
70 | else if (!is('file', path.resolve(entry, pkg.main))) {
71 | console.log(" %s package.json’s 'main' property points to a missing file!", logSymbols.error);
72 | console.log(" %s (shouldn’t that be 'Resources/app.js'?)", logSymbols.error);
73 | failures++;
74 | }
75 | else {
76 | console.log(" %s the package.json has a valid main property", logSymbols.info);
77 | }
78 | }
79 | catch (e) {
80 | console.log(" %s couldn’t read the package.json!", logSymbols.error);
81 | console.log(e);
82 | failures++;
83 | }
84 | }
85 |
86 | if (failures && !simulate) {
87 | console.log("");
88 | process.exit();
89 | }
90 |
91 | console.log("");
92 |
93 | console.log(" 2. Configuring the tiapp.xml");
94 | console.log(" -------------------------");
95 |
96 | var tiapp
97 | var tiappFile = path.resolve(entry, 'tiapp.xml');
98 |
99 | try {
100 | tiapp = require('tiapp.xml').load(tiappFile);
101 | console.log(" %s tiapp.xml parsed correctly", logSymbols.info);
102 | }
103 | catch (e) {
104 | tiapp = null;
105 | console.log(" %s couldn’t parse the tiapp.xml", logSymbols.error);
106 | failures++;
107 | }
108 |
109 | if (failures && !simulate) {
110 | console.log("");
111 | process.exit();
112 | }
113 |
114 | if (tiapp) {
115 |
116 | tiapp.getPlugins().forEach(function (plugin) {
117 | var id = plugin.id;
118 | var version = plugin.version;
119 | if (id === 'ti.alloy') {
120 | console.log(" %s this plugin does NOT work yet with Alloy", logSymbols.error);
121 | failures++;
122 | }
123 | else if (id === 'titaniumifier') {
124 | console.log(" %s v%s of '%s' already set, will overwrite", logSymbols.warning, version, id);
125 | warnings++;
126 | }
127 | });
128 |
129 | if (failures && !simulate) {
130 | console.log("");
131 | process.exit();
132 | }
133 |
134 | tiapp.setPlugin('titaniumifier', '1.0.0');
135 |
136 | var plugins = tiapp.getPlugins();
137 |
138 | if (simulate && plugins.length > 1) {
139 | console.log(" %s the plugins for this app will be:", logSymbols.info);
140 | plugins.forEach(function (plugin, i) {
141 | console.log(" – '%s' <%s>", plugin.id, (plugin.version || 'no specific version'));
142 | });
143 | }
144 | else if (simulate) {
145 | console.log(" %s will setup 'titaniumifier' v%s in the tiapp.xml", logSymbols.info, v);
146 | }
147 |
148 | if (!simulate) {
149 | try {
150 | tiapp.write();
151 |
152 | console.log(" %s plugin 'titaniumifier' installed in tiapp.xml", logSymbols.success);
153 | }
154 | catch (err) {
155 | console.error(" %s issues while installing the plugin in tiapp.xml", logSymbols.error);
156 | console.error(err);
157 | process.exit();
158 | }
159 | }
160 |
161 | }
162 |
163 | console.log("");
164 |
165 | console.log(" 3. Plugin files");
166 | console.log(" ------------");
167 |
168 | var hooksDir = path.resolve(entry, 'plugins', 'titaniumifier', v, 'hooks');
169 | var hookFile = path.resolve(hooksDir, 'titaniumifier.js');
170 | var sourceFile = path.resolve(__dirname, '..', 'plugin', v, 'hook.js');
171 |
172 | if (is('directory', hooksDir)) {
173 | console.log(" %s directory '%s' already here", logSymbols.warning, path.relative(entry, hooksDir));
174 | warnings++;
175 | }
176 | else if (!simulate) {
177 | mkdirp.sync(hooksDir);
178 | console.log(" %s directory '%s' built", logSymbols.success, path.relative(entry, hooksDir));
179 | }
180 | else {
181 | console.log(" %s will create the directory '%s'", logSymbols.info, path.relative(entry, hooksDir));
182 | }
183 |
184 | if (is('file', hookFile)) {
185 | console.log(" %s hook '%s' already here", logSymbols.warning, path.relative(entry, hookFile));
186 | warnings++;
187 | }
188 | else if (!simulate) {
189 | fs.symlinkSync(sourceFile, hookFile);
190 | console.log(" %s hook '%s' (sym)linked", logSymbols.success, path.relative(entry, hookFile));
191 | }
192 | else {
193 | console.log(" %s will (sym)link the hook into '%s'", logSymbols.info, path.relative(entry, hookFile));
194 | }
195 |
196 | console.log("");
197 | console.log("");
198 |
199 | if (simulate) {
200 | if (failures) {
201 | console.log(" %s %s failure(s)", logSymbols.error, failures);
202 | }
203 |
204 | if (warnings) {
205 | console.log(" %s %s warning(s)", logSymbols.warning, warnings);
206 | }
207 |
208 | if (!failures) {
209 | console.log(" %s Finished the simulation, now run it with `--no-simulate`!", logSymbols.success);
210 | }
211 | }
212 | else {
213 | console.log(" %s Finished the installation, enjoy!", logSymbols.success);
214 | }
215 |
216 | console.log("");
217 | }
218 |
219 | function is(type, file) {
220 | try {
221 | var stats = fs.statSync(file);
222 | return !stats ? false :
223 | (type === 'file') ? stats.isFile() :
224 | (type === 'directory') ? stats.isDirectory() :
225 | false;
226 | }
227 | catch (e) {
228 | if (e.code === 'ENOENT') {
229 | return false;
230 | }
231 | else {
232 | throw e;
233 | }
234 | }
235 | }
236 |
237 | function resolve(p) {
238 | return path.resolve(process.cwd(), p || '.');
239 | }
240 |
--------------------------------------------------------------------------------
/bin/titaniumifier:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var packer = require('../packer');
4 | var pkg = require('../package');
5 |
6 | var logSymbols = require('log-symbols');
7 | var mkdirp = require('mkdirp');
8 | var path = require('path');
9 | var program = require('commander');
10 | var updateNotifier = require('update-notifier');
11 |
12 | updateNotifier({ pkg: pkg }).notify();
13 |
14 | program
15 | .version(pkg.version)
16 | .option('-i, --in ', 'The module to titaniumify', process.cwd())
17 | .option('-o, --out ', 'Where to write the module', process.cwd())
18 | .option('-s, --simulate', 'Just test the build process')
19 | .parse(process.argv);
20 |
21 | build(resolve(program.in), resolve(program.out), program.simulate);
22 |
23 | function build(entry, dist, simulate) {
24 |
25 | console.log("");
26 | console.log(" %s working on '%s'", logSymbols.info, entry);
27 |
28 | if (!simulate) {
29 | console.log(" %s will write in '%s'", logSymbols.info, dist);
30 | }
31 | else {
32 | console.log(" %s simulation mode", logSymbols.info);
33 | }
34 |
35 | console.log("");
36 |
37 | packer.build({ entry: entry }).then(function (zip) {
38 | if (simulate) return;
39 |
40 | var newdir = mkdirp.sync(dist);
41 |
42 | if (newdir) {
43 | newdir = path.relative(process.cwd(), newdir);
44 | console.log(" %s dir '%s' wasn't there", logSymbols.warning, newdir);
45 | console.log("");
46 | }
47 |
48 | return zip.writeModule(dist);
49 | })
50 | .done(function () {
51 | if (simulate) console.log(" %s simulation works", logSymbols.success);
52 | else console.log(" %s zip correctly built", logSymbols.success);
53 | console.log("");
54 | }, function (err) {
55 | console.log(" %s errors!", logSymbols.error);
56 | throw err;
57 | });
58 | }
59 |
60 | function resolve(p) {
61 | return path.resolve(process.cwd(), p || '.');
62 | }
63 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./lib/titaniumifier');
--------------------------------------------------------------------------------
/lib/builtins/index.js:
--------------------------------------------------------------------------------
1 |
2 | var original = require('browserify/lib/builtins');
3 |
4 | // Shims
5 | exports.vm = require.resolve('vm-titanium');
6 | exports.os = require.resolve('titanium-os/src/titanium-os');
7 | exports.fs = require.resolve('ti-fs/src/ti-fs');
8 |
9 | // Titaniumifier built-ins
10 | exports[ '--console--' ] = require.resolve('ti-console/src/ti-console');
11 |
12 | // Titaniumifier internals
13 | exports[ '--global--' ] = require.resolve('../globals/global');
14 | exports[ '--process--' ] = require.resolve('../globals/process');
15 | exports[ '--timers--' ] = require.resolve('../globals/timers');
16 |
17 | Object.keys(original).forEach(function (key) {
18 | if (!(key in exports)) exports[ key ] = original[ key ];
19 | });
20 |
--------------------------------------------------------------------------------
/lib/globals/global.js:
--------------------------------------------------------------------------------
1 |
2 | module.exports = (function () { return this; })();
3 |
4 | module.exports.location = {};
5 |
--------------------------------------------------------------------------------
/lib/globals/index.js:
--------------------------------------------------------------------------------
1 |
2 | var path = require('path');
3 | var fs = require('fs');
4 | var readFileSync = fs.readFileSync;
5 |
6 | function fromPath(modulepath, extra) {
7 | return function () {
8 | return 'require(' + JSON.stringify(modulepath) + ')' + (extra ? '.' + extra : '');
9 | };
10 | }
11 |
12 | module.exports = {
13 |
14 | // see ../builtins/index.js
15 | console: fromPath('--console--'),
16 | process: fromPath('--process--'),
17 | global: fromPath('--global--'),
18 | clearInterval: fromPath('--timers--', 'clearInterval'),
19 | clearTimeout: fromPath('--timers--', 'clearTimeout'),
20 | setInterval: fromPath('--timers--', 'setInterval'),
21 | setTimeout: fromPath('--timers--', 'setTimeout'),
22 |
23 | Buffer: fromPath('buffer', 'Buffer'),
24 |
25 | __filename: function (filepath, basedir) {
26 | var file = '/' + path.relative(basedir, filepath);
27 | return JSON.stringify(file);
28 | },
29 |
30 | __dirname: function (filepath, basedir) {
31 | var dir = path.dirname('/' + path.relative(basedir, filepath));
32 | return JSON.stringify(dir);
33 | }
34 |
35 | };
36 |
--------------------------------------------------------------------------------
/lib/globals/process.js:
--------------------------------------------------------------------------------
1 | /* global Ti:true, Titanium:true */
2 |
3 | var process = module.exports = {};
4 |
5 | process.nextTick = function nextTick(fn) {
6 | setTimeout(fn, 0);
7 | };
8 |
9 | process.title = 'titanium';
10 | process.titanium = true;
11 | process.env = {};
12 | process.argv = [];
13 |
14 | process.binding = function (name) {
15 | throw new Error('process.binding is not supported');
16 | };
17 |
18 | process.cwd = function () {
19 | return '/';
20 | };
21 |
22 | process.chdir = function (dir) {
23 | throw new Error('process.chdir is not supported');
24 | };
25 |
26 | process.stdout = {};
27 | process.stderr = {};
28 |
29 | process.stdout.write = function (msg) {
30 | Ti.API.info(msg);
31 | };
32 |
33 | process.stderr.write = function (msg) {
34 | Ti.API.error(msg);
35 | };
36 |
37 | 'addEventListener removeEventListener removeListener hasEventListener fireEvent emit on off'.split(' ').forEach(function (name) {
38 | process[ name ] = noop;
39 | });
40 |
41 | function noop() {}
42 |
--------------------------------------------------------------------------------
/lib/globals/timers.js:
--------------------------------------------------------------------------------
1 |
2 | module.exports.clearInterval = clearInterval;
3 | module.exports.clearTimeout = clearTimeout;
4 | module.exports.setInterval = setInterval;
5 | module.exports.setTimeout = setTimeout;
6 |
7 | // See https://html.spec.whatwg.org/multipage/webappapis.html#dom-windowtimers-cleartimeout
8 |
9 | function clearInterval(intervalId) {
10 | try {
11 | return global.clearInterval(intervalId);
12 | }
13 | catch (e) {
14 | // Do nothing
15 | return undefined;
16 | }
17 | }
18 |
19 | function clearTimeout(timeoutId) {
20 | try {
21 | return global.clearTimeout(timeoutId);
22 | }
23 | catch (e) {
24 | // Do nothing
25 | return undefined;
26 | }
27 | }
28 |
29 | function setInterval(func, delay) {
30 | var args = [];
31 | for (var i = 2, l = arguments.length; i < l; ++i) {
32 | args[ i - 2 ] = arguments[ i ];
33 | }
34 |
35 | return global.setInterval(function () {
36 | func.apply(this, args);
37 | }, +delay);
38 | }
39 |
40 | function setTimeout(func, delay) {
41 | var args = [];
42 | for (var i = 2, l = arguments.length; i < l; ++i) {
43 | args[ i - 2 ] = arguments[ i ];
44 | }
45 |
46 | return global.setTimeout(function () {
47 | func.apply(this, args);
48 | }, +delay);
49 | }
50 |
--------------------------------------------------------------------------------
/lib/manifest.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var semver = require('semver');
4 | var guid = require('guid');
5 |
6 | var DEFAULT_MIN_SDK = '3.2.0.GA';
7 |
8 | exports.buildFromPackage = buildFromPackage;
9 | exports.buildManifest = buildManifest;
10 | exports.validatePackage = validatePackage;
11 |
12 | function validatePackage(pkg) {
13 | var titaniumManifest = pkg.titaniumManifest || {};
14 |
15 | if (!titaniumManifest.guid && !pkg.guid) {
16 | throw new Error("No `guid` found. Here’s one for you: " + guid.raw());
17 | }
18 |
19 | if (!pkg.name) {
20 | throw new Error("No `name` found!");
21 | }
22 |
23 | getMinSDKFromPackage(pkg);
24 |
25 | return pkg;
26 | }
27 |
28 | function buildFromPackage(pkg) {
29 | var authorObj = getAuthorFromPackage(pkg);
30 |
31 | var titaniumManifest = pkg.titaniumManifest || {};
32 |
33 | var version = pkg.version;
34 | var description = pkg.description;
35 | var author = getAuthorFull(authorObj);
36 | var license = getLicenseFromPackage(pkg);
37 | var copyright = getCopyrightFromPackage(pkg);
38 | var name = titaniumManifest.name || pkg.name;
39 | var moduleid = titaniumManifest.moduleid || pkg.name;
40 | var guid = titaniumManifest.guid || pkg.guid;
41 | var platform = 'commonjs';
42 | var minsdk = getMinSDKFromPackage(pkg);
43 |
44 | return buildManifest({
45 | 'version': version,
46 | 'description': description,
47 | 'author': author,
48 | 'license': license,
49 | 'copyright': copyright,
50 | 'name': name,
51 | 'moduleid': moduleid,
52 | 'guid': guid,
53 | 'platform': platform,
54 | 'minsdk': minsdk
55 | });
56 | }
57 |
58 | function buildManifest(data) {
59 | return Object.keys(data).map(function (key) {
60 | var value = data[key];
61 | return key + ':' + (value ? (' ' + value) : '');
62 | }).join('\n');
63 | }
64 |
65 | function getCopyrightFromPackage(pkg) {
66 | if (pkg.copyright) {
67 | return pkg.copyright;
68 | }
69 | else {
70 | var year = new Date().getFullYear();
71 | var author = getAuthorName(getAuthorFromPackage(pkg));
72 | return [
73 | 'Copyright', '©', year, author
74 | ].join(' ');
75 | }
76 | }
77 |
78 | function getLicenseFromPackage(pkg) {
79 | if (pkg.license) {
80 | return licenseToString(pkg.license);
81 | }
82 | else if (pkg.licenses) {
83 | return pkg.licenses.map(licenseToString).join(', ');
84 | }
85 | }
86 |
87 | function licenseToString(license) {
88 | if (typeof license === 'string') {
89 | return license;
90 | }
91 | else if (typeof license === 'object') {
92 | return license.type;
93 | }
94 | else {
95 | return '-';
96 | }
97 | }
98 |
99 | function getAuthorFromPackage(pkg) {
100 | var author = pkg.author;
101 | var contributors = pkg.contributors;
102 |
103 | if (author) {
104 | return author;
105 | }
106 | else if (contributors && contributors.length) {
107 | return contributors[0];
108 | }
109 | else {
110 | return {};
111 | }
112 | }
113 |
114 | function getAuthorName(author) {
115 | if (typeof author === 'string') {
116 | var pos;
117 | if ((pos = author.indexOf('<')) >= 0 ||
118 | (pos = author.indexOf('(')) >= 0) {
119 |
120 | return author.slice(0, pos).trim();
121 | }
122 | else {
123 | return author.trim();
124 | }
125 | }
126 | else {
127 | return (author.name || author.email || author.url || '-').trim();
128 | }
129 | }
130 |
131 | function getAuthorFull(author) {
132 | if (typeof author === 'string') {
133 | return author;
134 | }
135 | else {
136 | return [
137 | author.name,
138 | author.email && ('<' + author.email + '>'),
139 | author.url && ('(' + author.url + ')')
140 | ].filter(function (piece) {
141 | return piece;
142 | }).join(' ');
143 | }
144 | }
145 |
146 | function getMinSDKFromPackage(pkg) {
147 | if (pkg.engines && pkg.engines.titaniumsdk) {
148 | return getMinSDK(pkg.engines.titaniumsdk);
149 | }
150 | else {
151 | return DEFAULT_MIN_SDK;
152 | }
153 | }
154 |
155 | function getMinSDK(titaniumsdk) {
156 | var range;
157 |
158 | try {
159 | range = semver.Range(titaniumsdk);
160 | }
161 | catch (e) {
162 | throw new Error(
163 | "Invalid SDK version '" + titaniumsdk + "'. Did you include '.GA' or" +
164 | " similar?");
165 | }
166 |
167 | var gteVersions = [];
168 | var minsdk;
169 |
170 | range.set.forEach(function (set) {
171 | set.forEach(function (comp) {
172 | if (comp.operator === '>=') {
173 | gteVersions.push(comp.semver.format());
174 | }
175 | else if (comp.operator === '>') {
176 | throw new Error(
177 | "Invalid SDK version '" + titaniumsdk + "'. Only" +
178 | " equal-or-greater-then ranges are valid.");
179 | }
180 | else {
181 | // we skip these, because could be a byproduct of '1.0.*', which will
182 | // be parsed into [ '>= 1.0.0', '< 1.1.0' ]
183 | }
184 | });
185 | });
186 |
187 | if (gteVersions.length === 0) {
188 | throw new Error(
189 | "Invalid SDK version '" + titaniumsdk + "'. Use something in the form" +
190 | " '>= 3.4.0' or '3.4.*'.");
191 | }
192 | if (gteVersions.length > 1) {
193 | // we get only the lowest of all the ranges we get (this should be a
194 | // warning…)
195 | minsdk = gteVersions.sort(semver.compareLoose)[ 0 ];
196 | }
197 | else {
198 | minsdk = gteVersions[ 0 ];
199 | }
200 |
201 | // the build at the of the version is almost useless, .GA is the way to go
202 | // because if the user has an RC installed it will work anyway
203 | return minsdk + '.GA';
204 | }
205 |
206 | function licenseToString(license) {
207 | if (typeof license === 'string') {
208 | return license;
209 | }
210 | else if (typeof license === 'object') {
211 | return license.type;
212 | }
213 | else {
214 | return '-';
215 | }
216 | }
217 |
218 | function identity(o) {
219 | return o;
220 | }
221 |
--------------------------------------------------------------------------------
/lib/packer-build.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var fs = require('./util/fs');
4 | var manifest = require('./manifest');
5 | var pack = require('./packer-pack');
6 |
7 | var AdmZip = require('adm-zip');
8 | var Promise = require('bluebird');
9 | var path = require('path');
10 |
11 | var UNKNOWN_LICENSE = 'Unknown License';
12 |
13 | module.exports = build;
14 |
15 | function build(cfg) {
16 | return Promise.props(cfg)
17 | .then(function (cfg) {
18 |
19 | if (!cfg.entry) {
20 | throw new Error("No entry specified");
21 | }
22 |
23 | if (!cfg.package) {
24 | cfg.package = getPackage(cfg);
25 | }
26 |
27 | if (!cfg.manifest) {
28 | cfg.manifest = getManifest(cfg);
29 | }
30 |
31 | if (!cfg.license) {
32 | cfg.license = getLicense(cfg);
33 | }
34 |
35 | return Promise.props(cfg);
36 | })
37 | .then(function (cfg) {
38 |
39 | cfg.packed = pack(cfg.entry, cfg);
40 |
41 | return Promise.props(cfg);
42 | })
43 | .then(function (cfg) {
44 |
45 | var titaniumManifest = cfg.package.titaniumManifest || {};
46 |
47 | var moduleid = titaniumManifest.moduleid || cfg.package.name;
48 | var version = cfg.package.version + (cfg.noDependencies ? '-bare' : '');
49 | var pkg = cfg.package;
50 |
51 | cfg.bundlename = moduleid + '.js';
52 | cfg.zipname = (moduleid + '-commonjs-' + version + '.zip').toLowerCase();
53 | cfg.internalPath = 'modules/commonjs/' + moduleid + '/' + version;
54 |
55 | pkg._nativeDependencies = cfg.packed.nativeDependencies;
56 | pkg.main = cfg.bundlename;
57 |
58 | var zip = new AdmZip();
59 |
60 | zip.addLocalFolderToModule = addLocalFolderToModule.bind(null, zip, cfg);
61 | zip.addFileToModule = addFileToModule.bind(null, zip, cfg);
62 | zip.writeModule = writeModule.bind(null, zip, cfg);
63 | zip.writeBundle = writeBundle.bind(null, zip, cfg);
64 |
65 | zip.addFileToModule('/manifest', cfg.manifest);
66 | zip.addFileToModule('/package.json', JSON.stringify(cfg.package, null, 2));
67 | zip.addFileToModule('/' + cfg.bundlename, cfg.packed.source);
68 | zip.addFileToModule('/LICENSE', cfg.license);
69 |
70 | var directories = pkg.directories || {};
71 |
72 | var exampleDir = directories.example || 'example';
73 | var documentationDir = directories.documentation || 'documentation';
74 |
75 | exampleDir = path.resolve(cfg.entry, exampleDir);
76 | documentationDir = path.resolve(cfg.entry, documentationDir);
77 |
78 | return Promise.all([
79 | fs.isDirectory(exampleDir),
80 | fs.isDirectory(documentationDir)
81 | ]).spread(function (hasExample, hasDocumentation) {
82 | if (hasExample) {
83 | zip.addLocalFolderToModule(exampleDir, '/example');
84 | }
85 |
86 | if (hasDocumentation) {
87 | zip.addLocalFolderToModule(documentationDir, '/documentation');
88 | }
89 |
90 | return zip;
91 | });
92 | });
93 | }
94 |
95 | function addLocalFolderToModule(zip, cfg, localPath, zipPath) {
96 | zipPath = cfg.internalPath + zipPath;
97 | return zip.addLocalFolder(localPath, zipPath);
98 | }
99 |
100 | function addFileToModule(zip, cfg, filename, content, comment) {
101 | filename = cfg.internalPath + filename;
102 | content = Buffer.isBuffer(content) ? content : (new Buffer(content));
103 | return zip.addFile(filename, content, comment);
104 | }
105 |
106 | function writeBundle(zip, cfg, dir) {
107 | return fs.writeFile(
108 | path.resolve(dir, cfg.bundlename), cfg.packed.source, 'utf8');
109 | }
110 |
111 | function writeModule(zip, cfg, dir) {
112 | return fs.writeFile(path.resolve(dir, cfg.zipname), zip.toBuffer(), 'binary');
113 | }
114 |
115 | function getLicense(cfg) {
116 | return Promise.resolve(cfg.entry)
117 | .then(function (entry) {
118 | return fs.readFile(path.resolve(entry, 'LICENSE'), 'utf8');
119 | })
120 | .catch(isENOENT, function (err) {
121 | return UNKNOWN_LICENSE;
122 | });
123 | }
124 |
125 | function isENOENT(err) {
126 | return ((err.cause || err).code === 'ENOENT');
127 | }
128 |
129 | function getPackage(cfg) {
130 | return Promise.resolve(cfg.entry)
131 | .then(function (entry) {
132 | return fs.readFile(path.resolve(entry, 'package.json'), 'utf8');
133 | })
134 | .then(JSON.parse);
135 | }
136 |
137 | function getManifest(cfg) {
138 | return Promise.resolve(cfg.package)
139 | .then(manifest.validatePackage)
140 | .then(manifest.buildFromPackage);
141 | }
142 |
--------------------------------------------------------------------------------
/lib/packer-pack.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var Promise = require('bluebird');
4 | var browserify = require('browserify');
5 | var path = require('path');
6 | var titaniumResolve = require('titanium-resolve');
7 |
8 | var fs = require('./util/fs');
9 |
10 | var BUILTINS = require('./builtins');
11 | var GLOBAL_VARS = require('./globals');
12 | var PRELUDE_PATH = path.resolve(__dirname, 'util', '_prelude.js');
13 | var PRELUDE_SRC = require('fs').readFileSync(PRELUDE_PATH, 'utf8');
14 |
15 | var has = Object.prototype.hasOwnProperty;
16 |
17 | module.exports = pack;
18 | module.exports.getBundle = getBundle;
19 |
20 | function getPackage(entryfile) {
21 | return fs.isFile(entryfile).then(function (isFile) {
22 | if (isFile) return entryfile;
23 | else return path.resolve(entryfile, 'package.json');
24 | })
25 | .then(function (entry) {
26 | return fs
27 | .readFile(entry, 'utf8')
28 | .then(JSON.parse)
29 | .then(function (pkg) {
30 | return {
31 | path: entry,
32 | pkg: pkg
33 | };
34 | });
35 | });
36 | }
37 |
38 | function addDeps(to, deps) {
39 | if (Array.isArray(deps)) {
40 | deps.forEach(function (dep) {
41 | to.push(dep);
42 | });
43 | }
44 | else if (typeof deps === 'string') {
45 | to.push(deps);
46 | }
47 | else if (deps) {
48 | addDeps(to, Object.keys(deps));
49 | }
50 | }
51 |
52 | // cfg = {
53 | // noDependencies // do not pack dependencies with it
54 | // useTitaniumPlatformResolve // TODO
55 | // debug // build source maps
56 | // standalone //
57 | // exportRequire //
58 | // }
59 |
60 | function getBundle(entry, cfg) {
61 | return getPackage(entry).then(function (data) {
62 |
63 | var entry = path.dirname(data.path);
64 | var pkg = data.pkg;
65 | var titaniumManifest = pkg.titaniumManifest || {};
66 |
67 | var moduleid = titaniumManifest.moduleid || pkg.name;
68 |
69 | var opts = pkg.titaniumifier || pkg.npmifier || pkg.browserify || {};
70 |
71 | opts.extensions || (opts.extensions = [ '.js', '.json' ]);
72 | opts.transforms || (opts.transforms = []);
73 | opts.ignores || (opts.ignores = []);
74 | opts.externals || (opts.externals = []);
75 |
76 | var addExternals = addDeps.bind(null, opts.externals);
77 |
78 | addExternals(pkg.peerDependencies);
79 | addExternals(pkg.nativeDependencies);
80 |
81 | if (cfg.noDependencies) {
82 | addExternals(pkg.dependencies);
83 | addExternals(pkg.devDependencies);
84 | addExternals(pkg.optionalDependencies);
85 | }
86 |
87 | opts.ignoreMissing = !!opts.ignoreMissing;
88 |
89 | var b = browserify({
90 | basedir: entry,
91 | builtins: BUILTINS,
92 | debug: cfg.debug,
93 | extensions: opts.extensions,
94 | externalRequireName: cfg.exportRequire ? 'module.exports' : undefined,
95 | insertGlobalVars: GLOBAL_VARS,
96 | ignoreMissing: false,
97 | standalone: (cfg.standalone === false) ? undefined : moduleid,
98 | prelude: PRELUDE_SRC,
99 | preludePath: PRELUDE_PATH
100 | });
101 |
102 | b.plugin(fixResolver, {
103 | resolve: titaniumResolve
104 | });
105 |
106 | if (Array.isArray(opts.transforms)) {
107 | opts.transforms.forEach(function (transform) {
108 | b.transform(transform);
109 | });
110 | }
111 | else {
112 | Object.keys(opts.transforms).forEach(function (transform) {
113 | b.transform(transform, opts.transforms[ transform ]);
114 | });
115 | }
116 |
117 | opts.ignores.forEach(function (ignore) {
118 | b.ignore(ignore);
119 | });
120 |
121 | opts.externals.forEach(function (external) {
122 | b.exclude(external);
123 | });
124 |
125 | if (cfg.useTitaniumPlatformResolve) {
126 | TODO;
127 | /*b.transform(titaniumPlatformResolve.createTransform({
128 | platforms: [ build.platformName ],
129 | extensions: opts.extensions
130 | }));*/
131 | }
132 |
133 | return {
134 | entry: entry,
135 | pkg: pkg,
136 | opts: opts,
137 | bundle: b
138 | };
139 | });
140 | }
141 |
142 | function pack(entry, cfg, callback) {
143 | cfg || (cfg = {});
144 | var promise = getBundle(entry, cfg).then(function (data) {
145 |
146 | var entry = data.entry;
147 | var pkg = data.pkg;
148 | var b = data.bundle;
149 | var opts = data.opts;
150 |
151 | var entrypoint = path.resolve(entry, pkg.main || 'index.js');
152 |
153 | var passedPackages = {};
154 | var nativeDependencies = clone(pkg.nativeDependencies);
155 |
156 | b.on('package', function (pkg) {
157 | // consider only interesting packages
158 | if (!pkg.nativeDependencies) return;
159 | // pass only once per package
160 | if (has.call(passedPackages, pkg.__dirname)) return;
161 | passedPackages[ pkg.__dirname ] = true;
162 | // merge dependencies
163 | Object.keys(pkg.nativeDependencies).forEach(function (key) {
164 | // TODO better error/collision check
165 | if (has.call(nativeDependencies, key)) return;
166 | nativeDependencies[ key ] = pkg.nativeDependencies[ key ];
167 | });
168 | });
169 |
170 | return new Promise(function (resolve, reject) {
171 | titaniumResolve(entrypoint, {
172 | paths: b._mdeps.paths,
173 | modules: b._mdeps.options.modules,
174 | filename: path.resolve(entry, 'package.json'),
175 | extensions: opts.extensions
176 | }, function (err, result) {
177 | if (err) return reject(err);
178 |
179 | b.add(result);
180 |
181 | b.bundle(function (err, result) {
182 | if (err) return reject(err);
183 | resolve(result);
184 | });
185 | });
186 | })
187 | .then(function (result) {
188 | return {
189 | source: result,
190 | nativeDependencies: nativeDependencies
191 | };
192 | });
193 | });
194 |
195 | if (callback) {
196 | promise.done(callback.bind(null, null), callback.bind(null));
197 | }
198 |
199 | return promise;
200 | }
201 |
202 | function clone(obj) {
203 | return (obj == null) ? {} : Object.keys(obj).reduce(function (memo, key) {
204 | memo[ key ] = obj[ key ];
205 | return memo;
206 | }, {});
207 | }
208 |
209 | function fixResolver(b, opts) {
210 | b._mdeps.resolver = (opts.resolve || b._mdeps.resolver);
211 | }
212 |
--------------------------------------------------------------------------------
/lib/packer.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | exports.pack = require('./packer-pack');
4 | exports.build = require('./packer-build');
5 |
--------------------------------------------------------------------------------
/lib/scripts/prepublish.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var uglify = require('uglify-js');
4 | var fs = require('fs');
5 | var path = require('path');
6 |
7 | var src = fs.readFileSync(path.resolve(__dirname, '..', 'util', 'prelude.js'), 'utf8');
8 | fs.writeFileSync(path.resolve(__dirname, '..', 'util', '_prelude.js'), uglify(src));
9 |
--------------------------------------------------------------------------------
/lib/titaniumifier.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | exports.manifest = require('./manifest');
4 | exports.packer = require('./packer');
5 |
--------------------------------------------------------------------------------
/lib/util/fs.js:
--------------------------------------------------------------------------------
1 |
2 | var Promise = require('bluebird');
3 | var fs = require('fs');
4 | var mkdirp = require('mkdirp');
5 | var path = require('path');
6 | var rimraf = require('rimraf');
7 |
8 | var slice = Array.prototype.slice;
9 |
10 | function lift(from, name) {
11 | exports[ name ] = Promise.promisify(from[ name ], from);
12 | }
13 |
14 | lift(fs, 'readFile');
15 | lift(fs, 'writeFile');
16 | lift(fs, 'stat');
17 | lift(fs, 'rename');
18 | lift(fs, 'readdir');
19 |
20 | exports.rimraf = Promise.promisify(rimraf);
21 |
22 | exports.mkdirp = Promise.promisify(mkdirp);
23 |
24 | exports.mv = exports.rename;
25 |
26 | exports.isFile = Promise.promisify(function (file, cb) {
27 | fs.stat(file, function (err, stat) {
28 | if (err && err.code === 'ENOENT') cb(null, false);
29 | else if (err) cb(err);
30 | else cb(null, stat.isFile() || stat.isFIFO());
31 | });
32 | });
33 |
34 | exports.isDirectory = Promise.promisify(function (file, cb) {
35 | fs.stat(file, function (err, stat) {
36 | if (err && err.code === 'ENOENT') cb(null, false);
37 | else if (err) cb(err);
38 | else cb(null, stat.isDirectory());
39 | });
40 | });
41 |
--------------------------------------------------------------------------------
/lib/util/prelude.js:
--------------------------------------------------------------------------------
1 |
2 | /* jshint asi:true */
3 |
4 | // modules are defined as an array
5 | // [ module function, map of requireuires ]
6 | //
7 | // map of requireuires is short require name -> numeric require
8 | //
9 | // anything defined in a previous bundle is accessed via the
10 | // orig method which is the requireuire for previous bundles
11 |
12 | (function outer (modules, cache, entry) {
13 |
14 | var slice = Array.prototype.slice;
15 |
16 | if (!Function.prototype.bind) {
17 | Object.defineProperty(Function.prototype, 'bind', {
18 | enumerable: false,
19 | configurable: true,
20 | writable: true,
21 | value: function (ctx) {
22 | if (typeof this !== "function") {
23 | // closest thing possible to the ECMAScript 5 internal IsCallable function
24 | throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
25 | }
26 |
27 | var fn = this;
28 | var args = slice.call(arguments, 1);
29 |
30 | function binded() {
31 | return fn.apply((this instanceof binded && ctx) ? this : ctx, args.concat(slice.call(arguments)));
32 | }
33 |
34 | binded.prototype = Object.create(fn.prototype);
35 | binded.prototype.contructor = binded;
36 |
37 | return binded;
38 | }
39 | });
40 | }
41 |
42 | // Save the require from previous bundle to this closure if any
43 | var previousRequire = typeof require == "function" && require;
44 |
45 | function newRequire(name, jumped){
46 | if(!cache[name]) {
47 | if(!modules[name]) {
48 | // if we cannot find the the module within our internal map or
49 | // cache jump to the current global require ie. the last bundle
50 | // that was added to the page.
51 | var currentRequire = typeof require == "function" && require;
52 | if (!jumped && currentRequire) {
53 | if (currentRequire.length === 2) {
54 | return currentRequire(name, true);
55 | }
56 | else {
57 | return currentRequire(name);
58 | }
59 | }
60 |
61 | // If there are other bundles on this page the require from the
62 | // previous one is saved to 'previousRequire'. Repeat this as
63 | // many times as there are bundles until the module is found or
64 | // we exhaust the require chain.
65 | if (previousRequire && previousRequire.length === 2) {
66 | return previousRequire(name, true);
67 | }
68 | else if (previousRequire) {
69 | return previousRequire(name);
70 | }
71 | var err = new Error('Cannot find module \'' + name + '\'');
72 | err.code = 'MODULE_NOT_FOUND';
73 | throw err;
74 | }
75 | var m = cache[name] = {exports:{}};
76 | modules[name][0].call(m.exports, function(x){
77 | var id = modules[name][1][x];
78 | return newRequire(id ? id : x);
79 | },m,m.exports,outer,modules,cache,entry);
80 | }
81 | return cache[name].exports;
82 | }
83 | for(var i=0;i
2 |
3 |
4 |
98 |
--------------------------------------------------------------------------------
/manifest.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./lib/manifest');
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "titaniumifier",
3 | "version": "1.5.2",
4 | "description": "Get a Titanium SDK CommonJS module out of a Node package!",
5 | "author": {
6 | "name": "Pier Paolo Ramon",
7 | "email": "pierpaolo.ramon@smc.it",
8 | "url": "https://github.com/yuchi"
9 | },
10 | "license": "LGPL2.1",
11 | "repository": {
12 | "type": "git",
13 | "url": "https://github.com/smclab/titaniumifier.git"
14 | },
15 | "main": "index.js",
16 | "directories": {
17 | "test": "./test",
18 | "lib": "./lib",
19 | "bin": "./bin"
20 | },
21 | "scripts": {
22 | "test": "grunt test",
23 | "prepublish": "node lib/scripts/prepublish.js"
24 | },
25 | "keywords": [
26 | "titanium",
27 | "mobile",
28 | "browserify",
29 | "static",
30 | "analysis"
31 | ],
32 | "dependencies": {
33 | "adm-zip": "0.5.9",
34 | "bluebird": "^2.5.1",
35 | "browserify": "^11.0.1",
36 | "commander": "^2.5.1",
37 | "guid": "0.0.12",
38 | "log-symbols": "^1.0.1",
39 | "mkdirp": "^0.5.0",
40 | "rimraf": "^2.2.8",
41 | "semver": "^5.0.1",
42 | "ti-console": "^0.1.4",
43 | "ti-fs": "^0.1.1",
44 | "tiapp.xml": "^0.2.2",
45 | "titanium-os": "^0.1.1",
46 | "titanium-resolve": "^0.4.0",
47 | "touch": "^1.0.0",
48 | "update-notifier": "^0.5.0",
49 | "vm-titanium": "0.0.1"
50 | },
51 | "devDependencies": {
52 | "grunt": "^0.4.2",
53 | "grunt-cli": "^0.1.13",
54 | "grunt-contrib-clean": "^0.6.0",
55 | "grunt-contrib-jshint": "^0.11.2",
56 | "grunt-mocha-test": "^0.12.4",
57 | "grunt-titanium": "^0.3.1",
58 | "grunt-zip": "^0.17.0",
59 | "longjohn": "^0.2.4",
60 | "mocha": "^1.20.0",
61 | "moment": "^2.5.1",
62 | "reduce": "^1.0.1",
63 | "reduce-component": "^1.0.1",
64 | "should": "^7.0.2",
65 | "ti-mocha": "^0.2.0",
66 | "uglify-js": "^1.3.5"
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/packer.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./lib/packer');
--------------------------------------------------------------------------------
/plugin/1.0.0/hook.js:
--------------------------------------------------------------------------------
1 |
2 | exports.cliVersion = '>= 3.4.0';
3 |
4 | exports.init = function babel$init(logger, config, cli, nodeappc) {
5 |
6 | var fs = require('fs');
7 | var path = require('path');
8 | var touch = require("touch");
9 | var mkdirp = require('mkdirp');
10 |
11 | var packer = require('../../packer');
12 |
13 | var has = Object.prototype.hasOwnProperty;
14 |
15 | var APP_CONTENT = 'require("bundled_dependencies")("app_js")';
16 | var PREFIX = "[titaniumifier] ".grey;
17 |
18 | var resolved = {};
19 | var resolvedIds = {};
20 |
21 | var jsanalyze;
22 |
23 | function getId(ctx, filename) {
24 | var resourcesDir = path.resolve(ctx.projectDir, 'Resources');
25 | var id = path.relative(resourcesDir, filename);
26 |
27 | return id.replace(/[\.\/]/g, '_');
28 | }
29 |
30 | function getConsumer(id) {
31 | return 'require("bundled_dependencies")(' + JSON.stringify(id) + ')';
32 | }
33 |
34 | cli.on('build.pre.compile', {
35 | pre: function titaniumifier$compile$pre(data, callback) {
36 |
37 | var ctx = data;
38 |
39 | var platform = ctx.platformName;
40 |
41 | if (platform === 'iphone' || platform === 'ipad') {
42 | platform = 'ios';
43 | }
44 |
45 | ctx.titaniumifierDir = path.resolve(ctx.projectDir, 'build', 'titaniumifier');
46 | ctx.titaniumifierBuildDir = path.resolve(ctx.titaniumifierDir, platform);
47 |
48 | ctx.swallowFrom = path.resolve(ctx.titaniumifierDir, '.swallowFrom');
49 | ctx.swallowTo = path.resolve(ctx.titaniumifierDir, '.swallowTo');
50 |
51 | ctx.titaniumifierAppFilename = path.resolve(ctx.titaniumifierDir, 'app.js');
52 | ctx.titaniumifierMain = path.resolve(ctx.projectDir, 'Resources', 'app.js');
53 |
54 | ctx.bundleLocation = path.resolve(ctx.projectDir, 'Resources', platform, 'bundled_dependencies.js');
55 |
56 | mkdirp.sync(ctx.titaniumifierBuildDir);
57 | mkdirp.sync(path.dirname(ctx.swallowFrom));
58 | touch.sync(ctx.swallowFrom);
59 |
60 | logger.trace(PREFIX + "Do we need to encrypt? (%s)", String(ctx.encryptJS ? 'yes' : 'no').cyan);
61 |
62 | /*if (platform === 'ios') {
63 | ctx.finalBundleLocation = (
64 | ctx.encryptJS ?
65 | path.resolve(ctx.buildAssetsDir, 'bundled_dependencies') :
66 | path.resolve(ctx.xcodeAppDir, 'bundled_dependencies.js')
67 | );
68 |
69 | if (ctx.encryptJS) {
70 | mkdirp.sync(ctx.xcodeAppDir);
71 | }
72 | }
73 | else if (platform === 'android') {
74 | TODO;
75 | }
76 | else {
77 | TODO;
78 | }*/
79 |
80 | packer.pack.getBundle(ctx.projectDir, {
81 | standalone: false,
82 | exportRequire: true,
83 | basedir: ctx.projectDir
84 | }).then(function (data) {
85 | var pkg = data.pkg;
86 | var b = data.bundle;
87 |
88 | // TODO package.files is a terribly wrong idea!
89 | var filesOriginal = (pkg.files || [ pkg.main || 'Resources/app.js' ]);
90 |
91 | var files = filesOriginal.map(function (f) {
92 | var file = path.resolve(ctx.projectDir, f);
93 | var id = getId(ctx, file);
94 | var consumer = path.resolve(ctx.titaniumifierBuildDir, id);
95 | var consumerSource = getConsumer(id);
96 |
97 | logger.debug(PREFIX + "Writing: %s", String(id).cyan);
98 | logger.trace(PREFIX + "File location: %s", String(consumer).cyan);
99 |
100 | resolvedIds[ file ] = consumer;
101 |
102 | mkdirp.sync(path.dirname(consumer));
103 | fs.writeFileSync(consumer, consumerSource);
104 |
105 | return {
106 | id: id,
107 | file: file,
108 | consumer: consumer,
109 | consumerSource: consumerSource
110 | };
111 | });
112 |
113 | (ctx.tiapp.modules || []).forEach(function (nativeModule) {
114 | logger.debug(PREFIX + "Module %s is considered external", nativeModule.id.cyan);
115 |
116 | b.external(nativeModule.id);
117 | });
118 |
119 | b.pipeline.get('deps').on('data', function (data) {
120 | resolved[ data.file ] = data.entry;
121 | });
122 |
123 | b.require(files.map(function (row) {
124 | return {
125 | file: row.file,
126 | entry: false,
127 | expose: row.id
128 | };
129 | }));
130 |
131 | b.bundle(function (err, result) {
132 | err && logger.error(err);
133 | if (err) return callback(err);
134 |
135 | mkdirp.sync(path.dirname(ctx.bundleLocation));
136 |
137 | fs.writeFile(ctx.bundleLocation, result, function (err) {;
138 | err && logger.error(err);
139 | callback(err);
140 | });
141 | });
142 | })
143 | .catch(function (err) {
144 | callback(err);
145 | });
146 |
147 | /*jsanalyze = require(ctx.titaniumSdkPath + '/node_modules/titanium-sdk/lib/jsanalyze');
148 | // use it this way:
149 | // jsanalyze.analyzeJsFile(data.file, { minify: ctx.minifyJS });*/
150 | }
151 | });
152 |
153 | cli.on('build.ios.copyResource', {
154 | pre: titaniumifier$copyResource$pre
155 | });
156 |
157 | cli.on('build.android.copyResource', {
158 | pre: titaniumifier$copyResource$pre
159 | });
160 |
161 | function titaniumifier$copyResource$pre(data, callback) {
162 | var args = data.args;
163 |
164 | var jsFilesToEncrypt = this.jsFilesToEncrypt;
165 |
166 | var from = args[0];
167 | var to = args[1];
168 |
169 | var ctx = data.ctx;
170 | var ext = path.extname(from);
171 |
172 | var fromResources = path.relative(path.resolve(ctx.projectDir, 'Resources'), from);
173 |
174 | var isFromResources = (fromResources.charAt(0) !== '.');
175 |
176 | if (has.call(resolvedIds, from)) {
177 | logger.info(PREFIX + "Replacing %s", from.cyan);
178 |
179 | data.args[0] = resolvedIds[ from ];
180 | }
181 | else if (!isFromResources || (from === ctx.bundleLocation)) {
182 | // do nothing if it’s the bundle or if it’s a module
183 | }
184 | else if (has.call(resolved, from) && !resolved[ from ]) {
185 | logger.debug(PREFIX + "Swallowing %s", from.cyan);
186 |
187 | data.args[0] = ctx.swallowFrom;
188 | }
189 | else if (ext === '.js') {
190 | logger.warn(PREFIX + "File %s is lost", from.cyan);
191 |
192 | data.args[0] = ctx.swallowFrom;
193 | }
194 |
195 | this.jsFilesToEncrypt = jsFilesToEncrypt;
196 |
197 | callback(null);
198 | }
199 |
200 | };
201 |
--------------------------------------------------------------------------------
/test/manifest/expected/manifest.01:
--------------------------------------------------------------------------------
1 | version: 1.2.3
2 | description: Lorem ipsum (dolor) amet
3 | author: John Appleseed (http://appleseed.it)
4 | license: BSD-2-Clause
5 | copyright: Copyright © $YEAR$ John Appleseed
6 | name: example
7 | moduleid: example
8 | guid: 005f7d23-04d8-4d49-8c16-66694408e4b9
9 | platform: commonjs
10 | minsdk: 3.2.0.GA
--------------------------------------------------------------------------------
/test/manifest/expected/manifest.02:
--------------------------------------------------------------------------------
1 | version: 1.2.3
2 | description: Lorem ipsum (dolor) amet
3 | author: John Appleseed (http://appleseed.it)
4 | license: BSD-2-Clause, MIT
5 | copyright: some random © stuff (c) here
6 | name: example
7 | moduleid: example
8 | guid: 005f7d23-04d8-4d49-8c16-66694408e4b9
9 | platform: commonjs
10 | minsdk: 3.2.0.GA
--------------------------------------------------------------------------------
/test/manifest/expected/manifest.03:
--------------------------------------------------------------------------------
1 | version: 1.2.3
2 | description: Lorem ipsum (dolor) amet
3 | author: John Appleseed (http://appleseed.it)
4 | license: BSD-2-Clause, MIT
5 | copyright: Copyright © $YEAR$ John Appleseed
6 | name: example
7 | moduleid: example
8 | guid: 005f7d23-04d8-4d49-8c16-66694408e4b9
9 | platform: commonjs
10 | minsdk: 3.2.0.GA
--------------------------------------------------------------------------------
/test/manifest/expected/manifest.04:
--------------------------------------------------------------------------------
1 | version: 1.2.3
2 | description: Lorem ipsum (dolor) amet
3 | author: John Appleseed
4 | license: BSD-2-Clause
5 | copyright: Copyright © $YEAR$ John Appleseed
6 | name: example
7 | moduleid: example
8 | guid: 005f7d23-04d8-4d49-8c16-66694408e4b9
9 | platform: commonjs
10 | minsdk: 3.2.0.GA
--------------------------------------------------------------------------------
/test/manifest/expected/manifest.05:
--------------------------------------------------------------------------------
1 | version: 1.2.3
2 | description: Lorem ipsum (dolor) amet
3 | author: John Appleseed
4 | license: BSD-2-Clause
5 | copyright: Copyright © $YEAR$ John Appleseed
6 | name: example
7 | moduleid: example
8 | guid: 005f7d23-04d8-4d49-8c16-66694408e4b9
9 | platform: commonjs
10 | minsdk: 3.2.0.GA
11 |
--------------------------------------------------------------------------------
/test/manifest/expected/manifest.06:
--------------------------------------------------------------------------------
1 | version: 1.2.3
2 | description: Lorem ipsum (dolor) amet
3 | author: John Appleseed
4 | license: BSD-2-Clause
5 | copyright: Copyright © $YEAR$ John Appleseed
6 | name: my-example
7 | moduleid: example
8 | guid: 005f7d23-04d8-4d49-8c16-66694408e4b9
9 | platform: commonjs
10 | minsdk: 3.2.0.GA
11 |
--------------------------------------------------------------------------------
/test/manifest/expected/manifest.07:
--------------------------------------------------------------------------------
1 | version: 1.2.3
2 | description: Lorem ipsum (dolor) amet
3 | author: John Appleseed
4 | license: BSD-2-Clause
5 | copyright: Copyright © $YEAR$ John Appleseed
6 | name: example
7 | moduleid: it.smc.example
8 | guid: 005f7d23-04d8-4d49-8c16-66694408e4b9
9 | platform: commonjs
10 | minsdk: 3.2.0.GA
11 |
--------------------------------------------------------------------------------
/test/manifest/expected/manifest.08:
--------------------------------------------------------------------------------
1 | version: 1.2.3
2 | description: Lorem ipsum (dolor) amet
3 | author: John Appleseed
4 | license: BSD-2-Clause
5 | copyright: Copyright © $YEAR$ John Appleseed
6 | name: my-example
7 | moduleid: it.smc.example
8 | guid: 005f7d23-04d8-4d49-8c16-66694408e4b9
9 | platform: commonjs
10 | minsdk: 3.2.0.GA
11 |
--------------------------------------------------------------------------------
/test/manifest/expected/manifest.09:
--------------------------------------------------------------------------------
1 | version: 1.2.3
2 | description: Lorem ipsum (dolor) amet
3 | author: John Appleseed
4 | license: BSD-2-Clause
5 | copyright: Copyright © $YEAR$ John Appleseed
6 | name: example
7 | moduleid: example
8 | guid: 005f7d23-04d8-4d49-8c16-66694408e4b9
9 | platform: commonjs
10 | minsdk: 3.4.1.GA
11 |
--------------------------------------------------------------------------------
/test/manifest/expected/manifest.10:
--------------------------------------------------------------------------------
1 | version: 1.2.3
2 | description: Lorem ipsum (dolor) amet
3 | author: John Appleseed
4 | license: BSD-2-Clause
5 | copyright: Copyright © $YEAR$ John Appleseed
6 | name: example
7 | moduleid: example
8 | guid: 005f7d23-04d8-4d49-8c16-66694408e4b9
9 | platform: commonjs
10 | minsdk: 3.4.0.GA
11 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.01.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
4 | "version": "1.2.3",
5 | "description": "Lorem ipsum (dolor) amet",
6 | "main": "index.js",
7 | "author": "John Appleseed (http://appleseed.it)",
8 | "license": "BSD-2-Clause"
9 | }
10 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.02.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
4 | "copyright": "some random © stuff (c) here",
5 | "version": "1.2.3",
6 | "description": "Lorem ipsum (dolor) amet",
7 | "main": "index.js",
8 | "author": {
9 | "name": "John Appleseed",
10 | "email": "john@appleseed.it",
11 | "url": "http://appleseed.it"
12 | },
13 | "licenses": [
14 | "BSD-2-Clause",
15 | "MIT"
16 | ]
17 | }
18 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.03.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
4 | "version": "1.2.3",
5 | "description": "Lorem ipsum (dolor) amet",
6 | "main": "index.js",
7 | "author": {
8 | "name": "John Appleseed",
9 | "email": "john@appleseed.it",
10 | "url": "http://appleseed.it"
11 | },
12 | "licenses": [
13 | "BSD-2-Clause",
14 | "MIT"
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.04.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
4 | "version": "1.2.3",
5 | "description": "Lorem ipsum (dolor) amet",
6 | "main": "index.js",
7 | "author": "John Appleseed",
8 | "license": "BSD-2-Clause"
9 | }
10 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.05.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "guid": "wrong",
4 | "titaniumManifest": {
5 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9"
6 | },
7 | "version": "1.2.3",
8 | "description": "Lorem ipsum (dolor) amet",
9 | "main": "index.js",
10 | "author": "John Appleseed",
11 | "license": "BSD-2-Clause"
12 | }
13 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.06.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
4 | "titaniumManifest": {
5 | "name": "my-example"
6 | },
7 | "version": "1.2.3",
8 | "description": "Lorem ipsum (dolor) amet",
9 | "main": "index.js",
10 | "author": "John Appleseed",
11 | "license": "BSD-2-Clause"
12 | }
13 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.07.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
4 | "titaniumManifest": {
5 | "moduleid": "it.smc.example"
6 | },
7 | "version": "1.2.3",
8 | "description": "Lorem ipsum (dolor) amet",
9 | "main": "index.js",
10 | "author": "John Appleseed",
11 | "license": "BSD-2-Clause"
12 | }
13 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.08.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "titaniumManifest": {
4 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
5 | "name": "my-example",
6 | "moduleid": "it.smc.example"
7 | },
8 | "version": "1.2.3",
9 | "description": "Lorem ipsum (dolor) amet",
10 | "main": "index.js",
11 | "author": "John Appleseed",
12 | "license": "BSD-2-Clause"
13 | }
14 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.09.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
4 | "version": "1.2.3",
5 | "description": "Lorem ipsum (dolor) amet",
6 | "main": "index.js",
7 | "author": "John Appleseed",
8 | "license": "BSD-2-Clause",
9 | "engines": {
10 | "node": "*",
11 | "titaniumsdk": ">= 3.4.1"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.10.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
4 | "version": "1.2.3",
5 | "description": "Lorem ipsum (dolor) amet",
6 | "main": "index.js",
7 | "author": "John Appleseed",
8 | "license": "BSD-2-Clause",
9 | "engines": {
10 | "titaniumsdk": "3.4.*"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.INVALID.1.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "version": "1.2.3",
4 | "description": "Lorem ipsum (dolor) amet",
5 | "main": "index.js",
6 | "author": "John Appleseed (http://appleseed.it)",
7 | "license": "BSD-2-Clause"
8 | }
9 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.INVALID.2.json:
--------------------------------------------------------------------------------
1 | {
2 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
3 | "version": "1.2.3",
4 | "description": "Lorem ipsum (dolor) amet",
5 | "main": "index.js",
6 | "author": "John Appleseed (http://appleseed.it)",
7 | "license": "BSD-2-Clause"
8 | }
9 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.INVALID.3.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "version": "1.2.3",
4 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
5 | "engines": {
6 | "titaniumsdk": ">= 3.4.1.GA"
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.INVALID.4.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "version": "1.2.3",
4 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
5 | "engines": {
6 | "titaniumsdk": "> 3.4.1"
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/test/manifest/fixtures/package.INVALID.5.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "version": "1.2.3",
4 | "guid": "005f7d23-04d8-4d49-8c16-66694408e4b9",
5 | "engines": {
6 | "titaniumsdk": "3.4.1"
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/test/manifest/index.js:
--------------------------------------------------------------------------------
1 |
2 | var manifest = require('../../manifest');
3 |
4 | var should = require('should');
5 |
6 | var path = require('path');
7 | var fs = require('fs');
8 |
9 | describe("Cases:", function () {
10 | var fixturesDir = path.resolve(__dirname, 'fixtures');
11 |
12 | fs.readdirSync(fixturesDir).forEach(function (filename) {
13 | var fullname = path.resolve(fixturesDir, filename);
14 | var invalidPackage = filename.indexOf('INVALID') >= 0;
15 |
16 | it(filename, function () {
17 | var pkg = JSON.parse(fs.readFileSync(fullname, 'utf8'));
18 |
19 | // Validation
20 |
21 | if (invalidPackage) {
22 | validate.should.throw();
23 | return;
24 | }
25 | else {
26 | validate();
27 | }
28 |
29 | // Building
30 |
31 | build(filename, fullname, pkg);
32 |
33 | function validate() {
34 | manifest.validatePackage(pkg);
35 | }
36 | });
37 | });
38 | });
39 |
40 | function build(filename, fullname, pkg) {
41 | var expectedFilename = fullname
42 | .replace('fixtures', 'expected')
43 | .replace('package', 'manifest')
44 | .replace('.json', '');
45 |
46 | var result = manifest.buildFromPackage(pkg).trim();
47 |
48 | var expected = fs.readFileSync(expectedFilename, 'utf8')
49 | .trim()
50 | .replace('$YEAR$', new Date().getFullYear());
51 |
52 | var resultLines = result.split('\n');
53 | var expectedLines = expected.split('\n');
54 |
55 | resultLines.forEach(function (line, i) {
56 | line.should.be.eql(expectedLines[i]);
57 | });
58 | }
59 |
--------------------------------------------------------------------------------
/test/packer/fake-module-1/index-titanium.js:
--------------------------------------------------------------------------------
1 |
2 | require('should');
3 |
4 | function test(msg, fn) {
5 | try {
6 | fn.call(this);
7 | console.log("[OK] " + msg);
8 | }
9 | catch (e) {
10 | console.error("[NOT-OK] " + msg);
11 | throw e;
12 | }
13 | }
14 |
15 | test("Renamed module", function () {
16 | require('reduce')([ 1, 2, 3 ], function (a, b) {
17 | return a + b;
18 | }, 0).should.be.equal(6);
19 | });
20 |
21 | test("Some console tests", function () {
22 | console.should.have.a.property('log');
23 | console.should.have.a.property('warn');
24 | console.should.have.a.property('error');
25 | console.should.have.a.property('trace');
26 | console.should.have.a.property('assert');
27 | });
28 |
29 | test("Some global tests", function () {
30 | require('./setup-global-var.js');
31 |
32 | (typeof globalVar).should.not.be.equal('undefined');
33 | });
34 |
35 | test("Console tests", function () {
36 | console.log("You should see this message and an inspection...");
37 | console.dir({ answer: 42 });
38 | });
39 |
40 | test("Moment and similar", function () {
41 | var moment = require('moment');
42 | moment.lang(require('moment/lang/it'));
43 |
44 | var dayOfTheEpoch = moment(0).format('dddd');
45 |
46 | console.log("In italy the day of the epoch is called %s", dayOfTheEpoch);
47 |
48 | dayOfTheEpoch.toLowerCase().should.be.equal('giovedì');
49 | });
--------------------------------------------------------------------------------
/test/packer/fake-module-1/index.js:
--------------------------------------------------------------------------------
1 |
2 | require('should');
3 |
4 | throw new Error("Should NEVER call the package.main when there's a titanium prop");
5 |
--------------------------------------------------------------------------------
/test/packer/fake-module-1/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fake-module-1",
3 | "guid": "b91da39e-e3e3-f75a-ff4a-cc2d29b31bff",
4 | "private": true,
5 | "version": "1.2.3",
6 | "description": "Hallo",
7 | "main": "index.js",
8 | "author": "",
9 | "license": "BSD-2-Clause",
10 | "dependencies": {
11 | "reduce-component": "~1.0.1",
12 | "should": "~3.1.2"
13 | },
14 | "titanium": {
15 | "useBrowser": true,
16 | "index.js": "./index-titanium.js",
17 | "reduce": "reduce-component"
18 | },
19 | "devDependencies": {
20 | "moment": "~2.5.1"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test/packer/fake-module-1/setup-global-var.js:
--------------------------------------------------------------------------------
1 |
2 | global.globalVar = 42;
3 |
--------------------------------------------------------------------------------
/test/packer/fake-module-2/index-titanium.js:
--------------------------------------------------------------------------------
1 |
2 | require('should');
3 |
4 | function test(msg, fn) {
5 | try {
6 | fn.call(this);
7 | console.log("[OK] " + msg);
8 | }
9 | catch (e) {
10 | console.error("[NOT-OK] " + msg);
11 | throw e;
12 | }
13 | }
14 |
15 | var answer = 42;
16 |
17 | test("Testing 'os'", function () {
18 | require('os').arch().should.be.equal('fake42');
19 | });
20 |
21 | test("Smoke test", function () {
22 | (answer).should.be.equal(answer);
23 | });
24 |
--------------------------------------------------------------------------------
/test/packer/fake-module-2/index.js:
--------------------------------------------------------------------------------
1 |
2 | require('should');
3 |
4 | throw new Error("Should NEVER call the package.main when there's a titanium prop");
5 |
--------------------------------------------------------------------------------
/test/packer/fake-module-2/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fake-module-2",
3 | "titaniumManifest": {
4 | "guid": "b91da39e-e3e3-f75a-ff4a-cc2d29b31bff",
5 | "moduleid": "fake-name"
6 | },
7 | "private": true,
8 | "version": "1.2.3",
9 | "description": "Hallo",
10 | "main": "index.js",
11 | "author": "",
12 | "license": "BSD-2-Clause",
13 | "dependencies": {
14 | "should": "~3.1.2"
15 | },
16 | "titanium": {
17 | "useBrowser": true,
18 | "index.js": "./index-titanium.js"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test/packer/index.js:
--------------------------------------------------------------------------------
1 |
2 | require('should');
3 | require('longjohn');
4 |
5 | var AdmZip = require('adm-zip');
6 |
7 | var vm = require('vm');
8 | var path = require('path');
9 | var packer = require('../../packer');
10 | var fs = require('../../lib/util/fs');
11 |
12 | var buildDir = path.resolve(__dirname, 'build');
13 |
14 | var Titanium = {
15 | Platform: {
16 | architecture: 'fake42'
17 | },
18 | API: {
19 | log: console.log.bind(console),
20 | info: console.log.bind(console),
21 | error: console.error.bind(console),
22 | warn: console.warn.bind(console),
23 | trace: console.trace.bind(console)
24 | }
25 | };
26 |
27 | before(function () {
28 | return fs.rimraf(buildDir).then(function () {
29 | return fs.mkdirp(buildDir);
30 | });
31 | });
32 |
33 | describe("Building", function () {
34 |
35 | it("should work", function () {
36 | this.timeout(20e3);
37 |
38 | return packer.build({
39 | entry: path.resolve(__dirname, 'module-1')
40 | })
41 | .tap(function (zip) {
42 | return zip.writeModule(buildDir);
43 | })
44 | .tap(function (zip) {
45 | return zip.writeBundle(buildDir);
46 | });
47 | });
48 |
49 | it("should create the right zip", function () {
50 | return assertIsFile(path.resolve(buildDir, 'module-1-commonjs-0.1.2.zip'));
51 | });
52 |
53 | it("should extract the bundle", function () {
54 | return assertIsFile(path.resolve(buildDir, 'module-1.js'));
55 | });
56 |
57 | it("should write lower case zipfiles", function () {
58 | return packer.build({
59 | entry: path.resolve(__dirname, 'module-2')
60 | })
61 | .then(function (zip) {
62 | return zip.writeModule(buildDir);
63 | })
64 | .then(function () {
65 | return assertIsFile(path.resolve(
66 | buildDir, 'fake-upper-case-name-commonjs-0.1.2.zip'));
67 | });
68 | });
69 |
70 | it("should bundle the collateral folders", function () {
71 | var zip = new AdmZip(path.resolve(
72 | buildDir, 'module-1-commonjs-0.1.2.zip'));
73 |
74 | zip.getEntry('modules/commonjs/module-1/0.1.2/example/app.js')
75 | .name.should.eql('app.js');
76 |
77 | zip.getEntry('modules/commonjs/module-1/0.1.2/documentation/index.md')
78 | .name.should.eql('index.md');
79 | });
80 |
81 | });
82 |
83 | describe("Bundling", function () {
84 | var entry = path.resolve(__dirname, 'module-1');
85 | var packedFile = path.resolve(buildDir, 'module-1.js');
86 |
87 | var promise = packer.pack(entry, {
88 | // no config
89 | });
90 |
91 | it("should work", function () {
92 | return promise.then(function (packed) {
93 | return fs.writeFile(packedFile, packed.source);
94 | });
95 | });
96 |
97 | it("should have merged native deps", function () {
98 | return promise.then(function (packed) {
99 | packed.should.have.a.property('nativeDependencies').eql({
100 | 'a.native.dep': '*',
101 | 'another.native.dep': '*'
102 | });
103 | });
104 | });
105 |
106 | it("shouldn’t leak our paths", function () {
107 | return promise.then(function (packed) {
108 | var source = packed.source.toString('utf8');
109 | var root = path.resolve(__dirname, '..', '..');
110 |
111 | source.should.not.containEql(root);
112 | });
113 | });
114 |
115 | it("should have resolved correctly the shadowed main", function () {
116 | var _module = { exports: {} };
117 |
118 | return fs.readFile(packedFile).then(function (src) {
119 | vm.runInNewContext(src, {
120 | Titanium: Titanium,
121 | Ti: Titanium,
122 | console: console,
123 | describe: describe,
124 | it: it,
125 | exports: _module.exports,
126 | module: _module,
127 | clearInterval: clearInterval,
128 | clearTimeout: clearTimeout,
129 | setInterval: setInterval,
130 | setTimeout: setTimeout
131 | }, packedFile);
132 |
133 | _module.exports.should.eql(42);
134 | });
135 | });
136 |
137 | });
138 |
139 | function assertIsFile(file) {
140 | return fs.isFile(file).then(function (isFile) {
141 | isFile.should.be.true;
142 | });
143 | }
144 |
--------------------------------------------------------------------------------
/test/packer/module-1/docs/index.md:
--------------------------------------------------------------------------------
1 |
2 | Something goes here…
3 |
--------------------------------------------------------------------------------
/test/packer/module-1/example/app.js:
--------------------------------------------------------------------------------
1 |
2 | // Something here…
3 |
--------------------------------------------------------------------------------
/test/packer/module-1/index.js:
--------------------------------------------------------------------------------
1 |
2 | throw new Error("Shadowed file called instead of titanium.js");
3 |
--------------------------------------------------------------------------------
/test/packer/module-1/node_modules/example/index.js:
--------------------------------------------------------------------------------
1 | module.exports = "example";
2 |
--------------------------------------------------------------------------------
/test/packer/module-1/node_modules/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "nativeDependencies": {
4 | "another.native.dep": "*"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/test/packer/module-1/node_modules/insert-global/index.js:
--------------------------------------------------------------------------------
1 | global.globalVar = 42;
2 |
--------------------------------------------------------------------------------
/test/packer/module-1/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ti-module-1",
3 | "guid": "0236f974-f7bf-f2dc-ca26-175cf5a14d14",
4 | "version": "0.1.2",
5 | "titaniumManifest": {
6 | "moduleid": "module-1"
7 | },
8 | "main": "index.js",
9 | "directories": {
10 | "documentation": "docs"
11 | },
12 | "titanium": {
13 | "./index.js": "./titanium.js"
14 | },
15 | "nativeDependencies": {
16 | "a.native.dep": "*"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/test/packer/module-1/titanium.js:
--------------------------------------------------------------------------------
1 |
2 | var assert = require('assert');
3 |
4 | // We’re using the hosted Mocha here.
5 |
6 | describe("Shadowing", function (){
7 | it("should work on `main`", function () {
8 | // The fact itself we’re here means it’s working
9 | });
10 | });
11 |
12 | describe("Requiring", function () {
13 | it("should work with `node_modules` deps" , function () {
14 | assert.equal(require('example'), 'example');
15 | });
16 |
17 | it("should work with json too", function () {
18 | assert.equal(require('./package').name, "ti-module-1");
19 | });
20 |
21 | it("should work outside the module too", function () {
22 | assert.equal(require('../../../package').name, 'titaniumifier');
23 | });
24 |
25 | it("should throw on missing (native) dependencies", function () {
26 | try {
27 | // directly specified by the package.json
28 | require('a.native.dep');
29 | }
30 | catch (e1) {
31 | assert.equal(e1.code, 'MODULE_NOT_FOUND');
32 | return;
33 |
34 | /*try {
35 | // TODO specified by a require module
36 | require('another.native.dep');
37 | }
38 | catch (e2) {
39 | assert.equal(e2.code, 'MODULE_NOT_FOUND');
40 | return;
41 | }*/
42 | }
43 |
44 | throw new Error("Shouldn’t have reached this point");
45 | });
46 |
47 | });
48 |
49 | describe("Global context", function () {
50 | it("should work as expected", function () {
51 | require('insert-global');
52 |
53 | assert.equal(typeof globalVar, 'number');
54 | assert.equal(typeof global.globalVar, 'number');
55 | assert.equal(global.globalVar, 42);
56 | });
57 | });
58 |
59 | describe("Globals", function () {
60 | it('process', function () {
61 | assert.equal(typeof process, 'object');
62 | });
63 |
64 | it('__dirname', function () {
65 | assert.equal(typeof __dirname, 'string');
66 | });
67 |
68 | it('__filename', function () {
69 | assert.equal(typeof __filename, 'string');
70 | });
71 |
72 | it('setTimeout', function (done) {
73 | setTimeout(function (arg) {
74 | assert.equal(arg, 'something');
75 | done();
76 | }, 10, 'something');
77 | });
78 |
79 | it('clearTimeout', function (done) {
80 | var timeoutId = setTimeout(
81 | done, 10, new Error("this timeout should have been cleared"));
82 |
83 | setTimeout(done, 20, null);
84 |
85 | clearTimeout(timeoutId);
86 | });
87 |
88 | it('setInterval', function (done) {
89 | var count = 0;
90 | var timeoutId = setTimeout(
91 | done, 50, new Error("interval executed " + count + " times"));
92 | var intervalId = setInterval(function (arg) {
93 | assert.equal(arg, 'something');
94 |
95 | if ((count++) > 1) {
96 | clearTimeout(timeoutId);
97 | clearInterval(intervalId);
98 | done();
99 | }
100 | }, 10, 'something');
101 | });
102 |
103 | it('clearInterval', function (done) {
104 | var intervalId = setInterval(
105 | done, 10, new Error("this interval should have been cleared"));
106 |
107 | setTimeout(done, 20, null);
108 |
109 | clearInterval(intervalId);
110 | });
111 | });
112 |
113 | // Exporting something
114 |
115 | module.exports = 42;
116 |
--------------------------------------------------------------------------------
/test/packer/module-2/index.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smclab/titaniumifier/f16ed73ce8243a41056cc49b3498c8188555b6e1/test/packer/module-2/index.js
--------------------------------------------------------------------------------
/test/packer/module-2/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "module-2",
3 | "titaniumManifest": {
4 | "guid": "aa59d3bd-0972-cca1-4ef3-dd12538dc73f",
5 | "moduleid": "fake-UPPER-CASE-name"
6 | },
7 | "private": true,
8 | "version": "0.1.2",
9 | "description": "Hallo",
10 | "main": "index.js",
11 | "author": "",
12 | "license": "BSD-2-Clause"
13 | }
14 |
--------------------------------------------------------------------------------
/test/runtime/app/app.js:
--------------------------------------------------------------------------------
1 | /* global mocha:false */
2 | /* global Ti:false */
3 |
4 | require('ti-mocha');
5 |
6 | var should = require('should');
7 |
8 | describe('Smoke tests', function () {
9 | it('should work', function () {
10 | true.should.be.true;
11 | });
12 | });
13 |
14 | describe('Require', function () {
15 | it('should work', function () {
16 | require('module-a');
17 | });
18 | });
19 |
20 | describe('Module calling', function () {
21 | var DeepThink;
22 | var deepthink;
23 |
24 | it('should work', function () {
25 | DeepThink = require('module-a');
26 |
27 | deepthink = new DeepThink();
28 |
29 | deepthink.answer().should.be.eql(42);
30 |
31 | deepthink.answer.is(deepthink.answer()).should.be.true;
32 | });
33 |
34 | it('should throw on missing native deps', function () {
35 | (function () {
36 | deepthink.magratea();
37 | }).should.throw();
38 | });
39 |
40 | it('should work inside module, between modules', function () {
41 | deepthink.identity().call(null, 42).should.eql(42);
42 | require('module-c').call(null, 42).should.eql(42);
43 |
44 | should(deepthink.identity() === require('module-c')).be.true;
45 | });
46 | });
47 |
48 | mocha.run(function (failures) {
49 | if (failures > 0) {
50 | Ti.API.error('[TESTS WITH FAILURES]');
51 | }
52 | else {
53 | Ti.API.error('[TESTS ALL OK]');
54 | }
55 | });
56 |
--------------------------------------------------------------------------------
/test/runtime/module-a/index.js:
--------------------------------------------------------------------------------
1 |
2 | module.exports = exports = DeepThink.DeepThink = DeepThink;
3 |
4 | function DeepThink() {
5 | this.answer = require('module-b');
6 | }
7 |
8 | DeepThink.prototype.magratea = function () {
9 | require('i.dont.exist'); // Throws
10 | };
11 |
12 | DeepThink.prototype.identity = function () {
13 | return require('module-c');
14 | };
15 |
--------------------------------------------------------------------------------
/test/runtime/module-a/node_modules/module-b/index.js:
--------------------------------------------------------------------------------
1 | module.exports = exports = answer.answer = answer;
2 |
3 | exports.is = is;
4 |
5 | function answer() {
6 | return require('./the-answer.js');
7 | }
8 |
9 | function is(test) {
10 | return answer() === test;
11 | }
12 |
--------------------------------------------------------------------------------
/test/runtime/module-a/node_modules/module-b/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "module-b",
3 | "version": "2.3.4",
4 | "titanium": {
5 | "./the-answer.js": "./the-real-answer.js"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/test/runtime/module-a/node_modules/module-b/the-answer.js:
--------------------------------------------------------------------------------
1 | module.exports = 12;
2 |
--------------------------------------------------------------------------------
/test/runtime/module-a/node_modules/module-b/the-real-answer.js:
--------------------------------------------------------------------------------
1 | module.exports = 42;
2 |
--------------------------------------------------------------------------------
/test/runtime/module-a/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ti-module-a",
3 | "version": "1.2.3",
4 | "titaniumManifest": {
5 | "guid": "bf0d14f6-3ccd-1462-f818-18a5cfef4796",
6 | "name": "Module A",
7 | "moduleid": "module-a"
8 | },
9 | "dependencies": {
10 | "module-a": "*"
11 | },
12 | "nativeDependencies": {
13 | "i.dont.exist": "*",
14 | "module-c": "*"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/test/runtime/module-c/index.js:
--------------------------------------------------------------------------------
1 | module.exports = function (n) {
2 | return n;
3 | };
4 |
--------------------------------------------------------------------------------
/test/runtime/module-c/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ti-module-c",
3 | "version": "1.2.3",
4 | "titaniumManifest": {
5 | "guid": "b1c35419-64d2-84bb-58e7-04f00ad1a683",
6 | "name": "Module B",
7 | "moduleid": "module-c"
8 | },
9 | "dependencies": {},
10 | "nativeDependencies": {}
11 | }
12 |
--------------------------------------------------------------------------------
/test/runtime/tiapp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | grunttitanium.test
4 | test
5 | 1.0
6 | not specified
7 |
8 |
9 | not specified
10 | appicon.png
11 | false
12 | false
13 | true
14 | 6c43b4bf-d641-457d-9f69-f71248d07a0b
15 | dp
16 |
17 |
18 |
19 | UISupportedInterfaceOrientations~iphone
20 |
21 | UIInterfaceOrientationPortrait
22 |
23 | UISupportedInterfaceOrientations~ipad
24 |
25 | UIInterfaceOrientationPortrait
26 | UIInterfaceOrientationPortraitUpsideDown
27 | UIInterfaceOrientationLandscapeLeft
28 | UIInterfaceOrientationLandscapeRight
29 |
30 | UIRequiresPersistentWiFi
31 |
32 | UIPrerenderedIcon
33 |
34 | UIStatusBarHidden
35 |
36 | UIStatusBarStyle
37 | UIStatusBarStyleDefault
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | true
48 | true
49 |
50 | default
51 |
52 |
53 | module-a
54 | module-c
55 |
56 |
57 | true
58 | true
59 | true
60 | true
61 | true
62 |
63 | 3.5.0.GA
64 |
65 |
--------------------------------------------------------------------------------