imdone-core 1.44.6 → 1.45.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.
@@ -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,24 @@ 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.getNewCardsFile({title})
446
+ path = this.getFullPath(path)
447
+
448
+ const { isFile, isDirectory } = this.preparePathForWriting(path)
449
+
450
+ if (!template) template = this.getNewCardTemplate(path, isFile)
436
451
 
437
452
  if (comments) template = Task.addToLastCommentInContent(template, comments, this.config.isMetaNewLine())
438
453
 
454
+ let relativePath = _path.relative(this.path, path)
455
+ if (isDirectory) relativePath += _path.sep
456
+
439
457
  const data = {
440
458
  list,
441
459
  path,
460
+ relativePath,
442
461
  template,
443
- isDirectory: stat.isDirectory(),
462
+ isDirectory,
444
463
  }
445
464
  if (emit) this.emit('project.newCard', data)
446
465
  return data
@@ -475,7 +494,6 @@ module.exports = class WorkerProject extends Project {
475
494
 
476
495
  this.repo.moveTask({ task, newList, newPos }, (err) => {
477
496
  if (err) return reject(err)
478
-
479
497
  resolve({ file, task })
480
498
  })
481
499
  })
@@ -545,9 +563,9 @@ module.exports = class WorkerProject extends Project {
545
563
  setFilter(filter) {
546
564
  this.emit('project.filter', { filter })
547
565
  }
548
-
549
- getNewCardTemplate(file, stat) {
550
- const frontMatter = this.getNewCardFileFrontMatter(file, stat)
566
+
567
+ getNewCardTemplate(file, isFile) {
568
+ const frontMatter = this.getNewCardFileFrontMatter(file, isFile)
551
569
  const card = newCard(
552
570
  {
553
571
  frontMatter,
@@ -562,9 +580,9 @@ module.exports = class WorkerProject extends Project {
562
580
  return card.formatContent(frontMatter.template).content
563
581
  }
564
582
 
565
- getNewCardFileFrontMatter(file, stat) {
583
+ getNewCardFileFrontMatter(file, isFile) {
566
584
  let fileContent = ''
567
- if (file && stat.isFile()) {
585
+ if (file && isFile) {
568
586
  fileContent = fileGateway.readFileSync(file, 'utf8')
569
587
  } else if (JOURNAL_TYPE.NEW_FILE === this.config.journlType) {
570
588
  fileContent = this.config.journalTemplate
@@ -597,8 +615,7 @@ module.exports = class WorkerProject extends Project {
597
615
  if (!this.config) return ''
598
616
  const filePath = this.appendNewCardsTo(title)
599
617
  if (!filePath) return ''
600
- if (fileGateway.existsSync(filePath))
601
- return relPath ? filePath.replace(this.path, '') : filePath
618
+ return filePath
602
619
  }
603
620
 
604
621
  appendNewCardsTo(title) {
@@ -613,22 +630,12 @@ module.exports = class WorkerProject extends Project {
613
630
  const fileFolder = this.getFullPath(this.config.journalPath)
614
631
  const filePath = _path.join(fileFolder, fileName)
615
632
 
616
- if (!fileGateway.existsSync(fileFolder))
617
- fileGateway.mkdirpSync(fileFolder)
618
- if (!fileGateway.existsSync(filePath))
619
- fileGateway.writeFileSync(filePath, this.config.journalTemplate)
620
-
621
633
  return filePath
622
634
  }
623
635
  }
624
636
 
625
637
  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
638
+ return fileGateway.sanitizeFileName(fileName, this.config.replaceSpacesWith)
632
639
  }
633
640
 
634
641
  getJournalFile() {
@@ -643,13 +650,7 @@ module.exports = class WorkerProject extends Project {
643
650
  `${journalFilePrefix}${today}${journalFileSuffix}.md`
644
651
  )
645
652
 
646
- const fullFolderPath = this.getFullPath(folderPath)
647
653
  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
654
  return { filePath, fullFilePath }
654
655
  }
655
656
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imdone-core",
3
- "version": "1.44.6",
3
+ "version": "1.45.1",
4
4
  "description": "imdone-core",
5
5
  "main": "index.js",
6
6
  "scripts": {