Skip to content

Commit

Permalink
Merge pull request #401 from nodejitsu/no-spaces
Browse files Browse the repository at this point in the history
[fix] Validate package.json properties as a whole word
  • Loading branch information
julianduque committed Mar 7, 2013
2 parents ccfc2d9 + 25d3c0b commit 1b86ef0
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions lib/jitsu/package.js
Expand Up @@ -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);
});
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
});
Expand All @@ -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);
Expand All @@ -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);
});
});

});
};

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -644,7 +644,7 @@ package.available = function (pkg, dir, callback, createPackage) {
} else {
callback(null, pkg);
}

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

});

}
} else { //nothing is wrong
callback(null, pkg);
Expand Down Expand Up @@ -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')
Expand All @@ -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);
});
}
Expand All @@ -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');
}
Expand Down

0 comments on commit 1b86ef0

Please sign in to comment.