CB-8358 Make --link an alias for --shared for create/update. Make it work with gradle

This commit is contained in:
Andrew Grieve 2015-01-23 14:38:05 -05:00
parent f459eaa5ea
commit a4c9bf7d30
3 changed files with 33 additions and 17 deletions

View File

@ -23,14 +23,14 @@ var create = require('./lib/create');
var args = require('./lib/simpleargs').getArgs(process.argv); var args = require('./lib/simpleargs').getArgs(process.argv);
if (args['--help'] || args._.length === 0) { if (args['--help'] || args._.length === 0) {
console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'create')) + ' <path_to_new_project> <package_name> <project_name> [<template_path>] [--shared]'); console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'create')) + ' <path_to_new_project> <package_name> <project_name> [<template_path>] [--link]');
console.log(' <path_to_new_project>: Path to your new Cordova Android project'); console.log(' <path_to_new_project>: Path to your new Cordova Android project');
console.log(' <package_name>: Package name, following reverse-domain style convention'); console.log(' <package_name>: Package name, following reverse-domain style convention');
console.log(' <project_name>: Project name'); console.log(' <project_name>: Project name');
console.log(' <template_path>: Path to a custom application template to use'); console.log(' <template_path>: Path to a custom application template to use');
console.log(' --shared will use the CordovaLib project directly instead of making a copy.'); console.log(' --link will use the CordovaLib project directly instead of making a copy.');
process.exit(1); process.exit(1);
} }
create.createProject(args._[0], args._[1], args._[2], args._[3], args['--shared'], args['--cli']).done(); create.createProject(args._[0], args._[1], args._[2], args._[3], args['--link'] || args['--shared'], args['--cli']).done();

View File

