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.
Files changed (163) hide show
  1. package/.dependency-cruiser.cjs +412 -0
  2. package/.github/workflows/ci.yml +2 -2
  3. package/.imdoneignore +2 -1
  4. package/README.md +2 -2
  5. package/_index.md +7 -0
  6. package/build.js +57 -0
  7. package/esm-migration.md +446 -0
  8. package/lib/FileProjectContext.js +13 -0
  9. package/lib/ProjectContext.js +19 -18
  10. package/lib/adapters/date-time.js +3 -8
  11. package/lib/adapters/environment.js +3 -0
  12. package/lib/adapters/file-gateway.js +133 -106
  13. package/lib/adapters/git-download.js +36 -16
  14. package/lib/adapters/index.js +9 -0
  15. package/lib/adapters/logger.js +136 -0
  16. package/lib/adapters/markdown.js +31 -19
  17. package/lib/adapters/parsers/DateLanguageParser.js +11 -9
  18. package/lib/adapters/parsers/content-transformer.js +35 -30
  19. package/lib/adapters/parsers/file/LocalFileParserFactory.js +8 -9
  20. package/lib/adapters/parsers/file/ReadStreamCodeParser.js +8 -8
  21. package/lib/adapters/parsers/file/ReadStreamMarkdownParser.js +4 -4
  22. package/lib/adapters/parsers/file/ReadStreamTaskParser.js +5 -3
  23. package/lib/adapters/parsers/file/index.js +4 -0
  24. package/lib/adapters/parsers/function-parser.js +1 -5
  25. package/lib/adapters/parsers/index.js +5 -0
  26. package/lib/adapters/parsers/task/CardContentParser.js +23 -32
  27. package/lib/adapters/parsers/task/CheckStyleTaskParser.js +2 -2
  28. package/lib/adapters/parsers/task/CodeStyleTaskParser.js +2 -2
  29. package/lib/adapters/parsers/task/HashStyleTaskParser.js +3 -3
  30. package/lib/adapters/parsers/task/MarkdownStyleTaskParser.js +2 -2
  31. package/lib/adapters/parsers/task/TaskParser.js +1 -1
  32. package/lib/adapters/parsers/task/index.js +6 -0
  33. package/lib/adapters/storage/config.js +15 -20
  34. package/lib/adapters/storage/index.js +2 -0
  35. package/lib/adapters/storage/tags.js +11 -12
  36. package/lib/adapters/yaml.js +8 -5
  37. package/lib/card.js +25 -26
  38. package/lib/checksum.js +22 -0
  39. package/lib/cli.js +114 -0
  40. package/lib/config.js +106 -71
  41. package/lib/constants.js +21 -50
  42. package/lib/context/ApplicationContext.js +7 -4
  43. package/lib/context/index.js +1 -0
  44. package/lib/default-settings.js +3 -3
  45. package/lib/domain/entities/View.js +4 -11
  46. package/lib/domain/entities/index.js +1 -0
  47. package/lib/domain/index.js +2 -0
  48. package/lib/domain/usecases/GetViewsUsecase.js +6 -12
  49. package/lib/domain/usecases/SaveViewUsecase.js +8 -14
  50. package/lib/domain/usecases/index.js +2 -0
  51. package/lib/file.js +1158 -1162
  52. package/lib/get-tasks-to-modify.js +117 -0
  53. package/lib/index.js +23 -0
  54. package/lib/languages.js +4 -5
  55. package/lib/list.js +46 -95
  56. package/lib/migrate-config.js +5 -5
  57. package/lib/mixins/index.js +2 -0
  58. package/lib/mixins/repo-fs-store.js +224 -289
  59. package/lib/mixins/repo-watched-fs-store.js +158 -147
  60. package/lib/plugins/archive-plugin.js +10 -8
  61. package/lib/plugins/default-board-actions-plugin.js +2 -2
  62. package/lib/plugins/default-board-properties-plugin.js +7 -7
  63. package/lib/plugins/default-plugins.js +7 -0
  64. package/lib/plugins/epic-plugin.js +6 -5
  65. package/lib/plugins/extension-plugin.js +24 -17
  66. package/lib/plugins/index.js +9 -0
  67. package/lib/plugins/persist-tags-plugin.js +4 -3
  68. package/lib/plugins/plugin-manager.js +89 -52
  69. package/lib/plugins/plugin-registry.js +12 -16
  70. package/lib/project-factory.js +21 -24
  71. package/lib/project.js +97 -144
  72. package/lib/repository.js +1323 -1555
  73. package/lib/task.js +562 -580
  74. package/lib/tools.js +39 -113
  75. package/lib/usecases/actions.js +32 -0
  76. package/lib/usecases/get-project-tags.js +3 -12
  77. package/lib/usecases/get-tasks-in-file.js +4 -7
  78. package/lib/usecases/index.js +4 -0
  79. package/package.json +44 -66
  80. package/scripts/delete-markdown-indexes.js +87 -0
  81. package/scripts/generate-index.js +35 -0
  82. package/{index-markdown.js → scripts/index-markdown.js} +7 -7
  83. package/tsconfig.json +15 -0
  84. package/types/FileProjectContext.d.ts +4 -0
  85. package/types/ProjectContext.d.ts +9 -0
  86. package/types/adapters/date-time.d.ts +2 -0
  87. package/types/adapters/environment.d.ts +1 -0
  88. package/types/adapters/file-gateway.d.ts +51 -0
  89. package/types/adapters/git-download.d.ts +1 -0
  90. package/types/adapters/index.d.ts +9 -0
  91. package/types/adapters/logger.d.ts +24 -0
  92. package/types/adapters/markdown.d.ts +13 -0
  93. package/types/adapters/parsers/DateLanguageParser.d.ts +1 -0
  94. package/types/adapters/parsers/content-transformer.d.ts +10 -0
  95. package/types/adapters/parsers/file/LocalFileParserFactory.d.ts +5 -0
  96. package/types/adapters/parsers/file/ReadStreamCodeParser.d.ts +13 -0
  97. package/types/adapters/parsers/file/ReadStreamMarkdownParser.d.ts +7 -0
  98. package/types/adapters/parsers/file/ReadStreamTaskParser.d.ts +19 -0
  99. package/types/adapters/parsers/file/index.d.ts +4 -0
  100. package/types/adapters/parsers/function-parser.d.ts +1 -0
  101. package/types/adapters/parsers/index.d.ts +5 -0
  102. package/types/adapters/parsers/task/CardContentParser.d.ts +45 -0
  103. package/types/adapters/parsers/task/CheckStyleTaskParser.d.ts +12 -0
  104. package/types/adapters/parsers/task/CodeStyleTaskParser.d.ts +14 -0
  105. package/types/adapters/parsers/task/HashStyleTaskParser.d.ts +13 -0
  106. package/types/adapters/parsers/task/MarkdownStyleTaskParser.d.ts +14 -0
  107. package/types/adapters/parsers/task/TaskParser.d.ts +7 -0
  108. package/types/adapters/parsers/task/index.d.ts +6 -0
  109. package/types/adapters/storage/config.d.ts +6 -0
  110. package/types/adapters/storage/index.d.ts +2 -0
  111. package/types/adapters/storage/tags.d.ts +3 -0
  112. package/types/adapters/yaml.d.ts +2 -0
  113. package/types/card.d.ts +166 -0
  114. package/types/checksum.d.ts +8 -0
  115. package/types/config.d.ts +61 -0
  116. package/types/constants.d.ts +46 -0
  117. package/types/context/ApplicationContext.d.ts +24 -0
  118. package/types/context/index.d.ts +1 -0
  119. package/types/default-settings.d.ts +2 -0
  120. package/types/domain/entities/FileProjectContext.d.ts +5 -0
  121. package/types/domain/entities/View.d.ts +17 -0
  122. package/types/domain/entities/index.d.ts +1 -0
  123. package/types/domain/index.d.ts +2 -0
  124. package/types/domain/usecases/GetViewsUsecase.d.ts +4 -0
  125. package/types/domain/usecases/SaveViewUsecase.d.ts +8 -0
  126. package/types/domain/usecases/index.d.ts +2 -0
  127. package/types/file.d.ts +344 -0
  128. package/types/get-tasks-to-modify.d.ts +3 -0
  129. package/types/index.d.ts +23 -0
  130. package/types/languages.d.ts +649 -0
  131. package/types/list.d.ts +30 -0
  132. package/types/migrate-config.d.ts +1 -0
  133. package/types/mixins/index.d.ts +2 -0
  134. package/types/mixins/repo-fs-store.d.ts +2 -0
  135. package/types/mixins/repo-watched-fs-store.d.ts +2 -0
  136. package/types/plugins/archive-plugin.d.ts +8 -0
  137. package/types/plugins/default-board-actions-plugin.d.ts +9 -0
  138. package/types/plugins/default-board-properties-plugin.d.ts +16 -0
  139. package/types/plugins/default-plugins.d.ts +6 -0
  140. package/types/plugins/epic-plugin.d.ts +19 -0
  141. package/types/plugins/extension-plugin.d.ts +15 -0
  142. package/types/plugins/index.d.ts +9 -0
  143. package/types/plugins/persist-tags-plugin.d.ts +4 -0
  144. package/types/plugins/plugin-manager.d.ts +68 -0
  145. package/types/plugins/plugin-registry.d.ts +1 -0
  146. package/types/project-factory.d.ts +14 -0
  147. package/types/project.d.ts +158 -0
  148. package/types/repository.d.ts +996 -0
  149. package/types/task.d.ts +202 -0
  150. package/types/tools.d.ts +29 -0
  151. package/types/usecases/actions.d.ts +7 -0
  152. package/types/usecases/get-imdone-url.d.ts +1 -0
  153. package/types/usecases/get-project-tags.d.ts +1 -0
  154. package/types/usecases/get-tasks-in-file.d.ts +4 -0
  155. package/types/usecases/index.d.ts +4 -0
  156. package/vitest.config.js +13 -0
  157. package/cli.js +0 -74
  158. package/index.js +0 -1
  159. package/lib/adapters/readers/FileSystemProjectReader.js +0 -45
  160. package/lib/context/StreamingApplicationContext.js +0 -31
  161. package/lib/controlers/SaveViewController.js +0 -10
  162. package/lib/domain/entities/FileProjectContext.js +0 -10
  163. package/lib/domain/usecases/OpenProjectUsecase.js +0 -13
