Skip to content

Commit

Permalink
Merge pull request #419 from adamwdraper/develop
Browse files Browse the repository at this point in the history
2.0.2
  • Loading branch information
adamwdraper authored Dec 17, 2016
2 parents 8c0760b + 257e852 commit 45fa585
Show file tree
Hide file tree
Showing 127 changed files with 1,081 additions and 2,865 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ Icon
# --------------------
node_modules/
.sass-cache
temp/
150 changes: 92 additions & 58 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
var fs = require('fs');

module.exports = function(grunt) {

var minifiedFiles = {
'min/numeral.min.js' : [
'numeral.js'
],
'min/locales.min.js': [
'locales.js'
],
'min/numeral-with-locales.min.js': [
'numeral-with-locales.js'
]
};
var compileType = function() {
var type = this.data.type;
var template = grunt.file.read('templates/types.js');
var anon = grunt.file.read('templates/anon.js');
var files = grunt.file.expand([
'src/' + type + '/*.js'
]);
var regexp = /\}\(this, function \(numeral\) \{\s([\s\S]+)(?:\s\}\)\);)/;
var content = '';
var file;
var i;

// all the lang files need to be added manually
fs.readdirSync('./src/locales').forEach(function (path) {
var file = path.slice(0, -3),
destination = 'min/locales/' + file + '.min.js',
src = ['src/locales/' + path];
for (i = 0; i < files.length; i++) {
file = grunt.file.read(files[i]);

minifiedFiles[destination] = src;
});
content += '\n' + grunt.template.process(anon, {
data: {
content: file.match(regexp)[1]
}
}) + '\n';
}

grunt.file.write('temp/' + type + '.js', content);

if (type === 'locales') {
grunt.file.write('locales.js', grunt.template.process(template, {
data: {
type: type,
content: content
}
}));
}
},
compileNumeral = function() {
var regexp = /([\s])return numeral;(?:\s\}\)\);)/;
var numeral = grunt.file.read('src/numeral.js');
var formats = grunt.file.read('temp/formats.js');
var index = numeral.indexOf('return numeral;');

numeral = numeral.substr(0, index) + '\n' + formats + numeral.substr(index);

grunt.file.write('numeral.js', numeral);
};

grunt.initConfig({
mochaTest : {
Expand All @@ -34,9 +55,8 @@ module.exports = function(grunt) {
karma: {
options: {
files: [
'src/numeral.js',
'src/formats/*.js',
'src/locales/*.js',
'numeral.js',
'locales.js',
'tests/numeral.js',
'tests/formats/*.js',
'tests/locales/*.js'
Expand All @@ -58,35 +78,39 @@ module.exports = function(grunt) {
configFile: 'karma-ci.conf.js'
}
},
uglify: {
my_target: {
files: minifiedFiles
compile: {
locales: {
type: 'locales'
},
options: {
preserveComments: 'some'
formats: {
type: 'formats'
}
},
concat: {
numeral: {
src: [
'src/numeral.js',
'src/formats/*.js'
],
dest: 'numeral.js'
},
locales: {
src: [
'src/locales/*.js'
],
dest: 'locales.js'
uglify: {
min: {
files: [
{
expand: true,
cwd: 'src/',
src: [
'locales/*.js'
],
dest: 'min/',
ext: '.min.js'
},
{
expand: true,
src: [
'numeral.js',
'locales.js'
],
dest: 'min/',
ext: '.min.js'
}
]
},
numeralWithLocales: {
src: [
'src/numeral.js',
'src/formats/*.js',
'src/locales/*.js'
],
dest: 'numeral-with-locales.js'
options: {
preserveComments: 'some'
}
},
jshint: {
Expand All @@ -103,50 +127,60 @@ module.exports = function(grunt) {
'eqnull': true,
'newcap': true,
'noarg': true,
'onevar': true,
'undef': true,
'sub': true,
'strict': false,
'quotmark': 'single'
'quotmark': 'single',
'globals': {
'define': true
}
}
}
});

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-karma');

grunt.registerTask('default', [
'test'
]);

grunt.registerTask('test', [
grunt.registerMultiTask('compile', compileType);

grunt.registerTask('compile:numeral', compileNumeral);

grunt.registerTask('build', [
'jshint',
'compile',
'compile:numeral'
]);

grunt.registerTask('test', [
'build',
'mochaTest',
'karma:local'
]);

grunt.registerTask('test:npm', [
'jshint',
'build',
'mochaTest'
]);

grunt.registerTask('test:browser', [
'jshint',
'build',
'karma:local'
]);

// P
grunt.registerTask('build', [
'concat',
grunt.registerTask('dist', [
'build',
'uglify'
]);

// Travis CI task.
grunt.registerTask('travis', [
'jshint',
'build',
'mochaTest',
'karma:ci'
]);
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Develop [![Build Status](https://travis-ci.org/adamwdraper/Numeral-js.svg?branch

# Contributing

#### Important: Please create your branch from and submit pull requests to the `develop` branch.
#### Important: Please create your branch from and submit pull requests to the `develop` branch. All pull requests must include the appropriate tests.

1. Fork the library

Expand All @@ -35,11 +35,16 @@ Develop [![Build Status](https://travis-ci.org/adamwdraper/Numeral-js.svg?branch

6. To test your tests, run `grunt`

7. When all your tests are passing, run `grunt build` to minify all files
7. When all your tests are passing, run `grunt dist` to compile and minify all files

8. Submit a pull request to the `develop` branch.


### Formats

Formats now exist in their own files and act more or less as plugins. Check out the [bytes format](https://github.com/adamwdraper/Numeral-js/blob/master/src/formats/bytes.js) for an example of how to create one.


### Locales

When naming locale files use the [ISO 639-1 language codes](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) supplemented by [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes when necessary.
Expand All @@ -51,6 +56,10 @@ See [the english unit tests](https://github.com/adamwdraper/Numeral-js/blob/mast

# Changelog

### 2.0.2

Bug fix: Updated module definitions

### 2.0.1

Bug fix: Fixed regression for webpack/browserify/rollup
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "numeral",
"repo": "adamwdraper/Numeral-js",
"version": "2.0.1",
"version": "2.0.2",
"description": "Format and manipulate numbers.",
"keywords": [
"numeral",
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "numeral",
"repo": "adamwdraper/Numeral-js",
"version": "2.0.1",
"version": "2.0.2",
"description": "Format and manipulate numbers.",
"keywords": [
"numeral",
Expand Down
Loading

0 comments on commit 45fa585

Please sign in to comment.