@ -59,15 +59,25 @@ function copyJsAndLibrary(projectPath, shared, projectName) {
console.log("Deleting " + oldJar); console.log("Deleting " + oldJar);
shell.rm('-f', oldJar); shell.rm('-f', oldJar);
}); });
var wasSymlink = true;
try {
// Delete the symlink if it was one.
fs.unlinkSync(nestedCordovaLibPath)
} catch (e) {
wasSymlink = false;
}
// Delete old library project if it existed. // Delete old library project if it existed.
if (shared) { if (shared) {
shell.rm('-rf', nestedCordovaLibPath); shell.rm('-rf', nestedCordovaLibPath);
} else { } else if (!wasSymlink) {
// Delete only the src, since eclipse can't handle its .project file being deleted. // Delete only the src, since eclipse can't handle its .project file being deleted.
shell.rm('-rf', path.join(nestedCordovaLibPath, 'src')); shell.rm('-rf', path.join(nestedCordovaLibPath, 'src'));
} }
}); });
if (!shared) { if (shared) {
var relativeFrameworkPath = path.relative(projectPath, getFrameworkDir(projectPath, true));
fs.symlinkSync(relativeFrameworkPath, nestedCordovaLibPath, 'dir');
} else {
shell.mkdir('-p', nestedCordovaLibPath); shell.mkdir('-p', nestedCordovaLibPath);
shell.cp('-f', path.join(ROOT, 'framework', 'AndroidManifest.xml'), nestedCordovaLibPath); shell.cp('-f', path.join(ROOT, 'framework', 'AndroidManifest.xml'), nestedCordovaLibPath);
shell.cp('-f', path.join(ROOT, 'framework', 'project.properties'), nestedCordovaLibPath); shell.cp('-f', path.join(ROOT, 'framework', 'project.properties'), nestedCordovaLibPath);
@ -94,7 +104,7 @@ function extractSubProjectPaths(data) {
return Object.keys(ret); return Object.keys(ret);
} }
function writeProjectProperties(projectPath, target_api, shared) { function writeProjectProperties(projectPath, target_api) {
var dstPath = path.join(projectPath, 'project.properties'); var dstPath = path.join(projectPath, 'project.properties');
var templatePath = path.join(ROOT, 'bin', 'templates', 'project', 'project.properties'); var templatePath = path.join(ROOT, 'bin', 'templates', 'project', 'project.properties');
var srcPath = fs.existsSync(dstPath) ? dstPath : templatePath; var srcPath = fs.existsSync(dstPath) ? dstPath : templatePath;
@ -107,7 +117,7 @@ function writeProjectProperties(projectPath, target_api, shared) {
/^(\.\.[\\\/])+framework$/m.exec(p) /^(\.\.[\\\/])+framework$/m.exec(p)
); );
}); });
subProjects.unshift(shared ? path.relative(projectPath, path.join(ROOT, 'framework')) : 'CordovaLib'); subProjects.unshift('CordovaLib');
data = data.replace(/^\s*android\.library\.reference\.\d+=.*\n/mg, ''); data = data.replace(/^\s*android\.library\.reference\.\d+=.*\n/mg, '');
if (!/\n$/.exec(data)) { if (!/\n$/.exec(data)) {
data += '\n'; data += '\n';
@ -278,12 +288,20 @@ exports.createProject = function(project_path, package_name, project_name, proje
copyBuildRules(project_path); copyBuildRules(project_path);
}); });
// Link it to local android install. // Link it to local android install.
writeProjectProperties(project_path, target_api, use_shared_project); writeProjectProperties(project_path, target_api);
}).then(function() { console.log(generateDoneMessage('create', use_shared_project));
console.log('Project successfully created.');
}); });
} }
function generateDoneMessage(type, link) {
var pkg = require('../../package');
var msg = 'Android project ' + (type == 'update' ? 'updated ' : 'created ') + 'with ' + pkg.name + '@' + pkg.version;
if (link) {
msg += ' and has a linked CordovaLib';
}
return msg;
}
// Attribute removed in Cordova 4.4 (CB-5447). // Attribute removed in Cordova 4.4 (CB-5447).
function removeDebuggableFromManifest(projectPath) { function removeDebuggableFromManifest(projectPath) {
var manifestPath = path.join(projectPath, 'AndroidManifest.xml'); var manifestPath = path.join(projectPath, 'AndroidManifest.xml');
@ -302,7 +320,6 @@ function extractProjectNameFromManifest(projectPath) {
// Returns a promise. // Returns a promise.
exports.updateProject = function(projectPath, shared) { exports.updateProject = function(projectPath, shared) {
var newVersion = fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf-8').trim();
return Q() return Q()
.then(function() { .then(function() {
var projectName = extractProjectNameFromManifest(projectPath); var projectName = extractProjectNameFromManifest(projectPath);
@ -311,9 +328,8 @@ exports.updateProject = function(projectPath, shared) {
copyScripts(projectPath); copyScripts(projectPath);
copyBuildRules(projectPath); copyBuildRules(projectPath);
removeDebuggableFromManifest(projectPath); removeDebuggableFromManifest(projectPath);
writeProjectProperties(projectPath, target_api, shared); writeProjectProperties(projectPath, target_api);
console.log('Android project is now at version ' + newVersion); console.log(generateDoneMessage('update', shared));
console.log('If you updated from a pre-3.2.0 version and use an IDE, we now require that you import the "CordovaLib" library project.');
}); });
}; };

View File

@ -23,9 +23,9 @@ var create = require('./lib/create');
var args = require('./lib/simpleargs').getArgs(process.argv); var args = require('./lib/simpleargs').getArgs(process.argv);
if (args['--help'] || args._.length === 0) { if (args['--help'] || args._.length === 0) {
console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update')) + ' <path_to_project> [--shared]'); console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update')) + ' <path_to_project> [--link]');
console.log(' --shared will use the CordovaLib project directly instead of making a copy.'); console.log(' --link will use the CordovaLib project directly instead of making a copy.');
process.exit(1); process.exit(1);
} }
create.updateProject(args._[0], args['--shared']).done(); create.updateProject(args._[0], args['--link'] || args['--shared']).done();