Skip to content

Commit

Permalink
🚧 still mostly broken. fastify + resource resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Feb 19, 2024
1 parent 4a48b5d commit 898486e
Show file tree
Hide file tree
Showing 63 changed files with 2,508 additions and 1,923 deletions.
212 changes: 100 additions & 112 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import esbuild from "esbuild";
import process from "process";
import builtins from 'builtin-modules';
import { copy } from 'esbuild-plugin-copy';
import extra from "fs-extra";
import fs from "fs";
import path from "path";
import path, { basename } from 'path';
import { sassPlugin } from 'esbuild-sass-plugin';
import { readdir } from "fs";
import { basename } from "path";
import { readdirSync } from "fs";
import { config } from "dotenv";

config();

const staticAssetsPlugin = {
name: 'static-assets-plugin',
Expand All @@ -21,216 +20,205 @@ const staticAssetsPlugin = {
},
};

const banner =
`/*
const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = (process.argv[2] === 'production');
const OUTPUT_DIR = prod || !process.env.OUTDIR ? "./build/" : process.env.OUTDIR;
const dir = process.env.OUTDIR ? process.env.OUTDIR : "./build";

const map = {
'src/main.ts': 'main',
'src/scss/layout/main.scss': 'css/layout',
};

const themeDir = 'src/scss/theme/source/';
const files = readdirSync(themeDir);
files.forEach(function (file) {
if (file.endsWith('.scss')) {
const source = themeDir + file;
const target = 'dist/theme/' + basename(file).replaceAll('.scss', '');
map[source] = target;
}
});

const entryPoints = Object.entries(map)
.map(([k,v]) => {
return { 'in': k, 'out': v};
});

const parameters = {
banner: {
js: banner,
},
entryPoints: ['src/main.ts'],
entryPoints,
bundle: true,
external: ['obsidian', 'electron', ...builtins],
platform: 'node',
external: [
'obsidian',
'electron',
"codemirror",
'@codemirror/language',
'@codemirror/state',
'@codemirror/view',
'moment',
...builtins
],
loader: {
'.png': 'dataurl',
'.woff': 'dataurl',
'.woff2': 'dataurl',
'.eot': 'dataurl',
'.ttf': 'dataurl',
'.svg': 'dataurl',
},
format: 'cjs',
// minify: prod,
target: 'es2020',
logLevel: "info",
// sourcemap: prod ? false : 'inline',
sourcemap: 'inline',
treeShaking: true,
outfile: OUTPUT_DIR + '/main.js',
outdir: dir,
plugins: [
staticAssetsPlugin,
sassPlugin({ filter: /.(s[ac]ss|css)$/ }),
copy({
assets: {
from: ['manifest.json', 'README.md', 'styles.css', 'distVersion.json'],
to: [OUTPUT_DIR],
from: ['manifest.json'],
to: ['./manifest.json']
}
}),
copy({
assets: {
from: ['src/template/**/*'],
to: ['./template/*']
from: ['README.md'],
to: ['./README.md']
}
}),
copy({
assets: {
from: ['node_modules/reveal.js/dist/*'],
to: ['./dist/*'],
from: ['distVersion.json'],
to: ['./distVersion.json']
}
}),
copy({
assets: {
from: ['src/scss/theme/source/fonts/league-gothic/*'],
to: ['./dist/theme/fonts/league-gothic/*'],
from: ['src/template/**/*'],
to: ['./template/']
}
}),
copy({
assets: {
from: ['src/scss/theme/source/fonts/source-sans-pro/*'],
to: ['./dist/theme/fonts/source-sans-pro/*'],
from: ['node_modules/reveal.js/dist/**/*'],
to: ['./dist/'],
}
}),
copy({
assets: {
from: ['src/scss/theme/source/fonts/lato/*'],
to: ['./dist/theme/fonts/lato/*'],
from: ['src/scss/theme/source/fonts/**/*'],
to: ['./dist/theme/fonts/'],
}
}),
copy({
assets: {
from: ['node_modules/reveal.js/plugin/**/*'],
to: ['./plugin'],
keepStructure: true
from: ['node_modules/highlight.js/styles/vs2015.css'],
to: ['./css/'],
}
}),
copy({
assets: {
from: ['node_modules/mathjax/es5/**/*'],
to: ['./plugin/math/mathjax'],
keepStructure: true
from: ['node_modules/@fortawesome/fontawesome-free/js/all.min.js'],
to: ['./dist/fontawesome/'],
}
}),
copy({
assets: {
from: ['node_modules/reveal.js-mermaid-plugin/plugin/mermaid/*'],
to: ['./plugin/mermaid/*'],
from: [
'node_modules/reveal.js/plugin/**/*',
],
to: ['./plugin/'],
keepStructure: true
}
}),
copy({
assets: {
from: ['node_modules/highlight.js/styles/vs2015.css'],
to: ['./css/*'],
from: ['node_modules/reveal.js-plugins/chalkboard/*'],
to: ['./plugin/chalkboard/'],
}
}),
copy({
assets: {
from: ['node_modules/@fortawesome/fontawesome-free/js/all.min.js'],
to: ['./dist/fontawesome/*'],
from: ['node_modules/chart.js/dist/*'],
to: ['./plugin/chart/'],
}
}),
copy({
assets: {
from: ['node_modules/reveal.js-plugins/chalkboard/**/*'],
to: ['./plugin/chalkboard'],
keepStructure: true
from: ['node_modules/reveal.js-plugins/chart/*'],
to: ['./plugin/chart/'],
}
}),
copy({
assets: {
from: ['node_modules/reveal.js-plugins/customcontrols/*'],
to: ['./plugin/customcontrols/*'],
to: ['./plugin/customcontrols/'],
keepStructure: true
}
}),
copy({
assets: {
from: ['node_modules/reveal.js-menu/*'],
to: ['./plugin/menu/*'],
from: ['node_modules/reveal.js-elapsed-time-bar/plugin/elapsed-time-bar/*'],
to: ['./plugin/elapsed-time-bar/'],
}
}),
copy({
assets: {
from: ['node_modules/reveal.js-plugins/chart/**/*'],
to: ['./plugin/chart'],
from: ['node_modules/mathjax/es5/**/*'],
to: ['./plugin/math/mathjax'],
keepStructure: true
}
}),
copy({
assets: {
from: ['node_modules/chart.js/dist/chart.min.js'],
to: ['./plugin/chart/*'],
}
}),
copy({
assets: {
from: ['node_modules/reveal.js-elapsed-time-bar/plugin/elapsed-time-bar/elapsed-time-bar.js'],
to: ['./plugin/elapsed-time-bar/*'],
from: ['node_modules/reveal.js-menu/*'],
to: ['./plugin/menu/'],
}
}),
copy({
assets: {
from: ['node_modules/reveal-pointer/dist/pointer.js'],
to: ['./plugin/reveal-pointer/*'],
from: ['node_modules/reveal.js-mermaid-plugin/plugin/mermaid/*'],
to: ['./plugin/mermaid/'],
}
}),
copy({
assets: {
from: ['node_modules/reveal-pointer/dist/pointer.css'],
to: ['./plugin/reveal-pointer/*'],
from: [
'node_modules/reveal.js-pointer/dist/pointer.js',
'node_modules/reveal.js-pointer/dist/pointer.css'],
to: ['./plugin/reveal-pointer/'],
}
}),
copy({
assets: prod ? {} : {
from: ['.hotreload'],
to: [OUTPUT_DIR],
to: ['.hotreload'],
},
once: true
}),
],
};

function buildAllThemes(themeDir) {
readdir(themeDir, function (err, files) {
files.forEach(function (file) {
if (file.endsWith('.scss')) {
const source = themeDir + file;
const target = OUTPUT_DIR + '/dist/theme/' + basename(file).replaceAll('.scss', '.css');
buildScss(source, target);
}
});
});
}

function buildScss(source, target) {
return esbuild.build({
entryPoints: [
source,
],
outfile: target,
plugins: [
sassPlugin(),
staticAssetsPlugin
]
});
}

function flatten(lists) {
return lists.reduce((a, b) => a.concat(b), []);
}

function getDirectories(srcpath) {
return fs.readdirSync(srcpath)
.map(file => path.join(srcpath, file))
.filter(path => fs.statSync(path).isDirectory());
}

function getDirectoriesRecursive(srcpath) {
return [srcpath, ...flatten(getDirectories(srcpath).map(getDirectoriesRecursive))];
}

const scssDirs = getDirectoriesRecursive('src/scss');
const templateDirs = getDirectoriesRecursive('src/template');

if (prod) {
await esbuild.build(parameters)
.then(buildScss('src/scss/layout/main.scss', OUTPUT_DIR + '/css/layout.css'))
.then(buildScss('src/scss/theme/source/mattropolis.scss', OUTPUT_DIR + '/css/mattropolis.css'))
.then(buildAllThemes('src/scss/theme/source/'))
.catch((x) => {
if (x.errors) {
console.error(x.errors);
} else {
console.error(x);
}
process.exit(1)
});
await esbuild.build(parameters).catch((x) => {
if (x.errors) {
console.error(x.errors);
} else {
console.error(x);
}
process.exit(1)
});
} else {
let ctx = await esbuild.context(parameters);
await ctx.watch();
await ctx.watch()
}
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
"@typescript-eslint/eslint-plugin": "^7.0.1",
"auto-changelog": "^2.4.0",
"builtin-modules": "^3.3.0",
"chart.js": "^4.4.1",
"dotenv": "^16.4.4",
"electron": "^28.2.3",
"esbuild": "^0.20.0",
"esbuild-plugin-copy": "^2.1.1",
"esbuild-sass-plugin": "^3.0.0",
"eslint": "^8.56.0",
"highlight.js": "^11.9.0",
"jest": "^29.7.0",
"mathjax": "^3.2.2",
"obsidian": "^1.4.11",
"reveal-elapsed-time-bar": "^0.1.3",
Expand All @@ -59,26 +60,28 @@
"reveal.js-plugins": "^4.2.5",
"reveal.js-pointer": "^0.1.4",
"sass": "^1.71.0",
"ts-jest": "^29.1.2",
"ts-mockito": "^2.6.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
},
"dependencies": {
"@codemirror/state": "^6.0.0",
"@codemirror/view": "^6.0.0",
"@codemirror/state": "^6.4.0",
"@codemirror/view": "^6.24.0",
"@fastify/static": "^7.0.1",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/js-yaml": "^4.0.9",
"@typescript-eslint/parser": "^7.0.1",
"chart.js": "3",
"color": "^4.2.3",
"express": "^4.18.2",
"fastify": "^4.26.1",
"fs-extra": "^11.2.0",
"glob": "^10.3.10",
"jest": "^29.7.0",
"js-yaml": "^4.1.0",
"jszip": "^3.10.1",
"mustache": "^4.2.0",
"request": "^2.88.2",
"ts-jest": "^29.1.2",
"ts-mockito": "^2.6.1",
"yaml-front-matter": "^4.1.1"
},
"resolutions": {
Expand Down
Loading

0 comments on commit 898486e

Please sign in to comment.