Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "titanium",
"version": "8.1.5",
"version": "8.2.0",
"author": "TiDev, Inc. <npm@tidev.io>",
"description": "Command line interface for building Titanium SDK apps",
"type": "module",
Expand Down
42 changes: 29 additions & 13 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const sdkCommands = {
build: 'builds a project',
clean: 'removes previous build directories',
create: 'creates a new project',
project: 'get and set tiapp.xml settings'
project: 'get and set tiapp.xml settings',
serve: 'serves a project through the Titanium Vite runtime',
};

/**
Expand Down Expand Up @@ -416,12 +417,17 @@ export class CLI {
const cmd = args.pop();
args.pop(); // discard argv

// remove any trailing undefined args
while (args.length && args[args.length - 1] === undefined) {
args.pop();
// Commander keeps declared and excess positional args on the command.
const positionalArgs = Array.isArray(cmd?.args) ? cmd.args.slice() : [];
if (positionalArgs.length) {
this.argv._ = positionalArgs;
} else {
// Fallback for command handlers that pass positional args directly.
while (args.length && args[args.length - 1] === undefined) {
args.pop();
}
this.argv._ = args;
}

this.argv._ = args;
this.applyArgv(cmd);

if (!this.ready) {
Expand Down Expand Up @@ -621,20 +627,19 @@ export class CLI {
}

/**
* If the current command is the "build" command, this function will check
* if the "build" command has a `--platform` option (which is should), then
* prompt for the platform is not explicitly passed in.
* If the current command supports platform-specific config, this function
* checks for the `--platform` option and prompts when missing.
*
* Finally, the platform specific options and flags are added to the
* Commander.js "build" command context so that the second parse will
* pick up the newly defined options/flags.
* Finally, the platform specific options and flags are added to the command
* context so that the second parse picks up the newly defined options/flags.
*
* @returns {Promise}
* @access private
*/
async initBuildPlatform() {
const cmdName = this.command.name();
if (cmdName !== 'build') {
// Commands with build-style platform branches.
if (cmdName !== 'build' && cmdName !== 'serve') {
return;
}

Expand All @@ -643,6 +648,15 @@ export class CLI {
return;
}

// Support shorthand positional platform syntax, e.g. `ti serve ios`.
// Commander parses this into processedArgs via the [platform] argument
// declared in loadCommand().
const positionalPlatform = this.command.processedArgs?.[0];
if (!this.argv.platform && positionalPlatform && platformOption.values.includes(positionalPlatform)) {
this.debugLogger.trace(`Converting positional platform argument "${positionalPlatform}" to --platform`);
this.argv.platform = positionalPlatform;
}

// when specifying `--platform ios`, the SDK's option callback converts
// it to `iphone`, however the platform config uses `ios` and we must
// convert it back
Expand Down Expand Up @@ -983,6 +997,8 @@ export class CLI {
this.command.createHelp = () => {
return Object.assign(new TiHelp(this, conf.platforms), this.command.configureHelp());
};

cmd.argument('[platform]', 'target platform');
}

applyCommandConfig(this, cmdName, cmd, conf);
Expand Down
2 changes: 1 addition & 1 deletion test/commands/ti-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('ti build', () => {

const output = stripColor(stdout);
assert.match(output, /Titanium Command-Line Interface/);
assert.match(output, /Usage: titanium build \[options\]/);
assert.match(output, /Usage: titanium build \[options\] \[platform\]/);
assert.match(output, /Builds an existing app or module project./);
assert.match(output, /Build Options:/);
assert.match(output, /Global Options:/);
Expand Down
Loading