Add babel

This commit is contained in:
Tom Raithel
2017-01-20 08:29:47 +01:00
parent 37ae2943d5
commit a120849d56
5 changed files with 59 additions and 47 deletions

3
.babelrc Normal file
View File

@@ -0,0 +1,3 @@
{
"presets": ["latest"]
}

View File

@@ -4,14 +4,16 @@
"description": "",
"main": "index.js",
"scripts": {
"create": "node ./scripts/create.js",
"clean": "node ./scripts/clean.js",
"create": "npm run clean && babel-node ./scripts/create.js",
"clean": "babel-node ./scripts/clean.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Tom Raithel <t.raithel@googlemail.com> (http://www.tomraithel.de)",
"license": "MIT",
"dependencies": {
"async": "2.1.4",
"babel-cli": "6.22.2",
"babel-preset-latest": "6.22.0",
"front-matter": "2.1.1",
"fs-extra": "2.0.0",
"marked": "0.3.6"

View File

@@ -1,24 +1,14 @@
var fs = require('fs-extra');
var async = require('async');
var file = require('./file');
import { emptyDir } from 'fs-extra';
import { distPath } from './file';
var distDir = file.distDir();
var distDir = distPath();
console.log('<<< start cleaning dist dir: ', distDir);
async.series([
function(callback) {
fs.ensureDir(distDir, callback);
},
function(callback) {
fs.emptyDir(distDir, callback);
}
],
function(err, results) {
if (!err) {
console.log('done cleaning dist dir >>>');
} else {
console.error(err);
}
emptyDir(distDir, (err) => {
if (!err) {
console.log('done cleaning dist dir >>>');
} else {
console.error(err);
}
);
});

View File

@@ -1,21 +1,35 @@
var fs = require('fs-extra');
var frontmatter = require('front-matter');
var marked = require('marked');
var file = require('./file');
import {
readFile,
outputFile,
} from 'fs-extra';
import frontmatter from 'front-matter';
import marked from 'marked';
import waterfall from 'async/waterfall';
import {
srcPath,
distPath,
} from './file';
var fileName = file.path('radar/v1/tools/grunt.md');
const fileName = srcPath('v1/tools/grunt.md');
fs.readFile(fileName, 'utf8', function(err, data) {
if (err) throw err;
console.log('<<< start creating files');
var item = frontmatter(data);
waterfall([
(callback) => {
readFile(fileName, 'utf8', callback);
},
(data, callback) => {
const item = frontmatter(data);
const html = marked(item.body);
var html = marked(item.body);
console.log(item.attributes);
console.log(html);
fs.outputFile(file.distDir() + '/test.html', html, function (err) {
console.log(err) // => null
})
});
outputFile(distPath('test3.html'), html, callback);
}
],
(err, results) => {
if (!err) {
console.log('done creating files >>>');
} else {
console.error(err);
}
}
);

View File

@@ -1,10 +1,13 @@
var path = require('path');
import path from 'path';
module.exports = {
path: function(relativePath) {
return path.resolve(__dirname, '..', relativePath)
},
distDir: function() {
return this.path('dist');
}
};
export const relativePath = (...relativePath) => (
path.resolve(__dirname, '..', ...relativePath)
);
export const srcPath = (pathInSrc = '') => (
relativePath('radar', pathInSrc)
);
export const distPath = (pathInDist = '') => (
relativePath('dist', pathInDist)
);