@@ -1,127 +1,154 @@
1
- const tools = require('../tools')
2
- const _path = require('path')
3
- let fs = require('fs')
4
- const sanitize = require('sanitize-filename')
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
- async function exists(path) {
6
+ let fs = _fs
7
+
8
+ export async function exists(path) {
7
9
  try {
8
- await fs.promises.access(path)
9
- return path
10
+ return await stat(path)
10
11
  } catch {
11
12
  return false
12
13
  }
13
14
  }
14
15
 
15
- function mkdirpSync(path) {
16
- console.warn('sync call')
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
- const gateway = {
29
- init(fileSystem = fs) {
30
- fs = fileSystem
31
- },
24
+ export function init(fileSystem = fs) {
25
+ fs = fileSystem
26
+ }
32
27
 
33
- sep: _path.sep,
28
+ export const sep = _path.sep
34
29
 
35
- existsSync(...args) {
36
- console.warn('sync call')
37
- return fs.existsSync.apply({}, args)
38
- },
30
+ export function existsSync(...args) {
31
+ logger.warn('existsSync call')
32
+ return fs.existsSync.apply({}, args)
33
+ }
39
34
 
40
- exists,
35
+ export const stat = fs.promises.stat
41
36
 
42
- async stat(path, opts) {
43
- try {
44
- return await fs.promises.stat(path, opts)
45
- }
46
- catch {
47
- return false
48
- }
49
- },
50
-
51
- readFileSync(...args) {
52
- console.warn('sync call')
53
- return fs.readFileSync.apply({}, args)
54
- },
55
-
56
- appendFileSync(...args) {
57
- console.warn('sync call')
58
- return fs.appendFileSync.apply({}, args)
59
- },
60
-
61
- writeFileSync(...args) {
62
- console.warn('sync call')
63
- return fs.writeFileSync.apply({}, args)
64
- },
65
-
66
- writeFile(...args) {
67
- return fs.promises.writeFile.apply({}, args)
68
- },
69
-
70
- async readdir(...args) {
71
- return fs.promises.readdir.apply({}, args)
72
- },
73
-
74
- unlinkSync(...args) {
75
- console.warn('sync call')
76
- return fs.unlinkSync.apply({}, args)
77
- },
78
-
79
- mkdirpSync,
80
-
81
- async mkdir(path) {
82
- return fs.promises.mkdir(path)
83
- },
84
-
85
- async readFile(path) {
86
- return fs.promises.readFile(path, 'utf8')
87
- },
88
-
89
- statSync,
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
- module.exports = gateway
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
- var wget = require('download');
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
- module.exports = download;
6
+ export async function downloadPlugin(repo, dest) {
7
+ const url = github(normalize(repo));
8
+ const response = await fetch(url);
4
9
 
5
- async function download(repo, dest) {
6
- var url = github(normalize(repo));
7
- return wget(url, dest, { extract: true, strip: 1 })
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
- var owner = string.split('/')[0];
22
- var name = string.split('/')[1];
23
- var branch = 'master';
42
+ function normalize(string) {
43
+ let [owner, name] = string.split('/');
44
+ let branch = 'master';
24
45
 
25
- if (~name.indexOf('#')) {
26
- branch = name.split('#')[1];
27
- name = name.split('#')[0];
46
+ if (name.includes('#')) {
47
+ [name, branch] = name.split('#');
28
48
  }
29
49
 
30
50
  return {
31
- owner: owner,
32
- name: name,
33
- branch: 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 }
@@ -1,14 +1,17 @@
1
- const checkbox = require('markdown-it-checkbox')
2
- const imageSize = require('markdown-it-imsize')
3
- const emoji = require('markdown-it-emoji')
4
- const mark = require('markdown-it-mark')
5
- const removeMD = require('remove-markdown')
6
- const path = require('path');
7
-
8
- const MarkdownIt = require('markdown-it')
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 = new MarkdownIt({html: true, breaks: true})
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
- module.exports = {
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
- removeMD
176
+ renderMarkdown,
177
+ removeMD,
178
+ _setPlatform,
179
+ allEmoji
168
180
  }
@@ -1,10 +1,12 @@
1
- const chrono = require('chrono-node')
1
+ import { Chrono } from 'chrono-node'
2
2
 
3
- module.exports = {
4
- replaceDateLanguage(text, asDate) {
5
- return text.replace(/\(?\${(.*?)}\)?/g, (match, p1) => {
6
- const date = chrono.parseDate(p1)
7
- return date ? date.toISOString() : p1
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
+ }