imdone-core 2.0.7 → 2.0.9

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.
@@ -36,9 +36,18 @@ export async function loadYamlConfig(filePath) {
36
36
  }
37
37
  return configLike
38
38
  }
39
+ export async function isImdoneProject(projectPath) {
40
+ const configPath = _path.join(projectPath, CONFIG_FILE_YML)
41
+ const configLike = await loadYamlConfig(configPath)
42
+ if (!configLike) return false
43
+ return true
44
+ }
39
45
 
40
46
  export async function findImdonePath(cwd) {
41
47
  const configDir = await findUp(CONFIG_DIR, { cwd, type: 'directory' })
48
+ if (!configDir) {
49
+ throw new Error(`Could not find imdone directory in ${cwd}`)
50
+ }
42
51
  return _path.dirname(configDir)
43
52
  }
44
53
 
package/lib/card.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Task } from './task.js'
2
2
  import _path from 'path'
3
- import _pick from 'lodash.pick'
4
3
  import _isFunction from 'lodash.isfunction'
5
4
  import _isObject from 'lodash.isobject'
6
5
  import _isEmpty from 'lodash.isempty'
@@ -100,39 +99,69 @@ export function newCard(task, _project, dontParse) {
100
99
  }
101
100
 
102
101
  get defaultData() {
102
+ // Extract all required properties in alphabetical order with destructuring
103
+ const {
104
+ allContext,
105
+ allMeta,
106
+ allTags,
107
+ beforeText,
108
+ completed,
109
+ content,
110
+ context,
111
+ created,
112
+ due,
113
+ filteredListName,
114
+ fullPath,
115
+ id,
116
+ interpretedContent,
117
+ lastLine,
118
+ line,
119
+ list,
120
+ meta,
121
+ metaKeys,
122
+ progress,
123
+ projectPath,
124
+ rawTask,
125
+ relPath,
126
+ source,
127
+ started,
128
+ tags,
129
+ text,
130
+ topics,
131
+ totals
132
+ } = this;
133
+
134
+ // Return a new object with all the extracted properties
103
135
  return {
104
- ..._pick(
105
- this,
106
- ...['beforeText',
107
- 'rawTask',
108
- 'id',
109
- 'text',
110
- 'progress',
111
- 'line',
112
- 'lastLine',
113
- 'list',
114
- 'source',
115
- 'due',
116
- 'created',
117
- 'started',
118
- 'completed',
119
- 'tags',
120
- 'context',
121
- 'meta',
122
- 'allTags',
123
- 'allContext',
124
- 'allMeta',
125
- 'metaKeys',
126
- 'content',
127
- 'filteredListName',
128
- 'interpretedContent',
129
- 'projectPath',
130
- 'relPath',
131
- 'fullPath',
132
- 'totals',
133
- 'topics'].sort()
134
- ),
135
- }
136
+ allContext,
137
+ allMeta,
138
+ allTags,
139
+ beforeText,
140
+ completed,
141
+ content,
142
+ context,
143
+ created,
144
+ due,
145
+ filteredListName,
146
+ fullPath,
147
+ id,
148
+ interpretedContent,
149
+ lastLine,
150
+ line,
151
+ list,
152
+ meta,
153
+ metaKeys,
154
+ progress,
155
+ projectPath,
156
+ rawTask,
157
+ relPath,
158
+ source,
159
+ started,
160
+ tags,
161
+ text,
162
+ topics,
163
+ totals
164
+ };
136
165
  }
137
166
 
138
167
  // TODO Add isInCodeFile property to card
package/lib/clone.js ADDED
@@ -0,0 +1,36 @@
1
+ export function cloneDeep(obj, seen = new WeakMap()) {
2
+ if (obj === null || typeof obj !== 'object') return obj
3
+
4
+ if (seen.has(obj)) return seen.get(obj)
5
+
6
+ if (typeof obj === 'function') return obj
7
+
8
+ if (obj instanceof Date) return new Date(obj)
9
+ if (obj instanceof RegExp) return new RegExp(obj)
10
+ if (obj instanceof Map) {
11
+ const result = new Map()
12
+ seen.set(obj, result)
13
+ for (const [key, value] of obj.entries()) {
14
+ result.set(cloneDeep(key, seen), cloneDeep(value, seen))
15
+ }
16
+ return result
17
+ }
18
+
19
+ if (obj instanceof Set) {
20
+ const result = new Set()
21
+ seen.set(obj, result)
22
+ for (const value of obj.values()) {
23
+ result.add(cloneDeep(value, seen))
24
+ }
25
+ return result
26
+ }
27
+
28
+ const result = Array.isArray(obj) ? [] : {}
29
+ seen.set(obj, result)
30
+
31
+ for (const key of Object.keys(obj)) {
32
+ result[key] = cloneDeep(obj[key], seen)
33
+ }
34
+
35
+ return result
36
+ }
package/lib/file.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import _isObject from 'lodash.isobject'
2
2
  import _assign from 'lodash.assign'
