2021-02-19 00:18:45 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016-2021 Martin Donath <martin.donath@squidfunk.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// import { build } from "esbuild"
|
|
|
|
import { minify as minhtml } from "html-minifier"
|
2021-02-20 20:03:53 +03:00
|
|
|
import { concat } from "rxjs"
|
|
|
|
import { concatMap } from "rxjs/operators"
|
2021-02-19 00:18:45 +03:00
|
|
|
|
2021-02-20 20:03:53 +03:00
|
|
|
import { copyAll } from "./copy"
|
|
|
|
import { base, resolve } from "./resolve"
|
|
|
|
import { transformStyle } from "./transform"
|
2021-02-19 00:18:45 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Program
|
|
|
|
* ------------------------------------------------------------------------- */
|
|
|
|
|
2021-02-20 20:03:53 +03:00
|
|
|
/* Copy all dependencies */
|
|
|
|
const dependencies$ = concat(
|
2021-02-19 00:18:45 +03:00
|
|
|
|
|
|
|
/* Copy Material Design icons */
|
|
|
|
...["*.svg", "../LICENSE"]
|
|
|
|
.map(pattern => copyAll(pattern, {
|
2021-02-20 20:03:53 +03:00
|
|
|
src: "node_modules/@mdi/svg/svg",
|
|
|
|
out: `${base}/.icons/material`
|
2021-02-19 00:18:45 +03:00
|
|
|
})),
|
|
|
|
|
|
|
|
/* Copy GitHub octicons */
|
|
|
|
...["*.svg", "../../LICENSE"]
|
|
|
|
.map(pattern => copyAll(pattern, {
|
2021-02-20 20:03:53 +03:00
|
|
|
src: "node_modules/@primer/octicons/build/svg",
|
|
|
|
out: `${base}/.icons/octicons`
|
2021-02-19 00:18:45 +03:00
|
|
|
})),
|
|
|
|
|
|
|
|
/* Copy FontAwesome icons */
|
|
|
|
...["**/*.svg", "../LICENSE.txt"]
|
|
|
|
.map(pattern => copyAll(pattern, {
|
2021-02-20 20:03:53 +03:00
|
|
|
src: "node_modules/@fortawesome/fontawesome-free/svgs",
|
|
|
|
out: `${base}/.icons/fontawesome`
|
|
|
|
})),
|
|
|
|
|
|
|
|
/* Copy Lunr.js search stemmers and segmenter */
|
|
|
|
...["min/*.js", "tinyseg.js"]
|
|
|
|
.map(pattern => copyAll(pattern, {
|
|
|
|
src: "node_modules/lunr-languages",
|
|
|
|
out: `${base}/assets/javascripts/lunr`
|
2021-02-19 00:18:45 +03:00
|
|
|
}))
|
|
|
|
)
|
|
|
|
|
2021-02-20 20:03:53 +03:00
|
|
|
/* Copy all assets */
|
2021-02-19 00:18:45 +03:00
|
|
|
const assets$ = concat(
|
|
|
|
|
2021-02-20 20:03:53 +03:00
|
|
|
/* Copy icons, images and configurations */
|
2021-02-19 00:18:45 +03:00
|
|
|
...[".icons/*.svg", "assets/images/*", "**/*.{py,yml}"]
|
|
|
|
.map(pattern => copyAll(pattern, {
|
2021-02-20 20:03:53 +03:00
|
|
|
src: "src",
|
|
|
|
out: base
|
2021-02-19 00:18:45 +03:00
|
|
|
})),
|
|
|
|
|
2021-02-20 20:03:53 +03:00
|
|
|
/* Copy and minify template files */
|
|
|
|
copyAll("**/*.html", {
|
|
|
|
src: "src",
|
|
|
|
out: base,
|
|
|
|
fn: content => {
|
|
|
|
const metadata = require("../package.json")
|
|
|
|
const banner =
|
|
|
|
"{#-\n" +
|
|
|
|
" This file was automatically generated - do not edit\n" +
|
|
|
|
"-#}\n"
|
|
|
|
|
|
|
|
/* Normalize line feeds and minify HTML */
|
|
|
|
const html = content.replace(/\r\n/gm, "\n")
|
|
|
|
return banner + minhtml(html, {
|
|
|
|
collapseBooleanAttributes: true,
|
|
|
|
includeAutoGeneratedTags: false,
|
|
|
|
minifyCSS: true,
|
|
|
|
minifyJS: true,
|
|
|
|
removeComments: true,
|
|
|
|
removeScriptTypeAttributes: true,
|
|
|
|
removeStyleLinkTypeAttributes: true
|
|
|
|
})
|
|
|
|
|
|
|
|
/* Remove empty lines without collapsing everything */
|
|
|
|
.replace(/^\s*[\r\n]/gm, "")
|
|
|
|
|
|
|
|
/* Write theme version into template */
|
|
|
|
.replace("$md-name$", metadata.name)
|
|
|
|
.replace("$md-version$", metadata.version)
|
|
|
|
}
|
|
|
|
})
|
2021-02-19 00:18:45 +03:00
|
|
|
)
|
|
|
|
|
2021-02-20 20:03:53 +03:00
|
|
|
/* Transform stylesheets with SASS and PostCSS */
|
|
|
|
const styles$ = resolve("**/[!_]*.scss", { cwd: "src" })
|
2021-02-19 00:18:45 +03:00
|
|
|
.pipe(
|
2021-02-20 20:03:53 +03:00
|
|
|
concatMap(file => transformStyle({
|
|
|
|
src: `src/${file}`,
|
|
|
|
out: `${base}/${file.replace(/\.scss$/, ".css")}`,
|
|
|
|
optimize: true // TODO: wrap with commander
|
|
|
|
}))
|
2021-02-19 00:18:45 +03:00
|
|
|
)
|
2021-02-20 20:03:53 +03:00
|
|
|
|
|
|
|
/* Compile everything */
|
|
|
|
concat(
|
|
|
|
dependencies$,
|
|
|
|
assets$,
|
|
|
|
styles$
|
|
|
|
)
|
|
|
|
.subscribe()
|