Skip to content

Commit

Permalink
#12 - Manage the deprecated syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
carloshpds committed Jan 9, 2016
1 parent e285bca commit 3709d45
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 33 deletions.
12 changes: 9 additions & 3 deletions dist/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ var ConfigModule = function() {
/*
* Required resources
*/
var defaultOptions = require('./defaults.js')();
var chalk = require('chalk');
var _ = require('lodash');
var defaultOptions = require('./defaults.js')(),
chalk = require('chalk'),
_ = require('lodash')
migrateModule = null ;



Expand All @@ -24,11 +25,16 @@ var ConfigModule = function() {
* @return {Object} user options, merged with default options and analyzed by necessary files
*/
function setup (options) {
var userOptions = options;
options = mergeWithDefaultOptions(options);

// Set default options in global options to never require ./defaults.js more than once
options.defaultOptions = defaultOptions;

migrateModule = require('./migrate.js')(userOptions, options);
migrateModule.setup();
migrateModule.migrate();

return options;
}

Expand Down
7 changes: 7 additions & 0 deletions dist/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ module.exports = function(){
}


// Migrate properties
defaultOptions.migrate = {
active : true,
trace: false
}


return defaultOptions;

}
94 changes: 79 additions & 15 deletions dist/config/migrate.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,106 @@


/**
* Basebuild config module, to setup everything before start working
* Basebuild migrate module, to prevent
*/
var MigrateModule = function(options) {
var options = options || null;
var MigrateModule = function(options, mergedOptions) {
var options = options || null,
utilsModule = require('../' + mergedOptions.modulesData['utils'].uses)(options),
mergedOptions = mergedOptions || null,
warnedAbout = {},
migrateWarnings = [],
$ = mergedOptions.plugins;


function setup (mergedOptions) {
options = mergedOptions;
var migrateMessages = {
soon : '($dotLocation) and will be removed soon',
soonTo : '($dotLocation) and will be removed soon, use $newValue instead',
removed : '($dotLocation) has been removed',
removedTo : '($dotLocation) has been removed, use $newValue instead',
};


function setup () {
}

function readDotNotation (property) {
properties = property.split('.');

for (var i = 0; i < properties.length; i++) {
properties[i];
};
function setMergedOptions(mergedOptions){
mergedOptions = mergedOptions;
}


function migrate() {
migrateWarnProp({
obj : mergedOptions.modulesData['scripts'],
prop : 'isEnabled',
msg : getMessage({
type : 'soonTo',
dotLocation : 'modulesData.scripts',
newValue : 'active'
})
});
}


function getMessage (args) {
args = args || {};
var message = migrateMessages[args.type];

for(key in args){
message = message.replace('$' + key, $.chalk.red(args[key]) );
}

return message;
}


function migrateWarn(msg, prop) {
if ( !warnedAbout[ msg ] ) {
warnedAbout[ msg ] = true;
migrateWarnings.push( msg );
if ( console && console.warn ) {
console.warn( utilsModule.getBaseBuildName() + $.chalk.yellow( "Migrate warning: " + $.chalk.red(prop) + " is deprecated " + msg) );
if ( mergedOptions.migrate.trace && console.trace ) {
console.trace();
}
}
}
}

function migrateWarnProp( args ) {
if ( Object.defineProperty ) {
try {
Object.defineProperty( args.obj, args.prop, {
configurable: true,
enumerable: true,
get: function() {
migrateWarn( args.msg, args.prop );
return args.value;
},
set: function( newValue ) {
migrateWarn( args.msg, args.prop );
args.value = newValue;
}
});
return;
} catch( err ) {
// IE8 is a dope about Object.defineProperty, can't warn there
}
}

function migrateFrom (from, to) {

obj[ args.prop ] = args.value;
}


/**
* API
*/
return {
defaultOptions : defaultOptions,
setMergedOptions : setMergedOptions,
setup : setup,
mergeWithDefaultOptions : mergeWithDefaultOptions
migrate : migrate,
migrateWarn : migrateWarn,
migrateWarnProp : migrateWarnProp,
getMessage : getMessage
}
}

Expand Down
28 changes: 13 additions & 15 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,7 @@ var gutil = require('gulp-util');


var basebuildMainScript = function(options){


/**
* Config phase
*/
var configModule = require('./config/config.js')();
options = configModule.setup(options);
var defaultOptions = options.defaultOptions;



/**
* Utils
*/
var baseBuildUtils = require(defaultOptions.modulesData['utils'].uses)(options);
var baseBuildName = baseBuildUtils.getBaseBuildName();
var packageJSON = require('../package.json');

/*
Expand All @@ -37,6 +22,19 @@ var basebuildMainScript = function(options){
console.log(' ' + chalk.red(' |___/ ' + chalk.green('v' + packageJSON.version)) );
console.log('\n\n');

/**
* Config phase
*/
var configModule = require('./config/config.js')();
options = configModule.setup(options);
var defaultOptions = options.defaultOptions;

/**
* Utils
*/
var baseBuildUtils = require(defaultOptions.modulesData['utils'].uses)(options);
var baseBuildName = baseBuildUtils.getBaseBuildName();

/*
==========================
Read gulp files
Expand Down

0 comments on commit 3709d45

Please sign in to comment.