From: Iskren Chernev Date: Sat, 29 Oct 2016 07:10:36 +0000 (-0700) Subject: Apply custom header to generated files X-Git-Tag: 2.16.0~24^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ae579eb0d1bb688db2902072fafa37863bf59a4;p=thirdparty%2Fmoment.git Apply custom header to generated files --- diff --git a/tasks/transpile.js b/tasks/transpile.js index 75c4f4cd8..517e90da7 100644 --- a/tasks/transpile.js +++ b/tasks/transpile.js @@ -68,7 +68,7 @@ module.exports = function (grunt) { } function transpile(opts) { - // base, entry, skip, headerFile, skipLines, target + // base, entry, skipMoment, headerFile, skipLines, target var umdName = opts.headerFile != null && opts.headerFile !== 'none' ? 'not_used' : opts.umdName, headerFile = opts.headerFile ? opts.headerFile : 'templates/default.js', header = getHeaderByFile(headerFile), @@ -77,7 +77,6 @@ module.exports = function (grunt) { return rollupBundle({ entry: path.join(opts.base, opts.entry), skipMoment: opts.skipMoment != null ? opts.skipMoment : false, - // skip: opts.skip || [], umdName: umdName }).then(function (code) { var fixed = header + code.split('\n').slice(skipLines).join('\n'); @@ -143,7 +142,7 @@ module.exports = function (grunt) { }); } - function generateLocales(target, localeFiles) { + function generateLocales(target, localeFiles, opts) { var files = localeFiles, code = [ 'import moment from "./moment";' @@ -159,32 +158,9 @@ module.exports = function (grunt) { base: 'src', code: code, target: target, - skipMoment: true, - headerFile: 'none', //'templates/locale-header.js', - skipLines: 0, // 5 - }); - } - - function generateMomentWithLocales(target, localeFiles) { - var files = localeFiles, - code = [ - 'import moment from "./moment";' - ].concat(files.map(function (file) { - var identifier = path.basename(file, '.js').replace('-', '_'); - return 'import ' + identifier + ' from "./' + file + '";'; - })).concat([ - // Reset the language back to 'en', because every defineLocale - // also sets it. - 'moment.locale("en");', - 'export default moment;' - ]).join('\n'); - - return transpileCode({ - base: 'src', - code: code, - target: target, - headerFile: 'none', //'templates/locale-header.js', - skipLines: 0, // 5 + skipMoment: opts.skipMoment, + headerFile: 'templates/locale-header.js', + skipLines: 7 }); } @@ -196,10 +172,7 @@ module.exports = function (grunt) { entry: 'moment.js', umdName: 'moment', target: 'build/umd/moment.js', - - skipLines: 0, // 5 - headerFile: 'none', // wasn't set --> default - + skipLines: 5, moveComments: true }).then(function () { grunt.log.ok('build/umd/moment.js'); @@ -207,8 +180,8 @@ module.exports = function (grunt) { return transpileMany({ base: 'src', pattern: 'locale/*.js', - headerFile: 'none', // 'templates/locale-header.js', - skipLines: 0, // 5 + headerFile: 'templates/locale-header.js', + skipLines: 7, moveComments: true, targetDir: 'build/umd', skipMoment: true, @@ -219,8 +192,8 @@ module.exports = function (grunt) { return transpileMany({ base: 'src', pattern: 'test/moment/*.js', - headerFile: 'none', //'templates/test-header.js', - skipLines: 0, // 5 + headerFile: 'templates/test-header.js', + skipLines: 7, moveComments: true, targetDir: 'build/umd', skipMoment: true @@ -231,8 +204,8 @@ module.exports = function (grunt) { return transpileMany({ base: 'src', pattern: 'test/locale/*.js', - headerFile: 'none', //'templates/test-header.js', - skipLines: 0, // 5 + headerFile: 'templates/test-header.js', + skipLines: 7, moveComments: true, targetDir: 'build/umd', skipMoment: true @@ -242,13 +215,17 @@ module.exports = function (grunt) { }).then(function () { return generateLocales( 'build/umd/min/locales.js', - grunt.file.expand({cwd: 'src'}, 'locale/*.js' - )); + grunt.file.expand({cwd: 'src'}, 'locale/*.js'), + {skipMoment: true} + ); }).then(function () { grunt.log.ok('build/umd/min/locales.js'); }).then(function () { - return generateMomentWithLocales('build/umd/min/moment-with-locales.js', - grunt.file.expand({cwd: 'src'}, 'locale/*.js')); + return generateLocales( + 'build/umd/min/moment-with-locales.js', + grunt.file.expand({cwd: 'src'}, 'locale/*.js'), + {skipMoment: false} + ); }).then(function () { grunt.log.ok('build/umd/min/moment-with-locales.js'); }).then(done, function (e) { diff --git a/templates/default.js b/templates/default.js index 3d6d4af85..095a78f54 100644 --- a/templates/default.js +++ b/templates/default.js @@ -2,4 +2,4 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : global.moment = factory() -}(this, function () { 'use strict'; +}(this, (function () { 'use strict'; diff --git a/templates/locale-header.js b/templates/locale-header.js index f568f80ca..eadcc1d81 100644 --- a/templates/locale-header.js +++ b/templates/locale-header.js @@ -3,4 +3,4 @@ && typeof require === 'function' ? factory(require('../moment')) : typeof define === 'function' && define.amd ? define(['../moment'], factory) : factory(global.moment) -}(this, function (moment) { 'use strict'; +}(this, (function (moment) { 'use strict'; diff --git a/templates/test-header.js b/templates/test-header.js index aee69d38c..1b208a359 100644 --- a/templates/test-header.js +++ b/templates/test-header.js @@ -3,4 +3,4 @@ && typeof require === 'function' ? factory(require('../../moment')) : typeof define === 'function' && define.amd ? define(['../../moment'], factory) : factory(global.moment) -}(this, function (moment) { 'use strict'; +}(this, (function (moment) { 'use strict';