Beispiel #1
0
	return function (finished) {
		ti.platformOptions(logger, config, cli, 'build', function (platformConf) {
			finished({
				title: __('Build'),
				desc: __('builds a project'),
				extendedDesc: 'Builds an existing app or module project.',
				options: appc.util.mix({
					platform: {
						abbr: 'p',
						callback: function (value) {
							return ti.resolvePlatform(value);
						},
						desc: __('the target build platform'),
						hint: __('platform'),
						prompt: {
							label: __('Target platform [%s]', ti.availablePlatforms.join(',')),
							error: __('Invalid platform'),
							validator: function (platform) {
								platform = platform.trim();
								if (!platform) {
									throw new appc.exception(__('Invalid platform'));
								}
								if (ti.availablePlatforms.indexOf(platform) == -1) {
									throw new appc.exception(__('Invalid platform: %s', platform));
								}
								return true;
							}
						},
						required: true,
						values: ti.availablePlatforms
					},
					'project-dir': {
						abbr: 'd',
						desc: __('the directory containing the project, otherwise the current working directory')
					}
				}, ti.commonOptions(logger, config)),
				platforms: platformConf
			});
		});
	};
Beispiel #2
0
	return function (finished) {
		ti.platformOptions(logger, config, cli, 'build', function (platformConf) {
			finished({
				flags: {
					'build-only': {
						abbr: 'b',
						desc: __('only perform the build; if true, does not install or run the app')
					},
					force: {
						abbr: 'f',
						desc: __('force a full rebuild')
					}
				},
				options: appc.util.mix({
					platform: {
						abbr: 'p',
						callback: function (platform) {
							return ti.resolvePlatform(platform);
						},
						desc: __('the target build platform'),
						hint: __('platform'),
						prompt: {
							label: __('Target platform [%s]', ti.availablePlatforms.join(',')),
							error: __('Invalid platform'),
							validator: function (platform) {
								platform = platform.trim();
								if (!platform) {
									throw new appc.exception(__('Invalid platform'));
								}
								if (ti.availablePlatforms.indexOf(platform) == -1) {
									throw new appc.exception(__('Invalid platform: %s', platform));
								}
								
								// it's possible that platform was not specified at the command line in which case the it would
								// be prompted for. that means that validate() was unable to apply default values for platform-
								// specific options and scan for platform-specific hooks, so we must do it here.
								
								var p = platformConf[platform];
								p && p.options && Object.keys(p.options).forEach(function (name) {
									if (p.options[name].default && cli.argv[name] === undefined) {
										cli.argv[name] = p.options[name].default;
									}
								});
								
								cli.scanHooks(afs.resolvePath(path.dirname(module.filename), '..', '..', platform, 'cli', 'hooks'));
								
								return true;
							}
						},
						required: true,
						skipValueCheck: true,
						values: ti.availablePlatforms
					},
					'project-dir': {
						abbr: 'd',
						desc: __('the directory containing the project, otherwise the current working directory')
					}
				}, ti.commonOptions(logger, config)),
				platforms: platformConf
			});
		});
	};
