Skip to content

Commit

Permalink
Merge branch 'alignment' of https://github.com/metalsmith/metadata in…
Browse files Browse the repository at this point in the history
…to next
  • Loading branch information
wernerglinka committed Feb 17, 2022
2 parents d3fc01e + 87ad5ff commit 52ef55e
Show file tree
Hide file tree
Showing 75 changed files with 1,571 additions and 916 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
env:
node: true
es6: true
extends:
- 'eslint:recommended'
- 'plugin:node/recommended'
- 'plugin:import/recommended'
- 'prettier'
parserOptions:
ecmaVersion: 2020
rules:
no-console: error
prefer-const: error
no-var: error
node/exports-style: [0, error]
import/first: error
import/no-anonymous-default-export: error
import/no-unassigned-import: error
import/no-internal-modules: error
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Automatically normalize line endings for all text-based files
# http://git-scm.com/docs/gitattributes#_end_of_line_conversion
* text=auto eol=lf

# For binary file types, prevent converting CRLF chars
*.jpg -text
*.png -text
9 changes: 9 additions & 0 deletions .github/workflows/gitter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
on: create

jobs:
notify:
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: curl --data-urlencode "message=[${{github.repository}} ${{github.ref_name}}](https://github.com/${{github.repository}}/releases/${{github.ref_name}}) released" ${{secrets.GITTER_CUSTOM_WEBHOOK}}
63 changes: 63 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI
on:
push:
branches: ['**']
pull_request:
branches: ['master']

jobs:
pre-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
cache: 'npm'

- run: npm install
- run: npm run format:check
- run: npm run lint:check

branch-test:
if: github.ref_name != 'master' && success()
needs: pre-test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest', 'windows-latest']
node: ['12.0']
name: Testing Node ${{ matrix.node }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
cache: 'npm'

- run: npm install
- run: npm test

test:
if: github.ref_name == 'master' && success()
needs: pre-test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest', 'windows-latest']
node: ['12.0', '14.0', '16.0']
name: Testing Node ${{ matrix.node }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: 'npm'

- run: npm install
- run: npm test
- if: matrix.os == 'ubuntu-latest' && matrix.node == '16.0'
run: npm run coverage
- if: matrix.os == 'ubuntu-latest' && matrix.node == '16.0'
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ github.token }}
path-to-lcov: ./coverage.info
2 changes: 1 addition & 1 deletion .release-it.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"hooks": {
"before:init": ["npm run lint", "npm test"],
"before:init": ["npm run format:check", "npm run lint:check", "npm test"],
"after:bump": "auto-changelog --sort-commits date-desc -p --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release)'",
"after:npm:bump": "npm pack",
"after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
Expand Down
43 changes: 0 additions & 43 deletions .travis.yml

This file was deleted.

10 changes: 9 additions & 1 deletion Readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ A metalsmith plugin to load global metadata from files and directories.

## Installation

NPM:

```bash
npm install @metalsmith/metadata
```

Yarn:

```bash
$ npm install metalsmith-metadata
yarn add @metalsmith/metadata
```

## Usage
Expand Down
23 changes: 20 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
'use strict';

<<<<<<< HEAD
const debug = require('debug')('metalsmith-metameta');
=======
// eslint-disable-next-line no-unused-vars
const debug = require('debug')('@metalsmith/metadata');
>>>>>>> 87ad5ff9f9bb56fb5f728cdf898f1ec6ec05fe3e
const {
promises: { readFile, readdir }
} = require('fs');
Expand Down Expand Up @@ -64,7 +69,7 @@ function groupMetadataSources(arr, src) {
* @param {*} string - YAML file
* @returns .json string
*/
function yamlToJSON(string) {
function yamlToJS(string) {
try {
return yaml.load(string);
} catch (e) {
Expand Down Expand Up @@ -98,11 +103,15 @@ function toJson(file, ext) {
switch (ext) {
case '.yaml':
case '.yml':
<<<<<<< HEAD
try {
fileContent = yamlToJSON(file);
} catch(e) {
debug(e);
}
=======
fileContent = yamlToJS(fileBuffer);
>>>>>>> 87ad5ff9f9bb56fb5f728cdf898f1ec6ec05fe3e
break;
case '.toml':
try { // remove object prototype
Expand Down Expand Up @@ -193,11 +202,17 @@ async function getDirectoryObject(directoryPath, optionKey, allMetadata) {
if (groupMetadata.length) {
allMetadata[optionKey] = groupMetadata;
} else {
// eslint-disable-next-line no-undef
done(`No files found in this directory "${key}"`);
}
})
.catch((e) => {
<<<<<<< HEAD
debug(e);
=======
// eslint-disable-next-line no-undef
done(e.message);
>>>>>>> 87ad5ff9f9bb56fb5f728cdf898f1ec6ec05fe3e
});
}
Expand Down Expand Up @@ -243,6 +258,8 @@ function initMetadata(options) {
// array to hold all active promises during external file reads. Will be
// used with Promise.allSettled to invoke done()
const allPromises = [];
const srcDirectory = metalsmith.source();
const msSourceFolder = srcDirectory;

// create array with all option values relative to metalsmith directory
const allOptions = Object.keys(options).map(key => (
Expand Down Expand Up @@ -320,8 +337,8 @@ function initMetadata(options) {
allPromises.push(extDirectoryPromise);
});

// Promise.all is used to invoke done()
Promise.allSettled(allPromises).then(() => done());
// Promise.allSettled is used to invoke done()
Promise.all(allPromises).then(() => done());
};
}

Expand Down
Loading

0 comments on commit 52ef55e

Please sign in to comment.