3
- import _omit from 'lodash.omit'
4
- import _get from 'lodash.get'
3
+ import { omit } from './omit.js'
5
4
  import crypto from 'crypto'
6
5
  import Emitter from 'events'
7
6
  import path from 'path'
@@ -278,7 +277,7 @@ export class File extends Emitter {
278
277
  beforeTextModified = trackMarkdownChecklistChanges({task, config, modify})
279
278
 
280
279
  if (
281
- _get(config, 'settings.cards.trackChanges') &&
280
+ config?.settings?.cards?.trackChanges &&
282
281
  task.hasListChanged(lists)
283
282
  ) {
284
283
  const list = task.list
@@ -1016,7 +1015,7 @@ export class File extends Emitter {
1016
1015
  }
1017
1016
 
1018
1017
  toJSON () {
1019
- return _omit(this, ['domain', '_events', '_maxListeners'])
1018
+ return omit(this, ['domain', '_events', '_maxListeners'])
1020
1019
  }
1021
1020
 
1022
1021
  getRepoId () {
package/lib/index.js CHANGED
@@ -2,6 +2,7 @@ export * from './FileProjectContext.js';
2
2
  export * from './ProjectContext.js';
3
3
  export * from './card.js';
4
4
  export * from './checksum.js';
5
+ export * from './clone.js';
5
6
  export * from './config.js';
6
7
  export * from './constants.js';
7
8
  export * from './default-settings.js';
@@ -10,6 +11,7 @@ export * from './get-tasks-to-modify.js';
10
11
  export * from './languages.js';
11
12
  export * from './list.js';
12
13
  export * from './migrate-config.js';
14
+ export * from './omit.js';
13
15
  export * from './project-factory.js';
14
16
  export * from './project.js';
15
17
  export * from './repository.js';
@@ -1,7 +1,7 @@
1
- import _cloneDeep from 'lodash.clonedeep'
2
1
  import _path from 'path'
3
2
  import uniqid from 'uniqid'
4
3
  import { defaultSettings as _defaultSettings } from './default-settings.js'
4
+ import { cloneDeep } from './clone.js'
5
5
 
6
6
  export function buildMigrateConfig (repo, defaultSettings = _defaultSettings) {
7
7
  const path = repo.path
@@ -149,8 +149,8 @@ export function buildMigrateConfig (repo, defaultSettings = _defaultSettings) {
149
149
  config.settings.kudosProbability = 0.33
150
150
  }
151
151
 
152
- const defaultCardsSettings = _cloneDeep(defaultSettings.cards)
153
- const cardsSettings = _cloneDeep(config.settings.cards)
152
+ const defaultCardsSettings = cloneDeep(defaultSettings.cards)
153
+ const cardsSettings = cloneDeep(config.settings.cards)
154
154
 
155
155
  delete defaultSettings.cards
156
156
  delete config.settings.cards
@@ -1,5 +1,4 @@
1
1
  import _path from 'path'
2
- import _cloneDeep from 'lodash.clonedeep'
3
2
  import _isFunction from 'lodash.isfunction'
4
3
  import _isUndefined from 'lodash.isundefined'
5
4
  import _assign from 'lodash.assign'
@@ -173,7 +172,7 @@ export function fileSystemStoreMixin(repo, fs = realFs) {
173
172
  }
174
173
 
175
174
  repo.updateConfig = async function (loadedConfig) {
176
- var baseConfig = _cloneDeep(DEFAULT_CONFIG)
175
+ var baseConfig = structuredClone(DEFAULT_CONFIG)
177
176
  var include_lists = baseConfig.code.include_lists
178
177
  const currentConfig = repo.config
179
178
  if (currentConfig && currentConfig.code)
@@ -192,7 +191,7 @@ export function fileSystemStoreMixin(repo, fs = realFs) {
192
191
  await repo.migrateTasksByConfig(currentConfig, newConfig)
193
192
  repo.config = newConfig
194
193
  repo.config.code.include_lists = include_lists
195
- var _languages = _cloneDeep(languages)
194
+ var _languages = structuredClone(languages)
196
195
  repo.languages = repo.config.languages
197
196
  ? _assign(_languages, repo.config.languages)
198
197
  : _languages
package/lib/omit.js ADDED
@@ -0,0 +1,9 @@
1
+ export function omit(obj, keys) {
2
+ const result = {}
3
+ for (const key in obj) {
4
+ if (Object.prototype.hasOwnProperty.call(obj, key) && !keys.includes(key)) {
5
+ result[key] = obj[key]
6
+ }
7
+ }
8
+ return result
9
+ }
@@ -2,10 +2,9 @@ import Emitter from 'events'
2
2
  import Plugin from 'imdone-api'
3
3
  import _path from 'path'
4
4
  import { downloadPlugin } from '../adapters/git-download.js'
5
- import rimraf from 'rimraf'
6
5
  import chokidar from 'chokidar'
7
6
  import debounce from 'lodash.debounce'
8
- import { exists, mkdir, readdir } from '../adapters/file-gateway.js'
7
+ import { exists, mkdir, readdir, rm } from '../adapters/file-gateway.js'
9
8
  import { appContext } from '../context/ApplicationContext.js'
10
9
  // import { createRequire } from 'node:module';
11
10
 
@@ -83,26 +82,21 @@ export class PluginManager extends Emitter {
83
82
  }
84
83
 
85
84
  async uninstallPlugin(pluginName) {
86
- return new Promise((resolve, reject) => {
87
85
  logger.log('Preparing to uninstall plugin:', pluginName)
88
86
  const pluginClassName = Object.keys(this.pluginsMap).find((key) => {
89
87
  return this.getPlugin(key).info.name === pluginName
90
88
  })
91
89
  if (!pluginClassName) {
92
- return reject(new Error('Unable to find plugin:' + pluginName))
90
+ throw new Error('Unable to find plugin:' + pluginName)
93
91
  }
94
92
  const { info } = this.getPlugin(pluginClassName)
95
93
  const { path } = info
96
94
  // const pkg = { version, name }
97
95
  logger.log('Uninstalling:', info)
98
96
 
99
- rimraf(path, (err) => {
100
- if (err) return reject(err)
101
- delete this.pluginsMap[pluginClassName]
102
- this.emit('plugin-uninstalled', pluginName)
103
- resolve()
104
- })
105
- })
97
+ await rm(path, { recursive: true, force: true })
98
+ delete this.pluginsMap[pluginClassName]
99
+ this.emit('plugin-uninstalled', pluginName)
106
100
  }
107
101
 
108
102
  async installPlugin({ name, version }) {
package/lib/project.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Project } from 'imdone-api/lib/project.js';
2
2
  import { PluginManager } from './plugins/plugin-manager.js';
3
3
  import { Repository } from './repository.js';
4
- import _cloneDeep from 'lodash.clonedeep';
5
4
  import { newCard } from './card.js';
6
5
  import { constants } from './constants.js';
7
6
  const { JOURNAL_TYPE, CONFIG_DIR } = constants;
@@ -15,6 +14,7 @@ import _isString from 'lodash.isstring';
15
14
  import _isFunction from 'lodash.isfunction';
16
15
  import { exec } from 'node:child_process';
17
16
  import { sort } from 'fast-sort';
17
+ import { cloneDeep } from './clone.js'
18
18
  import { Task } from './task.js';
19
19
  import eol from 'eol';
20
20
  import { renderMarkdown, extractWikilinkTopics } from './adapters/markdown.js';
@@ -484,7 +484,7 @@ export class WorkerProject extends Project {
484
484
  filterLists(filter, lists = this.lists) {
485
485
  return lists.map((list) => {
486
486
  let newList = { ...list, tasks: [] }
487
- newList = _cloneDeep(newList)
487
+ newList = cloneDeep(newList)
488
488
  newList.tasks = Repository.query(list.tasks, filter)
489
489
  return newList
490
490
  })
package/lib/repository.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import _isFunction from 'lodash.isfunction'
2
2
  import _isUndefined from 'lodash.isundefined'
3
3
  import _isString from 'lodash.isstring'
4
- import _omit from 'lodash.omit'
4
+ import { omit } from './omit.js'
5
5
  import _reject from 'lodash.reject'
6
6
  import _noop from 'lodash.noop'
7
7
  import _some from 'lodash.some'
@@ -395,7 +395,7 @@ export class Repository extends Emitter {
395
395
  async addList (list) {
396
396
  if (this.listExists(list.name)) return;
397
397
 
398
- list = _omit(list, 'tasks');
398
+ list = omit(list, 'tasks');
399
399
  this.config.lists.push(new List(list));
400
400
 
401
401
  if (!list.filter && !/[a-z]/.test(list.name)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imdone-core",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "imdone-core",
5
5
  "repository": {
6
6
  "type": "git",
@@ -60,21 +60,15 @@
60
60
  "js-yaml": "^3.14.1",
61
61
  "json-fns": "^1.0.0",
62
62
  "lodash.assign": "^4.2.0",
63
- "lodash.clone": "^4.5.0",
64
- "lodash.clonedeep": "^4.5.0",
65
63
  "lodash.debounce": "^4.0.8",
66
- "lodash.get": "^4.4.2",
67
64
  "lodash.groupby": "^4.6.0",
68
65
  "lodash.isempty": "^4.4.0",
69
- "lodash.isequal": "^4.5.0",
70
66
  "lodash.isfunction": "^3.0.9",
71
67
  "lodash.isnumber": "^3.0.3",
72
68
  "lodash.isobject": "^3.0.2",
73
69
  "lodash.isstring": "^4.0.1",
74
70
  "lodash.isundefined": "^3.0.1",
75
71
  "lodash.noop": "^3.0.1",
76
- "lodash.omit": "^4.5.0",
77
- "lodash.pick": "^3.1.0",
78
72
  "lodash.reject": "^4.6.0",
79
73
  "lodash.remove": "^4.7.0",
80
74
  "lodash.some": "^4.6.0",
@@ -96,7 +90,6 @@
96
90
  "prompts": "^2.4.2",
97
91
  "readdirp": "^4.1.2",
98
92
  "remove-markdown": "^0.3.0",
99
- "rimraf": "^3.0.2",
100
93
  "sanitize-filename": "^1.6.3",
101
94
  "sift": "^17.1.3",
102
95
  "simple-git": "^3.19.1",
@@ -115,12 +108,7 @@
115
108
  "expect.js": "~0.3.1",
116
109
  "fs-extra": "^11.1.0",
117
110
  "json-stringify-safe": "~5.0.0",
118
- "mocha": "^11.1.0",
119
- "mocha-each": "^2.0.1",
120
111
  "prettier": "^2.5.1",
121
- "should": "13.1.3",
122
- "sinon": "^19.0.2",
123
- "sinon-chai": "^4.0.0",
124
112
  "typescript": "^5.8.2",
125
113
  "vitest": "^3.0.8"
126
114
  }
@@ -2,5 +2,6 @@ export function load(projectPath: any, configPath?: string): Promise<Config | un
2
2
  export function save(config: any, projectPath: any): Promise<void>;
3
3
  export function loadForFilePath(filePath: any): Promise<Config | undefined>;
4
4
  export function loadYamlConfig(filePath: any): Promise<{} | undefined>;
5
+ export function isImdoneProject(projectPath: any): Promise<boolean>;
5
6
  export function findImdonePath(cwd: any): Promise<string>;
6
7
  import { Config } from '../../config.js';
package/types/card.d.ts CHANGED
@@ -15,7 +15,36 @@ export function newCard(task: any, _project: any, dontParse: any): {
15
15
  readonly projectPath: any;
16
16
  readonly relPath: any;
17
17
  readonly fullPath: string | undefined;
18
- readonly defaultData: any;
18
+ readonly defaultData: {
19
+ allContext: any;
20
+ allMeta: any;
21
+ allTags: any;
22
+ beforeText: any;
23
+ completed: any;
24
+ content: any;
25
+ context: any;
26
+ created: any;
27
+ due: any;
28
+ filteredListName: any;
29
+ fullPath: string | undefined;
30
+ id: any;
31
+ interpretedContent: any;
32
+ lastLine: any;
33
+ line: any;
34
+ list: any;
35
+ meta: any;
36
+ metaKeys: string[] | undefined;
37
+ progress: any;
38
+ projectPath: any;
39
+ rawTask: any;
40
+ relPath: any;
41
+ source: any;
42
+ started: any;
43
+ tags: any;
44
+ text: any;
45
+ topics: string[] | undefined;
46
+ totals: any;
47
+ };
19
48
  initData(): void;
20
49
  dataKeys: string[] | undefined;
21
50
  data: any;
@@ -0,0 +1 @@
1
+ export function cloneDeep(obj: any, seen?: WeakMap<WeakKey, any>): any;
package/types/file.d.ts CHANGED
@@ -113,7 +113,36 @@ export class File extends Emitter<[never]> {
113
113
  readonly projectPath: any;
114
114
  readonly relPath: any;
115
115
  readonly fullPath: string | undefined;
116
- readonly defaultData: any;
116
+ readonly defaultData: {
117
+ allContext: any;
118
+ allMeta: any;
119
+ allTags: any;
120
+ beforeText: any;
121
+ completed: any;
122
+ content: any;
123
+ context: any;
124
+ created: any;
125
+ due: any;
126
+ filteredListName: any;
127
+ fullPath: string | undefined;
128
+ id: any;
129
+ interpretedContent: any;
130
+ lastLine: any;
131
+ line: any;
132
+ list: any;
133
+ meta: any;
134
+ metaKeys: string[] | undefined;
135
+ progress: any;
136
+ projectPath: any;
137
+ rawTask: any;
138
+ relPath: any;
139
+ source: any;
140
+ started: any;
141
+ tags: any;
142
+ text: any;
143
+ topics: string[] | undefined;
144
+ totals: any;
145
+ };
117
146
  initData(): void;
118
147
  dataKeys: string[] | undefined;
119
148
  data: any;
@@ -265,7 +294,7 @@ export class File extends Emitter<[never]> {
265
294
  getTaskAtLine(line: any): any;
266
295
  getLinePos(lineNo: any): any;
267
296
  getLineNumber(pos: any, content?: any): number;
268
- toJSON(): any;
297
+ toJSON(): {};
269
298
  getRepoId(): any;
270
299
  getPath(): any;
271
300
  getFullPath(): string;
package/types/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./FileProjectContext.js";
2
2
  export * from "./ProjectContext.js";
3
3
  export * from "./card.js";
4
4
  export * from "./checksum.js";
5
+ export * from "./clone.js";
5
6
  export * from "./config.js";
6
7
  export * from "./constants.js";
7
8
  export * from "./default-settings.js";
@@ -10,6 +11,7 @@ export * from "./get-tasks-to-modify.js";
10
11
  export * from "./languages.js";
11
12
  export * from "./list.js";
12
13
  export * from "./migrate-config.js";
14
+ export * from "./omit.js";
13
15
  export * from "./project-factory.js";
14
16
  export * from "./project.js";
15
17
  export * from "./repository.js";
@@ -0,0 +1 @@
1
+ export function omit(obj: any, keys: any): {};
@@ -10,7 +10,7 @@ export class PluginManager extends Emitter<[never]> {
10
10
  stopDevMode(): void;
11
11
  initDevMode(): void;
12
12
  reloadPlugins(): Promise<void>;
13
- uninstallPlugin(pluginName: any): Promise<any>;
13
+ uninstallPlugin(pluginName: any): Promise<void>;
14
14
  installPlugin({ name, version }: {
15
15
  name: any;
16
16
  version: any;
@@ -150,7 +150,7 @@ export class WorkerProject {
150
150
  name: any;
151
151
  version: any;
152
152
  }): Promise<void>;
153
- uninstallPlugin(name: any): Promise<any>;
153
+ uninstallPlugin(name: any): Promise<void>;
154
154
  refresh(): Promise<void>;
155
155
  renderMarkdown(content: any, filePath: any): any;
156
156
  extractWikilinkTopics(markdown: any): string[];