mirror of
https://github.com/morten-olsen/plainidx.git
synced 2026-02-08 01:06:24 +01:00
init
This commit is contained in:
2
packages/tools-cli/.gitignore
vendored
Normal file
2
packages/tools-cli/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules/
|
||||
/dist/
|
||||
2
packages/tools-cli/bin/cli.mjs
Executable file
2
packages/tools-cli/bin/cli.mjs
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
import '../dist/cli.js';
|
||||
27
packages/tools-cli/package.json
Normal file
27
packages/tools-cli/package.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "@plaindb/tools-cli",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"main": "dist/exports.js",
|
||||
"bin": {
|
||||
"plaindb": "bin/cli.mjs"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc --build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@plaindb/fs-system": "workspace:*",
|
||||
"@plaindb/plaindb": "workspace:*",
|
||||
"@plaindb/plugin-core": "workspace:*",
|
||||
"@plaindb/plugin-markdown": "workspace:*",
|
||||
"sqlite3": "^5.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.10.1",
|
||||
"typescript": "^5.7.2"
|
||||
}
|
||||
}
|
||||
53
packages/tools-cli/src/cli.ts
Normal file
53
packages/tools-cli/src/cli.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { SystemFileSystem } from '@plaindb/fs-system';
|
||||
import { CorePlugin } from '@plaindb/plugin-core';
|
||||
import { MarkdownPlugin } from '@plaindb/plugin-markdown';
|
||||
import { resolve } from 'path';
|
||||
import { PlainDB } from '../../plaindb/dist/exports.js';
|
||||
|
||||
const fs = new SystemFileSystem({
|
||||
cwd: resolve('/Users/alice/Documents/Exo'),
|
||||
});
|
||||
|
||||
const { plugins, documents, close } = new PlainDB({
|
||||
fs,
|
||||
getDBConfig: () => ({
|
||||
client: 'sqlite',
|
||||
useNullAsDefault: false,
|
||||
connection: {
|
||||
filename: ':memory:',
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
await plugins.add([MarkdownPlugin]);
|
||||
|
||||
await fs.update();
|
||||
|
||||
const tags1 = await plugins.action(CorePlugin, 'getTags', undefined);
|
||||
|
||||
console.log('Done', tags1);
|
||||
|
||||
const demoDocument = await documents.get('hello/world.md');
|
||||
|
||||
demoDocument.data = Buffer.from(`
|
||||
# Hello World
|
||||
|
||||
:tag[hello]
|
||||
`);
|
||||
|
||||
await demoDocument.save();
|
||||
|
||||
const tags2 = await plugins.action(CorePlugin, 'getTags', undefined);
|
||||
console.log('Done', tags2);
|
||||
|
||||
demoDocument.data = Buffer.from(`
|
||||
# Hello World
|
||||
|
||||
:tag[world]
|
||||
`);
|
||||
await demoDocument.save();
|
||||
|
||||
const tags3 = await plugins.action(CorePlugin, 'getTags', undefined);
|
||||
console.log('Done', tags3);
|
||||
|
||||
await close();
|
||||
9
packages/tools-cli/tsconfig.json
Normal file
9
packages/tools-cli/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user