Skip to content

Commit

Permalink
#114 print bundles info in lmd-info(); print name conflicts;
Browse files Browse the repository at this point in the history
#162 Do not stream styles and scripts If they are not defined
  • Loading branch information
azproduction committed Dec 12, 2013
1 parent 601bcc8 commit d36a2bb
Show file tree
Hide file tree
Showing 45 changed files with 2,066 additions and 1,285 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -138,4 +138,5 @@
**v1.11.x**

- `styles` - styles builder. See [demo](http://lmdjs.org/examples/features/styles/), [code](examples/features/styles/)
- default bundle separator replaced from `-bundle-` to `.`
- default bundle separator changed from `-bundle-` to `.`
- empty styles and scripts will not be printed into file
46 changes: 43 additions & 3 deletions Makefile
Expand Up @@ -4,26 +4,51 @@ MOCHA = $(BIN)/mocha

all: test

test: build_test
test: test_plugins test_builder build_examples

test_builder:
@echo 'travis_fold:start:test_builder'
$(MOCHA) -u bdd -R spec --recursive test/build
@echo 'travis_fold:end:test_builder'

test_plugins: build_test
@echo 'travis_fold:start:test_plugins'
@node ./test/qunit/run-test.js
@echo 'travis_fold:end:test_plugins'

build_test:
@echo 'travis_fold:start:build_test'
@cd test/qunit; node $(LMD_BUILD) build test
@cd test/qunit; node $(LMD_BUILD) build node_test
@cd test/qunit; node $(LMD_BUILD) build worker_test
@cd test/qunit; node $(LMD_BUILD) build promise_test
@echo 'travis_fold:end:build_test'

build_stats:
@cd test/qunit; node $(LMD_BUILD) build test --stats_auto --stats --stats_sendto
@cd test/qunit; node $(LMD_BUILD) build node_test
@cd test/qunit; node $(LMD_BUILD) build worker_test
@cd test/qunit; node $(LMD_BUILD) build promise_test

# This is smoke test
build_examples:
@echo 'travis_fold:start:smoke'
# Features
@cd examples/features/adaptation; node ../$(LMD_BUILD) build index
@cd examples/features/bundles; node ../$(LMD_BUILD) build index
@cd examples/features/depends; node ../$(LMD_BUILD) build index
@cd examples/features/extends; node ../$(LMD_BUILD) build dev
@cd examples/features/glob; node ../$(LMD_BUILD) build index
@cd examples/features/ignore_module; node ../$(LMD_BUILD) build ignoring
@cd examples/features/interpolation; node ../$(LMD_BUILD) build index
@cd examples/features/mixins; node ../$(LMD_BUILD) build index
@cd examples/features/lmdjs_configs; node ../$(LMD_BUILD) build index
@cd examples/features/mixins; node ../$(LMD_BUILD) build index+prod+ru --output=index-prod.ru.js
@cd examples/features/multi_module; node ../$(LMD_BUILD) build index
@cd examples/features/optimize; node ../$(LMD_BUILD) build index
@cd examples/features/sandbox; node ../$(LMD_BUILD) build index
@cd examples/features/styles; node ../$(LMD_BUILD) build index

# Plugins
@cd examples/plugins/amd; node ../$(LMD_BUILD) build index
@cd examples/plugins/async; node ../$(LMD_BUILD) build index
@cd examples/plugins/async_plainonly; node ../$(LMD_BUILD) build index
Expand All @@ -32,12 +57,27 @@ build_examples:
@cd examples/plugins/css; node ../$(LMD_BUILD) build index
@cd examples/plugins/image; node ../$(LMD_BUILD) build index
@cd examples/plugins/js; node ../$(LMD_BUILD) build index
@cd examples/plugins/match; node ../$(LMD_BUILD) build index
@cd examples/plugins/node; node ../$(LMD_BUILD) build index
@cd examples/plugins/parallel; node ../$(LMD_BUILD) build index
@cd examples/plugins/preload; node ../$(LMD_BUILD) build index
@cd examples/plugins/promise; node ../$(LMD_BUILD) build index
@cd examples/plugins/stats; node ../$(LMD_BUILD) build index
@cd examples/plugins/stats_coverage; node ../$(LMD_BUILD) build index
@cd examples/plugins/user_plugins; node ../$(LMD_BUILD) build index

# Demos
@cd examples/demos/backbone_lmd; node ../$(LMD_BUILD) build dev
@cd examples/demos/backbone_lmd; node ../$(LMD_BUILD) build dev-cache
@cd examples/demos/basic; node ../$(LMD_BUILD) build index.development
@cd examples/demos/basic; node ../$(LMD_BUILD) build index.production
@cd examples/demos/getting_started; node ../$(LMD_BUILD) build index
@cd examples/demos/getting_started; node ../$(LMD_BUILD) build index+ru
@cd examples/demos/mock_chat/js/amd; node ../../../$(LMD_BUILD) build index
@cd examples/demos/mock_chat/js/lmd; node ../../../$(LMD_BUILD) build index
@cd examples/demos/mock_chat/js/lmd_cache; node ../../../$(LMD_BUILD) build index
@echo 'travis_fold:end:smoke'

coverage: build_test
rm -rf coverage/*
jscoverage --exclude=modules --exclude=vendors --exclude=mock ./test/qunit ./test/coverage
Expand All @@ -57,4 +97,4 @@ run_stats:
help:
@echo "USAGE:\n\tmake\n\tmake test\ntmake coverage\n\tmake run_qunit\n\tmake run_coverage"

.PHONY: all test clean test_builder
.PHONY: all test clean test_builder test_plugins
168 changes: 124 additions & 44 deletions bin/lmd_actions/info.js
Expand Up @@ -80,27 +80,30 @@ function printValue(value) {
return value;
}

function printModules(cli, config, deepModulesInfo, sortColumnName) {
var modules = config.modules || {};

var modulesNames = Object.keys(modules);
function printModules(cli, config, deepModulesInfo, conflicts, sortColumnName) {
var modulesCount = 0;
var bundles = common.groupModulesByBundles(config);
common.iterateModulesInfo(bundles, function () {
modulesCount++;
});

if (!modulesNames.length) {
if (!modulesCount) {
return;
}

cli.ok(('Modules (' + modulesNames.length + ')').white.bold.underline);
cli.ok(('Modules (' + modulesCount + ')').white.bold.underline);
cli.ok('');

var headers = ['name', 'depends', 'type', 'lazy', 'greedy', 'coverage', 'sandbox'];
var headers = ['name', 'depends', 'type', 'lazy', 'greedy', 'coverage', 'sandbox', 'bundle'];

var columnLengths = headers.map(function (item) {
return item.length;
});

var moduleRows = modulesNames.map(function (moduleName) {
var module = modules[moduleName],
moduleExtra = deepModulesInfo[moduleName];
var moduleRows = [];

common.iterateModulesInfo(bundles, function (module, moduleName, bundleName) {
var moduleExtra = deepModulesInfo[bundleName][moduleName];

if (moduleName.length > columnLengths[0]) {
columnLengths[0] = moduleName.length;
Expand All @@ -114,15 +117,16 @@ function printModules(cli, config, deepModulesInfo, sortColumnName) {
columnLengths[2] = moduleExtra.type.length;
}

return [
return moduleRows.push([
moduleName,
module.depends ? module.depends : false,
moduleExtra.type,
!!module.is_lazy,
!!module.is_greedy,
!!module.is_coverage,
!!module.is_sandbox
];
!!module.is_sandbox,
bundleName === common.ROOT_BUNDLE_ID ? false : bundleName
]);
});

var sortColumnIndex = headers.indexOf(sortColumnName);
Expand Down Expand Up @@ -158,7 +162,11 @@ function printModules(cli, config, deepModulesInfo, sortColumnName) {
}

if (!index && rowIndex) {
item = item.cyan;
if (item in conflicts) {
item = item.yellow;
} else {
item = item.cyan;
}
}

// type=not-found
Expand Down Expand Up @@ -236,43 +244,62 @@ function printFlags(cli, config, availableFlags) {
cli.ok('');
}

function printModulePathsAndDepends(cli, config, deepModulesInfo, isDeepAnalytics) {
var modules = config.modules || {},
modulesNames = Object.keys(modules),
globalsNames = common.getGlobals(config);
function printModulePathsAndDepends(cli, config, deepModulesInfo, conflicts, isDeepAnalytics) {
var modulesCount = 0,
longestName = 0,
modulesNames = [];

var bundles = common.groupModulesByBundles(config);

if (!modulesNames.length) {
common.iterateModulesInfo(bundles, function (module, name) {
modulesCount++;
if (longestName < name.length) {
longestName = name.length;
}
modulesNames.push(name);
});

var globalsNames = common.getGlobals(config);

if (!modulesCount) {
return;
}

cli.ok('Module Paths, Depends and Features'.white.bold.underline);
cli.ok('');

var longestName = modulesNames.reduce(function (max, name) {
return max < name.length ? name.length : max;
}, 0);

modulesNames.forEach(function (name) {
var moduleShortPadding = new Array(longestName - name.length + 2).join(' '),
modulePath = [].concat(modules[name].path);
common.iterateModulesInfo(bundles, function (module, moduleName, bundleName) {
var moduleShortPadding = new Array(longestName - moduleName.length + 2).join(' '),
modulePath = [].concat(module.path);

var moduleLongPadding = new Array(name.length + 5).join(' ') + moduleShortPadding;
var moduleLongPadding = new Array(moduleName.length + 5).join(' ') + moduleShortPadding;

if (modules[name].is_exists) {
if (module.is_exists) {
modulePath.forEach(function (modulePath, index) {
var moduleInfo;
if (moduleName in conflicts) {
modulePath = modulePath.yellow;
} else {
modulePath = modulePath.green;
}

if (!index) {
moduleInfo = name.cyan + moduleShortPadding + ' <- ' + modulePath.green;
moduleInfo = moduleName.cyan + moduleShortPadding + ' <- ' + modulePath;
} else {
moduleInfo = moduleLongPadding + modulePath.green;
moduleInfo = moduleLongPadding + modulePath;
}

if (moduleName in conflicts) {
cli.ok(moduleInfo + ' (name conflict)');
} else {
cli.ok(moduleInfo);
}
cli.ok(moduleInfo);
});
} else {
modulePath.forEach(function (modulePath, index) {
var moduleInfo;
if (!index) {
moduleInfo = name.cyan + moduleShortPadding + ' <- ' + modulePath.red;
moduleInfo = moduleName.cyan + moduleShortPadding + ' <- ' + modulePath.red;
} else {
moduleInfo = moduleLongPadding + modulePath.red;
}
Expand All @@ -282,7 +309,7 @@ function printModulePathsAndDepends(cli, config, deepModulesInfo, isDeepAnalytic
if (!isDeepAnalytics) {
return;
}
var depends = deepModulesInfo[name].depends;
var depends = deepModulesInfo[bundleName][moduleName].depends;
if (depends.length) {
depends.forEach(function (name) {
var moduleType = common.discoverModuleType(name, modulesNames, globalsNames);
Expand All @@ -297,16 +324,69 @@ function printModulePathsAndDepends(cli, config, deepModulesInfo, isDeepAnalytic
cli.ok(' +-' + name.toString().yellow + ' (' + moduleType + ')');
}
});

cli.ok('');
}
var features = Object.keys(deepModulesInfo[name].features);
var features = Object.keys(deepModulesInfo[bundleName][moduleName].features);
if (features.length) {
cli.ok(' ' + 'Uses'.green + ': ' + features.join(', '));
cli.ok('');
}
});

// modulesNames.forEach(function (name) {
// var moduleShortPadding = new Array(longestName - name.length + 2).join(' '),
// modulePath = [].concat(modules[name].path);
//
// var moduleLongPadding = new Array(name.length + 5).join(' ') + moduleShortPadding;
//
// if (modules[name].is_exists) {
// modulePath.forEach(function (modulePath, index) {
// var moduleInfo;
// if (!index) {
// moduleInfo = name.cyan + moduleShortPadding + ' <- ' + modulePath.green;
// } else {
// moduleInfo = moduleLongPadding + modulePath.green;
// }
// cli.ok(moduleInfo);
// });
// } else {
// modulePath.forEach(function (modulePath, index) {
// var moduleInfo;
// if (!index) {
// moduleInfo = name.cyan + moduleShortPadding + ' <- ' + modulePath.red;
// } else {
// moduleInfo = moduleLongPadding + modulePath.red;
// }
// cli.error(moduleInfo + ' (not exists)');
// });
// }
// if (!isDeepAnalytics) {
// return;
// }
// var depends = deepModulesInfo[name].depends;
// if (depends.length) {
// depends.forEach(function (name) {
// var moduleType = common.discoverModuleType(name, modulesNames, globalsNames);
// switch (moduleType) {
// case 'in-package':
// cli.ok(' +-' + name.toString().cyan);
// break;
// case 'global':
// cli.ok(' +-' + name.toString().cyan + ' (' + moduleType + ')');
// break;
// default:
// cli.ok(' +-' + name.toString().yellow + ' (' + moduleType + ')');
// }
// });
//
// cli.ok('');
// }
// var features = Object.keys(deepModulesInfo[name].features);
// if (features.length) {
// cli.ok(' ' + 'Uses'.green + ': ' + features.join(', '));
// cli.ok('');
// }
// });

cli.ok('');
}

Expand Down Expand Up @@ -486,9 +566,11 @@ module.exports = function (cli, argv, cwd) {
cli.ok('');
}

var deepModulesInfo = common.collectModulesInfo(config);
printModules(cli, config, deepModulesInfo, sortOrder);
printModulePathsAndDepends(cli, config, deepModulesInfo, isDeepAnalytics);
var deepModulesInfo = common.collectModulesInfo(config),
conflicts = common.getSuspiciousNames(config, deepModulesInfo).conflicts;

printModules(cli, config, deepModulesInfo, conflicts, sortOrder);
printModulePathsAndDepends(cli, config, deepModulesInfo, conflicts, isDeepAnalytics);
printStyles(cli, config);
printUserPlugins(cli, config);
printFlags(cli, config, flags.concat(extraFlags));
Expand All @@ -514,11 +596,9 @@ module.exports = function (cli, argv, cwd) {
var errors = config.errors;

// pipe warnings
for (var noduleName in deepModulesInfo) {
deepModulesInfo[noduleName].warns.forEach(function (warning) {
errors.push(warning);
});
}
common.iterateModulesInfo(deepModulesInfo, function (info) {
errors.push.apply(errors, info.warns)
});

errors = errors.concat(common.collectFlagsWarnings(config, deepModulesInfo));

Expand Down

0 comments on commit d36a2bb

Please sign in to comment.