Compare commits
3 Commits
v0.1.1
...
406f8ddb74
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
406f8ddb74 | ||
|
|
cf8574664f | ||
|
|
036a19bf88 |
1193
package-lock.json
generated
1193
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@takerofnotes/plugin-filesystem",
|
"name": "@takerofnotes/plugin-filesystem",
|
||||||
"version": "0.1.1",
|
"version": "0.2.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/nicwands/takerofnotes-plugin-filesystem.git"
|
"url": "git+https://github.com/nicwands/takerofnotes-plugin-filesystem.git"
|
||||||
@@ -10,18 +10,19 @@
|
|||||||
"exports": "./dist/index.js",
|
"exports": "./dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rollup -c",
|
"build": "rollup -c",
|
||||||
|
"test": "vitest",
|
||||||
"prepublishOnly": "npm run build"
|
"prepublishOnly": "npm run build"
|
||||||
},
|
},
|
||||||
"author": "nicwands",
|
"author": "nicwands",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "Filesystem storage plugin for Taker of Notes",
|
"description": "Filesystem storage plugin for Taker of Notes",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@takerofnotes/plugin-sdk": "^0.1.0",
|
"@takerofnotes/plugin-sdk": "^0.3.1"
|
||||||
"gray-matter": "^4.0.3"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^29.0.0",
|
"@rollup/plugin-commonjs": "^29.0.0",
|
||||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||||
"rollup": "^4.59.0"
|
"rollup": "^4.59.0",
|
||||||
|
"vitest": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { BaseNotesAdapter } from '@takerofnotes/plugin-sdk'
|
import { BaseNotesAdapter } from '@takerofnotes/plugin-sdk'
|
||||||
import matter from 'gray-matter'
|
|
||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
@@ -21,16 +20,13 @@ export default class FileSystemAdapter extends BaseNotesAdapter {
|
|||||||
const notes = []
|
const notes = []
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (!file.endsWith('.md')) continue
|
if (!file.endsWith('.json')) continue
|
||||||
|
|
||||||
const fullPath = path.join(this.notesDir, file)
|
const fullPath = path.join(this.notesDir, file)
|
||||||
const raw = await fs.readFile(fullPath, 'utf8')
|
const fileContent = await fs.readFile(fullPath, 'utf8')
|
||||||
const parsed = matter(raw)
|
const parsedFile = JSON.parse(fileContent)
|
||||||
|
|
||||||
notes.push({
|
notes.push(parsedFile)
|
||||||
...parsed.data,
|
|
||||||
content: parsed.content,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return notes
|
return notes
|
||||||
@@ -45,21 +41,15 @@ export default class FileSystemAdapter extends BaseNotesAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async delete(id) {
|
async delete(id) {
|
||||||
const filePath = path.join(this.notesDir, `${id}.md`)
|
const filePath = path.join(this.notesDir, `${id}.json`)
|
||||||
await fs.unlink(filePath)
|
await fs.unlink(filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
async _write(note) {
|
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, {
|
const stringifiedNote = JSON.stringify(note)
|
||||||
id: note.id,
|
|
||||||
title: note.title,
|
|
||||||
category: note.category ?? null,
|
|
||||||
createdAt: note.createdAt,
|
|
||||||
updatedAt: note.updatedAt,
|
|
||||||
})
|
|
||||||
|
|
||||||
await fs.writeFile(filePath, fileContent, 'utf8')
|
await fs.writeFile(filePath, stringifiedNote, 'utf8')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export default definePlugin({
|
|||||||
name: 'Filesystem',
|
name: 'Filesystem',
|
||||||
description: 'Store notes as markdown files on your local filesystem',
|
description: 'Store notes as markdown files on your local filesystem',
|
||||||
version: '0.1.0',
|
version: '0.1.0',
|
||||||
apiVersion: '0.1.0',
|
apiVersion: '0.3.1',
|
||||||
configSchema: [
|
configSchema: [
|
||||||
{
|
{
|
||||||
key: 'notesDir',
|
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