Skip to content
Permalink
Browse files

Merge pull request #401 from nodejitsu/no-spaces

[fix] Validate package.json properties as a whole word
  • Loading branch information...
julianduque committed Mar 7, 2013
2 parents ccfc2d9 + 25d3c0b commit 1b86ef0a078b0522f374a73578cf7bc4fc90c4a3
Showing with 25 additions and 25 deletions.
  1. +25 −25 lib/jitsu/package.js
@@ -75,14 +75,14 @@ package.read = function (dir, callback) {
if (!data.length) {
return callback(new Error('package.json is empty'));
}

try {
data = JSON.parse(data.toString());
}
}
catch (ex) {
return callback(new Error('Invalid package.json file'));
}

callback(null, data);
});
};
@@ -129,7 +129,7 @@ package.create = function (dir, callback) {
if (err) {
return callback(err);
}

package.write(pkg, dir, true, function (err, pkg) {
if (err) {
return callback(err);
@@ -251,10 +251,10 @@ package.validate = function (pkg, dir, options, callback) {
if (err) {
return callback(err);
}

package.write(pkg, dir, true, function (err, pkg) {
return err
? callback(err)
return err
? callback(err)
: tryAnalyze(pkg, dir, callback);
});
});
@@ -275,7 +275,7 @@ package.write = function (pkg, dir, create, callback) {
callback = create;
create = null;
}

delete pkg.analyzed;

jitsu.log.warn('About to write ' + path.join(dir, 'package.json').magenta);
@@ -294,15 +294,15 @@ package.write = function (pkg, dir, create, callback) {
if (!result) {
return create ? package.create(dir, callback) : callback(new Error('Save package.json cancelled.'));
}

fs.readFile(path.resolve(path.join(dir, 'package.json')), function (e, data) {
var offset = data ? ladder(data.toString()) : 2;

fs.writeFile(path.join(dir, 'package.json'), JSON.stringify(pkg, null, offset) + '\n', function (err) {
return err ? callback(err) : callback(null, pkg, dir);
});
});

});
};

@@ -426,7 +426,7 @@ package.updateTarball = function (version, pkg, existing, firstSnapshot, callbac
jitsu.log.silly('Done creating snapshot ' + version.magenta);
return err ? callback(err) : callback(null, version, pkg);
});

if (emitter && !jitsu.config.get('raw') && process.stdout.isTTY ) {
var size;
emitter.on('start', function (stats) {
@@ -541,13 +541,13 @@ package.properties = function (dir) {
name: 'name',
unique: true,
message: 'App name',
validator: /[\w|\-]+/,
validator: /^[\w|\-]+$/,
default: path.basename(dir)
},
{
name: 'subdomain',
unique: true,
validator: /[\w|\-|\_]+/,
validator: /^[\w|\-|\_]+$/,
help: [
'',
'The ' + 'subdomain '.grey + 'is where the app will reside',
@@ -644,7 +644,7 @@ package.available = function (pkg, dir, callback, createPackage) {
} else {
callback(null, pkg);
}

});
}
// only subdomain is taken
@@ -667,9 +667,9 @@ package.available = function (pkg, dir, callback, createPackage) {
} else {
callback(null, pkg);
}

});

}
} else { //nothing is wrong
callback(null, pkg);
@@ -718,7 +718,7 @@ function tryAnalyze (target, dir, callback) {
if (target.analyzed) {
return callback(null, target);
}

var noanalyze = !((jitsu.config.get('analyze') === 'true')
|| (jitsu.config.get('analyze') === true))
|| ((jitsu.config.get('noanalyze') === 'true')
@@ -737,8 +737,8 @@ function tryAnalyze (target, dir, callback) {
}

target.analyzed = true;
return updates
? package.write(addedDeps, dir, true, callback)
return updates
? package.write(addedDeps, dir, true, callback)
: callback(null, addedDeps);
});
}
@@ -757,12 +757,12 @@ function policeDependencies (pkg) {

function fillPackage (base, dir, callback) {
base = base || {};
var subdomain, descriptors, missing;
missing = ['name', 'subdomain', 'version'].filter(function (prop) {
return !base[prop]
var subdomain, descriptors, missing;

missing = ['name', 'subdomain', 'version'].filter(function (prop) {
return !base[prop]
});

if (!(base.scripts && base.scripts.start)) {
missing.push('scripts.start');
}

0 comments on commit 1b86ef0

Please sign in to comment.
You can’t perform that action at this time.