Beispiel #3
0
		cli.createHook('build.config', function (callback) {
			ti.platformOptions(logger, config, cli, 'build', function (platformConf) {
				var conf = {
					flags: {
						'build-only': {
							abbr: 'b',
							desc: __('only perform the build; if true, does not install or run the app')
						},
						force: {
							abbr: 'f',
							desc: __('force a full rebuild')
						},
						legacy: {
							desc: __('build using the old Python-based builder.py; deprecated')
						},
						'skip-js-minify': {
							default: false,
							desc: __('bypasses JavaScript minification; %s builds are never minified; only supported for %s and %s', 'simulator'.cyan, 'Android'.cyan, 'iOS'.cyan)
						}
					},
					options: appc.util.mix({
						platform: {
							abbr: 'p',
							callback: function (platform) {
								cli.argv.$originalPlatform = platform;
								platform = ti.resolvePlatform(platform);

								var p = platformConf[platform];
								p && p.options && Object.keys(p.options).forEach(function (name) {
									if (p.options[name].default && cli.argv[name] === undefined) {
										cli.argv[name] = p.options[name].default;
									}
								});

								return platform;
							},
							desc: __('the target build platform'),
							hint: __('platform'),
							order: 2,
							prompt: {
								label: __('Target platform'),
								error: __('Invalid platform'),
								validator: function (platform) {
									if (!platform) {
										throw new Error(__('Invalid platform'));
									} else if (ti.availablePlatforms.indexOf(platform) == -1) {
										throw new Error(__('Invalid platform: %s', platform));
									}
									return true;
								}
							},
							required: true,
							skipValueCheck: true,
							values: ti.targetPlatforms
						},
						'project-dir': {
							abbr: 'd',
							callback: function (projectDir) {
								// load the tiapp.xml
								try {
									var tiapp = cli.tiapp = new tiappxml(path.join(projectDir, 'tiapp.xml'));
								} catch (ex) {
									logger.error(ex);
									logger.log();
									process.exit(1);
								}

								tiapp.properties || (tiapp.properties = {});

								// make sure the tiapp.xml is sane
								ti.validateTiappXml(logger, config, tiapp);

								// check that the Titanium SDK version is correct
								if (!ti.validateCorrectSDK(logger, config, cli, 'build')) {
									throw new cli.GracefulShutdown;
								}

								return projectDir;
							},
							desc: __('the directory containing the project'),
							default: process.env.SOURCE_ROOT ? path.join(process.env.SOURCE_ROOT, '..', '..') : '.',
							order: 1,
							prompt: function (callback) {
								callback(fields.file({
									promptLabel: __('Where is the __project directory__?'),
									complete: true,
									showHidden: true,
									ignoreDirs: new RegExp(config.get('cli.ignoreDirs')),
									ignoreFiles: /.*/,
									validate: conf.options['project-dir'].validate
								}));
							},
							required: true,
							validate: function (projectDir, callback) {
								var isDefault = projectDir == conf.options['project-dir'].default;

								var dir = appc.fs.resolvePath(projectDir);

								if (!fs.existsSync(dir)) {
									return callback(new Error(__('Project directory does not exist')));
								}

								var tiappFile = path.join(dir, 'tiapp.xml');

								// try to find the tiapp.xml
								while (!fs.existsSync(tiappFile)) {
									dir = path.dirname(dir);
									if (dir == '/') {
										if (!isDefault) {
											callback(new Error(__('Invalid project directory "%s" because tiapp.xml not found', projectDir)));
											return;
										} else {
											callback(true);
											return;
										}
									}
									tiappFile = path.join(dir, 'tiapp.xml');
								}

								callback(null, dir);
							}
						}
					}, ti.commonOptions(logger, config)),
					platforms: platformConf
				};
				callback(conf);
			});
		})(function (err, results, result) {
		cli.createHook('build.config', function (callback) {
			ti.platformOptions(logger, config, cli, 'build', function (platformConf) {
				callback({
					flags: {
						'build-only': {
							abbr: 'b',
							desc: __('only perform the build; if true, does not install or run the app')
						},
						force: {
							abbr: 'f',
							desc: __('force a full rebuild')
						},
						legacy: {
							desc: __('build using the old Python-based builder.py')
						},
						'skip-js-minify': {
							default: false,
							desc: __('bypasses JavaScript minification; %s builds are never minified; only supported for %s and %s', 'simulator'.cyan, 'Android'.cyan, 'iOS'.cyan)
						}
					},
					options: appc.util.mix({
						platform: {
							abbr: 'p',
							callback: function (platform) {
								cli.argv.$originalPlatform = platform;
								return ti.resolvePlatform(platform);
							},
							desc: __('the target build platform'),
							hint: __('platform'),
							prompt: {
								label: __('Target platform [%s]', ti.targetPlatforms.join(',')),
								error: __('Invalid platform'),
								validator: function (platform) {
									if (!platform) {
										throw new appc.exception(__('Invalid platform'));
									}

									platform = platform.trim();

									// temp: ti.availablePlatforms contains "iphone" and "ipad" which aren't going to be valid supported platforms
									if (ti.availablePlatforms.indexOf(platform) == -1) {
										throw new appc.exception(__('Invalid platform: %s', platform));
									}

									// now that we've passed the validation, transform and continue
									platform = ti.resolvePlatform(platform);

									// it's possible that platform was not specified at the command line in which case the it would
									// be prompted for. that means that validate() was unable to apply default values for platform-
									// specific options and scan for platform-specific hooks, so we must do it here.

									var p = platformConf[platform];
									p && p.options && Object.keys(p.options).forEach(function (name) {
										if (p.options[name].default && cli.argv[name] === undefined) {
											cli.argv[name] = p.options[name].default;
										}
									});

									cli.scanHooks(afs.resolvePath(path.dirname(module.filename), '..', '..', platform, 'cli', 'hooks'));

									return true;
								}
							},
							required: true,
							skipValueCheck: true,
							values: ti.targetPlatforms
						},
						'project-dir': {
							abbr: 'd',
							desc: __('the directory containing the project, otherwise the current working directory')
						}
					}, ti.commonOptions(logger, config)),
					platforms: platformConf
				});
			});
		})(function (err, results, result) {
Beispiel #5
0
exports.config = function (logger, config, cli) {
	return {
		desc: __('install and run an app'),
		platforms: ti.platformOptions(logger, config, cli, module)
	};
};
Beispiel #6
0
exports.config = function (logger, config, cli) {
	return {
		desc: __('creates a new mobile application or module'),
		flags: {
			force: {
				abbr: 'f',
				desc: __('force project creation even if path already exists')
			}
		},
		options: appc.util.mix({
			platforms: {
				abbr: 'p',
				desc: __('the target build platform'),
				prompt: {
					default: ti.availablePlatforms,
					label: __('Target platforms'),
					error: __('Invalid list of target platforms'),
					validator: function (platforms) {
						var p = ti.scrubPlatforms(platforms);
						if (p.bad.length) {
							throw new appc.exception(__('Invalid platforms: %s', p.bad.join(', ')));
						}
						return true;
					},
				},
				required: true,
				values: ti.availablePlatforms,
				skipValueCheck: true // we do our own validation
			},
			type: {
				abbr: 't',
				default: 'app',
				desc: __('the type of project to create'),
				values: ['app', 'module']
			},
			id: {
				desc: __("the App ID in the format 'com.companyname.appname'"),
				prompt: {
					label: __('App ID'),
					error: __('Invalid App ID'),
					pattern: /^([a-z_]{1}[a-z0-9_]*(\.[a-z_]{1}[a-z0-9_]*)*)$/
				},
				required: true
			},
			template: {
				desc: __('the name of the project template to use'),
				default: 'default'
			},
			name: {
				abbr: 'n',
				desc: __('the name of the project'),
				prompt: {
					label: __('Project name'),
					error: __('Invalid project name'),
					pattern: /^[A-Za-z]+[A-Za-z0-9_-]*$/
				},
				required: true
			},
			dir: {
				abbr: 'd',
				default: config.app.workspace || '',
				desc: __('the directory to place the project in'),
				prompt: {
					label: __('Directory to place project'),
					error: __('Invalid directory'),
					validator: function (dir) {
						dir = appc.fs.resolvePath(dir);
						if (!appc.fs.exists(dir)) {
							throw new appc.exception(__('Specified directory does not exist'));
						}
						if (!appc.fs.isDirWritable(dir)) {
							throw new appc.exception(__('Specified directory not writable'));
						}
						return true;
					}
				},
				required: !config.app.workspace
			}
		}, ti.commonOptions(logger, config)),
		platforms: ti.platformOptions(logger, config, cli, module)
	};
};