Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade rollup config work with 2.35.1 and other dependencies #5

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .eslintrc

This file was deleted.

4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

{
"extends": "@cutting/eslint-config"
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
node_modules
dist
junit.xml
.coverage
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# @cutting/rollup-plugin-md

markdown plugin for [rollup](https://github.com/rollup/rollup) using [marked](https://www.npmjs.com/package/marked).

Forked from [rollup-plugin-md](https://github.com/xiaofuzi/rollup-plugin-md).

## Install

```node
npm install rollup-plugin-md --save
```bash
# npm
npm install @cutting/rollup-plugin-md --save

# yarn
yarn add @cutting/rollup-plugin-md -D
```

## usage
Expand All @@ -13,16 +23,16 @@ console.log( `Template for render: ${md}` );

```js
import { rollup } from 'rollup';
import md from 'rollup-plugin-md';
import { md } from '@cutting/rollup-plugin-md';

rollup({
entry: 'main.js',
plugins: [
md({
marked: {
//marked options
}
})
]
entry: 'main.js',
plugins: [
md({
marked: {
//marked options
}
})
]
});
```
44 changes: 25 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
{
"name": "rollup-plugin-md",
"version": "0.0.6",
"name": "@cutting/rollup-plugin-md",
"version": "0.3.1",
"description": "a rollup plugin for markdown files",
"main": "dist/rollup-plugin-md.js",
"jsnext:main": "dist/rollup-plugin-md.mjs",
"main": "dist/index.js",
"module": "dist/rollup-plugin-md.esm.js",
"browser": "dist/rollup-plugin-md.esm.js",
"types": "dist/md.d.ts",
"scripts": {
"test": "mocha test/*.js --compilers js:buble/register",
"pretest": "npm run build",
"build": "rollup -c",
"prebuild": "rm -rf dist/*"
"test": "NODE_ENV=test cutting test",
"test:ci": "CI=true NODE_ENV=test cutting test",
"build": "NODE_ENV=production cutting rollup",
"prebuild": "rm -rf dist/*",
"prepublish": "yarn build"
},
"files": [
"dist"
],
"keywords": [
"rollup",
"plugin",
"md",
"markdown"
],
"author": "yangxiaofu",
"author": "Paul Cowan <[email protected]>",
"license": "ISC",
"dependencies": {
"marked": "^0.3.6",
"rollup": "^0.34.7",
"rollup-plugin-buble": "^0.12.1",
"rollup-pluginutils": "^1.5.1"
"marked": "^1.2.7",
"rollup": "^2.35.1",
"@rollup/pluginutils": "^4.1.0"
},
"devDependencies": {
"assert": "^1.4.1",
"eslint": "^3.2.2",
"mocha": "^3.0.2",
"rollup-plugin-node-resolve": "^2.0.0",
"source-map-support": "^0.4.2"
"@cutting/devtools": "^4.2.0",
"@cutting/eslint-config": "^4.2.0",
"@types/marked": "^1.2.1",
"assert": "^2.0.0",
"eslint": "^7.16.0",
"source-map-support": "^0.5.19"
}
}
}
21 changes: 0 additions & 21 deletions rollup.config.js

This file was deleted.

26 changes: 0 additions & 26 deletions src/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type { MdOptions } from './md';
export { md } from './md';
35 changes: 35 additions & 0 deletions src/md.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { rollup } from 'rollup';
import { md } from './md';
import so from 'source-map-support';

so.install();

process.chdir(__dirname);

describe('rollup-plugin-md', () => {
it('converts md', async () => {
const bundle = await rollup({
input: 'samples/main.js',
plugins: [
md({
marked: {
gfm: true,
breaks: false,
pedantic: false,
smartLists: true,
smartypants: false,
},
}),
],
});

const result = await bundle.generate({
format: 'es',
});

expect(result.output[0].code)
.toContain(`var md = "<h2 id=\\"rollup-plugin-md\\">rollup-plugin-md</h2>\\n<p>a simple plugin</p>\\n";

console.log('md: ', md);`);
});
});
37 changes: 37 additions & 0 deletions src/md.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { PluginImpl } from 'rollup';
import type { MarkedOptions } from 'marked';
import marked from 'marked';
import { createFilter } from '@rollup/pluginutils';

const ext = /\.md$/;

export type MdOptions = { marked?: MarkedOptions } & {
include?: string | RegExp | (string | RegExp)[];
exclude?: string | RegExp | (string | RegExp)[];
};

export const md: PluginImpl<MdOptions> = (options = {}) => {
const filter = createFilter(options.include || ['**/*.md'], options.exclude);
if (options.marked) {
marked.setOptions(options.marked);
}
return {
name: 'md',

transform(md, id) {
if (!ext.test(id)) {
return null;
}

if (!filter(id)) {
return null;
}

const data = marked(md);
return {
code: `export default ${JSON.stringify(data.toString())};`,
map: { mappings: '' },
};
},
};
};
2 changes: 2 additions & 0 deletions src/samples/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import md from './test.md';
console.log('md: ', md);
File renamed without changes.
2 changes: 0 additions & 2 deletions test/samples/main.js

This file was deleted.

35 changes: 0 additions & 35 deletions test/test.js

This file was deleted.

16 changes: 16 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "@cutting/devtools/typescript/tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"../../node_modules",
"./dist",
"src/**/*.test.ts",
"samples/**/*.*"
]
}
Loading