Skip to content

Commit

Permalink
Merge 0674cc9 into 9ac182c
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Feb 13, 2021
2 parents 9ac182c + 0674cc9 commit 2f8fa2d
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 84 deletions.
File renamed without changes.
3 changes: 3 additions & 0 deletions .eslintrc → .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "canonical",
"parserOptions": {
"requireConfigFile": false
},
"rules": {
"filenames/match-exported": 0,
"import/no-commonjs": 0,
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
coverage
dist
node_modules
package-lock.json
*.log
.*
!.babelrc
!.babelrc.json
!.editorconfig
!.eslintignore
!.eslintrc
!.eslintrc.json
!.flowconfig
!.gitignore
!.npmignore
!.travis.yml
!.README
!.ncurc.js
6 changes: 6 additions & 0 deletions .ncurc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = {
// Todo [husky@>=6]: Might be MIT again
reject: ['husky'],
};
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: node_js
node_js:
- node
- 8
- 14
- 12
- 10
script:
- npm run lint
- npm run test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ Returns file size formatted in human friendly format.
Generates:

```markdown
8.57 KB
8.47 KB
2.54 KB

```
Expand Down
51 changes: 27 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@
"dependencies": {
"bluebird": "^3.7.2",
"deadlink": "^1.1.3",
"filesize": "^6.0.1",
"get-urls": "^9.2.0",
"filesize": "^6.1.0",
"get-urls": "^10.0.0",
"gitinfo": "^2.4.0",
"glob": "^7.1.6",
"jsonfile": "^5.0.0",
"lodash": "^4.17.15",
"jsonfile": "^6.1.0",
"lodash": "^4.17.20",
"markdown-contents": "^1.0.11",
"marked": "^0.8.0",
"moment": "^2.24.0",
"marked": "^2.0.0",
"moment": "^2.29.1",
"stack-trace": "^0.0.10",
"yargs": "^15.1.0"
"yargs": "^16.2.0"
},
"description": "Github markdown preprocessor.",
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/node": "^7.8.4",
"@babel/plugin-transform-flow-strip-types": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/register": "^7.8.3",
"@babel/cli": "^7.12.16",
"@babel/core": "^7.12.16",
"@babel/node": "^7.12.16",
"@babel/plugin-transform-flow-strip-types": "^7.12.13",
"@babel/preset-env": "^7.12.16",
"@babel/register": "^7.12.13",
"babel-plugin-istanbul": "^6.0.0",
"chai": "^4.2.0",
"chai": "^4.3.0",
"chai-as-promised": "^7.1.1",
"coveralls": "^3.0.9",
"eslint": "~6.8.0",
"eslint-config-canonical": "~19.0.1",
"coveralls": "^3.1.0",
"eslint": "~7.20.0",
"eslint-config-canonical": "~25.8.17",
"husky": "^4.2.3",
"mocha": "^7.0.1",
"nock": "^11.8.2",
"nyc": "^15.0.0",
"mocha": "^8.3.0",
"nock": "^13.0.7",
"nyc": "^15.1.0",
"require-uncached": "^2",
"semantic-release": "^17.0.3",
"sinon": "^8.1.1"
"semantic-release": "^17.3.9",
"sinon": "^9.2.4"
},
"husky": {
"hooks": {
Expand All @@ -64,11 +64,14 @@
"type": "git",
"url": "https://github.com/gajus/gitdown"
},
"engines": {
"node": ">=10"
},
"scripts": {
"build": "babel ./src --out-dir ./dist --copy-files",
"create-readme": "babel-node ./src/bin/index.js ./.README/README.md --output-file ./README.md",
"lint": "eslint ./src ./tests",
"test": "mocha \"./tests/**/*.js\" --require @babel/register"
"lint": "eslint --report-unused-disable-directives ./src ./tests",
"test": "nyc mocha \"./tests/**/*.js\" --require @babel/register --timeout 9000"
},
"version": "2.5.2"
}
12 changes: 7 additions & 5 deletions src/bin/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const path = require('path');
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
const yargs = require('yargs');

