Skip to content

Commit

Permalink
Merge pull request #17 from jasonmit/locale-mismatch
Browse files Browse the repository at this point in the history
warn on locale mismatch
  • Loading branch information
jasonmit committed Aug 23, 2015
2 parents d2e4f52 + d73d145 commit 7eeb081
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
31 changes: 24 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var defaults = require('lodash.defaults');
var rename = require('broccoli-stew').rename;
var existsSync = require('exists-sync');
var chalk = require('chalk');

module.exports = {
name: 'moment',
Expand All @@ -18,6 +20,7 @@ module.exports = {
}

this.app = app;
this.options = this.getConfig();
this.importDependencies(app);
},

Expand All @@ -27,7 +30,7 @@ module.exports = {
}

var vendor = this.treePaths.vendor;
var options = this.getConfig();
var options = this.options;

if (options.includeTimezone) {
app.import(path.join(vendor, 'moment-timezone', 'tz.js'), { prepend: true });
Expand All @@ -48,8 +51,10 @@ module.exports = {

getConfig: function() {
var projectConfig = ((this.project.config(process.env.EMBER_ENV) || {}).moment || {});
var momentPath = path.join(this.project.bowerDirectory, 'moment');

var config = defaults(projectConfig, {
momentPath: momentPath,
includeTimezone: null,
includeLocales: []
});
Expand All @@ -59,6 +64,18 @@ module.exports = {
return typeof locale === 'string';
}).map(function(locale) {
return locale.replace('.js', '').trim().toLowerCase();
}).filter(function(locale) {
if (locale === 'en') {
// `en` is included by default. quietly ignore if user specifies it in the list
return false;
}

if (!existsSync(path.join(momentPath, 'locale', locale + '.js'))) {
console.log(chalk.red('ember-moment: Specified locale `' + locale + '` but could not find in moment/locale.\nVisit https://github.com/moment/moment/tree/master/locale to view the full list of supported locales.'));
return false;
}

return true;
});
}

Expand All @@ -67,15 +84,13 @@ module.exports = {

treeForVendor: function(vendorTree) {
var trees = [];
var options = this.getConfig();
var options = this.options;

if (vendorTree) {
trees.push(vendorTree);
}

var momentPath = path.join(this.project.bowerDirectory, 'moment');

trees.push(new Funnel(momentPath, {
trees.push(new Funnel(options.momentPath, {
destDir: 'moment',
include: [new RegExp(/\.js$/)],
exclude: ['tests', 'ender', 'package'].map(function(key) {
Expand All @@ -84,13 +99,15 @@ module.exports = {
}));

if (Array.isArray(options.includeLocales) && options.includeLocales.length) {
trees.push(new Funnel(momentPath, {
var localeTree = new Funnel(options.momentPath, {
srcDir: 'locale',
destDir: path.join('moment', 'locales'),
include: options.includeLocales.map(function(locale) {
return new RegExp(locale + '.js$');
})
}));
});

trees.push(localeTree);
}

if (options.includeTimezone) {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-cli-moment-shim",
"version": "0.6.1",
"version": "0.6.2",
"description": "Brings moment and moment-timezone into your Ember applications",
"scripts": {
"start": "ember server",
Expand All @@ -24,7 +24,9 @@
"broccoli-funnel": "^0.2.3",
"broccoli-merge-trees": "^0.2.1",
"broccoli-stew": "^0.3.3",
"chalk": "^1.1.1",
"ember-cli-babel": "^5.0.0",
"exists-sync": "0.0.3",
"lodash.defaults": "^3.1.2"
},
"devDependencies": {
Expand Down

0 comments on commit 7eeb081

Please sign in to comment.