imdone-core 1.54.11 → 1.54.12

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/lib/constants.js CHANGED
@@ -50,13 +50,14 @@ module.exports = {
50
50
  SORT_FILE: path.join(CONFIG_DIR, 'sort.json'),
51
51
  TEMPLATES_DIR: path.join(CONFIG_DIR, 'templates'),
52
52
  IGNORE_FILE: '.imdoneignore',
53
+ PAUSE_FILE: '.imdonepause',
53
54
  DEFAULT_FILE_PATTERN: '^(readme\\.md|home\\.md|readme\\.w+|home\\.w+)$',
54
55
  DEFAULT_IGNORE,
55
56
  DEFAULT_IGNORE_DIRS,
56
57
  DEFAULT_IGNORE_EXTS,
57
58
  ERRORS: {
58
59
  NOT_A_FILE: 'file must be of type File',
59
- CALLBACK_REQUIRED: 'Last paramter must be a callback function',
60
+ CALLBACK_REQUIRED: 'Last parameter must be a callback function',
60
61
  NO_CONTENT: 'File has no content',
61
62
  LIST_NOT_FOUND: 'List not found',
62
63
  TASK_NOT_FOUND: 'Task not found',
@@ -4,7 +4,8 @@ var fsStore = require('./repo-fs-store'),
4
4
  log = require('debug')('imdone-mixins:repo-watched-fs-store'),
5
5
  File = require('../file'),
6
6
  constants = require('../constants'),
7
- sane = require('sane')
7
+ sane = require('sane'),
8
+ path = require('path')
8
9
 
9
10
  module.exports = mixin
10
11
 
@@ -18,6 +19,7 @@ function mixin(repo, fs = require('fs')) {
18
19
  var _destroy = repo.destroy
19
20
  var _init = repo.init
20
21
  var initializing = false
22
+ var paused = false
21
23
 
22
24
  repo.init = function (cb) {
23
25
  if (initializing) {
@@ -33,9 +35,17 @@ function mixin(repo, fs = require('fs')) {
33
35
  initializing = false
34
36
  return cb ? cb(err) : null
35
37
  }
36
- repo.initWatcher(() => {
37
- initializing = false
38
- if (cb) cb(err, files)
38
+ // Check if pause file exists on init
39
+ const pauseFilePath = path.join(repo.path, constants.PAUSE_FILE)
40
+ fs.access(pauseFilePath, fs.constants.F_OK, (accessErr) => {
41
+ if (!accessErr) {
42
+ log('Pause file detected on init. Pausing repository.')
43
+ paused = true
44
+ }
45
+ repo.initWatcher(() => {
46
+ initializing = false
47
+ if (cb) cb(err, files)
48
+ })
39
49
  })
40
50
  })
41
51
  }
@@ -57,9 +67,19 @@ function mixin(repo, fs = require('fs')) {
57
67
  initializing = false
58
68
  return cb ? cb(err) : null
59
69
  }
60
- repo.initWatcher(() => {
61
- initializing = false
62
- return cb ? cb(err, files) : null
70
+ // Check if pause file exists on refresh
71
+ const pauseFilePath = path.join(repo.path, constants.PAUSE_FILE)
72
+ fs.access(pauseFilePath, fs.constants.F_OK, (accessErr) => {
73
+ if (!accessErr) {
74
+ log('Pause file detected on refresh. Pausing repository.')
75
+ paused = true
76
+ } else {
77
+ paused = false
78
+ }
79
+ repo.initWatcher(() => {
80
+ initializing = false
81
+ return cb ? cb(err, files) : null
82
+ })
63
83
  })
64
84
  })
65
85
  }
@@ -72,6 +92,10 @@ function mixin(repo, fs = require('fs')) {
72
92
  return path === constants.IGNORE_FILE
73
93
  }
74
94
 
95
+ var _isImdonePause = function (path) {
96
+ return path === constants.PAUSE_FILE
97
+ }
98
+
75
99
  const onConfigChange = function (file) {
76
100
  console.info('Loading config. Observed a change to:', file)
77
101
  const label = `Refresh repo: ${repo.path}`
@@ -85,6 +109,30 @@ function mixin(repo, fs = require('fs')) {
85
109
 
86
110
  const onIgnoreChange = onConfigChange
87
111
 
112
+ repo.pause = async function () {
113
+ log('Pausing watcher for:', repo.path)
114
+ paused = true
115
+ return Promise.resolve()
116
+ }
117
+
118
+ repo.resume = async function () {
119
+ log('Resuming watcher for:', repo.path)
120
+ paused = false
121
+ return new Promise((resolve, reject) => {
122
+ repo.refresh((err, files) => {
123
+ if (err) {
124
+ console.error('Error refreshing repo on resume', err)
125
+ return reject(err)
126
+ }
127
+ resolve(files)
128
+ })
129
+ })
130
+ }
131
+
132
+ repo.isPaused = function () {
133
+ return paused
134
+ }
135
+
88
136
  repo.initWatcher = function (cb) {
89
137
  console.log('initializing watcher for:', repo.path)
90
138
  repo.watcher = sane(repo.path, {
@@ -98,6 +146,11 @@ function mixin(repo, fs = require('fs')) {
98
146
  onIgnoreChange(file)
99
147
  }
100
148
 
149
+ // Don't ignore the pause file so we can detect it
150
+ if (_isImdonePause(file)) {
151
+ return false
152
+ }
153
+
101
154
  const ignore = !repo.shouldInclude(file)
102
155
  if (!ignore || /^.*\.(jpg|gif|pdf|png)$/i.test(file)) {
103
156
  repo.addFilePath(file)
@@ -119,6 +172,11 @@ function mixin(repo, fs = require('fs')) {
119
172
  })
120
173
  .on('add', function (path, root, stat) {
121
174
  console.log('Watcher received add event for file: ' + path)
175
+ if (_isImdonePause(path)) {
176
+ console.log('Pause file detected. Pausing repository.')
177
+ return repo.pause()
178
+ }
179
+ if (paused) return log('Watcher is paused. Ignoring add event for: ' + path)
122
180
  if (stat.isDirectory()) return
123
181
  var file = repo.getFile(path)
124
182
  if (file === undefined) {
@@ -148,6 +206,8 @@ function mixin(repo, fs = require('fs')) {
148
206
  `Watcher received change event for file: ${path} repoPath: ${repo.path}`,
149
207
  stat.mtime
150
208
  )
209
+ if (_isImdonePause(path)) return log('Ignoring change to pause file')
210
+ if (paused) return log('Watcher is paused. Ignoring change event for: ' + path)
151
211
  if (!path || stat.isDirectory()) return
152
212
  var file = repo.getFile(path) || path
153
213
  const isFile = File.isFile(file)
@@ -178,6 +238,11 @@ function mixin(repo, fs = require('fs')) {
178
238
  })
179
239
  .on('delete', function (path) {
180
240
  log('Watcher received unlink event for file: ' + path)
241
+ if (_isImdonePause(path)) {
242
+ console.log('Pause file deleted. Resuming repository.')
243
+ return repo.resume()
244
+ }
245
+ if (paused) return log('Watcher is paused. Ignoring delete event for: ' + path)
181
246
  repo.removeFilePath(path)
182
247
  var file = new File({
183
248
  repoId: repo.getId(),
package/lib/repository.js CHANGED
@@ -624,6 +624,33 @@ Repository.prototype.readFileContent = function (file, cb) {
624
624
  inMixinsNoop(cb)
625
625
  }
626
626
 
627
+ /**
628
+ * Pause file watching (Implemented in mixins)
629
+ * @method pause
630
+ * @return Promise
631
+ */
632
+ Repository.prototype.pause = async function () {
633
+ return Promise.resolve()
634
+ }
635
+
636
+ /**
637
+ * Resume file watching (Implemented in mixins)
638
+ * @method resume
639
+ * @return Promise
640
+ */
641
+ Repository.prototype.resume = async function () {
642
+ return Promise.resolve()
643
+ }
644
+
645
+ /**
646
+ * Check if file watching is paused (Implemented in mixins)
647
+ * @method isPaused
648
+ * @return Boolean
649
+ */
650
+ Repository.prototype.isPaused = function () {
651
+ return false
652
+ }
653
+
627
654
  /**
628
655
  * Description
629
656
  * @method readFile
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imdone-core",
3
- "version": "1.54.11",
3
+ "version": "1.54.12",
4
4
  "description": "imdone-core",
5
5
  "main": "index.js",
6
6
  "bin": {