mirror of
https://github.com/jesse-r-s-hines/obsidian-open-tab-settings.git
synced 2026-07-22 05:43:41 +00:00
Glob all i18n files
This commit is contained in:
parent
d105532b6a
commit
55d1f2d08a
3 changed files with 34 additions and 6 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import esbuild from "esbuild";
|
||||
import process from "process";
|
||||
import { builtinModules } from "node:module";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
const banner =
|
||||
`/*
|
||||
|
|
@ -17,6 +19,32 @@ const context = await esbuild.context({
|
|||
},
|
||||
entryPoints: ["src/main.ts"],
|
||||
bundle: true,
|
||||
plugins: [{
|
||||
name: "import-glob",
|
||||
setup: (build) => {
|
||||
build.onResolve({ filter: /^glob:.*$/ }, async (args) => {
|
||||
return {
|
||||
path: args.path.replace(/^glob:/, ''),
|
||||
namespace: 'import-glob',
|
||||
pluginData: { resolveDir: args.resolveDir },
|
||||
};
|
||||
});
|
||||
build.onLoad({ filter: /.*/, namespace: 'import-glob' }, async (args) => {
|
||||
const files = fs.globSync(args.path, {cwd: args.pluginData.resolveDir})
|
||||
.map((f) => f.split(path.sep).join('/'))
|
||||
.sort();
|
||||
return {
|
||||
contents: [
|
||||
...files.map((module, i) => `import m${i} from './${module}'`),
|
||||
"export default {",
|
||||
...files.map((f, i) => `${JSON.stringify(path.basename(f, path.extname(f)))}: m${i},`),
|
||||
"}",
|
||||
].join("\n"),
|
||||
resolveDir: args.pluginData.resolveDir,
|
||||
};
|
||||
});
|
||||
},
|
||||
}],
|
||||
external: [
|
||||
"obsidian",
|
||||
"electron",
|
||||
|
|
|
|||
5
src/glob.d.ts
vendored
Normal file
5
src/glob.d.ts
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
declare module 'glob:*' {
|
||||
const modules: Record<string, any>;
|
||||
export default modules;
|
||||
}
|
||||
|
|
@ -1,11 +1,6 @@
|
|||
import i18next from 'i18next';
|
||||
import { getLanguage } from 'obsidian';
|
||||
|
||||
// esbuild doesn't have an easy way to include all files in a dir, so we'll list them manually
|
||||
import en from './locales/en.json';
|
||||
const locales = {
|
||||
en,
|
||||
}
|
||||
import locales from 'glob:./locales/*.json';
|
||||
|
||||
export async function initializeI18n() {
|
||||
return await i18next.init({
|
||||
|
|
|
|||
Loading…
Reference in a new issue