]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
checkmark babel convert 3517/head 3518/head
authorMaggie Pint <magpint@microsoft.com>
Sat, 22 Oct 2016 02:23:00 +0000 (19:23 -0700)
committerMaggie Pint <magpint@microsoft.com>
Sat, 22 Oct 2016 02:23:00 +0000 (19:23 -0700)
.babelrc [new file with mode: 0644]
package.json
tasks/transpile.js

diff --git a/.babelrc b/.babelrc
new file mode 100644 (file)
index 0000000..fd2925f
--- /dev/null
+++ b/.babelrc
@@ -0,0 +1,4 @@
+{
+  "plugins": ["transform-es2015-modules-umd"],
+  "presets": ["es2015"]
+}
\ No newline at end of file
index cc66d649c13a97c58ba0582a56cfa56c9d1169b6..65e6a58fd313b2760600874f74a229a36b01f838 100644 (file)
 {
-    "name": "moment",
-    "version": "2.15.1",
-    "description": "Parse, validate, manipulate, and display dates",
-    "homepage": "http://momentjs.com",
-    "author": "Iskren Ivov Chernev <iskren.chernev@gmail.com> (https://github.com/ichernev)",
-    "contributors": [
-        "Tim Wood <washwithcare@gmail.com> (http://timwoodcreates.com/)",
-        "Rocky Meza (http://rockymeza.com)",
-        "Matt Johnson <mj1856@hotmail.com> (http://codeofmatt.com)",
-        "Isaac Cambron <isaac@isaaccambron.com> (http://isaaccambron.com)",
-        "Andre Polykanine <andre@oire.org> (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 <iskren.chernev@gmail.com> (https://github.com/ichernev)",
+  "contributors": [
+    "Tim Wood <washwithcare@gmail.com> (http://timwoodcreates.com/)",
+    "Rocky Meza (http://rockymeza.com)",
+    "Matt Johnson <mj1856@hotmail.com> (http://codeofmatt.com)",
+    "Isaac Cambron <isaac@isaaccambron.com> (http://isaaccambron.com)",
+    "Andre Polykanine <andre@oire.org> (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"
+    ]
+  }
 }
index 3289384dfcdc842994849562ba01d0a3329ad8b4..71c63425f1805b84f159c02a3b2aeca649038b08 100644 (file)
@@ -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 () {