Skip to content

Commit

Permalink
Add comment on top of moment-with-locales.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ichernev committed Jun 15, 2016
1 parent 3ec23a5 commit 89fa774
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions tasks/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@ module.exports = function (grunt) {
var Promise = require('es6-promise').Promise;
var TMP_DIR = 'build/tmp';

function moveComments(code) {
var comments = [], rest = [];
code.split('\n').forEach(function (line) {
function moveComments(code, moveType) {
var comments = [], rest = [], skipId = -1;
code.split('\n').forEach(function (line, i) {
var isComment = false;
if (line.trim().slice(0, 3) === '//!') {
isComment = true;
}
if (isComment && moveType === 'main-only') {
if (i === skipId + 1 ||
line.trim() === '//! moment.js locale configuration') {
skipId = i;
// continue to next line
return;
}
}

if (isComment) {
comments.push(line.trim());
} else {
rest.push(line);
Expand Down Expand Up @@ -40,7 +53,7 @@ module.exports = function (grunt) {
var umd = bundle.toUmd({name: umdName}),
fixed = header + umd.code.split('\n').slice(skipLines).join('\n');
if (opts.moveComments) {
fixed = moveComments(fixed);
fixed = moveComments(fixed, opts.moveComments);
}
grunt.file.write(opts.target, fixed);
});
Expand Down Expand Up @@ -136,7 +149,8 @@ module.exports = function (grunt) {
base: 'src',
code: code,
umdName: 'moment',
target: target
target: target,
moveComments: 'main-only'
}).then(function () {
var code = grunt.file.read(target);
var getDefaultRegExp = new RegExp('var ([a-z$_]+) =\\s+{[^]\\s+get default \\(\\) { return ([a-z$_]+); }[^]\\s+}', '');
Expand Down

0 comments on commit 89fa774

Please sign in to comment.