Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
406f8ddb74 | ||
|
|
cf8574664f | ||
|
|
036a19bf88 | ||
|
|
8f86e354c0 | ||
|
|
55598053b9 | ||
|
|
8a0b27992c | ||
|
|
6ec688b994 | ||
|
|
990ed9dcec | ||
|
|
2684c0f27e | ||
|
|
28b17d4f08 |
1197
package-lock.json
generated
1197
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@@ -1,29 +1,28 @@
|
||||
{
|
||||
"name": "takerofnotes-plugin-filesystem",
|
||||
"version": "1.4.0",
|
||||
"name": "@takerofnotes/plugin-filesystem",
|
||||
"version": "0.2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/nicwands/takerofnotes-plugin-filesystem.git"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"exports": {
|
||||
".": "./dist/index.js"
|
||||
},
|
||||
"exports": "./dist/index.js",
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"test": "vitest",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"author": "nicwands",
|
||||
"license": "MIT",
|
||||
"description": "Filesystem storage plugin for Taker of Notes",
|
||||
"dependencies": {
|
||||
"gray-matter": "^4.0.3",
|
||||
"takerofnotes-plugin-sdk": "^0.3.0"
|
||||
"@takerofnotes/plugin-sdk": "^0.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^29.0.0",
|
||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||
"rollup": "^4.59.0"
|
||||
"rollup": "^4.59.0",
|
||||
"vitest": "^3.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// rollup.config.js
|
||||
import resolve from '@rollup/plugin-node-resolve'
|
||||
import commonjs from '@rollup/plugin-commonjs'
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BaseNotesAdapter } from 'takerofnotes-plugin-sdk'
|
||||
import matter from 'gray-matter'
|
||||
import { BaseNotesAdapter } from '@takerofnotes/plugin-sdk'
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
|
||||
@@ -21,16 +20,13 @@ export default class FileSystemAdapter extends BaseNotesAdapter {
|
||||
const notes = []
|
||||
|
||||
for (const file of files) {
|
||||
if (!file.endsWith('.md')) continue
|
||||
if (!file.endsWith('.json')) continue
|
||||
|
||||
const fullPath = path.join(this.notesDir, file)
|
||||
const raw = await fs.readFile(fullPath, 'utf8')
|
||||
const parsed = matter(raw)
|
||||
const fileContent = await fs.readFile(fullPath, 'utf8')
|
||||
const parsedFile = JSON.parse(fileContent)
|
||||
|
||||
notes.push({
|
||||
...parsed.data,
|
||||
content: parsed.content,
|
||||
})
|
||||
notes.push(parsedFile)
|
||||
}
|
||||
|
||||
return notes
|
||||
@@ -45,21 +41,15 @@ export default class FileSystemAdapter extends BaseNotesAdapter {
|
||||
}
|
||||
|
||||
async delete(id) {
|
||||
const filePath = path.join(this.notesDir, `${id}.md`)
|
||||
const filePath = path.join(this.notesDir, `${id}.json`)
|
||||
await fs.unlink(filePath)
|
||||
}
|
||||
|
||||
async _write(note) {
|
||||
const filePath = path.join(this.notesDir, `${note.id}.md`)
|
||||
const filePath = path.join(this.notesDir, `${note.id}.json`)
|
||||
|
||||
const fileContent = matter.stringify(note.content, {
|
||||
id: note.id,
|
||||
title: note.title,
|
||||
category: note.category ?? null,
|
||||
createdAt: note.createdAt,
|
||||
updatedAt: note.updatedAt,
|
||||
})
|
||||
const stringifiedNote = JSON.stringify(note)
|
||||
|
||||
await fs.writeFile(filePath, fileContent, 'utf8')
|
||||
await fs.writeFile(filePath, stringifiedNote, 'utf8')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import FileSystemAdapter from './FileSystemAdapter'
|
||||
import { definePlugin } from 'takerofnotes-plugin-sdk'
|
||||
import { definePlugin } from '@takerofnotes/plugin-sdk'
|
||||
|
||||
export default definePlugin({
|
||||
id: 'filesystem',
|
||||
name: 'Filesystem',
|
||||
description: 'Store notes as markdown files on your local filesystem',
|
||||
version: '1.0.0',
|
||||
apiVersion: '0.3.0',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.3.1',
|
||||
configSchema: [
|
||||
{
|
||||
key: 'notesDir',
|
||||
|
||||
45
test/plugin.test.js
Normal file
45
test/plugin.test.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import { describe, it } from 'vitest'
|
||||
import { runPluginTests } from '@takerofnotes/plugin-sdk'
|
||||
import plugin from './src/index.js'
|
||||
import FileSystemAdapter from './src/FileSystemAdapter.js'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import fs from 'fs'
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
const testDir = path.join(__dirname, 'test-notes')
|
||||
|
||||
if (!fs.existsSync(testDir)) {
|
||||
fs.mkdirSync(testDir, { recursive: true })
|
||||
}
|
||||
|
||||
const adapter = new FileSystemAdapter({ notesDir: testDir })
|
||||
const tests = runPluginTests({ plugin, adapter })
|
||||
|
||||
describe('Plugin Validation', () => {
|
||||
tests.validatePlugin(it, (a, b) => expect(a).toBe(b))
|
||||
})
|
||||
|
||||
describe('Adapter: init()', () => {
|
||||
tests.init(it)
|
||||
})
|
||||
|
||||
describe('Adapter: getAll()', () => {
|
||||
tests.getAll(it)
|
||||
})
|
||||
|
||||
describe('Adapter: create()', () => {
|
||||
tests.create(it)
|
||||
})
|
||||
|
||||
describe('Adapter: update()', () => {
|
||||
tests.update(it)
|
||||
})
|
||||
|
||||
describe('Adapter: delete()', () => {
|
||||
tests.delete(it)
|
||||
})
|
||||
|
||||
describe('Full CRUD Cycle', () => {
|
||||
tests.crudCycle(it)
|
||||
})
|
||||
1
test/test-notes/test-create-note.json
Normal file
1
test/test-notes/test-create-note.json
Normal file
@@ -0,0 +1 @@
|
||||
{"id":"test-create-note","data":"test-data"}
|
||||
1
test/test-notes/test-note-1.json
Normal file
1
test/test-notes/test-note-1.json
Normal file
@@ -0,0 +1 @@
|
||||
{"id":"test-note-1","data":"test-data"}
|
||||
1
test/test-notes/test-update-note-2.json
Normal file
1
test/test-notes/test-update-note-2.json
Normal file
@@ -0,0 +1 @@
|
||||
{"id":"test-update-note-2","data":"Updated data v2"}
|
||||
1
test/test-notes/test-update-note.json
Normal file
1
test/test-notes/test-update-note.json
Normal file
@@ -0,0 +1 @@
|
||||
{"id":"test-update-note","data":"Updated data"}
|
||||
7
vitest.config.js
Normal file
7
vitest.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user