From: Maggie Pint Date: Sat, 22 Oct 2016 02:23:00 +0000 (-0700) Subject: checkmark babel convert X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3517%2Fhead;p=thirdparty%2Fmoment.git checkmark babel convert --- diff --git a/.babelrc b/.babelrc new file mode 100644 index 000000000..fd2925f3d --- /dev/null +++ b/.babelrc @@ -0,0 +1,4 @@ +{ + "plugins": ["transform-es2015-modules-umd"], + "presets": ["es2015"] +} \ No newline at end of file diff --git a/package.json b/package.json index cc66d649c..65e6a58fd 100644 --- a/package.json +++ b/package.json @@ -1,98 +1,101 @@ { - "name": "moment", - "version": "2.15.1", - "description": "Parse, validate, manipulate, and display dates", - "homepage": "http://momentjs.com", - "author": "Iskren Ivov Chernev (https://github.com/ichernev)", - "contributors": [ - "Tim Wood (http://timwoodcreates.com/)", - "Rocky Meza (http://rockymeza.com)", - "Matt Johnson (http://codeofmatt.com)", - "Isaac Cambron (http://isaaccambron.com)", - "Andre Polykanine (https://github.com/oire)" + "name": "moment", + "version": "2.15.1", + "description": "Parse, validate, manipulate, and display dates", + "homepage": "http://momentjs.com", + "author": "Iskren Ivov Chernev (https://github.com/ichernev)", + "contributors": [ + "Tim Wood (http://timwoodcreates.com/)", + "Rocky Meza (http://rockymeza.com)", + "Matt Johnson (http://codeofmatt.com)", + "Isaac Cambron (http://isaaccambron.com)", + "Andre Polykanine (https://github.com/oire)" + ], + "keywords": [ + "moment", + "date", + "time", + "parse", + "format", + "validate", + "i18n", + "l10n", + "ender" + ], + "main": "./moment.js", + "jsnext:main": "./src/moment.js", + "typings": "./moment.d.ts", + "engines": { + "node": "*" + }, + "repository": { + "type": "git", + "url": "https://github.com/moment/moment.git" + }, + "bugs": { + "url": "https://github.com/moment/moment/issues" + }, + "license": "MIT", + "devDependencies": { + "babel-core": "^6.17.0", + "babel-plugin-transform-es2015-modules-umd": "^6.12.0", + "babel-preset-es2015": "^6.16.0", + "benchmark": "latest", + "coveralls": "^2.11.2", + "es6-promise": "latest", + "esperanto": "latest", + "grunt": "~0.4", + "grunt-benchmark": "latest", + "grunt-cli": "latest", + "grunt-contrib-clean": "latest", + "grunt-contrib-concat": "latest", + "grunt-contrib-copy": "latest", + "grunt-contrib-jshint": "latest", + "grunt-contrib-uglify": "latest", + "grunt-contrib-watch": "latest", + "grunt-env": "latest", + "grunt-exec": "latest", + "grunt-jscs": "latest", + "grunt-karma": "latest", + "grunt-nuget": "latest", + "grunt-string-replace": "latest", + "karma": "latest", + "karma-chrome-launcher": "latest", + "karma-firefox-launcher": "latest", + "karma-qunit": "latest", + "karma-sauce-launcher": "latest", + "load-grunt-tasks": "latest", + "nyc": "^2.1.4", + "qunit": "^0.7.5", + "qunit-cli": "^0.1.4", + "spacejam": "latest", + "typescript": "^1.8.10", + "uglify-js": "latest" + }, + "ender": "./ender.js", + "dojoBuild": "package.js", + "jspm": { + "files": [ + "moment.js", + "moment.d.ts", + "locale" ], - "keywords": [ - "moment", - "date", - "time", - "parse", - "format", - "validate", - "i18n", - "l10n", - "ender" - ], - "main": "./moment.js", - "jsnext:main": "./src/moment.js", - "typings": "./moment.d.ts", - "engines": { - "node": "*" - }, - "repository": { - "type": "git", - "url": "https://github.com/moment/moment.git" - }, - "bugs": { - "url": "https://github.com/moment/moment/issues" - }, - "license": "MIT", - "devDependencies": { - "uglify-js": "latest", - "es6-promise": "latest", - "grunt": "~0.4", - "grunt-cli": "latest", - "benchmark": "latest", - "esperanto": "latest", - "grunt-contrib-clean": "latest", - "grunt-contrib-concat": "latest", - "grunt-contrib-copy": "latest", - "grunt-contrib-jshint": "latest", - "grunt-contrib-uglify": "latest", - "grunt-contrib-watch": "latest", - "grunt-env": "latest", - "grunt-jscs": "latest", - "grunt-karma": "latest", - "grunt-nuget": "latest", - "grunt-benchmark": "latest", - "grunt-string-replace": "latest", - "grunt-exec": "latest", - "load-grunt-tasks": "latest", - "karma": "latest", - "karma-chrome-launcher": "latest", - "karma-firefox-launcher": "latest", - "karma-qunit": "latest", - "karma-sauce-launcher": "latest", - "qunit": "^0.7.5", - "qunit-cli": "^0.1.4", - "spacejam": "latest", - "typescript": "^1.8.10", - "coveralls": "^2.11.2", - "nyc": "^2.1.4" - }, - "ender": "./ender.js", - "dojoBuild": "package.js", - "jspm": { - "files": [ - "moment.js", - "moment.d.ts", - "locale" - ], - "map": { - "moment": "./moment" - }, - "buildConfig": { - "uglify": true - } - }, - "scripts": { - "test": "grunt test", - "coverage": "nyc npm test && nyc report", - "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls" + "map": { + "moment": "./moment" }, - "spm": { - "main": "moment.js", - "output": [ - "locale/*.js" - ] + "buildConfig": { + "uglify": true } + }, + "scripts": { + "test": "grunt test", + "coverage": "nyc npm test && nyc report", + "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls" + }, + "spm": { + "main": "moment.js", + "output": [ + "locale/*.js" + ] + } } diff --git a/tasks/transpile.js b/tasks/transpile.js index 3289384df..71c63425f 100644 --- a/tasks/transpile.js +++ b/tasks/transpile.js @@ -1,6 +1,6 @@ module.exports = function (grunt) { - var esperanto = require('esperanto'); var path = require('path'); + var babel = require('babel-core'); var Promise = require('es6-promise').Promise; var TMP_DIR = 'build/tmp'; @@ -39,24 +39,31 @@ module.exports = function (grunt) { } function transpile(opts) { - // base, entry, skip, headerFile, skipLines, target + // entry, skip, headerFile, skipLines, target var umdName = opts.headerFile ? 'not_used' : opts.umdName, headerFile = opts.headerFile ? opts.headerFile : 'templates/default.js', header = getHeaderByFile(headerFile), skipLines = opts.skipLines ? opts.skipLines : 5; - return esperanto.bundle({ - base: opts.base, - entry: opts.entry, - skip: opts.skip || [] - }).then(function (bundle) { - var umd = bundle.toUmd({name: umdName}), - fixed = header + umd.code.split('\n').slice(skipLines).join('\n'); - if (opts.moveComments) { - fixed = moveComments(fixed, opts.moveComments); + console.log('transpile entry' + opts.entry); + var promise = new Promise(function (resolve, reject) { + babel.transformFile(opts.entry, { + ignore: opts.skip || [] + }, function (err, result) { + if (err) { + reject(err); + } else { + console.log(opts.target); + var fixed = header + result.code.split('\n').slice(skipLines).join('\n'); + if (opts.moveComments) { + fixed = moveComments(fixed, opts.moveComments); + } + grunt.file.write(opts.target, fixed); + resolve(); } - grunt.file.write(opts.target, fixed); + }); }); + return promise; } function transpileMany(opts) { @@ -68,7 +75,6 @@ module.exports = function (grunt) { promise = promise.then(function () { return Promise.all(files.slice(i, i + batchSize).map(function (file) { return transpile({ - base: opts.base, entry: file, headerFile: opts.headerFile, skip: opts.skip, @@ -93,6 +99,7 @@ module.exports = function (grunt) { if (grunt.file.exists(tmpDir)) { return; } + console.log('start writing files'); files.forEach(function (file) { grunt.file.copy(path.join(base, file), path.join(tmpDir, file)); }); @@ -101,10 +108,13 @@ module.exports = function (grunt) { function transpileCode(opts) { var entry = opts.entry || path.basename(opts.target); prepareTemp(opts.base); - grunt.file.write(path.join(TMP_DIR, entry), opts.code); + console.log('temp prepped'); + var filePath = path.join(TMP_DIR, entry); + console.log(filePath); + console.log('code' + opts.code); + grunt.file.write(filePath, opts.code); return transpile({ - base: TMP_DIR, - entry: entry, + entry: filePath, umdName: opts.umdName || 'not_used', headerFile: opts.headerFile, skipLines: opts.skipLines, @@ -123,14 +133,15 @@ module.exports = function (grunt) { // Reset the language back to 'en', because every defineLocale // also sets it. 'moment.locale(\'en\');' - ]).join('\n'); + ]).join('\n'); + console.log(localeFiles); return transpileCode({ base: 'src', code: code, - target: target, skip: ['moment'], headerFile: 'templates/locale-header.js', - skipLines: 5 + skipLines: 5, + target: target }); } @@ -139,12 +150,12 @@ module.exports = function (grunt) { importCode = files.map(function (file) { var identifier = path.basename(file, '.js').replace('-', '_'); var fileNoExt = file.replace('.js', ''); - return 'import ' + identifier + ' from "./' + fileNoExt + '";'; + return 'import ' + identifier + ' from "src/' + fileNoExt + '";'; }).join('\n'), - code = 'import * as moment_export from "./moment";\n\n' + + code = 'import * as moment_export from "src/moment";\n\n' + importCode + '\n\n' + 'export default moment_export;'; - + console.log(code); return transpileCode({ base: 'src', code: code, @@ -202,8 +213,8 @@ module.exports = function (grunt) { grunt.log.ok('build/umd/locale/*.js'); }).then(function () { return transpileMany({ - base: 'src', - pattern: 'test/moment/*.js', + base: '', + pattern: 'src/test/moment/*.js', headerFile: 'templates/test-header.js', skipLines: 5, moveComments: true, @@ -214,8 +225,8 @@ module.exports = function (grunt) { grunt.log.ok('build/umd/test/moment/*.js'); }).then(function () { return transpileMany({ - base: 'src', - pattern: 'test/locale/*.js', + base: '', + pattern: 'src/test/locale/*.js', headerFile: 'templates/test-header.js', skipLines: 5, moveComments: true, @@ -226,7 +237,7 @@ module.exports = function (grunt) { grunt.log.ok('build/umd/test/locale/*.js'); }).then(function () { return generateLocales('build/umd/min/locales.js', - grunt.file.expand({cwd: 'src'}, 'locale/*.js')); + grunt.file.expand('src/locale/*.js')); }).then(function () { grunt.log.ok('build/umd/min/locales.js'); }).then(function () {