yanki 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/cli.js +7 -7
- package/dist/lib/index.d.ts +6 -3
- package/dist/lib/index.js +1 -1
- package/dist/{sync--_RR5Plw.js → sync-DIFG0pV-.js} +64 -64
- package/package.json +3 -3
- package/readme.md +1 -0
package/dist/bin/cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var Y=Object.defineProperty;var m=(e,t)=>Y(e,"name",{value:t,configurable:!0});import{y as J,u as h,k as T,j as D,l as I,b as
|
|
2
|
+
var Y=Object.defineProperty;var m=(e,t)=>Y(e,"name",{value:t,configurable:!0});import{y as J,u as h,k as T,j as D,l as I,b as M,c as U,f as L,s as z,h as j}from"../sync-DIFG0pV-.js";import s from"chalk";import{globby as H}from"globby";import W from"node:fs/promises";import q from"node:path";import B from"node:os";import F from"yargs";import{hideBin as G}from"yargs/helpers";import"rehype-mathjax";import"rehype-parse";import"node:crypto";var K="0.7.0";const N=process?.versions?.node!==void 0,d={verbose:!1,log(...e){if(!this.verbose)return;const t=s.gray("[Log]");N?console.warn(t,...e):console.log(t,...e)},logPrefixed(e,...t){this.info(s.blue(`[${e}]`),...t)},info(...e){if(!this.verbose)return;const t=s.green("[Info]");N?console.warn(t,...e):console.info(t,...e)},infoPrefixed(e,...t){this.info(s.blue(`[${e}]`),...t)},warn(...e){console.warn(s.yellow("[Warning]"),...e)},warnPrefixed(e,...t){this.warn(s.blue(`[${e}]`),...t)},error(...e){console.error(s.red("[Error]"),...e)},errorPrefixed(e,...t){this.error(s.blue(`[${e}]`),...t)}},y={"anki-auto-launch":{alias:"l",default:!1,describe:"Attempt to open the Anki desktop app if it's not already running. (Experimental, macOS only.)",type:"boolean"}},g={"anki-web":{alias:"w",default:!0,describe:'Automatically sync any changes to AnkiWeb after Yanki has finished syncing locally. If false, only local Anki data is updated and you must manually invoke a sync to AnkiWeb. This is the equivalent of pushing the "sync" button in the Anki app.',type:"boolean"}},w={"anki-connect":{default:"http://127.0.0.1:8765",describe:"Host and port of the Anki-Connect server. The default is usually fine. See the Anki-Connect documentation for more information.",type:"string"}},v={verbose:{default:!1,describe:"Enable verbose logging.",type:"boolean"}};function k(e){return{json:{default:!1,describe:e,type:"boolean"}}}m(k,"jsonOption");const S={"dry-run":{alias:"d",default:!1,describe:"Run without making any changes to the Anki database. See a report of what would have been done.",type:"boolean"}};function A(e){return{namespace:{alias:"n",default:J,describe:e,type:"string"}}}m(A,"namespaceOption");const x=B.homedir();function Q(e){if(typeof e!="string")throw new TypeError(`Expected a string, got ${typeof e}`);return x?e.replace(/^~(?=$|\/|\\)/,x):e}m(Q,"untildify");const b=m(e=>{const{code:t}=e.cause;throw t==="ECONNREFUSED"&&(d.error("Failed to connect to Anki. Make sure Anki is running and AnkiConnect is installed."),process.exitCode=1,process.exit()),e instanceof Error?e:new Error("Unknown error")},"ankiNotRunningErrorHandler"),R=F(G(process.argv));await R.scriptName("yanki").usage("$0 [command]","Run a Yanki command. Defaults to `sync` if a command is not provided.").command(["$0 <directory> [options]","sync <directory> [options]"],"Perform a one-way synchronization from a local directory of Markdown files to the Anki database. Any Markdown files in subdirectories are included as well.",e=>e.positional("directory",{demandOption:!0,describe:"The path to the local directory of Markdown files to sync.",type:"string"}).option(S).option(A("Advanced option for managing multiple Yanki synchronization groups. Case insensitive. See the readme for more information.")).option(w).option(y).option(g).option("manage-filenames",{alias:"m",choices:["off","prompt","response"],default:"off",describe:'Rename local note files to match their content. Useful if you want to feel have semantically reasonable note file names without managing them by hand. The `"prompt"` option will attempt to create the filename based on the "front" of the card, while `"response"` will prioritize the "back", "Cloze", or "type in the answer" portions of the card. Truncation, sanitization, and deduplication are taken care of.',type:"string"}).option("max-filename-length",{default:void 0,defaultDescription:"60",describe:"If `manage-filenames` is enabled, this option specifies the maximum length of the filename in characters.",type:"number"}).option(k("Output the sync report as JSON.")).option(v),async({ankiAutoLaunch:e,ankiConnect:t,ankiWeb:i,directory:n,dryRun:a,json:r,manageFilenames:o,maxFilenameLength:p,namespace:f,recursive:c=!0,verbose:u})=>{d.verbose=u;const l=Q(n),E=c?`${l}/**/*.md`:`${l}/*.md`,C=await H(E,{absolute:!0});if(C.length===0){d.error(`No Markdown files found in "${l}".`),process.exitCode=1;return}o==="off"&&p!==void 0&&d.warn("Ignoring `max-filename-length` option because `manage-filenames` is not enabled.");const{host:$,port:P}=h(t),O=await T(C,{ankiConnectOptions:{autoLaunch:e,host:$,port:P},ankiWeb:i,dryRun:a,filenameMode:o==="off"?void 0:o,manageFilenames:o!=="off",maxFilenameLength:p,namespace:f}).catch(b);r?(process.stdout.write(JSON.stringify(O,void 0,2)),process.stdout.write(`
|
|
3
3
|
`)):(process.stderr.write(D(O,u)),process.stderr.write(`
|
|
4
|
-
`))}).command("list [options]","Utility command to list Yanki-created notes in the Anki database.",e=>e.option(A("Advanced option to list notes in a specific namespace. Case insensitive. Notes from the default internal namespace are listed by default. Pass `'*'` to list all Yanki-created notes in the Anki database.")).options(w).options(y).option(k("Output the list of notes as JSON to stdout.")),async({ankiAutoLaunch:e,ankiConnect:t,json:i,namespace:
|
|
5
|
-
`)):(process.stdout.write(
|
|
6
|
-
`))}).command("delete [options]","Utility command to manually delete Yanki-created notes in the Anki database. This is for advanced use cases, usually the `sync` command takes care of deleting files from Anki Database once they're removed from the local file system.",e=>e.option(S).option(A("Advanced option to list notes in a specific namespace. Case insensitive. Notes from the default internal namespace are listed by default. If you've synced notes to multiple namespaces, Pass `'*'` to delete all Yanki-created notes in the Anki database.")).options(w).options(y).option(g).option(k("Output the list of deleted notes as JSON to stdout.")).option(v),async({ankiAutoLaunch:e,ankiConnect:t,ankiWeb:i,dryRun:
|
|
7
|
-
`)):(process.stderr.write(
|
|
8
|
-
`))}).command("style [options]","Utility command to set the CSS stylesheet for all present and future Yanki-created notes.",e=>e.option(S).option("css",{alias:"c",default:void 0,describe:"Path to the CSS stylesheet to set for all Yanki-created notes. If not provided, the default Anki stylesheet is used.",type:"string"}).options(w).options(y).option(g).option(k("Output the list of updated note types / models as JSON to stdout.")).option(v),async({ankiAutoLaunch:e,ankiConnect:t,ankiWeb:i,css:
|
|
9
|
-
`)):(process.stderr.write(j(u,
|
|
4
|
+
`))}).command("list [options]","Utility command to list Yanki-created notes in the Anki database.",e=>e.option(A("Advanced option to list notes in a specific namespace. Case insensitive. Notes from the default internal namespace are listed by default. Pass `'*'` to list all Yanki-created notes in the Anki database.")).options(w).options(y).option(k("Output the list of notes as JSON to stdout.")),async({ankiAutoLaunch:e,ankiConnect:t,json:i,namespace:n})=>{const{host:a,port:r}=h(t),o=await I({ankiConnectOptions:{autoLaunch:e,host:a,port:r},namespace:n}).catch(b);i?(process.stdout.write(JSON.stringify(o,void 0,2)),process.stdout.write(`
|
|
5
|
+
`)):(process.stdout.write(M(o)),process.stdout.write(`
|
|
6
|
+
`))}).command("delete [options]","Utility command to manually delete Yanki-created notes in the Anki database. This is for advanced use cases, usually the `sync` command takes care of deleting files from Anki Database once they're removed from the local file system.",e=>e.option(S).option(A("Advanced option to list notes in a specific namespace. Case insensitive. Notes from the default internal namespace are listed by default. If you've synced notes to multiple namespaces, Pass `'*'` to delete all Yanki-created notes in the Anki database.")).options(w).options(y).option(g).option(k("Output the list of deleted notes as JSON to stdout.")).option(v),async({ankiAutoLaunch:e,ankiConnect:t,ankiWeb:i,dryRun:n,json:a,namespace:r,verbose:o})=>{const{host:p,port:f}=h(t),c=await U({ankiConnectOptions:{autoLaunch:e,host:p,port:f},ankiWeb:i,dryRun:n,namespace:r}).catch(b);a?(process.stdout.write(JSON.stringify(c,void 0,2)),process.stdout.write(`
|
|
7
|
+
`)):(process.stderr.write(L(c,o)),process.stderr.write(`
|
|
8
|
+
`))}).command("style [options]","Utility command to set the CSS stylesheet for all present and future Yanki-created notes.",e=>e.option(S).option("css",{alias:"c",default:void 0,describe:"Path to the CSS stylesheet to set for all Yanki-created notes. If not provided, the default Anki stylesheet is used.",type:"string"}).options(w).options(y).option(g).option(k("Output the list of updated note types / models as JSON to stdout.")).option(v),async({ankiAutoLaunch:e,ankiConnect:t,ankiWeb:i,css:n,dryRun:a,json:r,verbose:o})=>{const{host:p,port:f}=h(t);let c;if(n!==void 0){if(q.extname(n)!==".css"){d.error("The provided CSS file must have a .css extension."),process.exitCode=1;return}try{c=await W.readFile(n,"utf8")}catch(l){l instanceof Error?d.error(`Error loading CSS file: ${l.message}`):d.error(`Unknown error loading CSS file: ${String(l)}`),process.exitCode=1;return}}const u=await z({ankiConnectOptions:{autoLaunch:e,host:p,port:f},ankiWeb:i,css:c??void 0,dryRun:a}).catch(b);r?(process.stdout.write(JSON.stringify(u,void 0,2)),process.stdout.write(`
|
|
9
|
+
`)):(process.stderr.write(j(u,o)),process.stderr.write(`
|
|
10
10
|
`))}).demandCommand(1).alias("h","help").version(K).alias("v","version").help().wrap(process.stdout.isTTY?Math.min(120,R.terminalWidth()):0).parse();
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -900,9 +900,11 @@ type RenameFilesReport = {
|
|
|
900
900
|
note: YankiNote;
|
|
901
901
|
}>;
|
|
902
902
|
};
|
|
903
|
+
type FilenameMode = 'prompt' | 'response';
|
|
903
904
|
type RenameFilesOptions = {
|
|
904
905
|
dryRun: boolean;
|
|
905
|
-
|
|
906
|
+
filenameMode: FilenameMode;
|
|
907
|
+
manageFilenames: boolean;
|
|
906
908
|
maxFilenameLength: number;
|
|
907
909
|
namespace: string;
|
|
908
910
|
obsidianVault: string | undefined;
|
|
@@ -961,9 +963,10 @@ type SyncOptions = {
|
|
|
961
963
|
ankiWeb: boolean;
|
|
962
964
|
defaultDeckName: string;
|
|
963
965
|
dryRun: boolean;
|
|
966
|
+
filenameMode: FilenameMode;
|
|
964
967
|
/** Only applies to syncFiles */
|
|
965
|
-
manageFilenames:
|
|
966
|
-
/** Only applies if manageFilenames is not `
|
|
968
|
+
manageFilenames: boolean;
|
|
969
|
+
/** Only applies if manageFilenames is not `false`. Will _not_ truncate user-specified file names in other cases. */
|
|
967
970
|
maxFilenameLength: number;
|
|
968
971
|
namespace: string;
|
|
969
972
|
/** Ensures that wiki-style links work correctly */
|
package/dist/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as l,d as n,a as i,e as p,g as m,i as f,f as d,b as u,h as y,j as c,n as O,o as R,l as S,r as F,s as N,k as g,m as h,u as k}from"../sync
|
|
1
|
+
import{c as l,d as n,a as i,e as p,g as m,i as f,f as d,b as u,h as y,j as c,n as O,o as R,l as S,r as F,s as N,k as g,m as h,u as k}from"../sync-DIFG0pV-.js";import"rehype-mathjax";import"rehype-parse";import"node:path";import"node:crypto";export{l as cleanNotes,n as defaultCleanOptions,i as defaultListOptions,p as defaultRenameFilesOptions,m as defaultStyleOptions,f as defaultSyncOptions,d as formatCleanReport,u as formatListReport,y as formatStyleReport,c as formatSyncReport,O as getNoteFromMarkdown,R as hostAndPortToUrl,S as listNotes,F as renameFiles,N as setStyle,g as syncFiles,h as syncNotes,k as urlToHostAndPort};
|