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.
@@ -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.error(`Error parsing config file: ${filePath}`)
36
+ logger.warn(`Error parsing config file: ${filePath}`)
37
37
  }
38
38
  return configLike
39
39
  }
@@ -15,7 +15,7 @@ export async function load(projectPath) {
15
15
  const { tags } = loadYAML(tagsData)
16
16
  return tags
17
17
  } catch (e) {
18
- logger.error(e)
18
+ logger.warn(e)
19
19
  return
20
20
  }
21
21
  }
package/lib/card.js CHANGED
@@ -204,7 +204,7 @@ export function newCard(task, _project, dontParse) {
204
204
  computed[key] = computedValue
205
205
  }
206
206
  } catch (e) {
207
- logger.error(e)
207
+ logger.warn(e)
208
208
  }
209
209
 
210
210
  const pluginData = pluginManager
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.error(`Error processing front-matter in:${this.path}`, err)
1342
+ logger.warn(`Error processing front-matter in:${this.path}`, err)
1343
1343
  }
1344
1344
  return {}
1345
1345
  }
@@ -1,2 +1,3 @@
1
1
  export * from './repo-fs-store.js';
2
+ export * from './repo-single-file-store.js';
2
3
  export * from './repo-watched-fs-store.js';
@@ -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
- let extension = _default
74
- const extensionPath = this.getExtensionPath(path)
75
- try {
76
- await exists(extensionPath)
77
- // delete require.cache[extensionPath]
78
- extension = await import(extensionPath)
79
- } catch (e) {
80
- if (['ENOENT', 'ERR_MODULE_NOT_FOUND'].includes(e.code)) {
81
- logger.log('No extension found at:', extensionPath)
82
- } else {
83
- logger.warn(`Error loading extension with error code ${e.code}`, e.message)
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 (typeof extension !== 'function') {
88
- logger.warn(
89
- `${extensionPath} does not export a function. Using default empty function. ${_default.toString()}`
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
- return extension
97
+ return extension
95
98
  }
96
99
  }
@@ -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.error('Error calculating list totals:', e)
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.error(e)
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.error(err)
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.error(
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.error(`Can't get file for task: {text:'${task.text}', path:'${task.source.path}', line:${task.line}}`)
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
+ }
@@ -1,4 +1,6 @@
1
1
  export * from './actions.js';
2
+ export * from './get-card-data.js';
2
3
  export * from './get-imdone-url.js';
3
4
  export * from './get-project-tags.js';
5
+ export * from './get-project-with-file.js';
4
6
  export * from './get-tasks-in-file.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imdone-core",
3
- "version": "2.0.21",
3
+ "version": "2.1.0",
4
4
  "description": "imdone-core",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,2 +1,3 @@
1
1
  export * from "./repo-fs-store.js";
2
+ export * from "./repo-single-file-store.js";
2
3
  export * from "./repo-watched-fs-store.js";
@@ -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;
@@ -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,4 @@
1
+ export function getCardData({ path, line }: {
2
+ path: any;
3
+ line: any;
4
+ }): Promise<any>;
@@ -0,0 +1 @@
1
+ export function getProjectWithFile(filePath: any, { loadInstalledPlugins, loadPluginsNotInstalled }?: {}): Promise<any>;
@@ -1,4 +1,6 @@
1
1
  export * from "./actions.js";
2
+ export * from "./get-card-data.js";
2
3
  export * from "./get-imdone-url.js";
3
4
  export * from "./get-project-tags.js";
5
+ export * from "./get-project-with-file.js";
4
6
  export * from "./get-tasks-in-file.js";