From: Iskren Chernev Date: Sun, 12 Jun 2016 08:53:53 +0000 (-0700) Subject: Add comment on top of moment-with-locales.js X-Git-Tag: 2.14.0~14^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89fa774a9d152f99de3ed6f542599376004db6a3;p=thirdparty%2Fmoment.git Add comment on top of moment-with-locales.js Fixes #3159 --- diff --git a/tasks/transpile.js b/tasks/transpile.js index bc7a9989b..3289384df 100644 --- a/tasks/transpile.js +++ b/tasks/transpile.js @@ -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); @@ -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); }); @@ -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+}', '');