Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17227] CLI: Passing empty option value, building the project returns Error

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2014-08-29T08:09:37.000+0000
Affected Version/sRelease 3.3.0
Fix Version/sRelease 3.4.0
ComponentsCLI
Labelscli, ft, qe-3.3.0, usability
ReporterOlga Romero
AssigneeFeon Sua Xin Miao
Created2014-06-26T23:40:15.000+0000
Updated2014-09-14T20:13:46.000+0000

Description

 -d, --project-dir <value>   the directory containing the project  [default: .]
When running
ti build -d
the output in the console is:
[ERROR] TypeError: Arguments to path.join must be strings
    at path.js:360:15
    at Array.filter (native)
    at exports.join (path.js:358:36)
    at conf.options.appc.util.mix.project-dir.callback (/Users/oromero/Library/Application Support/Titanium/mobilesdk/osx/3.3.0.v20140626144112/cli/commands/build.js:101:52)
    at Context.<anonymous> (/usr/local/lib/node_modules/titanium/lib/context.js:597:31)
    at Array.forEach (native)
    at Context.setArg (/usr/local/lib/node_modules/titanium/lib/context.js:576:35)
    at Context.<anonymous> (/usr/local/lib/node_modules/titanium/lib/context.js:675:9)
    at Context.parse (/usr/local/lib/node_modules/titanium/lib/context.js:772:6)
    at processConf (/usr/local/lib/node_modules/titanium/lib/context.js:364:21)
---------------------------------------------
    at run (/Users/oromero/Library/Application Support/Titanium/mobilesdk/osx/3.3.0.v20140626144112/node_modules/node-appc/lib/subprocess.js:59:8)
    at /Users/oromero/Library/Application Support/Titanium/mobilesdk/osx/3.3.0.v20140626144112/iphone/cli/lib/detect.js:415:9
    at /Users/oromero/Library/Application Support/Titanium/mobilesdk/osx/3.3.0.v20140626144112/node_modules/async/lib/async.js:511:21
    at /Users/oromero/Library/Application Support/Titanium/mobilesdk/osx/3.3.0.v20140626144112/node_modules/async/lib/async.js:227:13
    at /Users/oromero/Library/Application Support/Titanium/mobilesdk/osx/3.3.0.v20140626144112/node_modules/async/lib/async.js:111:13
    at Array.forEach (native)
    at _each (/Users/oromero/Library/Application Support/Titanium/mobilesdk/osx/3.3.0.v20140626144112/node_modules/async/lib/async.js:32:24)
    at async.each (/Users/oromero/Library/Application Support/Titanium/mobilesdk/osx/3.3.0.v20140626144112/node_modules/async/lib/async.js:110:9)

Comments

  1. Chris Barber 2014-08-21

    [~fmiao] You are correct, \-d should display the same error as \-\-project\-dir. The problem stems from context.js, but that's because of a feature, not a bug. The CLI supports flags and options. Flags are in the format \-\-flag\-name and when encountered, the CLI treats this as \-\-flag\-name true. Options are in the format \-\-option\-name somevalue. Because the CLI parser doesn't know of something is a flag or option, it treats them as flags. That means if you specify \-\-option\-name without a subsequent value, it will set the option value to true. This herein lies the problem. This is by design. So, while this isn't great, we have a solution. For every option, we simply need to check if the value is a boolean. All option values should be strings even if it is a number or boolean string. So, "hello world", "123", "true" are all valid option values. The option callbacks and validators will need to properly parse the values from the string format. As an example, here's what you need to do:
       'some-option': {
           validate: function (value, callback) {
               if (typeof value === 'boolean') {
                   return callback(true);
               }
               callback(null, value);
           }
       }
       
    For a real world example, look at the options in the iOS build script: https://github.com/appcelerator/titanium_mobile/blame/master/iphone/cli/commands/_build.js#L349-L351. You can see I added a bunch of them in this commit: https://github.com/appcelerator/titanium_mobile/commit/5ed0879a77d98cfcce35404a6be098d378224fd3. You just need to find the remaining options that are missing this, add them, and test.
  2. Chris Barber 2014-08-22

    [~fmiao] On a Mac, if you do \-\-, it automatically turns it into an "mdash". Since an mdash is not a dash, and probably is accidental, we treat \-\- and mdashes the same.
  3. Feon Sua Xin Miao 2014-08-25

    PR Master: https://github.com/appcelerator/titanium_mobile/pull/5983 Functional Test: 1. Create an app:
     
       ti create -t app -d . -n true -u http:// --id com.timob.test
       
    2. Build the app:
       ti build -d 
       //or
       ti build --project-dir
       
    Following error message should be shown:
       [ERROR] Invalid project directory "" because tiapp.xml not found
       
    3. Build the app again by passing a value to the option
       // In this case the project happened to be name 'true'
       ti build -d true
       // or
       ti build --project-dir true
       
    The build process should run without error.
  4. Ewan Harris 2014-09-02

    Verified fix on: Mac OSX 10.9.4 Appcelerator Studio, build: 3.4.0.201408291834 Titanium SDK build: 3.4.0.v20140829184521 Titanium CLI, build: 3.4.0-dev Alloy: 1.5.0-dev Created a new app and attempted to build using the ti build -project-dir command, after asking for the platform to target it showed the error as expected. I then built and passed in a value and the build process ran without error. The same is shown with the ti build -d command

JSON Source