]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Add comment on top of moment-with-locales.js
authorIskren Chernev <iskren.chernev@gmail.com>
Sun, 12 Jun 2016 08:53:53 +0000 (01:53 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 15 Jun 2016 09:20:23 +0000 (02:20 -0700)
Fixes #3159

tasks/transpile.js

index bc7a9989b309369df2eab62e5048b9836d3710bb..3289384dfcdc842994849562ba01d0a3329ad8b4 100644 (file)
@@ -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+}', '');