Skip to content

Commit

Permalink
Remove remaining uses of sails-util, RIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sgress454 committed Nov 2, 2016
1 parent f131ab6 commit 1fee468
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 57 deletions.
9 changes: 0 additions & 9 deletions lib/app/Sails.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,5 @@ Sails.prototype.toJSON = require('./private/toJSON');
// Controller
Sails.prototype.initializeController = require('./private/controller');

// Utilities
// Includes lodash, node's `util`, and a few additional
// static helper methods.
// (may be deprecated in a future release)
Sails.prototype.util = require('sails-util');




// Expose Sails constructor
module.exports = Sails;
19 changes: 8 additions & 11 deletions lib/app/configuration/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var _ = require('lodash');
var async = require('async');
var CaptainsLog = require('captains-log');
var path = require('path');
var fs = require('fs');


module.exports = function(sails) {
Expand Down Expand Up @@ -104,17 +105,13 @@ module.exports = function(sails) {
versionAndDependencyInfo: function(cb) {

var pathToThisVersionOfSails = path.join(__dirname, '../../..');
sails.util.getPackage(pathToThisVersionOfSails, function(err, json) {
if (err) return cb(err);

sails.version = json.version;
sails.majorVersion = sails.version.split('.')[0].replace(/[^0-9]/g, '');
sails.minorVersion = sails.version.split('.')[1].replace(/[^0-9]/g, '');
sails.patchVersion = sails.version.split('.')[2].replace(/[^0-9]/g, '');
sails.dependencies = json.dependencies;

cb();
});
var json;
try {
json = JSON.parse(fs.readFileSync(path.resolve(pathToThisVersionOfSails, 'package.json'), 'utf8'));
} catch (e) {
return cb(e);
}
cb();
},


Expand Down
3 changes: 1 addition & 2 deletions lib/app/private/controller/load-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
var path = require('path');
var _ = require('lodash');
var includeAll = require('include-all');
var sailsUtil = require('sails-util');

module.exports = function (results, cb) {

Expand Down Expand Up @@ -55,7 +54,7 @@ module.exports = function (results, cb) {
if (match) {
// If it looks like a traditional controller, but it's not a dictionary,
// throw it in the can.
if (!sailsUtil.isDictionary(module)) {
if (!_.isObject(module) || _.isArray(module) || _.isFunction(module)) {
return garbage.push(filePath);
}
// Get the controller identity (e.g. /somefolder/somecontroller)
Expand Down
35 changes: 22 additions & 13 deletions lib/app/private/isLocalSailsValid.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

var fs = require('fs');
var CaptainsLog = require('captains-log');
var sailsutil = require('sails-util');
var semver = require('semver');
var Err = require('../../../errors');

Expand All @@ -21,20 +20,30 @@ module.exports = function isLocalSailsValid(sailsPath, appPath) {

var sails = this;

var appPackageJSON, appDependencies;

// Has no package.json file
if (!fs.existsSync(appPath + '/package.json')) {
Err.warn.noPackageJSON();
}
else {
// Load this app's package.json and dependencies
try {
appPackageJSON = JSON.parse(fs.readFileSync(path.resolve(appPath, 'package.json'), 'utf8'));
} catch (e) {
Err.warn.notSailsApp();
return;
}

// Load this app's package.json and dependencies
var appPackageJSON = sailsutil.getPackageSync(appPath);
var appDependencies = appPackageJSON.dependencies;
appDependencies = appPackageJSON.dependencies;


// Package.json exists, but doesn't list Sails as a dependency
if (!(appDependencies && appDependencies.sails)) {
Err.warn.notSailsApp();
return;
// Package.json exists, but doesn't list Sails as a dependency
if (!(appDependencies && appDependencies.sails)) {
Err.warn.notSailsApp();
return;
}

}

// Ensure the target Sails exists
Expand All @@ -43,15 +52,15 @@ module.exports = function isLocalSailsValid(sailsPath, appPath) {
}

// Read the package.json in the local installation of Sails
var sailsPackageJSON = sailsutil.getPackageSync(sailsPath);

// Local Sails has a corrupted package.json
if (!sailsPackageJSON) {
var sailsPackageJSON;
try {
sailsPackageJSON = JSON.parse(fs.readFileSync(path.resolve(sailsPath, 'package.json'), 'utf8'));
} catch (e) {
// Local Sails has a missing or corrupted package.json
Err.warn.badLocalDependency(sailsPath, appDependencies.sails);
return;
}


// Lookup sails dependency requirement in app's package.json
var requiredSailsVersion = appDependencies.sails;

Expand Down
13 changes: 8 additions & 5 deletions lib/app/private/isSailsAppSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
* Module dependencies
*/

var fs = require('fs'),
path = require('path'),
sailsutil = require('sails-util');

var fs = require('fs');
var path = require('path');


/**
Expand All @@ -22,7 +20,12 @@ module.exports = function isSailsAppSync(appPath) {
}

// Package.json exists, but doesn't list Sails as a dependency
var appPackageJSON = sailsutil.getPackageSync(appPath);
var appPackageJSON;
try {
appPackageJSON = JSON.parse(fs.readFileSync(path.resolve(appPath, 'package.json'), 'utf8'));
} catch (e) {
return false;
}
var appDependencies = appPackageJSON.dependencies;
if (!(appDependencies && appDependencies.sails)) {
return false;
Expand Down
4 changes: 0 additions & 4 deletions lib/hooks/policies/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _ = require('lodash');
var util = require('sails-util');
var Err = require('../../../errors');

module.exports = function(sails) {
Expand All @@ -26,9 +25,6 @@ module.exports = function(sails) {
*/
initialize: function(cb) {

// Callback is optional
cb = util.optional(cb);

// Grab policies config & policy modules and trigger callback
this.loadMiddleware(function (err) {
if (err) { return cb(err); }
Expand Down
14 changes: 3 additions & 11 deletions lib/hooks/request/locals.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
/**
* Module dependencies
*/
var _ = require('lodash'),
util = require('sails-util');

var _ = require('lodash');

/**
* default locals
*
* Always share some basic metadata with views.
* Roughly analogous to `app.locals` in Express.
*
*
* > Application local variables are provided to all templates rendered
* > within the application. This is useful for providing helper functions
* > to templates, as well as app-level data.
* >
* > http://expressjs.com/api.html#app.locals
*
*
* @param {Request} req
* @param {Response} res
* @api private
Expand All @@ -35,16 +33,10 @@ module.exports = function _mixinLocals(req, res) {

_.extend(res.locals, {
_: _,
util: util,
session: req.session,
req: req,
res: res,
sails: req._sails
});

// May be deprecated in an upcoming release:
res.locals.title = req._sails.config.appName;
if (req.options.action) {
' | ' + util.str.capitalize(req.param('action'));
}
};
1 change: 0 additions & 1 deletion lib/hooks/security/csrf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = function(sails) {
*/

var _ = require('lodash');
var util = require('sails-util');
var pathToRegexp = require('path-to-regexp');

var grantCsrfToken = require('./grant-csrf-token');
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"sails-hook-orm": "~1.0.6",
"sails-hook-sockets": "^1.0.0",
"sails-stringfile": "~0.3.2",
"sails-util": "~0.11.0",
"semver": "4.3.6",
"serve-favicon": "2.3.0",
"serve-static": "1.10.2",
Expand Down

0 comments on commit 1fee468

Please sign in to comment.