Skip to content

Commit

Permalink
Upgrade deps, remove ESLint, use GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottsj committed May 3, 2020
1 parent c7a4668 commit c4ee1bf
Show file tree
Hide file tree
Showing 12 changed files with 2,826 additions and 2,404 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

21 changes: 0 additions & 21 deletions .eslintrc

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Test

on: [push]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install --global yarn@1
- run: yarn install
- run: yarn test
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Spencer Elliott
Copyright (c) 2020 Spencer Elliott

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# front-matter-loader

[![npm version](https://img.shields.io/npm/v/front-matter-loader.svg)](https://www.npmjs.com/package/front-matter-loader)
[![Greenkeeper badge](https://badges.greenkeeper.io/elliottsj/front-matter-loader.svg)](https://greenkeeper.io/)

Webpack loader to extract frontmatter using [jxson/front-matter](https://github.com/jxson/front-matter)
webpack loader to extract frontmatter using [jxson/front-matter](https://github.com/jxson/front-matter)

## Installation

Expand All @@ -27,30 +26,30 @@ Here is some example content
The frontmatter can be extracted like this (using [json-loader](https://github.com/webpack-contrib/json-loader)):

```js
var exampleFrontmatter = require('json-loader!front-matter-loader!./example.md')
var exampleFrontmatter = require('json-loader!front-matter-loader!./example.md');

console.log(exampleFrontmatter.attributes.title)
console.log(exampleFrontmatter.attributes.title);
// => 'Example'
console.log(exampleFrontmatter.attributes.description)
console.log(exampleFrontmatter.attributes.description);
// => 'This is an example'
console.log(exampleFrontmatter.body)
console.log(exampleFrontmatter.body);
// => 'Here is some example content'
```

To extract only the frontmatter attributes of the target file, use the `onlyAttributes` query parameter:

```js
var exampleAttributes = require('json-loader!front-matter-loader?onlyAttributes!./example.md')
console.log(exampleAttributes.title)
var exampleAttributes = require('json-loader!front-matter-loader?onlyAttributes!./example.md');
console.log(exampleAttributes.title);
// => 'Example'
console.log(exampleAttributes.description)
console.log(exampleAttributes.description);
// => 'This is an example'
```

To extract only the body content of the target file, use the `onlyBody` query parameter:

```js
var exampleContent = require('raw-loader!front-matter-loader?onlyBody!./example.md')
var exampleContent = require('raw-loader!front-matter-loader?onlyBody!./example.md');
```

For a complete example using a webpack config, see [example/](example/).
26 changes: 15 additions & 11 deletions example/example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ const webpack = require('webpack');
const config = require('./webpack.config');

test('extracts frontmatter and body as an object', () =>
new Promise(resolve => {
new Promise((resolve) => {
webpack(config, (error, stats) => {
const bundlePath = path.resolve(
stats.compilation.compiler.outputPath,
stats.toJson().assetsByChunkName.main,
stats.toJson().assetsByChunkName.main
);
expect(require(bundlePath)).toEqual({
// eslint-disable-line global-require
attributes: {
title: 'Example',
description: 'This is an example',
},
body: '\nHere is some example content\n',
frontmatter: 'title: Example\ndescription: This is an example',
});
expect(require(bundlePath)).toMatchInlineSnapshot(`
Object {
"attributes": Object {
"description": "This is an example",
"title": "Example",
},
"body": "Here is some example content
",
"bodyBegin": 6,
"frontmatter": "title: Example
description: This is an example",
}
`);
resolve();
});
}));
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var loaderUtils = require('loader-utils');
var fm = require('front-matter');

module.exports = function(source) {
module.exports = function (source) {
this.cacheable && this.cacheable();
var options = loaderUtils.getOptions(this) || {};

Expand Down
9 changes: 5 additions & 4 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ test('extracts frontmatter and body as an object', () => {
'"title":"Example",' +
'"description":"This is an example"' +
'},' +
'"body":"\\nHere is some example content",' +
'"body":"Here is some example content",' +
'"bodyBegin":6,' +
'"frontmatter":"title: Example\\ndescription: This is an example"' +
'}',
'}'
);
});

Expand All @@ -32,7 +33,7 @@ test('extracts only the frontmatter when onlyAttributes is passed', () => {
};

expect(frontMatterLoader.call(context, source)).toBe(
'{"title":"Example","description":"This is an example"}',
'{"title":"Example","description":"This is an example"}'
);
});

Expand All @@ -43,6 +44,6 @@ test('extracts only the body when onlyBody is passed', () => {
};

expect(frontMatterLoader.call(context, source)).toBe(
'\nHere is some example content',
'Here is some example content'
);
});
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"main": "index.js",
"scripts": {
"jest": "jest",
"lint": "eslint .",
"test": "npm run lint && npm run jest"
"format:check": "prettier --check .",
"format:write": "prettier --write .",
"test": "npm run format:check && npm run jest"
},
"repository": {
"type": "git",
Expand All @@ -24,16 +25,14 @@
},
"homepage": "https://github.com/elliottsj/front-matter-loader#readme",
"dependencies": {
"front-matter": "^2.0.2",
"loader-utils": "^1.1.0"
"front-matter": "^3.1.0",
"loader-utils": "^2.0.0"
},
"devDependencies": {
"eslint": "^4.0.0",
"eslint-plugin-prettier": "^2.1.2",
"jest": "^22.4.2",
"json-loader": "^0.5.4",
"prettier": "^1.4.4",
"webpack": "^4.1.1"
"jest": "25.5.4",
"json-loader": "0.5.7",
"prettier": "2.0.5",
"webpack": "4.43.0"
},
"jest": {
"testEnvironment": "node"
Expand Down
Loading

0 comments on commit c4ee1bf

Please sign in to comment.