Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CB-5913 Fail more gracefully on Windows when symlinks fail.

  • Loading branch information...
commit 343921493714a76e4ba92287703bc3f87c2c097f 1 parent c708712
@agrieve agrieve authored stevengill committed
Showing with 37 additions and 21 deletions.
  1. +5 −5 spec/create.spec.js
  2. +32 −16 src/create.js
View
10 spec/create.spec.js
@@ -62,17 +62,17 @@ describe('create command', function () {
describe('success', function() {
it('should create top-level directory structure appropriate for a cordova-cli project', function(done) {
cordova.raw.create(tempDir).then(function() {
- expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'platforms'));
- expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'merges'));
- expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'plugins'));
- expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'www'));
+ expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'platforms'));
+ expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'merges'));
+ expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'plugins'));
+ expect(mkdir).toHaveBeenCalledWith(path.join(tempDir, 'www'));
done();
});
});
it('should create hooks directory', function(done) {
var hooks_dir = path.join(tempDir, 'hooks');
cordova.raw.create(tempDir).then(function() {
- expect(mkdir).toHaveBeenCalledWith('-p', hooks_dir);
+ expect(mkdir).toHaveBeenCalledWith(hooks_dir);
expect(cp).toHaveBeenCalledWith(
path.resolve(__dirname, '..', 'templates', 'hooks-README.md'),
jasmine.any(String)
View
48 src/create.js
@@ -79,16 +79,7 @@ module.exports = function create (dir, id, name, cfg) {
return Q.reject(new CordovaError('Path already exists and is not empty: ' + dir));
}
- // Create basic project structure.
- shell.mkdir('-p', path.join(dir, 'platforms'));
- shell.mkdir('-p', path.join(dir, 'merges'));
- shell.mkdir('-p', path.join(dir, 'plugins'));
- shell.mkdir('-p', path.join(dir, 'hooks'));
-
- // Add hooks README.md
- shell.cp(path.join(__dirname, '..', 'templates', 'hooks-README.md'), path.join(dir, 'hooks', 'README.md'));
-
- // Write out .cordova/config.json file if necessary.
+ // Read / Write .cordova/config.json file if necessary.
var config_json = config(dir, cfg);
var p;
@@ -104,18 +95,18 @@ module.exports = function create (dir, id, name, cfg) {
events.emit('verbose', 'Symlinking custom www assets into "' + www_dir + '"');
} else {
p = lazy_load.custom(config_json.lib.www.uri, www_id, 'www', www_version)
- .then(function(dir) {
+ .then(function(d) {
events.emit('verbose', 'Copying custom www assets into "' + www_dir + '"');
- return dir;
+ return d;
});
}
} else {
// Nope, so use stock cordova-hello-world-app one.
events.emit('verbose', 'Using stock cordova hello-world application.');
p = lazy_load.cordova('www')
- .then(function(dir) {
+ .then(function(d) {
events.emit('verbose', 'Copying stock Cordova www assets into "' + www_dir + '"');
- return dir;
+ return d;
});
}
@@ -124,12 +115,37 @@ module.exports = function create (dir, id, name, cfg) {
while (fs.existsSync(path.join(www_lib, 'www'))) {
www_lib = path.join(www_lib, 'www');
}
+
+ var dirAlreadyExisted = fs.existsSync(dir);
+ if (!dirAlreadyExisted) {
+ shell.mkdir(dir);
+ }
if (symlink) {
- fs.symlinkSync(www_lib, www_dir, 'dir');
+ try {
+ fs.symlinkSync(www_lib, www_dir, 'dir');
+ } catch (e) {
+ if (!dirAlreadyExisted) {
+ fs.rmdirSync(dir);
+ }
+ if (process.platform.slice(0, 3) == 'win' && e.code == 'EPERM') {
+ throw new CordovaError('Symlinks on Windows require Administrator privileges');
+ }
+ throw e;
+ }
} else {
- shell.mkdir('-p', www_dir);
+ shell.mkdir(www_dir);
shell.cp('-rf', path.join(www_lib, '*'), www_dir);
}
+
+ // Create basic project structure.
+ shell.mkdir(path.join(dir, 'platforms'));
+ shell.mkdir(path.join(dir, 'merges'));
+ shell.mkdir(path.join(dir, 'plugins'));
+ shell.mkdir(path.join(dir, 'hooks'));
+
+ // Add hooks README.md
+ shell.cp(path.join(__dirname, '..', 'templates', 'hooks-README.md'), path.join(dir, 'hooks', 'README.md'));
+
var configPath = util.projectConfig(dir);
// Add template config.xml for apps that are missing it
if (!fs.existsSync(configPath)) {
Please sign in to comment.
Something went wrong with that request. Please try again.