CB-9254 copy over templates/PROJECT_NAME/Classes during cordova platform update
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/afe1fa08 Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/afe1fa08 Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/afe1fa08 Branch: refs/heads/4.1.x Commit: afe1fa08ced0fb68a0df390eebea755c0cce23d6 Parents: f4d4b63 Author: Steve Gill <stevengil...@gmail.com> Authored: Wed Feb 24 23:10:01 2016 -0800 Committer: Steve Gill <stevengil...@gmail.com> Committed: Fri Feb 26 14:41:14 2016 -0800 ---------------------------------------------------------------------- bin/lib/create.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/afe1fa08/bin/lib/create.js ---------------------------------------------------------------------- diff --git a/bin/lib/create.js b/bin/lib/create.js index ef14312..3863338 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -99,6 +99,34 @@ function copyScripts(projectPath) { }); } +/* + * Copy classes from cordova-ios/bin/template/__PROJECT_NAME__/Classes + * to cordova project. Replace strings in updated Classes + * + * @param {String} project_path path to cordova project + * @param {String} project_name name of cordova project + * @param {String} project_template_dir path to cordova-ios template directory + */ +function copyTemplateClasses(project_path, project_name, project_template_dir) { + var r = path.join(project_path, project_name); + + //copy updated classes from cordova-ios into cordova project + shell.cp('-rf', path.join(project_template_dir, '__PROJECT_NAME__', 'Classes','*'), path.join(r, 'Classes')); + + /* replace __PROJECT_NAME__ ACTIVITY string in: + * + * - ./__PROJECT_NAME__/Classes/AppDelegate.h + * - ./__PROJECT_NAME__/Classes/AppDelegate.m + * - ./__PROJECT_NAME__/Classes/MainViewController.h + * - ./__PROJECT_NAME__/Classes/MainViewController.m + */ + var project_name_esc = project_name.replace(/&/g, '\\&'); + shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'AppDelegate.h')); + shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'AppDelegate.m')); + shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'MainViewController.h')); + shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'MainViewController.m')); +} + function detectProjectName(projectDir) { var files = fs.readdirSync(projectDir); for (var i = 0; i < files.length; ++i) { @@ -209,7 +237,9 @@ exports.createProject = function(project_path, package_name, project_name, opts, exports.updateProject = function(projectPath, opts, events) { var projectName = detectProjectName(projectPath); + var project_template_dir = path.join(ROOT, 'bin', 'templates', 'project'); setShellFatal(true, function() { + copyTemplateClasses(projectPath, projectName, project_template_dir) copyJsAndCordovaLib(projectPath, projectName, opts.link); copyScripts(projectPath); events.emit('log',generateDoneMessage('update', opts.link)); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org