imdone-core 1.54.10 → 2.0.1
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/.dependency-cruiser.cjs +412 -0
- package/.github/workflows/ci.yml +2 -2
- package/.imdoneignore +2 -1
- package/README.md +2 -2
- package/_index.md +7 -0
- package/build.js +57 -0
- package/esm-migration.md +446 -0
- package/lib/FileProjectContext.js +13 -0
- package/lib/ProjectContext.js +19 -18
- package/lib/adapters/date-time.js +3 -8
- package/lib/adapters/environment.js +3 -0
- package/lib/adapters/file-gateway.js +133 -106
- package/lib/adapters/git-download.js +36 -16
- package/lib/adapters/index.js +9 -0
- package/lib/adapters/logger.js +136 -0
- package/lib/adapters/markdown.js +31 -19
- package/lib/adapters/parsers/DateLanguageParser.js +11 -9
- package/lib/adapters/parsers/content-transformer.js +35 -30
- package/lib/adapters/parsers/file/LocalFileParserFactory.js +8 -9
- package/lib/adapters/parsers/file/ReadStreamCodeParser.js +8 -8
- package/lib/adapters/parsers/file/ReadStreamMarkdownParser.js +4 -4
- package/lib/adapters/parsers/file/ReadStreamTaskParser.js +5 -3
- package/lib/adapters/parsers/file/index.js +4 -0
- package/lib/adapters/parsers/function-parser.js +1 -5
- package/lib/adapters/parsers/index.js +5 -0
- package/lib/adapters/parsers/task/CardContentParser.js +23 -32
- package/lib/adapters/parsers/task/CheckStyleTaskParser.js +2 -2
- package/lib/adapters/parsers/task/CodeStyleTaskParser.js +2 -2
- package/lib/adapters/parsers/task/HashStyleTaskParser.js +3 -3
- package/lib/adapters/parsers/task/MarkdownStyleTaskParser.js +2 -2
- package/lib/adapters/parsers/task/TaskParser.js +1 -1
- package/lib/adapters/parsers/task/index.js +6 -0
- package/lib/adapters/storage/config.js +15 -20
- package/lib/adapters/storage/index.js +2 -0
- package/lib/adapters/storage/tags.js +11 -12
- package/lib/adapters/yaml.js +8 -5
- package/lib/card.js +25 -26
- package/lib/checksum.js +22 -0
- package/lib/cli.js +114 -0
- package/lib/config.js +106 -71
- package/lib/constants.js +21 -50
- package/lib/context/ApplicationContext.js +7 -4
- package/lib/context/index.js +1 -0
- package/lib/default-settings.js +3 -3
- package/lib/domain/entities/View.js +4 -11
- package/lib/domain/entities/index.js +1 -0
- package/lib/domain/index.js +2 -0
- package/lib/domain/usecases/GetViewsUsecase.js +6 -12
- package/lib/domain/usecases/SaveViewUsecase.js +8 -14
- package/lib/domain/usecases/index.js +2 -0
- package/lib/file.js +1158 -1162
- package/lib/get-tasks-to-modify.js +117 -0
- package/lib/index.js +23 -0
- package/lib/languages.js +4 -5
- package/lib/list.js +46 -95
- package/lib/migrate-config.js +5 -5
- package/lib/mixins/index.js +2 -0
- package/lib/mixins/repo-fs-store.js +224 -289
- package/lib/mixins/repo-watched-fs-store.js +158 -147
- package/lib/plugins/archive-plugin.js +10 -8
- package/lib/plugins/default-board-actions-plugin.js +2 -2
- package/lib/plugins/default-board-properties-plugin.js +7 -7
- package/lib/plugins/default-plugins.js +7 -0
- package/lib/plugins/epic-plugin.js +6 -5
- package/lib/plugins/extension-plugin.js +24 -17
- package/lib/plugins/index.js +9 -0
- package/lib/plugins/persist-tags-plugin.js +4 -3
- package/lib/plugins/plugin-manager.js +89 -52
- package/lib/plugins/plugin-registry.js +12 -16
- package/lib/project-factory.js +21 -24
- package/lib/project.js +97 -144
- package/lib/repository.js +1323 -1555
- package/lib/task.js +562 -580
- package/lib/tools.js +39 -113
- package/lib/usecases/actions.js +32 -0
- package/lib/usecases/get-project-tags.js +3 -12
- package/lib/usecases/get-tasks-in-file.js +4 -7
- package/lib/usecases/index.js +4 -0
- package/package.json +44 -66
- package/scripts/delete-markdown-indexes.js +87 -0
- package/scripts/generate-index.js +35 -0
- package/{index-markdown.js → scripts/index-markdown.js} +7 -7
- package/tsconfig.json +15 -0
- package/types/FileProjectContext.d.ts +4 -0
- package/types/ProjectContext.d.ts +9 -0
- package/types/adapters/date-time.d.ts +2 -0
- package/types/adapters/environment.d.ts +1 -0
- package/types/adapters/file-gateway.d.ts +51 -0
- package/types/adapters/git-download.d.ts +1 -0
- package/types/adapters/index.d.ts +9 -0
- package/types/adapters/logger.d.ts +24 -0
- package/types/adapters/markdown.d.ts +13 -0
- package/types/adapters/parsers/DateLanguageParser.d.ts +1 -0
- package/types/adapters/parsers/content-transformer.d.ts +10 -0
- package/types/adapters/parsers/file/LocalFileParserFactory.d.ts +5 -0
- package/types/adapters/parsers/file/ReadStreamCodeParser.d.ts +13 -0
- package/types/adapters/parsers/file/ReadStreamMarkdownParser.d.ts +7 -0
- package/types/adapters/parsers/file/ReadStreamTaskParser.d.ts +19 -0
- package/types/adapters/parsers/file/index.d.ts +4 -0
- package/types/adapters/parsers/function-parser.d.ts +1 -0
- package/types/adapters/parsers/index.d.ts +5 -0
- package/types/adapters/parsers/task/CardContentParser.d.ts +45 -0
- package/types/adapters/parsers/task/CheckStyleTaskParser.d.ts +12 -0
- package/types/adapters/parsers/task/CodeStyleTaskParser.d.ts +14 -0
- package/types/adapters/parsers/task/HashStyleTaskParser.d.ts +13 -0
- package/types/adapters/parsers/task/MarkdownStyleTaskParser.d.ts +14 -0
- package/types/adapters/parsers/task/TaskParser.d.ts +7 -0
- package/types/adapters/parsers/task/index.d.ts +6 -0
- package/types/adapters/storage/config.d.ts +6 -0
- package/types/adapters/storage/index.d.ts +2 -0
- package/types/adapters/storage/tags.d.ts +3 -0
- package/types/adapters/yaml.d.ts +2 -0
- package/types/card.d.ts +166 -0
- package/types/checksum.d.ts +8 -0
- package/types/config.d.ts +61 -0
- package/types/constants.d.ts +46 -0
- package/types/context/ApplicationContext.d.ts +24 -0
- package/types/context/index.d.ts +1 -0
- package/types/default-settings.d.ts +2 -0
- package/types/domain/entities/FileProjectContext.d.ts +5 -0
- package/types/domain/entities/View.d.ts +17 -0
- package/types/domain/entities/index.d.ts +1 -0
- package/types/domain/index.d.ts +2 -0
- package/types/domain/usecases/GetViewsUsecase.d.ts +4 -0
- package/types/domain/usecases/SaveViewUsecase.d.ts +8 -0
- package/types/domain/usecases/index.d.ts +2 -0
- package/types/file.d.ts +344 -0
- package/types/get-tasks-to-modify.d.ts +3 -0
- package/types/index.d.ts +23 -0
- package/types/languages.d.ts +649 -0
- package/types/list.d.ts +30 -0
- package/types/migrate-config.d.ts +1 -0
- package/types/mixins/index.d.ts +2 -0
- package/types/mixins/repo-fs-store.d.ts +2 -0
- package/types/mixins/repo-watched-fs-store.d.ts +2 -0
- package/types/plugins/archive-plugin.d.ts +8 -0
- package/types/plugins/default-board-actions-plugin.d.ts +9 -0
- package/types/plugins/default-board-properties-plugin.d.ts +16 -0
- package/types/plugins/default-plugins.d.ts +6 -0
- package/types/plugins/epic-plugin.d.ts +19 -0
- package/types/plugins/extension-plugin.d.ts +15 -0
- package/types/plugins/index.d.ts +9 -0
- package/types/plugins/persist-tags-plugin.d.ts +4 -0
- package/types/plugins/plugin-manager.d.ts +68 -0
- package/types/plugins/plugin-registry.d.ts +1 -0
- package/types/project-factory.d.ts +14 -0
- package/types/project.d.ts +158 -0
- package/types/repository.d.ts +996 -0
- package/types/task.d.ts +202 -0
- package/types/tools.d.ts +29 -0
- package/types/usecases/actions.d.ts +7 -0
- package/types/usecases/get-imdone-url.d.ts +1 -0
- package/types/usecases/get-project-tags.d.ts +1 -0
- package/types/usecases/get-tasks-in-file.d.ts +4 -0
- package/types/usecases/index.d.ts +4 -0
- package/vitest.config.js +13 -0
- package/cli.js +0 -74
- package/index.js +0 -1
- package/lib/adapters/readers/FileSystemProjectReader.js +0 -45
- package/lib/context/StreamingApplicationContext.js +0 -31
- package/lib/controlers/SaveViewController.js +0 -10
- package/lib/domain/entities/FileProjectContext.js +0 -10
- package/lib/domain/usecases/OpenProjectUsecase.js +0 -13
|
@@ -1,127 +1,154 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import _path from 'path'
|
|
2
|
+
import _fs from 'fs'
|
|
3
|
+
import sanitize from 'sanitize-filename'
|
|
4
|
+
import { logger } from './logger.js'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
let fs = _fs
|
|
7
|
+
|
|
8
|
+
export async function exists(path) {
|
|
7
9
|
try {
|
|
8
|
-
await
|
|
9
|
-
return path
|
|
10
|
+
return await stat(path)
|
|
10
11
|
} catch {
|
|
11
12
|
return false
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
return require('mkdirp').sync(path, { fs })
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function statSync(path) {
|
|
21
|
-
console.warn('sync call')
|
|
16
|
+
export function statSync(path) {
|
|
17
|
+
logger.warn('statSync call')
|
|
22
18
|
try {
|
|
23
19
|
return fs.statSync(path)
|
|
24
20
|
} catch {
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
24
|
+
export function init(fileSystem = fs) {
|
|
25
|
+
fs = fileSystem
|
|
26
|
+
}
|
|
32
27
|
|
|
33
|
-
|
|
28
|
+
export const sep = _path.sep
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
export function existsSync(...args) {
|
|
31
|
+
logger.warn('existsSync call')
|
|
32
|
+
return fs.existsSync.apply({}, args)
|
|
33
|
+
}
|
|
39
34
|
|
|
40
|
-
|
|
35
|
+
export const stat = fs.promises.stat
|
|
41
36
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
readdirSyncRecursive(path) {
|
|
92
|
-
console.warn('sync call')
|
|
93
|
-
return tools.readdirSyncRecursive(fs, path)
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
readdirSync(path) {
|
|
97
|
-
console.warn('sync call')
|
|
98
|
-
return fs.readdirSync(path, { withFileTypes: true })
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
sanitizeFileName(fileName, replaceSpacesWith) {
|
|
102
|
-
// Remove markdown emoji
|
|
103
|
-
fileName = fileName.replace(/:\w+:/g, '').trim()
|
|
104
|
-
fileName = sanitize(fileName)
|
|
105
|
-
if (replaceSpacesWith)
|
|
106
|
-
fileName = fileName.replace(/ /g, replaceSpacesWith)
|
|
107
|
-
return fileName
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
preparePathForWriting(path) {
|
|
111
|
-
let stat = statSync(path)
|
|
112
|
-
if (!stat) {
|
|
113
|
-
let { dir, ext } = _path.parse(path)
|
|
114
|
-
if (!ext) {
|
|
115
|
-
dir = path
|
|
116
|
-
}
|
|
117
|
-
mkdirpSync(dir)
|
|
118
|
-
stat = statSync(path)
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
isFile: stat && stat.isFile(),
|
|
122
|
-
isDirectory: stat && stat.isDirectory()
|
|
37
|
+
export const lstat = fs.promises.lstat
|
|
38
|
+
|
|
39
|
+
export const lstatSync = fs.lstatSync
|
|
40
|
+
|
|
41
|
+
export function readFileSync(...args) {
|
|
42
|
+
logger.warn('readFileSync call')
|
|
43
|
+
return fs.readFileSync.apply({}, args)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function appendFileSync(...args) {
|
|
47
|
+
logger.warn('appendFileSync call')
|
|
48
|
+
return fs.appendFileSync.apply({}, args)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function writeFileSync(...args) {
|
|
52
|
+
logger.warn('writeFileSync call')
|
|
53
|
+
return fs.writeFileSync.apply({}, args)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const writeFile = fs.promises.writeFile
|
|
57
|
+
|
|
58
|
+
export async function readdir(...args) {
|
|
59
|
+
return fs.promises.readdir.apply({}, args)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function unlinkSync(...args) {
|
|
63
|
+
logger.warn('unlinkSync call')
|
|
64
|
+
return fs.unlinkSync.apply({}, args)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const unlink = fs.promises.unlink
|
|
68
|
+
|
|
69
|
+
export const mkdir = fs.promises.mkdir
|
|
70
|
+
|
|
71
|
+
export const readFile = fs.promises.readFile
|
|
72
|
+
|
|
73
|
+
export function readdirSyncRecursive(path) {
|
|
74
|
+
logger.warn('readdirSyncRecursive call')
|
|
75
|
+
// implement this function
|
|
76
|
+
let results = []
|
|
77
|
+
let list = fs.readdirSync(path)
|
|
78
|
+
list.forEach(function(file) {
|
|
79
|
+
file = _path.join(path, file)
|
|
80
|
+
let stat = fs.statSync(file)
|
|
81
|
+
if (stat && stat.isDirectory()) {
|
|
82
|
+
results = results.concat(readdirSyncRecursive(file))
|
|
83
|
+
} else {
|
|
84
|
+
results.push(file)
|
|
123
85
|
}
|
|
86
|
+
})
|
|
87
|
+
return results
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function readdirSync(path) {
|
|
91
|
+
logger.warn('readdirSync call')
|
|
92
|
+
return fs.readdirSync(path, { withFileTypes: true })
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function sanitizeFileName(fileName, replaceSpacesWith) {
|
|
96
|
+
// Remove markdown emoji
|
|
97
|
+
fileName = fileName.replace(/:\w+:/g, '').trim()
|
|
98
|
+
fileName = sanitize(fileName)
|
|
99
|
+
if (replaceSpacesWith)
|
|
100
|
+
fileName = fileName.replace(/ /g, replaceSpacesWith)
|
|
101
|
+
return fileName
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function statsProps(stats) {
|
|
105
|
+
return {
|
|
106
|
+
isFile: stats.isFile(),
|
|
107
|
+
isDirectory: stats.isDirectory()
|
|
124
108
|
}
|
|
125
109
|
}
|
|
126
110
|
|
|
127
|
-
|
|
111
|
+
export async function preparePathForWriting(path, directory = false) {
|
|
112
|
+
let stats = await exists(path)
|
|
113
|
+
if (stats) return statsProps(stats)
|
|
114
|
+
|
|
115
|
+
let { dir } = directory ? { dir: path } : _path.parse(path)
|
|
116
|
+
stats = await exists(dir)
|
|
117
|
+
if (stats) return statsProps(stats)
|
|
118
|
+
|
|
119
|
+
await mkdir(dir, { recursive: true })
|
|
120
|
+
stats = await exists(dir)
|
|
121
|
+
return statsProps(stats)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function cp(src, dest, opts) {
|
|
125
|
+
return fs.promises.cp(src, dest, opts)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function rm(path, opts) {
|
|
129
|
+
return fs.promises.rm(path, opts)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export default {
|
|
133
|
+
cp,
|
|
134
|
+
rm,
|
|
135
|
+
exists,
|
|
136
|
+
stat,
|
|
137
|
+
lstat,
|
|
138
|
+
lstatSync,
|
|
139
|
+
readFileSync,
|
|
140
|
+
appendFileSync,
|
|
141
|
+
writeFileSync,
|
|
142
|
+
writeFile,
|
|
143
|
+
readdir,
|
|
144
|
+
unlink,
|
|
145
|
+
mkdir,
|
|
146
|
+
readFile,
|
|
147
|
+
readdirSyncRecursive,
|
|
148
|
+
readdirSync,
|
|
149
|
+
sanitizeFileName,
|
|
150
|
+
preparePathForWriting,
|
|
151
|
+
unlinkSync,
|
|
152
|
+
existsSync,
|
|
153
|
+
sep
|
|
154
|
+
}
|
|
@@ -1,13 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import AdmZip from 'adm-zip';
|
|
3
|
+
import { cp, rm } from './file-gateway.js'
|
|
4
|
+
import path from 'node:path'
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
export async function downloadPlugin(repo, dest) {
|
|
7
|
+
const url = github(normalize(repo));
|
|
8
|
+
const response = await fetch(url);
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
if (!response.ok) {
|
|
11
|
+
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
15
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
16
|
+
const zip = AdmZip(buffer);
|
|
17
|
+
await zip.extractAllToAsync(dest, true);
|
|
18
|
+
const zipEntries = zip.getEntries();
|
|
19
|
+
const rootFolder = zipEntries[0].entryName.split(path.sep)[0];
|
|
20
|
+
const rootFolderPath = path.join(dest, rootFolder)
|
|
21
|
+
await cp(rootFolderPath, dest, {
|
|
22
|
+
recursive: true,
|
|
23
|
+
force: true, // overwrite if needed
|
|
24
|
+
errorOnExist: false,
|
|
25
|
+
});
|
|
26
|
+
await rm(rootFolderPath, {
|
|
27
|
+
recursive: true,
|
|
28
|
+
force: true, // overwrite if needed
|
|
29
|
+
});
|
|
8
30
|
}
|
|
9
31
|
|
|
10
|
-
function github(repo){
|
|
32
|
+
function github(repo) {
|
|
11
33
|
return 'https://github.com/'
|
|
12
34
|
+ repo.owner
|
|
13
35
|
+ '/'
|
|
@@ -17,19 +39,17 @@ function github(repo){
|
|
|
17
39
|
+ '.zip';
|
|
18
40
|
}
|
|
19
41
|
|
|
20
|
-
function normalize(string){
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var branch = 'master';
|
|
42
|
+
function normalize(string) {
|
|
43
|
+
let [owner, name] = string.split('/');
|
|
44
|
+
let branch = 'master';
|
|
24
45
|
|
|
25
|
-
if (
|
|
26
|
-
branch = name.split('#')
|
|
27
|
-
name = name.split('#')[0];
|
|
46
|
+
if (name.includes('#')) {
|
|
47
|
+
[name, branch] = name.split('#');
|
|
28
48
|
}
|
|
29
49
|
|
|
30
50
|
return {
|
|
31
|
-
owner
|
|
32
|
-
name
|
|
33
|
-
branch
|
|
51
|
+
owner,
|
|
52
|
+
name,
|
|
53
|
+
branch
|
|
34
54
|
};
|
|
35
55
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './date-time.js';
|
|
2
|
+
export * from './environment.js';
|
|
3
|
+
export * from './file-gateway.js';
|
|
4
|
+
export * from './git-download.js';
|
|
5
|
+
export * from './logger.js';
|
|
6
|
+
export * from './markdown.js';
|
|
7
|
+
export * from './yaml.js';
|
|
8
|
+
export * as parsers from './parsers/index.js';
|
|
9
|
+
export * as storage from './storage/index.js';
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { info, error as consoleError, warn as consoleWarn } from 'console'
|
|
2
|
+
|
|
3
|
+
// Log levels with numeric values for comparison
|
|
4
|
+
const LogLevel = {
|
|
5
|
+
ERROR: 0,
|
|
6
|
+
WARN: 1,
|
|
7
|
+
INFO: 2,
|
|
8
|
+
DEBUG: 3,
|
|
9
|
+
TRACE: 4,
|
|
10
|
+
NONE: -1 // Use this to disable all logging
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getCallerInfo() {
|
|
14
|
+
const err = new Error();
|
|
15
|
+
const stack = err.stack?.split('\n');
|
|
16
|
+
|
|
17
|
+
if (!stack || stack.length < 5) return {};
|
|
18
|
+
|
|
19
|
+
// stack[0] is "Error"
|
|
20
|
+
// stack[1] is this function (getCallerInfo)
|
|
21
|
+
// stack[2] is the formatMessage method
|
|
22
|
+
// stack[3] is the logger method (log, info, debug, etc.)
|
|
23
|
+
// stack[4] is the actual caller we want
|
|
24
|
+
|
|
25
|
+
const callerLine = stack[4] || stack[3]; // Get the actual caller, fallback to logger method if needed
|
|
26
|
+
const match = callerLine.match(/at (.+?) \((.+):(\d+):(\d+)\)/) ||
|
|
27
|
+
callerLine.match(/at (.+):(\d+):(\d+)/);
|
|
28
|
+
|
|
29
|
+
if (match) {
|
|
30
|
+
if (match.length === 5) {
|
|
31
|
+
return {
|
|
32
|
+
functionName: match[1],
|
|
33
|
+
file: match[2],
|
|
34
|
+
line: parseInt(match[3], 10),
|
|
35
|
+
column: parseInt(match[4], 10)
|
|
36
|
+
};
|
|
37
|
+
} else if (match.length === 4) {
|
|
38
|
+
return {
|
|
39
|
+
functionName: '<anonymous>',
|
|
40
|
+
file: match[1],
|
|
41
|
+
line: parseInt(match[2], 10),
|
|
42
|
+
column: parseInt(match[3], 10)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class Logger {
|
|
51
|
+
constructor() {
|
|
52
|
+
// Default log level
|
|
53
|
+
this.level = LogLevel.INFO
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Setter for log level
|
|
57
|
+
setLevel(level) {
|
|
58
|
+
if (level in LogLevel) {
|
|
59
|
+
this.level = LogLevel[level]
|
|
60
|
+
} else if (typeof level === 'number' && level >= -1 && level <= 4) {
|
|
61
|
+
this.level = level
|
|
62
|
+
} else {
|
|
63
|
+
consoleWarn(`Invalid log level: ${level}. Using default INFO level.`)
|
|
64
|
+
}
|
|
65
|
+
return this
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Check if the provided level should be logged
|
|
69
|
+
shouldLog(level) {
|
|
70
|
+
return level <= this.level
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
formatMessage(args) {
|
|
74
|
+
const info = getCallerInfo();
|
|
75
|
+
const prefix = info.file ? `[${info.file}:${info.line}] ${info.functionName} - ` : '';
|
|
76
|
+
|
|
77
|
+
if (typeof args[0] === 'string') {
|
|
78
|
+
args[0] = prefix + args[0];
|
|
79
|
+
} else {
|
|
80
|
+
args.unshift(prefix);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return args;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
log(...args) {
|
|
87
|
+
if (this.shouldLog(LogLevel.INFO)) {
|
|
88
|
+
info(...this.formatMessage(args));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
error(...args) {
|
|
93
|
+
if (this.shouldLog(LogLevel.ERROR)) {
|
|
94
|
+
consoleError(...this.formatMessage(args));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
warn(...args) {
|
|
99
|
+
if (this.shouldLog(LogLevel.WARN)) {
|
|
100
|
+
consoleWarn(...this.formatMessage(args));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
info(...args) {
|
|
105
|
+
if (this.shouldLog(LogLevel.INFO)) {
|
|
106
|
+
info(...this.formatMessage(args));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
debug(...args) {
|
|
111
|
+
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
112
|
+
info(`[DEBUG]`, ...this.formatMessage(args));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
trace(...args) {
|
|
117
|
+
if (this.shouldLog(LogLevel.TRACE)) {
|
|
118
|
+
info(`[TRACE]`, ...this.formatMessage(args));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
time(label) {
|
|
123
|
+
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
124
|
+
console.time(label)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
timeEnd(label) {
|
|
129
|
+
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
130
|
+
console.timeEnd(label)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const logger = new Logger()
|
|
136
|
+
export { LogLevel }
|
package/lib/adapters/markdown.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import checkbox from 'markdown-it-checkbox';
|
|
2
|
+
import imageSize from 'markdown-it-imsize';
|
|
3
|
+
import emoji from 'markdown-it-emoji';
|
|
4
|
+
import mark from 'markdown-it-mark';
|
|
5
|
+
import _removeMD from 'remove-markdown';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import markdownIt from 'markdown-it';
|
|
8
|
+
import { createRequire } from 'module';
|
|
9
|
+
|
|
10
|
+
export const allEmoji = createRequire(import.meta.url)('markdown-it-emoji/lib/data/full.json')
|
|
11
|
+
|
|
9
12
|
let _platform = process.platform
|
|
10
13
|
|
|
11
|
-
function extractWikilinkTopics(markdown) {
|
|
14
|
+
export function extractWikilinkTopics(markdown) {
|
|
12
15
|
const wikilinkRegex = /\[\[([a-zA-Z0-9\u00C0-\u017F/_\-. ]+)(?:\|([^\]]+))?\]\]/g;
|
|
13
16
|
const topics = [];
|
|
14
17
|
let match;
|
|
@@ -20,8 +23,21 @@ function extractWikilinkTopics(markdown) {
|
|
|
20
23
|
return topics;
|
|
21
24
|
}
|
|
22
25
|
|
|
26
|
+
export function _setPlatform(platform) {
|
|
27
|
+
_platform = platform
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function renderMarkdown (markdown, filePath) {
|
|
31
|
+
markdown = renderCancelledTasks(markdown)
|
|
32
|
+
return getRenderer(filePath).render(markdown)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function removeMD() {
|
|
36
|
+
return _removeMD.apply({}, arguments)
|
|
37
|
+
}
|
|
38
|
+
|
|
23
39
|
function getRenderer(filePath) {
|
|
24
|
-
const md =
|
|
40
|
+
const md = markdownIt({html: true, breaks: true})
|
|
25
41
|
|
|
26
42
|
md.use(checkbox)
|
|
27
43
|
.use(mark)
|
|
@@ -155,14 +171,10 @@ function renderCancelledTasks(markdown) {
|
|
|
155
171
|
return markdown.replace(/- \[-\] (.+)/gm, '- :no_entry_sign: ~~$1~~');
|
|
156
172
|
}
|
|
157
173
|
|
|
158
|
-
|
|
159
|
-
_setPlatform(platform) {
|
|
160
|
-
_platform = platform
|
|
161
|
-
},
|
|
162
|
-
renderMarkdown (markdown, filePath) {
|
|
163
|
-
markdown = renderCancelledTasks(markdown)
|
|
164
|
-
return getRenderer(filePath).render(markdown)
|
|
165
|
-
},
|
|
174
|
+
export default {
|
|
166
175
|
extractWikilinkTopics,
|
|
167
|
-
|
|
176
|
+
renderMarkdown,
|
|
177
|
+
removeMD,
|
|
178
|
+
_setPlatform,
|
|
179
|
+
allEmoji
|
|
168
180
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { Chrono } from 'chrono-node'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
export function replaceDateLanguage(text, asDate = false) {
|
|
4
|
+
const chrono = new Chrono();
|
|
5
|
+
return text.replace(/\(?\${(.*?)}\)?/g, (match, p1) => {
|
|
6
|
+
const date = chrono.parseDate(p1);
|
|
7
|
+
if (date) {
|
|
8
|
+
return asDate ? date : date.toISOString();
|
|
9
|
+
}
|
|
10
|
+
return match;
|
|
11
|
+
});
|
|
12
|
+
}
|