Skip to content

Commit

Permalink
Store tags and return from usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
piascikj committed Nov 20, 2024
1 parent 696d6f5 commit 56dbfd0
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 26 deletions.
3 changes: 2 additions & 1 deletion lib/adapters/storage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const Config = require('../../config')
module.exports = {
load,
save,
loadForFilePath
loadForFilePath,
findImdonePath,
}

async function load(projectPath) {
Expand Down
30 changes: 30 additions & 0 deletions lib/adapters/storage/tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { readFile, writeFile, exists } = require('../file-gateway')
const { CONFIG_DIR } = require('../../constants')
const { loadYAML, dumpYAML } = require('../yaml')
const _path = require('path')

module.exports = {
load,
save
}

async function load(projectPath) {
const tagsPath = getTagsPath(projectPath)
if (!(await exists(tagsPath))) return
const tagsData = await readFile(tagsPath, 'utf-8')
try {
const { tags } = loadYAML(tagsData)
return tags
} catch (e) {
console.error(e)
return
}
}

async function save(tags, projectPath) {
await writeFile(getTagsPath(projectPath), dumpYAML({ tags }))
}

function getTagsPath(projectPath) {
return _path.join(projectPath, CONFIG_DIR, 'tags.yml')
}
21 changes: 0 additions & 21 deletions lib/plugins/persist-meta-tags-plugin.js

This file was deleted.

13 changes: 13 additions & 0 deletions lib/plugins/persist-tags-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const Plugin = require('imdone-api')
const { save } = require('../adapters/storage/tags.js')

module.exports = class PersistTagsPlugin extends Plugin {
constructor(project) {
super(project)
}

async onBoardUpdate() {
await save(this.project.allTags, this.project.path)
}

}
9 changes: 5 additions & 4 deletions lib/plugins/plugin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = class PluginManager extends Emitter {
this.defaultPlugins = [
'./archive-plugin',
'./epic-plugin',
'./extension-plugin'
'./extension-plugin',
'./persist-tags-plugin',
]
this.pluginsMap = {}
this.pluginPath = _path.join(project.path, '.imdone', 'plugins')
Expand Down Expand Up @@ -234,13 +235,13 @@ module.exports = class PluginManager extends Emitter {
)
}

onBoardUpdate(lists) {
async onBoardUpdate(lists) {
if (!lists || lists.length == 0) return
this.eachPlugin(({ pluginInstance }) => {
this.eachPluginAsync(async ({ pluginInstance }) => {
// const timeLabel = `${this.getPluginName(pluginInstance)} onBoardUpdate time`
// console.time(timeLabel)
try {
pluginInstance.onBoardUpdate(lists)
await pluginInstance.onBoardUpdate(lists)
} catch (e) {
this.pluginError('onBoardUpdate', pluginInstance, e)
}
Expand Down
25 changes: 25 additions & 0 deletions lib/usecases/__tests__/get-project-tags.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const expect = require('expect.js');
const path = require('path');
const {
getFreshRepo
} = require('../../../test/helper')
const {
getTags
} = require('../get-project-tags.js')

const { createFileSystemProject } = require('../../project-factory.js')

describe('get-project-tags', () => {
it('should return a list of tags', async () => {
// Given
const repoPath = getFreshRepo('default-cards');
const project = createFileSystemProject({ path: repoPath });
await project.init();
project.toImdoneJSON();
const filePath = path.join(repoPath, 'imdone-readme.md');
// When
const tags = await getTags(filePath);
// Then
expect(tags.length).to.be(1);
});
});
17 changes: 17 additions & 0 deletions lib/usecases/get-project-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const {
load,
save
} = require('../adapters/storage/tags.js')

const {
findImdonePath
} = require('../adapters/storage/config.js')

module.exports = {
getTags
}

async function getTags(filePath) {
const projectPath = await findImdonePath(filePath)
return load(projectPath)
}

0 comments on commit 56dbfd0

Please sign in to comment.