mark-to-json
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -0,1 +1,11 @@ | ||
<a name="0.1.1"></a> | ||
## [0.1.1](https://github.com/lbw/mark-to-json/compare/v0.1.0...v0.1.1) (2018-08-21) | ||
### Bug Fixes | ||
* remove redundant code ([c4cf69f](https://github.com/lbw/mark-to-json/commit/c4cf69f)) | ||
<a name="0.1.0"></a> | ||
@@ -2,0 +12,0 @@ # [0.1.0](https://github.com/lbw/mark-to-json/compare/0713828...v0.1.0) (2018-08-21) |
@@ -7,2 +7,3 @@ "use strict"; | ||
const path = require('path'); | ||
const mkdirp = require('mkdirp'); | ||
const cws = require('fs').createWriteStream; | ||
@@ -25,11 +26,16 @@ class App { | ||
const normalizePath = path.resolve(process.cwd(), this.dest); | ||
utils_1.createDir(normalizePath); | ||
const ws = cws(normalizePath); | ||
ws.on('close', () => { | ||
logger_1.default.info(`[Write]`, `create static JSON file ${this.dest}`); | ||
mkdirp(path.dirname(this.dest), (e) => { | ||
if (e) { | ||
console.error(e); | ||
return; | ||
} | ||
const ws = cws(normalizePath); | ||
ws.on('close', () => { | ||
logger_1.default.info(`[Write]`, `create static JSON file ${this.dest}`); | ||
}); | ||
ws.write(utils_1.stringify(this.schema)); | ||
ws.end(); | ||
}); | ||
ws.write(utils_1.stringify(this.schema)); | ||
ws.end(); | ||
} | ||
} | ||
module.exports = App; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
function hasDir(dir) { | ||
try { | ||
fs.accessSync(dir, fs.constants.F_OK); | ||
} | ||
catch (err) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
exports.hasDir = hasDir; | ||
function createDir(dest) { | ||
const dirname = path.dirname(dest); | ||
if (!hasDir(dirname)) { | ||
fs.mkdirSync(dirname); | ||
} | ||
} | ||
exports.createDir = createDir; | ||
function isString(target) { | ||
@@ -23,0 +4,0 @@ return typeof target === 'string'; |
@@ -5,8 +5,8 @@ const Mtj = require('../lib/index'); | ||
token: fs.readFileSync('./samples/default.md', 'utf8'), | ||
dest: './samples/default.json', | ||
dest: './samples/nested/default.json', | ||
extraHeader: { | ||
errno: 0, | ||
to: 'samples/default' | ||
to: 'samples/nested/default' | ||
}, | ||
contentKey: 'content' | ||
}); |
import reader = require('gray-matter') | ||
import * as types from '../config/types' | ||
import { createDir, stringify } from './utils' | ||
import { stringify } from './utils' | ||
import logger from './utils/logger' | ||
const path = require('path') | ||
const mkdirp = require('mkdirp') | ||
const cws = require('fs').createWriteStream | ||
class App { | ||
__raw: reader.GrayMatterFile<string|Buffer> | ||
private __raw: reader.GrayMatterFile<string|Buffer> | ||
dest: string | ||
@@ -37,12 +38,17 @@ content: string | ||
createDir(normalizePath) | ||
mkdirp(path.dirname(this.dest), (e: Error) => { | ||
if (e) { | ||
console.error(e) | ||
return | ||
} | ||
const ws = cws( | ||
normalizePath | ||
) | ||
ws.on('close', () => { | ||
logger.info(`[Write]`, `create static JSON file ${this.dest}`) | ||
const ws = cws( | ||
normalizePath | ||
) | ||
ws.on('close', () => { | ||
logger.info(`[Write]`, `create static JSON file ${this.dest}`) | ||
}) | ||
ws.write(stringify(this.schema)) | ||
ws.end() | ||
}) | ||
ws.write(stringify(this.schema)) | ||
ws.end() | ||
} | ||
@@ -49,0 +55,0 @@ } |
@@ -1,21 +0,1 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
function hasDir (dir: string) { | ||
try { | ||
// 确保文件夹存在,此处不用确认文件是否存在 | ||
fs.accessSync(dir, fs.constants.F_OK) | ||
} catch (err) { | ||
return false | ||
} | ||
return true | ||
} | ||
function createDir (dest: string) { | ||
const dirname = path.dirname(dest) | ||
if (!hasDir(dirname)) { | ||
fs.mkdirSync(dirname) | ||
} | ||
} | ||
function isString (target: any) { | ||
@@ -30,5 +10,3 @@ return typeof target === 'string' | ||
export { | ||
hasDir, | ||
createDir, | ||
stringify | ||
} |
{ | ||
"name": "mark-to-json", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "parse markdown to json", | ||
@@ -13,3 +13,3 @@ "main": "dist/lib/index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/lbw/mark-to-json.git" | ||
"url": "git+https://github.com/lbwa/mark-to-json.git" | ||
}, | ||
@@ -26,3 +26,4 @@ "author": "Bowen <node_env@outlook.com>", | ||
"chalk": "^2.4.1", | ||
"gray-matter": "^4.0.1" | ||
"gray-matter": "^4.0.1", | ||
"mkdirp": "^0.5.1" | ||
}, | ||
@@ -29,0 +30,0 @@ "devDependencies": { |
# mark-to-json [![NpmVersion](https://img.shields.io/npm/v/mark-to-json.svg?style=flat-square)](https://www.npmjs.com/package/mark-to-json) [![NodeVersion](https://img.shields.io/node/v/mark-to-json.svg?style=flat-square)](https://www.npmjs.com/package/mark-to-json) | ||
> Parse markdown to JSON file | ||
> Parse the markdown into a JSON static file, also support multiple-level directories. | ||
@@ -17,2 +17,11 @@ ## Installing | ||
| API | Required | default | Description | | ||
| --- | -------- | ------- | ----------- | | ||
| token | true | | Your markdown file content including yaml matter | | ||
| dest | false | `./default.json` | Your JSON static file will be created at the place based on the current nodejs working path | | ||
| extraHeader | false | `{}` | It will be mix in JSON file if you want to add some extra data to JSON static file | | ||
| contentKey | false | `content` | It will be the key of markdown content part in JSON static file| | ||
## Sample | ||
```js | ||
@@ -36,1 +45,5 @@ const Mtj = require('mark-to-json') | ||
[here]:https://github.com/lbwa/mark-to-json/tree/master/samples | ||
## Changelog | ||
[Changelog](./CHANGELOG.md) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7597
48
2
3
153
+ Addedmkdirp@^0.5.1
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)