imdone-core 1.53.8 → 1.53.10

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/.imdoneignore CHANGED
@@ -2,6 +2,7 @@ coverage
2
2
  .nyc_output
3
3
  test/repos
4
4
  test/files
5
+ test/file-spec.js
5
6
  __tests__
6
7
  test-big-file.md
7
8
  tmp
@@ -4,7 +4,20 @@ let fs = require('fs')
4
4
  const sanitize = require('sanitize-filename')
5
5
 
6
6
 
7
- module.exports = gateway = {
7
+ function mkdirpSync(path) {
8
+ console.warn('sync call')
9
+ return require('mkdirp').sync(path, { fs })
10
+ }
11
+
12
+ function statSync(path) {
13
+ console.warn('sync call')
14
+ try {
15
+ return fs.statSync(path)
16
+ } catch {
17
+ }
18
+ }
19
+
20
+ const gateway = {
8
21
  init(fileSystem = fs) {
9
22
  fs = fileSystem
10
23
  },
@@ -53,10 +66,7 @@ module.exports = gateway = {
53
66
  return fs.unlinkSync.apply({}, args)
54
67
  },
55
68
 
56
- mkdirpSync(path) {
57
- console.warn('sync call')
58
- return require('mkdirp').sync(path, { fs })
59
- },
69
+ mkdirpSync,
60
70
 
61
71
  async mkdir(path) {
62
72
  return fs.promises.mkdir(path)
@@ -66,13 +76,7 @@ module.exports = gateway = {
66
76
  return fs.promises.readFile(path, 'utf8')
67
77
  },
68
78
 
69
- statSync(path) {
70
- console.warn('sync call')
71
- try {
72
- return fs.statSync(path)
73
- } catch {
74
- }
75
- },
79
+ statSync,
76
80
 
77
81
  readdirSyncRecursive(path) {
78
82
  console.warn('sync call')
@@ -94,14 +98,14 @@ module.exports = gateway = {
94
98
  },
95
99
 
96
100
  preparePathForWriting(path) {
97
- let stat = gateway.statSync(path)
101
+ let stat = statSync(path)
98
102
  if (!stat) {
99
103
  let { dir, ext } = _path.parse(path)
100
104
  if (!ext) {
101
105
  dir = path
102
106
  }
103
- gateway.mkdirpSync(dir)
104
- stat = gateway.statSync(path)
107
+ mkdirpSync(dir)
108
+ stat = statSync(path)
105
109
  }
106
110
  return {
107
111
  isFile: stat && stat.isFile(),
@@ -109,3 +113,5 @@ module.exports = gateway = {
109
113
  }
110
114
  }
111
115
  }
116
+
117
+ module.exports = gateway
@@ -0,0 +1,32 @@
1
+ const template = require('lodash.template')
2
+
3
+ module.exports = {
4
+ format,
5
+ }
6
+
7
+ function removeDisplayComments(description) {
8
+ return description.replace(/<!--\s*\[([\s\S]*?)\]\s*-->/g, '$1')
9
+ }
10
+
11
+ function format(content, data, mustache) {
12
+ const opts = { interpolate: /(?<![`\\])\${([\s\S]+?)}/g }
13
+
14
+ if (mustache) content = removeDisplayComments(content)
15
+
16
+ try {
17
+ content = template(content, opts)(data)
18
+ } catch (e) {
19
+ content = content.replace(opts.interpolate, `~~\${${e}}~~`)
20
+ }
21
+
22
+ if (mustache) {
23
+ const opts = { interpolate: /(?<!`){{([\s\S]+?)}}/g }
24
+ try {
25
+ content = template(content, opts)(data)
26
+ } catch (e) {
27
+ content = content.replace(opts.interpolate, `~~{{${e}}}~~`)
28
+ }
29
+ }
30
+
31
+ return content
32
+ }
package/lib/card.js CHANGED
@@ -9,16 +9,12 @@ const _get = require('lodash.get')
9
9
  const eol = require('eol')
10
10
  const allEmoji = require('markdown-it-emoji/lib/data/full.json')
11
11
  const { getFunctionSignature } = require('./adapters/parsers/function-parser')
12
-
12
+ const { format } = require('./adapters/parsers/content-transformer')
13
13
  const { removeMD } = require('./adapters/markdown')
14
14
 
15
15
  const CONTENT_TOKEN = '__CONTENT__'
16
16
  const lf = String(eol.lf)
17
17
 
18
- function removeDisplayComments(description) {
19
- return description.replace(/<!--\s*\[([\s\S]*?)\]\s*-->/g, '$1')
20
- }
21
-
22
18
  module.exports = function newCard(task, _project, dontParse) {
23
19
  const project = _project
24
20
  const pluginManager = _project && _project.pluginManager
@@ -240,27 +236,7 @@ module.exports = function newCard(task, _project, dontParse) {
240
236
  format(content, mustache) {
241
237
  const projectData = project ? { ...project.data } : {}
242
238
  const data = { ...this.data, ...projectData }
243
-
244
- const opts = { interpolate: /(?<![`\\])\${([\s\S]+?)}/g }
245
-
246
- if (mustache) content = removeDisplayComments(content)
247
-
248
- try {
249
- content = template(content, opts)(data)
250
- } catch (e) {
251
- content = content.replace(opts.interpolate, `~~\${${e}}~~`)
252
- }
253
-
254
- if (mustache) {
255
- const opts = { interpolate: /(?<!`){{([\s\S]+?)}}/g }
256
- try {
257
- content = template(content, opts)(data)
258
- } catch (e) {
259
- content = content.replace(opts.interpolate, `~~{{${e}}}~~`)
260
- }
261
- }
262
-
263
- return content
239
+ return format(content, data, mustache)
264
240
  }
265
241
 
266
242
  getCardMarkdown() {
@@ -13,9 +13,9 @@ module.exports = class DefaultBoardActionsPlugin extends Plugin {
13
13
  title: 'Duplicate card',
14
14
  keys: ['shift+d'],
15
15
  icon: 'clone',
16
- action: (task) => {
16
+ action: async (task) => {
17
17
  const timestamp = project.isoDateWithOffset
18
- project.newCard({
18
+ await project.newCard({
19
19
  list: project.config.getDefaultList(),
20
20
  path: task.relPath,
21
21
  template: task.content.replace(/(\screated:).*(\s)/, `$1${timestamp}$2`),
package/lib/project.js CHANGED
@@ -18,6 +18,7 @@ const Task = require('./task')
18
18
  const eol = require('eol')
19
19
  const { renderMarkdown, extractWikilinkTopics } = require('./adapters/markdown')
20
20
  const { getFunctionSignature } = require('./adapters/parsers/function-parser')
21
+ const { format } = require('./adapters/parsers/content-transformer')
21
22
 
22
23
  function calculateTotals(lists) {
23
24
  const totals = {}
@@ -51,6 +52,8 @@ module.exports = class WorkerProject extends Project {
51
52
  this.innerFilter = ''
52
53
  this.fileGateway = fileGateway
53
54
  this._updatedAt = undefined
55
+ this.data = {}
56
+ this.dataKeys = []
54
57
  }
55
58
 
56
59
  init(cb) {
@@ -497,13 +500,16 @@ module.exports = class WorkerProject extends Project {
497
500
  * @param {String} opts.comments - The comments to add to the new card
498
501
  * @param {Boolean} opts.emit - Whether to emit the new card event
499
502
  */
500
- newCard({ list, path, template, title, comments, emit = true }) {
503
+ async newCard({ list, path, template, title, comments, emit = true }) {
501
504
  if (!path || !_path.parse(path).ext) path = this.getNewCardsFile({title})
502
505
  path = this.getFullPath(path)
503
506
 
504
507
  const { isFile, isDirectory } = fileGateway.preparePathForWriting(path)
505
508
 
506
509
  if (!template) template = this.getNewCardTemplate(path, isFile)
510
+
511
+ const boardData = await this.pluginManager.getBoardProperties();
512
+ template = format(template, boardData)
507
513
 
508
514
  if (comments) template = Task.addToLastCommentInContent(template, comments, this.config.isMetaNewLine())
509
515
 
@@ -532,10 +538,14 @@ module.exports = class WorkerProject extends Project {
532
538
  meta = pluginMods.meta
533
539
  tags = pluginMods.tags
534
540
  contexts = pluginMods.contexts
535
- const cardData = this.newCard({list, path, title: eol.split(content)[0], emit: false})
541
+ const cardData = await this.newCard({list, path, title: eol.split(content)[0], emit: false})
536
542
  const filePath = cardData.path
537
543
  if (useCardTemplate) content += cardData.template
538
544
 
545
+ const boardData = await this.pluginManager.getBoardProperties();
546
+ const data = { ...boardData, ...cardData}
547
+ content = format(content, data)
548
+
539
549
  content = this.addTagsToContent(tags, content)
540
550
  content = this.addContextsToContent(contexts, content)
541
551
  content = this.addMetaToContent(meta, content)
@@ -733,11 +743,11 @@ module.exports = class WorkerProject extends Project {
733
743
  filter: (filter) => {
734
744
  this.setFilter(filter)
735
745
  },
736
- newCard: (list, path) => {
746
+ newCard: async (list, path) => {
737
747
  if (task.source.lang !== 'text')
738
748
  return this.alert('Unable to append cards in code files.')
739
749
  if (path) path = this.getFullPath(path)
740
- this.newCard({ list, path })
750
+ await this.newCard({ list, path })
741
751
  },
742
752
  alert: (msg) => {
743
753
  this.toast({ message: msg })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imdone-core",
3
- "version": "1.53.8",
3
+ "version": "1.53.10",
4
4
  "description": "imdone-core",
5
5
  "main": "index.js",
6
6
  "scripts": {