Skip to content

Commit faf55d2

Browse files
committed
feat: plugins
1 parent db239cc commit faf55d2

File tree

20 files changed

+446
-226
lines changed

20 files changed

+446
-226
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/*
22
!/src
3+
!/test

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Gerald
3+
Copyright (c) 2020 Gerald
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Visualize your Markdown as mindmaps.
88

99
This project is heavily inspired by [Markmap](https://github.com/dundalek/markmap).
1010

11-
See [online demo](https://markmap.js.org/repl).
11+
[Try it out](https://markmap.js.org/repl).
1212

1313
Requires Node.js >= 10.
1414

@@ -83,7 +83,7 @@ $ npm install markmap-lib
8383
Transform Markdown to markmap data:
8484

8585
```js
86-
import { transform } from 'markmap-lib/dist/transform.common';
86+
import { transform } from 'markmap-lib/dist/transform';
8787

8888
const data = transform(markdown);
8989
```
@@ -103,7 +103,7 @@ Create an SVG element with explicit width and height:
103103
Render a markmap to the SVG element:
104104

105105
```js
106-
import { markmap } from 'markmap-lib/dist/view.common';
106+
import { markmap } from 'markmap-lib/dist/view';
107107

108108
markmap('#markmap', data);
109109

@@ -132,7 +132,7 @@ window.MathJax = {
132132
and process Html with MathJax in `options.processHtml`:
133133

134134
```js
135-
import { markmap } from 'markmap-lib/dist/view.common';
135+
import { markmap } from 'markmap-lib/dist/view';
136136

137137
markmap('#markmap', data, {
138138
processHtml: nodes => {

bin/cli.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ program
1010
.arguments('<input>')
1111
.option('-o, --output <output>', 'specify filename of the output HTML')
1212
.option('--enable-mathjax', 'enable MathJax support')
13+
.option('--enable-prism', 'enable PrismJS support')
1314
.option('--no-open', 'do not open the output file after generation')
1415
.action((input, cmd) => {
1516
return createMarkmap({
1617
open: cmd.open,
1718
input,
1819
output: cmd.output,
1920
mathJax: cmd.enableMathjax,
21+
prism: cmd.enablePrism,
2022
});
2123
});
2224

gulpfile.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const fs = require('fs');
2+
const gulp = require('gulp');
3+
const babel = require('gulp-babel');
4+
const replace = require('gulp-replace');
5+
const log = require('fancy-log');
6+
const rollup = require('rollup');
7+
const del = require('del');
8+
const { defaultOptions } = require('@gera2ld/plaid');
9+
const rollupConfig = require('./rollup.conf');
10+
const pkg = require('./package.json');
11+
12+
const DIST = defaultOptions.distDir;
13+
const TEMPLATE = fs.readFileSync('templates/markmap.html', 'utf8');
14+
15+
function clean() {
16+
return del([DIST, 'types']);
17+
}
18+
19+
function buildCjs() {
20+
return gulp.src(['src/**/*.ts', '!**/*.d.ts'])
21+
.pipe(babel({
22+
presets: [
23+
['@babel/preset-env', {
24+
loose: true,
25+
}],
26+
],
27+
plugins: [
28+
['@babel/plugin-transform-runtime', {
29+
version: '^7.5.0',
30+
}],
31+
],
32+
}))
33+
.pipe(replace('process.env.VERSION', pkg.version))
34+
.pipe(replace('process.env.TEMPLATE', JSON.stringify(TEMPLATE)))
35+
.pipe(gulp.dest(DIST));
36+
}
37+
38+
function buildRollup() {
39+
return Promise.all(rollupConfig.map(async (config) => {
40+
const bundle = await rollup.rollup(config);
41+
await bundle.write(config.output);
42+
}));
43+
}
44+
45+
function wrapError(handle) {
46+
const wrapped = () => handle()
47+
.catch(err => {
48+
log(err.toString());
49+
});
50+
wrapped.displayName = handle.name;
51+
return wrapped;
52+
}
53+
54+
function watch() {
55+
gulp.watch('src/**', build);
56+
}
57+
58+
const safeBuildJs = wrapError(buildRollup);
59+
const build = gulp.parallel(buildCjs, safeBuildJs);
60+
61+
exports.clean = clean;
62+
exports.build = build;
63+
exports.dev = gulp.series(build, watch);

package.json

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
"description": "Visualize your Markdown as mindmaps with Markmap",
55
"author": "Gerald <i@gerald.top>",
66
"license": "MIT",
7+
"husky": {
8+
"hooks": {
9+
"pre-push": "npm run lint"
10+
}
11+
},
712
"bin": {
813
"markmap": "bin/cli.js"
914
},
1015
"engines": {
1116
"node": ">=10"
1217
},
13-
"husky": {
14-
"hooks": {
15-
"pre-push": "npm run lint"
16-
}
17-
},
1818
"scripts": {
19-
"dev": "rollup -wc rollup.conf.js",
20-
"clean": "del dist types",
21-
"build:js": "rollup -c rollup.conf.js",
19+
"dev": "gulp dev",
20+
"clean": "gulp clean",
21+
"build:js": "gulp build",
2222
"prebuild": "npm run ci && npm run clean",
2323
"prepublishOnly": "npm run build",
2424
"ci": "npm run lint",
@@ -29,8 +29,8 @@
2929
"access": "public"
3030
},
3131
"main": "dist/index.js",
32-
"unpkg": "dist/view.min.js",
33-
"jsdelivr": "dist/view.min.js",
32+
"unpkg": "dist/browser/view.min.js",
33+
"jsdelivr": "dist/browser/view.min.js",
3434
"files": [
3535
"bin",
3636
"dist",
@@ -42,34 +42,29 @@
4242
"mindmap"
4343
],
4444
"typings": "types/index.d.ts",
45+
"repository": "git@github.com:gera2ld/markmap-lib.git",
4546
"devDependencies": {
4647
"@babel/preset-typescript": "^7.9.0",
47-
"@gera2ld/plaid": "~1.5.0",
48-
"@rollup/plugin-alias": "^3.0.1",
49-
"@rollup/plugin-commonjs": "^11.0.2",
50-
"@rollup/plugin-json": "^4.0.2",
51-
"@rollup/plugin-node-resolve": "^7.1.1",
52-
"@rollup/plugin-replace": "^2.3.1",
53-
"@typescript-eslint/eslint-plugin": "^2.26.0",
54-
"@typescript-eslint/parser": "^2.26.0",
55-
"cross-env": "^7.0.2",
56-
"cssnano": "^4.1.10",
57-
"del-cli": "^3.0.0",
58-
"eslint": "^6.8.0",
59-
"husky": "^4.2.3",
60-
"rollup": "^2.3.1",
61-
"rollup-plugin-babel": "^4.4.0",
48+
"@gera2ld/plaid": "~2.0.0",
49+
"@gera2ld/plaid-rollup": "~2.0.0",
50+
"@typescript-eslint/eslint-plugin": "^2.30.0",
51+
"@typescript-eslint/parser": "^2.30.0",
52+
"del": "^5.1.0",
53+
"fancy-log": "^1.3.3",
54+
"gulp": "^4.0.2",
55+
"gulp-babel": "^8.0.0",
56+
"gulp-replace": "^1.0.0",
57+
"husky": "^4.2.5",
6258
"rollup-plugin-terser": "^5.3.0",
6359
"typescript": "^3.8.3"
6460
},
6561
"dependencies": {
66-
"@babel/runtime": "^7.9.2",
62+
"@babel/runtime": "^7.9.6",
6763
"@types/d3": "^5.7.2",
68-
"commander": "^5.0.0",
69-
"d3": "^5.15.0",
64+
"commander": "^5.1.0",
65+
"d3": "^5.16.0",
7066
"d3-flextree": "^2.1.1",
7167
"open": "^7.0.3",
7268
"remarkable": "^2.0.0"
73-
},
74-
"repository": "git@github.com:gera2ld/markmap-lib.git"
69+
}
7570
}

rollup.conf.js

Lines changed: 18 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,52 @@
11
const { terser } = require('rollup-plugin-terser');
2-
const { getRollupPlugins, getExternal, DIST } = require('./scripts/util');
2+
const { getRollupPlugins, getRollupExternal, defaultOptions } = require('@gera2ld/plaid');
33
const pkg = require('./package.json');
44

5+
const DIST = defaultOptions.distDir;
56
const BANNER = `/*! ${pkg.name} v${pkg.version} | ${pkg.license} License */`;
67

78
const globalList = [
89
'd3',
910
];
10-
const externalList = [
11-
...globalList,
12-
'fs',
13-
'path',
14-
'open',
15-
'remarkable',
16-
'd3-flextree',
17-
'./template',
18-
'./util',
19-
];
11+
const external = getRollupExternal();
2012
const bundleOptions = {
2113
extend: true,
2214
esModule: false,
2315
};
2416
const rollupConfig = [
2517
{
2618
input: {
27-
input: 'src/index.ts',
28-
plugins: getRollupPlugins(),
29-
external: getExternal(externalList),
30-
},
31-
output: {
32-
format: 'cjs',
33-
file: `${DIST}/index.js`,
34-
},
35-
},
36-
{
37-
input: {
38-
input: 'src/template.ts',
39-
plugins: getRollupPlugins(),
40-
external: getExternal(externalList),
41-
},
42-
output: {
43-
format: 'cjs',
44-
file: `${DIST}/template.js`,
45-
},
46-
},
47-
{
48-
input: {
49-
input: 'src/util.ts',
50-
plugins: getRollupPlugins(),
51-
external: getExternal(externalList),
52-
},
53-
output: {
54-
format: 'cjs',
55-
file: `${DIST}/util.js`,
56-
},
57-
},
58-
{
59-
input: {
60-
input: 'src/transform.ts',
61-
plugins: getRollupPlugins(),
62-
external: getExternal(externalList),
63-
},
64-
output: {
65-
format: 'cjs',
66-
file: `${DIST}/transform.common.js`,
67-
...bundleOptions,
68-
},
69-
},
70-
{
71-
input: {
72-
input: 'src/transform.ts',
73-
plugins: getRollupPlugins(),
19+
input: 'src/view.ts',
7420
external: globalList,
21+
plugins: getRollupPlugins({
22+
esm: true,
23+
extensions: defaultOptions.extensions,
24+
}),
7525
},
7626
output: {
7727
format: 'iife',
78-
file: `${DIST}/transform.js`,
28+
file: `${DIST}/browser/view.js`,
7929
name: 'markmap',
30+
globals: {
31+
d3: 'd3',
32+
},
8033
...bundleOptions,
8134
},
8235
minify: true,
8336
},
8437
{
8538
input: {
86-
input: 'src/view.ts',
87-
plugins: getRollupPlugins(),
88-
external: getExternal(externalList),
89-
},
90-
output: {
91-
format: 'cjs',
92-
file: `${DIST}/view.common.js`,
93-
...bundleOptions,
94-
},
95-
},
96-
{
97-
input: {
98-
input: 'src/view.ts',
99-
plugins: getRollupPlugins(),
39+
input: 'src/transform.ts',
10040
external: globalList,
41+
plugins: getRollupPlugins({
42+
esm: true,
43+
extensions: defaultOptions.extensions,
44+
}),
10145
},
10246
output: {
10347
format: 'iife',
104-
file: `${DIST}/view.js`,
48+
file: `${DIST}/browser/transform.js`,
10549
name: 'markmap',
106-
globals: {
107-
d3: 'd3',
108-
},
10950
...bundleOptions,
11051
},
11152
minify: true,

0 commit comments

Comments
 (0)