-
Notifications
You must be signed in to change notification settings - Fork 24
/
rollup.config.js
90 lines (76 loc) · 2.85 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import path from 'path';
import fs from 'fs';
import { marked } from 'marked';
// rollup.config.js
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import copy from 'rollup-plugin-copy';
import commonjs from '@rollup/plugin-commonjs';
import scss from 'rollup-plugin-scss';
export default {
input: './src/index.ts',
output: {
dir: 'build',
format: 'es',
// Removes the hash from the asset filename
assetFileNames: '[name][extname]',
},
plugins: [
// CSS
scss(),
// Typescript
nodeResolve({ preferBuiltins: true }),
typescript(),
commonjs(),
// Copy system.json & templates
copy({
targets: [
{ src: 'src/system.json', dest: 'build' },
{ src: 'src/templates/**/*.hbs', dest: 'build/' },
{ src: 'src/lang/*.json', dest: 'build/' },
{ src: 'src/assets/**/*', dest: 'build/' },
],
flatten: false,
}),
// Custom markdown parser
markdownParser({
targets: [
{ src: 'src/release-notes.md', dest: 'build/' },
],
}),
],
};
/* --- Custom Plugins --- */
function markdownParser(config) {
return {
name: 'markdown-parser',
buildEnd() {
// Read all markdown files from the config targets
const markdownFiles = config.targets
.filter((target) => target.src.endsWith('.md'))
.filter((target) => fs.existsSync(target.src))
.map((target) => {
return fs.readFileSync(target.src, 'utf8');
});
// Parse the markdown files
const parsedMarkdown = markdownFiles.map((file) => {
return marked(file);
});
// Write the parsed markdown to the output directory
parsedMarkdown.forEach((markdown, index) => {
// Get source path (except the top most directory)
const srcPath = path.dirname(config.targets[index].src).split(path.sep).slice(1).join(path.sep);
// Get file name without extension from the source path
const fileName = path.basename(config.targets[index].src, path.extname(config.targets[index].src));
// Construct the destination path
const dest = path.join(srcPath, config.targets[index].dest, `${fileName}.html`);
const destDir = path.join(srcPath, config.targets[index].dest);
if(!fs.existsSync(destDir)){
fs.mkdirSync(destDir);
}
// Write the parsed markdown to the destination path
fs.writeFileSync(dest, `<div>${markdown}</div>`);
});
}
}
}