imdone-core 1.44.6 → 1.45.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.
@@ -1,13 +1,15 @@
1
1
  const tools = require('../tools')
2
-
2
+ const _path = require('path')
3
3
  let fs = require('fs')
4
+ const sanitize = require('sanitize-filename')
5
+
4
6
 
5
7
  module.exports = {
6
8
  init(fileSystem = fs) {
7
9
  fs = fileSystem
8
10
  },
9
11
 
10
- sep: require('path').sep,
12
+ sep: _path.sep,
11
13
 
12
14
  existsSync(...args) {
13
15
  console.warn('sync call')
@@ -61,7 +63,10 @@ module.exports = {
61
63
 
62
64
  statSync(path) {
63
65
  console.warn('sync call')
64
- return fs.statSync(path)
66
+ try {
67
+ return fs.statSync(path)
68
+ } catch {
69
+ }
65
70
  },
66
71
 
67
72
  readdirSyncRecursive(path) {
@@ -73,4 +78,12 @@ module.exports = {
73
78
  console.warn('sync call')
74
79
  return fs.readdirSync(path, { withFileTypes: true })
75
80
  },
81
+ sanitizeFileName(fileName, replaceSpacesWith) {
82
+ // Remove markdown emoji
83
+ fileName = fileName.replace(/:\w+:/g, '').trim()
84
+ fileName = sanitize(fileName)
85
+ if (replaceSpacesWith)
86
+ fileName = fileName.replace(/ /g, replaceSpacesWith)
87
+ return fileName
88
+ }
76
89
  }
package/lib/card.js CHANGED
@@ -244,7 +244,7 @@ module.exports = function newCard(task, _project, dontParse) {
244
244
  format(content, mustache) {
245
245
  const data = this.data
246
246
 
247
- const opts = { interpolate: /(?<!`)\${([\s\S]+?)}/g }
247
+ const opts = { interpolate: /(?<![`\\])\${([\s\S]+?)}/g }
248
248
 
249
249
  if (mustache) content = removeDisplayComments(content)
250
250
 
package/lib/file.js CHANGED
@@ -278,6 +278,7 @@ File.prototype.transformTask = function ({config, modify, task}) {
278
278
  content = File.parseRemindDate(config, content)
279
279
  content = File.parseDeferDate(config, content)
280
280
  content = File.addCompleted({ task, content, config })
281
+ content = task.format(content)
281
282
  if (
282
283
  content.trim() !== task.content.trim()
283
284
  || trackListChanges.beforeTextModified
@@ -946,6 +947,7 @@ File.prototype.extractTaskWithDescription = function ({
946
947
  task.updateOrderMeta(config)
947
948
 
948
949
  task.orderModified = task.order + "" !== order + "" && !bothAreUndefNull(task.order, order)
950
+ task.init()
949
951
 
950
952
  return task
951
953
  }
@@ -85,9 +85,14 @@ function mixin(repo, fs = require('fs')) {
85
85
  })
86
86
  }
87
87
 
88
- repo.addFilePath = function (path) {
89
- if (!repo.allFiles.includes(path)) {
90
- repo.allFiles.push(path)
88
+ repo.addFilePath = async function (path) {
89
+ var relPath = repo.getRelativePath(path)
90
+ var fullPath = repo.getFullPath(path)
91
+
92
+ const stat = await fs.promises.lstat(fullPath)
93
+ if (stat.isDirectory()) relPath += _path.sep
94
+ if (!repo.allFiles.includes(relPath)) {
95
+ repo.allFiles.push(relPath)
91
96
  }
92
97
  }
93
98
 
@@ -329,6 +334,7 @@ function mixin(repo, fs = require('fs')) {
329
334
 
330
335
  file.setModifiedTime(stats.mtime)
331
336
  file.modified = false
337
+ repo.addFilePath(filePath)
332
338
  if (emitFileUpdate) repo.emit('file.saved', file)
333
339
  cb(null, file)
334
340
  })
@@ -13,6 +13,7 @@ function getEpicMeta(task) {
13
13
  module.exports = class EpicPlugin extends Plugin {
14
14
  constructor(project) {
15
15
  super(project)
16
+ this.epics = {}
16
17
  }
17
18
 
18
19
  onBeforeBoardUpdate() {
package/lib/project.js CHANGED
@@ -3,10 +3,10 @@ const PluginManager = require('./plugins/plugin-manager')
3
3
  const Repository = require('./repository')
4
4
  const _cloneDeep = require('lodash.clonedeep')
5
5
  const newCard = require('./card')
6
- const sanitize = require('sanitize-filename')
7
6
  const { JOURNAL_TYPE } = require('./constants')
8
7
  const _path = require('path')
9
8
  const moment = require('moment')
9
+ const { getIsoDateWithOffset } = require('./adapters/date-time')
10
10
  const fileGateway = require('./adapters/file-gateway')
11
11
  const matter = require('gray-matter')
12
12
  const _isObject = require('lodash.isobject')
@@ -175,6 +175,10 @@ module.exports = class WorkerProject extends Project {
175
175
  return this.getCards(this.filter)
176
176
  }
177
177
 
178
+ get isoDateWithOffset() {
179
+ return getIsoDateWithOffset()
180
+ }
181
+
178
182
  removeList(list) {
179
183
  this.repo.removeList(list)
180
184
  }
@@ -412,6 +416,22 @@ module.exports = class WorkerProject extends Project {
412
416
  this.emit('project.saveFile', { file: filePath, content })
413
417
  }
414
418
 
419
+ preparePathForWriting(path) {
420
+ let stat = fileGateway.statSync(path)
421
+ if (!stat) {
422
+ let { dir, ext } = _path.parse(path)
423
+ if (!ext) {
424
+ dir = path
425
+ }
426
+ fileGateway.mkdirpSync(dir)
427
+ stat = fileGateway.statSync(path)
428
+ }
429
+ return {
430
+ isFile: stat && stat.isFile(),
431
+ isDirectory: stat && stat.isDirectory()
432
+ }
433
+ }
434
+
415
435
  /*
416
436
  * @param {Object} opts - The options object
417
437
  * @param {String} opts.list - The list name to add the card to
@@ -422,25 +442,23 @@ module.exports = class WorkerProject extends Project {
422
442
  * @param {Boolean} opts.emit - Whether to emit the new card event
423
443
  */
424
444
  newCard({ list, path, template, title, comments, emit = true }) {
425
- if (path) {
426
- path = this.getFullPath(path)
427
- if (!fileGateway.existsSync(path)) {
428
- fileGateway.writeFileSync(path, '')
429
- }
430
- } // TODO: Need a way to handle new cards using new fie for each card
431
- else {
432
- path = this.getFullPath(this.getNewCardsFile({title}))
433
- }
434
- const stat = fileGateway.statSync(path)
435
- if (!template) template = this.getNewCardTemplate(path, stat)
445
+ if (!path || !_path.parse(path).ext) path = this.getFullPath(this.getNewCardsFile({title}))
446
+
447
+ const { isFile, isDirectory } = this.preparePathForWriting(path)
448
+
449
+ if (!template) template = this.getNewCardTemplate(path, isFile)
436
450
 
437
451
  if (comments) template = Task.addToLastCommentInContent(template, comments, this.config.isMetaNewLine())
438
452
 
453
+ let relativePath = _path.relative(this.path, path)
454
+ if (isDirectory) relativePath += _path.sep
455
+
439
456
  const data = {
440
457
  list,
441
458
  path,
459
+ relativePath,
442
460
  template,
443
- isDirectory: stat.isDirectory(),
461
+ isDirectory,
444
462
  }
445
463
  if (emit) this.emit('project.newCard', data)
446
464
  return data
@@ -475,7 +493,6 @@ module.exports = class WorkerProject extends Project {
475
493
 
476
494
  this.repo.moveTask({ task, newList, newPos }, (err) => {
477
495
  if (err) return reject(err)
478
-
479
496
  resolve({ file, task })
480
497
  })
481
498
  })
@@ -545,9 +562,9 @@ module.exports = class WorkerProject extends Project {
545
562
  setFilter(filter) {
546
563
  this.emit('project.filter', { filter })
547
564
  }
548
-
549
- getNewCardTemplate(file, stat) {
550
- const frontMatter = this.getNewCardFileFrontMatter(file, stat)
565
+
566
+ getNewCardTemplate(file, isFile) {
567
+ const frontMatter = this.getNewCardFileFrontMatter(file, isFile)
551
568
  const card = newCard(
552
569
  {
553
570
  frontMatter,
@@ -562,9 +579,9 @@ module.exports = class WorkerProject extends Project {
562
579
  return card.formatContent(frontMatter.template).content
563
580
  }
564
581
 
565
- getNewCardFileFrontMatter(file, stat) {
582
+ getNewCardFileFrontMatter(file, isFile) {
566
583
  let fileContent = ''
567
- if (file && stat.isFile()) {
584
+ if (file && isFile) {
568
585
  fileContent = fileGateway.readFileSync(file, 'utf8')
569
586
  } else if (JOURNAL_TYPE.NEW_FILE === this.config.journlType) {
570
587
  fileContent = this.config.journalTemplate
@@ -597,8 +614,7 @@ module.exports = class WorkerProject extends Project {
597
614
  if (!this.config) return ''
598
615
  const filePath = this.appendNewCardsTo(title)
599
616
  if (!filePath) return ''
600
- if (fileGateway.existsSync(filePath))
601
- return relPath ? filePath.replace(this.path, '') : filePath
617
+ return filePath
602
618
  }
603
619
 
604
620
  appendNewCardsTo(title) {
@@ -613,22 +629,12 @@ module.exports = class WorkerProject extends Project {
613
629
  const fileFolder = this.getFullPath(this.config.journalPath)
614
630
  const filePath = _path.join(fileFolder, fileName)
615
631
 
616
- if (!fileGateway.existsSync(fileFolder))
617
- fileGateway.mkdirpSync(fileFolder)
618
- if (!fileGateway.existsSync(filePath))
619
- fileGateway.writeFileSync(filePath, this.config.journalTemplate)
620
-
621
632
  return filePath
622
633
  }
623
634
  }
624
635
 
625
636
  sanitizeFileName(fileName) {
626
- fileName = fileName.replace(/:\w+:/g, '').trim()
627
- fileName = sanitize(fileName)
628
- if (this.config.replaceSpacesWith)
629
- fileName = fileName.replace(/ /g, this.config.replaceSpacesWith)
630
- // Remove markdown emoji
631
- return fileName
637
+ return fileGateway.sanitizeFileName(fileName, this.config.replaceSpacesWith)
632
638
  }
633
639
 
634
640
  getJournalFile() {
@@ -643,13 +649,7 @@ module.exports = class WorkerProject extends Project {
643
649
  `${journalFilePrefix}${today}${journalFileSuffix}.md`
644
650
  )
645
651
 
646
- const fullFolderPath = this.getFullPath(folderPath)
647
652
  const fullFilePath = this.getFullPath(filePath)
648
- if (!fileGateway.existsSync(fullFolderPath))
649
- fileGateway.mkdirpSync(fullFolderPath)
650
- if (!fileGateway.existsSync(fullFilePath)) {
651
- fileGateway.writeFileSync(fullFilePath, this.config.journalTemplate)
652
- }
653
653
  return { filePath, fullFilePath }
654
654
  }
655
655
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imdone-core",
3
- "version": "1.44.6",
3
+ "version": "1.45.0",
4
4
  "description": "imdone-core",
5
5
  "main": "index.js",
6
6
  "scripts": {