Expand All @@ -11,7 +11,11 @@ const argv = yargs
.options({
check: {
default: false,
description: 'Checks if the destination file represents the current state of the template. Terminates program with exit status 1 if generating a new document would result in changes of the target document. Terminates program with exit status 0 otherwise (without writng to the destination).',
description: 'Checks if the destination file represents the current ' +
'state of the template. Terminates program with exit status 1 if ' +
'generating a new document would result in changes of the target ' +
'document. Terminates program with exit status 0 otherwise (without ' +
'writng to the destination).',
type: 'boolean',
},
force: {
Expand Down Expand Up @@ -41,7 +45,7 @@ const argv = yargs

try {
fs.accessSync(inputFile, fs.constants.W_OK);
} catch (error) {
} catch {
// eslint-disable-next-line no-console
console.log('inputFile', inputFile);

Expand Down Expand Up @@ -72,7 +76,6 @@ const main = async () => {
const resolvedInputFile = path.resolve(process.cwd(), inputFile);
const resolvedOutputFile = path.resolve(process.cwd(), outputFile);

// eslint-disable-next-line global-require
const Gitdown = require('..');

const gitdown = Gitdown.readFile(resolvedInputFile);
Expand All @@ -86,7 +89,6 @@ const main = async () => {
// eslint-disable-next-line no-console
console.error('Gitdown destination file does not represent the current state of the template.');

// eslint-disable-next-line no-process-exit
process.exit(1);
}

Expand Down
43 changes: 18 additions & 25 deletions src/gitdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const Gitdown = {};
const fs = require('fs');
const path = require('path');
const Promise = require('bluebird');
const _ = require('lodash');
const marked = require('marked');
const Deadlink = require('deadlink');
const getUrls = require('get-urls');
const _ = require('lodash');
const MarkdownContents = require('markdown-contents');
const marked = require('marked');
const StackTrace = require('stack-trace');
const gitinfo = require('./helpers/gitinfo.js');
const contents = require('./helpers/contents.js');
const gitinfo = require('./helpers/gitinfo.js');
const Parser = require('./parser.js');

/**
Expand All @@ -29,24 +29,19 @@ Gitdown.read = (input) => {
*
* @returns {Promise}
*/
gitdown.get = () => {
return parser
.play(input)
.then((state) => {
let markdown;
gitdown.get = async () => {
const state = await parser.play(input);

markdown = state.markdown;
let markdown;
markdown = state.markdown;

if (gitdown.getConfig().headingNesting.enabled) {
markdown = Gitdown.nestHeadingIds(markdown);
}
if (gitdown.getConfig().headingNesting.enabled) {
markdown = Gitdown.nestHeadingIds(markdown);
}

return gitdown
.resolveURLs(markdown)
.then(() => {
return markdown.replace(/<!--\sgitdown:\s(:?off|on)\s-->/g, '');
});
});
await gitdown.resolveURLs(markdown);

return markdown.replace(/<!--\sgitdown:\s(:?off|on)\s-->/g, '');
};

/**
Expand All @@ -55,12 +50,10 @@ Gitdown.read = (input) => {
* @param {string} fileName
* @returns {Promise}
*/
gitdown.writeFile = (fileName) => {
return gitdown
.get()
.then((outputString) => {
return fs.writeFileSync(fileName, outputString);
});
gitdown.writeFile = async (fileName) => {
const outputString = await gitdown.get();

return fs.writeFileSync(fileName, outputString);
};

/**
Expand Down Expand Up @@ -341,7 +334,7 @@ Gitdown.nestHeadingIds.iterateTree = (tree, callback, index = 1) => {
nextIndex = index;

tree.forEach((article) => {
// eslint-disable-next-line callback-return
// eslint-disable-next-line promise/prefer-await-to-callbacks
callback(nextIndex++, article);

if (article.descendants) {
Expand Down
10 changes: 4 additions & 6 deletions src/helpers/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ const formatFileSize = require('filesize');

const helper = {};

helper.compile = (config = {}) => {
helper.compile = async (config = {}) => {
config.gzip = config.gzip || false;

if (!config.file) {
return Promise.reject(new Error('config.file must be provided.'));
}

return helper
.file(config.file, config.gzip)
.then((fileSize) => {
return helper.format(fileSize);
});
const fileSize = await helper.file(config.file, config.gzip);

return helper.format(fileSize);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/gitinfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const helper = {};
const _ = require('lodash');
const createGitinfo = require('gitinfo').default;
const _ = require('lodash');

helper.compile = (config, context) => {
const parserConfig = context.gitdown.getConfig().gitinfo;
Expand Down
7 changes: 3 additions & 4 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Path = require('path');
const _ = require('lodash');
const Promise = require('bluebird');
const glob = require('glob');
const _ = require('lodash');
const Locator = require('./locator.js');

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ const Parser = (gitdown) => {

try {
command = JSON.parse(match);
} catch (error) {
} catch {
throw new Error('Invalid Gitdown JSON ("' + match + '").');
}

Expand Down Expand Up @@ -113,7 +113,7 @@ const Parser = (gitdown) => {
});

outputMarkdown = outputMarkdown.replace(/⊂⊂I:(\d+)⊃⊃/g, (match, p1) => {
return ignoreSection[parseInt(p1, 10) - 1];
return ignoreSection[Number.parseInt(p1, 10) - 1];
});

return {
Expand Down Expand Up @@ -178,7 +178,6 @@ const Parser = (gitdown) => {
*/
parser.loadHelpers = () => {
glob.sync(Path.resolve(__dirname, './helpers/*.js')).forEach((helper) => {
// eslint-disable-next-line global-require
parser.registerHelper(Path.basename(helper, '.js'), require(helper));
});
};
Expand Down
2 changes: 1 addition & 1 deletion tests/gitdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const fs = require('fs');
const path = require('path');
const expect = require('chai').expect;
const requireNew = require('require-uncached');
const nock = require('nock');
const requireNew = require('require-uncached');
const sinon = require('sinon');

describe('Gitdown', () => {
Expand Down
24 changes: 20 additions & 4 deletions tests/helpers/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ describe('Parser.helpers.badge', () => {
it('returns markdown for the david badge', () => {
const badge = helper.compile({name: 'david-dev'}, gitinfoContext);

expect(badge).to.equal('[![Development Dependency Status](https://img.shields.io/david/dev/a/b.svg?style=flat-square)](https://david-dm.org/a/b#info=devDependencies)');
expect(badge).to.equal(
'[![Development Dependency Status](' +
'https://img.shields.io/david/dev/a/b.svg?style=flat-square' +
')](https://david-dm.org/a/b#info=devDependencies)',
);
});
});
describe('travis', () => {
Expand All @@ -144,20 +148,32 @@ describe('Parser.helpers.badge', () => {
it('returns markdown for the codeclimate gpa badge', () => {
const badge = helper.compile({name: 'codeclimate-gpa'}, gitinfoContext);

expect(badge).to.equal('[![Code Climate GPA](https://img.shields.io/codeclimate/github/a/b.svg?style=flat-square)](https://codeclimate.com/github/a/b)');
expect(badge).to.equal(
'[![Code Climate GPA]' +
'(https://img.shields.io/codeclimate/github/a/b.svg?style=flat-square' +
')](https://codeclimate.com/github/a/b)',
);
});
it('returns markdown for the codeclimate coverage badge', () => {
const badge = helper.compile({name: 'codeclimate-coverage'}, gitinfoContext);

expect(badge).to.equal('[![Code Climate Coverage](https://img.shields.io/codeclimate/coverage/github/a/b.svg?style=flat-square)](https://codeclimate.com/github/a/b)');
expect(badge).to.equal(
'[![Code Climate Coverage](' +
'https://img.shields.io/codeclimate/coverage/github/a/b.svg?style=flat-square' +
')](https://codeclimate.com/github/a/b)',
);
});
});

describe('appveyor', () => {
it('returns markdown for the AppVeyor badge', () => {
const badge = helper.compile({name: 'appveyor'}, gitinfoContext);

expect(badge).to.equal('[![AppVeyor build status](https://img.shields.io/appveyor/ci/a/b/c.svg?style=flat-square)](https://ci.appveyor.com/project/a/b/branch/c)');
expect(badge).to.equal(
'[![AppVeyor build status](' +
'https://img.shields.io/appveyor/ci/a/b/c.svg?style=flat-square' +
')](https://ci.appveyor.com/project/a/b/branch/c)',
);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Parser.helpers.date', () => {
helper = requireNew('../../src/helpers/date.js');
});
it('returns current UNIX timestamp', () => {
expect(helper.compile()).to.equal(String(Math.floor(new Date().getTime() / 1000)));
expect(helper.compile()).to.equal(String(Math.floor(Date.now() / 1_000)));
});
it('uses format parameter to adjust the format', () => {
expect(helper.compile({format: 'YYYY'})).to.equal(String(new Date().getUTCFullYear()));
Expand Down

0 comments on commit 2f8fa2d

Please sign in to comment.