imdone-core 2.0.21 → 2.1.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/lib/adapters/storage/config.js +1 -1
- package/lib/adapters/storage/tags.js +1 -1
- package/lib/card.js +1 -1
- package/lib/file.js +1 -1
- package/lib/mixins/index.js +1 -0
- package/lib/mixins/repo-single-file-store.js +41 -0
- package/lib/plugins/extension-plugin.js +25 -22
- package/lib/project-factory.js +28 -0
- package/lib/project.js +7 -3
- package/lib/repository.js +2 -2
- package/lib/usecases/get-card-data.js +10 -0
- package/lib/usecases/get-project-with-file.js +17 -0
- package/lib/usecases/index.js +2 -0
- package/package.json +1 -1
- package/types/mixins/index.d.ts +1 -0
- package/types/mixins/repo-single-file-store.d.ts +8 -0
- package/types/project-factory.d.ts +8 -0
- package/types/project.d.ts +1 -0
- package/types/usecases/get-card-data.d.ts +4 -0
- package/types/usecases/get-project-with-file.d.ts +1 -0
- package/types/usecases/index.d.ts +2 -0
|
@@ -33,7 +33,7 @@ export async function loadYamlConfig(filePath) {
|
|
|
33
33
|
if (configLike.watcher) delete configLike.watcher
|
|
34
34
|
|
|
35
35
|
} catch (e) {
|
|
36
|
-
logger.
|
|
36
|
+
logger.warn(`Error parsing config file: ${filePath}`)
|
|
37
37
|
}
|
|
38
38
|
return configLike
|
|
39
39
|
}
|
package/lib/card.js
CHANGED
package/lib/file.js
CHANGED
|
@@ -1339,7 +1339,7 @@ export class File extends Emitter {
|
|
|
1339
1339
|
return data
|
|
1340
1340
|
}
|
|
1341
1341
|
} catch (err) {
|
|
1342
|
-
logger.
|
|
1342
|
+
logger.warn(`Error processing front-matter in:${this.path}`, err)
|
|
1343
1343
|
}
|
|
1344
1344
|
return {}
|
|
1345
1345
|
}
|
package/lib/mixins/index.js
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { fileSystemStoreMixin } from './repo-fs-store.js'
|
|
2
|
+
import _path from 'path'
|
|
3
|
+
import { File } from '../file.js'
|
|
4
|
+
import { lstat } from '../adapters/file-gateway.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a mixin that extends the file system store to only load a single specified file
|
|
8
|
+
* @param {Object} repo - The repository instance
|
|
9
|
+
* @param {string} targetFilePath - The absolute path of the file to load
|
|
10
|
+
* @param {Object} fs - File system instance (optional)
|
|
11
|
+
* @returns {Object} The repository with single file functionality
|
|
12
|
+
*/
|
|
13
|
+
export function singleFileStoreMixin(repo, targetFilePath, fs) {
|
|
14
|
+
|
|
15
|
+
// Apply the base file system store mixin first
|
|
16
|
+
repo = fileSystemStoreMixin(repo, fs)
|
|
17
|
+
|
|
18
|
+
// Store the target file path as a relative path
|
|
19
|
+
const targetRelativePath = repo.getRelativePath(targetFilePath)
|
|
20
|
+
|
|
21
|
+
repo.getFilesInPath = async function (includeDirs) {
|
|
22
|
+
const stat = await lstat(targetFilePath)
|
|
23
|
+
|
|
24
|
+
if (!stat) {
|
|
25
|
+
throw new Error(`File not found: ${targetFilePath}`)
|
|
26
|
+
}
|
|
27
|
+
// Create and return only the target file
|
|
28
|
+
const file = new File({
|
|
29
|
+
project: repo.project,
|
|
30
|
+
repoId: repo.getId(),
|
|
31
|
+
filePath: targetRelativePath,
|
|
32
|
+
modifiedTime: stat.mtime,
|
|
33
|
+
createdTime: stat.birthtime,
|
|
34
|
+
size: stat.size
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return [file]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return repo
|
|
41
|
+
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import Plugin from 'imdone-api'
|
|
2
2
|
import _path from 'path'
|
|
3
3
|
import { exists } from '../adapters/file-gateway.js'
|
|
4
|
-
// import { createRequire } from 'node:module';
|
|
5
4
|
import { logger } from '../adapters/logger.js';
|
|
6
|
-
import { URL } from 'node:url';
|
|
7
|
-
// const require = createRequire(new URL(import.meta.url));
|
|
8
5
|
|
|
9
6
|
export default class ExtensionPlugin extends Plugin {
|
|
10
7
|
constructor(project) {
|
|
@@ -70,27 +67,33 @@ export default class ExtensionPlugin extends Plugin {
|
|
|
70
67
|
}
|
|
71
68
|
|
|
72
69
|
async loadExtensionModule(_default, ...path) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
70
|
+
let extension = _default
|
|
71
|
+
const extensionPath = this.getExtensionPath(path)
|
|
72
|
+
try {
|
|
73
|
+
await exists(extensionPath)
|
|
74
|
+
const importedModule = await import(extensionPath)
|
|
75
|
+
|
|
76
|
+
// Check if it's a module object with a default export
|
|
77
|
+
if (importedModule && typeof importedModule === 'object' && 'default' in importedModule) {
|
|
78
|
+
extension = importedModule.default
|
|
79
|
+
} else {
|
|
80
|
+
extension = importedModule
|
|
85
81
|
}
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
logger.
|
|
89
|
-
|
|
90
|
-
)
|
|
91
|
-
extension = _default
|
|
82
|
+
} catch (e) {
|
|
83
|
+
if (['ENOENT', 'ERR_MODULE_NOT_FOUND'].includes(e.code)) {
|
|
84
|
+
logger.log('No extension found at:', extensionPath)
|
|
85
|
+
} else {
|
|
86
|
+
logger.warn(`Error loading extension with error code ${e.code}`, e.message)
|
|
92
87
|
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (typeof extension !== 'function') {
|
|
91
|
+
logger.warn(
|
|
92
|
+
`${extensionPath} does not export a function. Using default empty function. ${_default.toString()}`
|
|
93
|
+
)
|
|
94
|
+
extension = _default
|
|
95
|
+
}
|
|
93
96
|
|
|
94
|
-
|
|
97
|
+
return extension
|
|
95
98
|
}
|
|
96
99
|
}
|
package/lib/project-factory.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { lstat } from './adapters/file-gateway.js'
|
|
1
2
|
import { Repository } from './repository.js'
|
|
2
3
|
import { watchedFileSystemStoreMixin } from './mixins/repo-watched-fs-store.js'
|
|
3
4
|
import { fileSystemStoreMixin } from './mixins/repo-fs-store.js'
|
|
5
|
+
import { singleFileStoreMixin } from './mixins/repo-single-file-store.js'
|
|
4
6
|
import { ProjectContext } from './ProjectContext.js'
|
|
5
7
|
import { WorkerProject } from './project.js'
|
|
6
8
|
import { appContext as context } from './context/ApplicationContext.js'
|
|
@@ -25,6 +27,32 @@ export function createFileSystemProject({
|
|
|
25
27
|
return context().project
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
export async function createFileSystemProjectWithFile({
|
|
31
|
+
path,
|
|
32
|
+
config,
|
|
33
|
+
filePath,
|
|
34
|
+
repo = singleFileStoreMixin(new Repository(_path.resolve(path), config), filePath),
|
|
35
|
+
loadInstalledPlugins,
|
|
36
|
+
loadPluginsNotInstalled
|
|
37
|
+
}) {
|
|
38
|
+
const stat = await lstat(filePath)
|
|
39
|
+
|
|
40
|
+
if (!stat) {
|
|
41
|
+
throw new Error(`File not found: ${targetFilePath}`)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
context().repo = repo
|
|
45
|
+
context().projectContext = new ProjectContext(repo)
|
|
46
|
+
context().project = new WorkerProject(repo)
|
|
47
|
+
if (loadInstalledPlugins) {
|
|
48
|
+
context().project.pluginManager.loadInstalledPlugins = loadInstalledPlugins
|
|
49
|
+
}
|
|
50
|
+
if (loadPluginsNotInstalled) {
|
|
51
|
+
context().project.pluginManager.loadPluginsNotInstalled = loadPluginsNotInstalled
|
|
52
|
+
}
|
|
53
|
+
return context().project
|
|
54
|
+
}
|
|
55
|
+
|
|
28
56
|
export function createWatchedFileSystemProject({
|
|
29
57
|
path,
|
|
30
58
|
config,
|
package/lib/project.js
CHANGED
|
@@ -28,7 +28,7 @@ function calculateTotals(lists = []) {
|
|
|
28
28
|
try {
|
|
29
29
|
totals[list.name] = list.tasks.length
|
|
30
30
|
} catch (e) {
|
|
31
|
-
logger.
|
|
31
|
+
logger.warn('Error calculating list totals:', e)
|
|
32
32
|
}
|
|
33
33
|
})
|
|
34
34
|
return totals
|
|
@@ -397,6 +397,10 @@ export class WorkerProject extends Project {
|
|
|
397
397
|
return cards
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
+
getFiles() {
|
|
401
|
+
return this.repo.getFiles()
|
|
402
|
+
}
|
|
403
|
+
|
|
400
404
|
filterCards(cards, filter) {
|
|
401
405
|
this.hideLists = []
|
|
402
406
|
const {
|
|
@@ -810,7 +814,7 @@ export class WorkerProject extends Project {
|
|
|
810
814
|
const func = new Function(`return ${actionFunction}`)()
|
|
811
815
|
func.apply(actionThis)
|
|
812
816
|
} catch (e) {
|
|
813
|
-
logger.
|
|
817
|
+
logger.warn(e)
|
|
814
818
|
logger.log('action:', actionFunction)
|
|
815
819
|
logger.log('this:', actionThis)
|
|
816
820
|
}
|
|
@@ -851,7 +855,7 @@ export class WorkerProject extends Project {
|
|
|
851
855
|
try {
|
|
852
856
|
actionFunction.apply(actionThis)
|
|
853
857
|
} catch (err) {
|
|
854
|
-
logger.
|
|
858
|
+
logger.warn(err)
|
|
855
859
|
logger.log('action:', actionFunction)
|
|
856
860
|
logger.log('this:', actionThis)
|
|
857
861
|
}
|
package/lib/repository.js
CHANGED
|
@@ -641,7 +641,7 @@ export class Repository extends Emitter {
|
|
|
641
641
|
include = File.isMarkdown(relPath)
|
|
642
642
|
}
|
|
643
643
|
} catch (e) {
|
|
644
|
-
logger.
|
|
644
|
+
logger.warn(
|
|
645
645
|
`Failed to check ignore status for dir: [${relPath}] in: [${this.path}]. It will be included.`,
|
|
646
646
|
e
|
|
647
647
|
)
|
|
@@ -1328,7 +1328,7 @@ export class Repository extends Emitter {
|
|
|
1328
1328
|
try {
|
|
1329
1329
|
beforeModifyContent = file.getContent()
|
|
1330
1330
|
} catch (e) {
|
|
1331
|
-
logger.
|
|
1331
|
+
logger.warn(`Can't get file for task: {text:'${task.text}', path:'${task.source.path}', line:${task.line}}`)
|
|
1332
1332
|
throw e
|
|
1333
1333
|
}
|
|
1334
1334
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getProjectWithFile } from './get-project-with-file.js';
|
|
2
|
+
|
|
3
|
+
export async function getCardData({ path, line }) {
|
|
4
|
+
const project = await getProjectWithFile(path)
|
|
5
|
+
await project.init()
|
|
6
|
+
|
|
7
|
+
const file = project.getFile(path)
|
|
8
|
+
const card = file.getTaskAtLine(line)
|
|
9
|
+
return {...card.data };
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Create a function that gets a project with exactly one file
|
|
2
|
+
// Use findImdonePath in lib/adapters/storage/config.js
|
|
3
|
+
// Create a function that loads the project from that path
|
|
4
|
+
import { findImdonePath } from '../adapters/storage/config.js'
|
|
5
|
+
import { createFileSystemProjectWithFile } from '../project-factory.js'
|
|
6
|
+
import { load as loadConfig } from '../adapters/storage/config.js'
|
|
7
|
+
|
|
8
|
+
export async function getProjectWithFile(filePath, { loadInstalledPlugins, loadPluginsNotInstalled } = {}) {
|
|
9
|
+
const projectPath = await findImdonePath(filePath)
|
|
10
|
+
// Load the config from that path
|
|
11
|
+
const config = await loadConfig(projectPath)
|
|
12
|
+
if (!projectPath) {
|
|
13
|
+
throw new Error('Project not found')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return await createFileSystemProjectWithFile({ path: projectPath, config, filePath, loadInstalledPlugins, loadPluginsNotInstalled })
|
|
17
|
+
}
|
package/lib/usecases/index.js
CHANGED
package/package.json
CHANGED
package/types/mixins/index.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a mixin that extends the file system store to only load a single specified file
|
|
3
|
+
* @param {Object} repo - The repository instance
|
|
4
|
+
* @param {string} targetFilePath - The absolute path of the file to load
|
|
5
|
+
* @param {Object} fs - File system instance (optional)
|
|
6
|
+
* @returns {Object} The repository with single file functionality
|
|
7
|
+
*/
|
|
8
|
+
export function singleFileStoreMixin(repo: Object, targetFilePath: string, fs: Object): Object;
|
|
@@ -5,6 +5,14 @@ export function createFileSystemProject({ path, config, repo, loadInstalledPlugi
|
|
|
5
5
|
loadInstalledPlugins: any;
|
|
6
6
|
loadPluginsNotInstalled: any;
|
|
7
7
|
}): any;
|
|
8
|
+
export function createFileSystemProjectWithFile({ path, config, filePath, repo, loadInstalledPlugins, loadPluginsNotInstalled }: {
|
|
9
|
+
path: any;
|
|
10
|
+
config: any;
|
|
11
|
+
filePath: any;
|
|
12
|
+
repo?: Object | undefined;
|
|
13
|
+
loadInstalledPlugins: any;
|
|
14
|
+
loadPluginsNotInstalled: any;
|
|
15
|
+
}): Promise<any>;
|
|
8
16
|
export function createWatchedFileSystemProject({ path, config, repo, loadInstalledPlugins, loadPluginsNotInstalled }: {
|
|
9
17
|
path: any;
|
|
10
18
|
config: any;
|
package/types/project.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export class WorkerProject {
|
|
|
71
71
|
getDefaultFilteredCards(): any[];
|
|
72
72
|
getAllCards(filter: any): any[];
|
|
73
73
|
getCards(filter: any, cards?: any[]): any[];
|
|
74
|
+
getFiles(): any;
|
|
74
75
|
filterCards(cards: any, filter: any): any[];
|
|
75
76
|
hideLists: any[] | undefined;
|
|
76
77
|
addMetadata(task: any, key: any, value: any): Promise<any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function getProjectWithFile(filePath: any, { loadInstalledPlugins, loadPluginsNotInstalled }?: {}): Promise<any>;
|