Add the documentation and new a build option (buildDev).

This commit is contained in:
vorotamoroz
2024-05-28 08:56:26 +01:00
parent 069b8513d1
commit bf3a6e7570
3 changed files with 79 additions and 65 deletions

View File

@@ -0,0 +1,34 @@
# How to add translations
## Getting ready
1. Clone this repository recursively.
```sh
git clone --recursive https://github.com/vrtmrz/obsidian-livesync
```
2. Make `ls-debug` folder under your vault's `.obsidian` folder (as like `.../dev/.obsidian/ls-debug`).
## Add translations for already defined terms
1. Install dependencies, and build the plug-in as dev. build.
```sh
cd obsidian-livesync
npm i -D
npm run buildDev
```
2. Copy the `main.js` to `.obsidian/plugins/obsidian-livesync` folder of your vault, and run Obsidian-Self-hosted LiveSync.
3. You will get the `missing-translation-yyyy-mm-dd.jsonl`, please fill in new translations.
4. Build the plug-in again, and confirm that displayed things were expected.
5. Merge them into `rosetta.ts`, and make the PR to `https://github.com/vrtmrz/livesync-commonlib`.
## Make messages to be translated
1. Find the message that you want to be translated.
2. Change the literal to a tagged template literal using `$f`, like below.
```diff
- Logger("Could not determine passphrase to save data.json! You probably make the configuration sure again!", LOG_LEVEL_URGENT);
+ Logger($f`Could not determine passphrase to save data.json! You probably make the configuration sure again!`, LOG_LEVEL_URGENT);
```
3. Make the PR to `https://github.com/vrtmrz/obsidian-livesync`.
4. Follow the steps of "Add translations for already defined terms" to add the translations.

View File

@@ -14,21 +14,24 @@ if you want to view the source, please visit the github repository of this plugi
*/ */
`; `;
const prod = process.argv[2] === "production"; const prod = process.argv[2] === "production";
const keepTest = !prod; const dev = process.argv[2] === "dev";
const keepTest = !prod || dev;
const terserOpt = { const terserOpt = {
sourceMap: (!prod ? { sourceMap: !prod
url: "inline" ? {
} : {}), url: "inline",
}
: {},
format: { format: {
indent_level: 2, indent_level: 2,
beautify: true, beautify: true,
comments: "some", comments: "some",
ecma: 2018, ecma: 2018,
preamble: banner, preamble: banner,
webkit: true webkit: true,
}, },
parse: { parse: {
// parse options // parse options
@@ -53,16 +56,6 @@ const terserOpt = {
ecma: 2018, ecma: 2018,
unused: true, unused: true,
}, },
// mangle: {
// // mangle options
// keep_classnames: true,
// keep_fnames: true,
// properties: {
// // mangle property options
// }
// },
ecma: 2018, // specify one of: 5, 2015, 2016, etc. ecma: 2018, // specify one of: 5, 2015, 2016, etc.
enclose: false, // or specify true, or "args:values" enclose: false, // or specify true, or "args:values"
@@ -72,25 +65,24 @@ const terserOpt = {
module: false, module: false,
// nameCache: null, // or specify a name cache object // nameCache: null, // or specify a name cache object
safari10: false, safari10: false,
toplevel: false toplevel: false,
} };
const manifestJson = JSON.parse(fs.readFileSync("./manifest.json") + ""); const manifestJson = JSON.parse(fs.readFileSync("./manifest.json") + "");
const packageJson = JSON.parse(fs.readFileSync("./package.json") + ""); const packageJson = JSON.parse(fs.readFileSync("./package.json") + "");
const updateInfo = JSON.stringify(fs.readFileSync("./updates.md") + ""); const updateInfo = JSON.stringify(fs.readFileSync("./updates.md") + "");
/** @type esbuild.Plugin[] */ /** @type esbuild.Plugin[] */
const plugins = [{ const plugins = [
name: 'my-plugin', {
name: "my-plugin",
setup(build) { setup(build) {
let count = 0; let count = 0;
build.onEnd(async result => { build.onEnd(async (result) => {
if (count++ === 0) { if (count++ === 0) {
console.log('first build:', result); console.log("first build:", result);
} else { } else {
console.log('subsequent build:'); console.log("subsequent build:");
} }
if (prod) { if (prod) {
console.log("Performing terser"); console.log("Performing terser");
@@ -106,7 +98,8 @@ const plugins = [{
} }
}); });
}, },
}]; },
];
const context = await esbuild.context({ const context = await esbuild.context({
banner: { banner: {
@@ -115,26 +108,12 @@ const context = await esbuild.context({
entryPoints: ["src/main.ts"], entryPoints: ["src/main.ts"],
bundle: true, bundle: true,
define: { define: {
"MANIFEST_VERSION": `"${manifestJson.version}"`, MANIFEST_VERSION: `"${manifestJson.version}"`,
"PACKAGE_VERSION": `"${packageJson.version}"`, PACKAGE_VERSION: `"${packageJson.version}"`,
"UPDATE_INFO": `${updateInfo}`, UPDATE_INFO: `${updateInfo}`,
"global": "window", global: "window",
}, },
external: [ external: ["obsidian", "electron", "crypto", "@codemirror/autocomplete", "@codemirror/collab", "@codemirror/commands", "@codemirror/language", "@codemirror/lint", "@codemirror/search", "@codemirror/state", "@codemirror/view", "@lezer/common", "@lezer/highlight", "@lezer/lr"],
"obsidian",
"electron",
"crypto",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr"],
// minifyWhitespace: true, // minifyWhitespace: true,
format: "cjs", format: "cjs",
target: "es2018", target: "es2018",
@@ -155,11 +134,11 @@ const context = await esbuild.context({
preprocess: sveltePreprocess(), preprocess: sveltePreprocess(),
compilerOptions: { css: "injected", preserveComments: false }, compilerOptions: { css: "injected", preserveComments: false },
}), }),
...plugins ...plugins,
], ],
}) });
if (prod) { if (prod || dev) {
await context.rebuild(); await context.rebuild();
process.exit(0); process.exit(0);
} else { } else {

View File

@@ -7,6 +7,7 @@
"scripts": { "scripts": {
"dev": "node esbuild.config.mjs", "dev": "node esbuild.config.mjs",
"build": "node esbuild.config.mjs production", "build": "node esbuild.config.mjs production",
"buildDev": "node esbuild.config.mjs dev",
"lint": "eslint src" "lint": "eslint src"
}, },
"keywords": [], "keywords": [],