|
1 | 1 | const fs = require('fs')
|
2 | 2 | const path = require('path')
|
| 3 | + |
| 4 | +const prettier = require('prettier') |
| 5 | +const Prism = require('prismjs') |
| 6 | +require('prismjs/plugins/custom-class/prism-custom-class') |
| 7 | + |
3 | 8 | const routes = require('./examples/src/routes')
|
4 | 9 |
|
5 | 10 | function flatten(routes, resolver) {
|
@@ -28,6 +33,59 @@ fs.writeFileSync(
|
28 | 33 | 'utf8'
|
29 | 34 | )
|
30 | 35 |
|
| 36 | +// --- |
| 37 | + |
| 38 | +function pipe(...fns) { |
| 39 | + return fns.reduceRight((f, g) => (...args) => f(g(...args)), fns.pop()) |
| 40 | +} |
| 41 | + |
| 42 | +Prism.plugins.customClass.map({ |
| 43 | + tag: 'text-code-red', |
| 44 | + 'attr-name': 'text-code-yellow', |
| 45 | + 'attr-value': 'text-code-green', |
| 46 | + deleted: 'text-code-red', |
| 47 | + inserted: 'text-code-green', |
| 48 | + punctuation: 'text-code-white', |
| 49 | + keyword: 'text-code-purple', |
| 50 | + string: 'text-code-green', |
| 51 | + function: 'text-code-blue', |
| 52 | + boolean: 'text-code-red', |
| 53 | + comment: 'text-gray-400 italic', |
| 54 | +}) |
| 55 | + |
| 56 | +const sourcePipeline = pipe( |
| 57 | + path => fs.readFileSync(path, 'utf8'), |
| 58 | + contents => prettier.format(contents, { parser: 'vue', printWidth: 100 }), |
| 59 | + contents => Prism.highlight(contents, Prism.languages.markup), |
| 60 | + contents => |
| 61 | + [ |
| 62 | + '<pre class="language-vue rounded-md bg-gray-800 py-3 px-4 overflow-x-auto">', |
| 63 | + '<code class="language-vue text-gray-200">', |
| 64 | + contents, |
| 65 | + '</code>', |
| 66 | + '</pre>', |
| 67 | + ].join('') |
| 68 | +) |
| 69 | + |
| 70 | +const skipRoutes = ['/'] |
| 71 | +const source = Object.assign( |
| 72 | + {}, |
| 73 | + ...flatten(routes, route => ({ |
| 74 | + urlPath: route.path, |
| 75 | + sourcePath: route.component, |
| 76 | + })) |
| 77 | + .filter(({ urlPath }) => !skipRoutes.includes(urlPath)) |
| 78 | + .map(({ urlPath, sourcePath }) => ({ |
| 79 | + [urlPath]: sourcePipeline(path.resolve(__dirname, 'examples', 'src', sourcePath), 'utf8'), |
| 80 | + })) |
| 81 | +) |
| 82 | +fs.writeFileSync( |
| 83 | + path.resolve(__dirname, './examples/src/.generated/source.json'), |
| 84 | + JSON.stringify(source, null, 2), |
| 85 | + 'utf8' |
| 86 | +) |
| 87 | +// --- |
| 88 | + |
31 | 89 | const TailwindUIPlugin = ({
|
32 | 90 | root, // project root directory, absolute path
|
33 | 91 | app, // Koa app instance
|
|
0 commit comments