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.
- package/.dependency-cruiser.cjs +412 -0
- package/.github/workflows/ci.yml +2 -2
- package/.imdoneignore +2 -1
- package/README.md +2 -2
- package/_index.md +7 -0
- package/build.js +57 -0
- package/esm-migration.md +446 -0
- package/lib/FileProjectContext.js +13 -0
- package/lib/ProjectContext.js +19 -18
- package/lib/adapters/date-time.js +3 -8
- package/lib/adapters/environment.js +3 -0
- package/lib/adapters/file-gateway.js +133 -106
- package/lib/adapters/git-download.js +36 -16
- package/lib/adapters/index.js +9 -0
- package/lib/adapters/logger.js +136 -0
- package/lib/adapters/markdown.js +31 -19
- package/lib/adapters/parsers/DateLanguageParser.js +11 -9
- package/lib/adapters/parsers/content-transformer.js +35 -30
- package/lib/adapters/parsers/file/LocalFileParserFactory.js +8 -9
- package/lib/adapters/parsers/file/ReadStreamCodeParser.js +8 -8
- package/lib/adapters/parsers/file/ReadStreamMarkdownParser.js +4 -4
- package/lib/adapters/parsers/file/ReadStreamTaskParser.js +5 -3
- package/lib/adapters/parsers/file/index.js +4 -0
- package/lib/adapters/parsers/function-parser.js +1 -5
- package/lib/adapters/parsers/index.js +5 -0
- package/lib/adapters/parsers/task/CardContentParser.js +23 -32
- package/lib/adapters/parsers/task/CheckStyleTaskParser.js +2 -2
- package/lib/adapters/parsers/task/CodeStyleTaskParser.js +2 -2
- package/lib/adapters/parsers/task/HashStyleTaskParser.js +3 -3
- package/lib/adapters/parsers/task/MarkdownStyleTaskParser.js +2 -2
- package/lib/adapters/parsers/task/TaskParser.js +1 -1
- package/lib/adapters/parsers/task/index.js +6 -0
- package/lib/adapters/storage/config.js +15 -20
- package/lib/adapters/storage/index.js +2 -0
- package/lib/adapters/storage/tags.js +11 -12
- package/lib/adapters/yaml.js +8 -5
- package/lib/card.js +25 -26
- package/lib/checksum.js +22 -0
- package/lib/cli.js +114 -0
- package/lib/config.js +106 -71
- package/lib/constants.js +21 -50
- package/lib/context/ApplicationContext.js +7 -4
- package/lib/context/index.js +1 -0
- package/lib/default-settings.js +3 -3
- package/lib/domain/entities/View.js +4 -11
- package/lib/domain/entities/index.js +1 -0
- package/lib/domain/index.js +2 -0
- package/lib/domain/usecases/GetViewsUsecase.js +6 -12
- package/lib/domain/usecases/SaveViewUsecase.js +8 -14
- package/lib/domain/usecases/index.js +2 -0
- package/lib/file.js +1158 -1162
- package/lib/get-tasks-to-modify.js +117 -0
- package/lib/index.js +23 -0
- package/lib/languages.js +4 -5
- package/lib/list.js +46 -95
- package/lib/migrate-config.js +5 -5
- package/lib/mixins/index.js +2 -0
- package/lib/mixins/repo-fs-store.js +224 -289
- package/lib/mixins/repo-watched-fs-store.js +158 -147
- package/lib/plugins/archive-plugin.js +10 -8
- package/lib/plugins/default-board-actions-plugin.js +2 -2
- package/lib/plugins/default-board-properties-plugin.js +7 -7
- package/lib/plugins/default-plugins.js +7 -0
- package/lib/plugins/epic-plugin.js +6 -5
- package/lib/plugins/extension-plugin.js +24 -17
- package/lib/plugins/index.js +9 -0
- package/lib/plugins/persist-tags-plugin.js +4 -3
- package/lib/plugins/plugin-manager.js +89 -52
- package/lib/plugins/plugin-registry.js +12 -16
- package/lib/project-factory.js +21 -24
- package/lib/project.js +97 -144
- package/lib/repository.js +1323 -1555
- package/lib/task.js +562 -580
- package/lib/tools.js +39 -113
- package/lib/usecases/actions.js +32 -0
- package/lib/usecases/get-project-tags.js +3 -12
- package/lib/usecases/get-tasks-in-file.js +4 -7
- package/lib/usecases/index.js +4 -0
- package/package.json +44 -66
- package/scripts/delete-markdown-indexes.js +87 -0
- package/scripts/generate-index.js +35 -0
- package/{index-markdown.js → scripts/index-markdown.js} +7 -7
- package/tsconfig.json +15 -0
- package/types/FileProjectContext.d.ts +4 -0
- package/types/ProjectContext.d.ts +9 -0
- package/types/adapters/date-time.d.ts +2 -0
- package/types/adapters/environment.d.ts +1 -0
- package/types/adapters/file-gateway.d.ts +51 -0
- package/types/adapters/git-download.d.ts +1 -0
- package/types/adapters/index.d.ts +9 -0
- package/types/adapters/logger.d.ts +24 -0
- package/types/adapters/markdown.d.ts +13 -0
- package/types/adapters/parsers/DateLanguageParser.d.ts +1 -0
- package/types/adapters/parsers/content-transformer.d.ts +10 -0
- package/types/adapters/parsers/file/LocalFileParserFactory.d.ts +5 -0
- package/types/adapters/parsers/file/ReadStreamCodeParser.d.ts +13 -0
- package/types/adapters/parsers/file/ReadStreamMarkdownParser.d.ts +7 -0
- package/types/adapters/parsers/file/ReadStreamTaskParser.d.ts +19 -0
- package/types/adapters/parsers/file/index.d.ts +4 -0
- package/types/adapters/parsers/function-parser.d.ts +1 -0
- package/types/adapters/parsers/index.d.ts +5 -0
- package/types/adapters/parsers/task/CardContentParser.d.ts +45 -0
- package/types/adapters/parsers/task/CheckStyleTaskParser.d.ts +12 -0
- package/types/adapters/parsers/task/CodeStyleTaskParser.d.ts +14 -0
- package/types/adapters/parsers/task/HashStyleTaskParser.d.ts +13 -0
- package/types/adapters/parsers/task/MarkdownStyleTaskParser.d.ts +14 -0
- package/types/adapters/parsers/task/TaskParser.d.ts +7 -0
- package/types/adapters/parsers/task/index.d.ts +6 -0
- package/types/adapters/storage/config.d.ts +6 -0
- package/types/adapters/storage/index.d.ts +2 -0
- package/types/adapters/storage/tags.d.ts +3 -0
- package/types/adapters/yaml.d.ts +2 -0
- package/types/card.d.ts +166 -0
- package/types/checksum.d.ts +8 -0
- package/types/config.d.ts +61 -0
- package/types/constants.d.ts +46 -0
- package/types/context/ApplicationContext.d.ts +24 -0
- package/types/context/index.d.ts +1 -0
- package/types/default-settings.d.ts +2 -0
- package/types/domain/entities/FileProjectContext.d.ts +5 -0
- package/types/domain/entities/View.d.ts +17 -0
- package/types/domain/entities/index.d.ts +1 -0
- package/types/domain/index.d.ts +2 -0
- package/types/domain/usecases/GetViewsUsecase.d.ts +4 -0
- package/types/domain/usecases/SaveViewUsecase.d.ts +8 -0
- package/types/domain/usecases/index.d.ts +2 -0
- package/types/file.d.ts +344 -0
- package/types/get-tasks-to-modify.d.ts +3 -0
- package/types/index.d.ts +23 -0
- package/types/languages.d.ts +649 -0
- package/types/list.d.ts +30 -0
- package/types/migrate-config.d.ts +1 -0
- package/types/mixins/index.d.ts +2 -0
- package/types/mixins/repo-fs-store.d.ts +2 -0
- package/types/mixins/repo-watched-fs-store.d.ts +2 -0
- package/types/plugins/archive-plugin.d.ts +8 -0
- package/types/plugins/default-board-actions-plugin.d.ts +9 -0
- package/types/plugins/default-board-properties-plugin.d.ts +16 -0
- package/types/plugins/default-plugins.d.ts +6 -0
- package/types/plugins/epic-plugin.d.ts +19 -0
- package/types/plugins/extension-plugin.d.ts +15 -0
- package/types/plugins/index.d.ts +9 -0
- package/types/plugins/persist-tags-plugin.d.ts +4 -0
- package/types/plugins/plugin-manager.d.ts +68 -0
- package/types/plugins/plugin-registry.d.ts +1 -0
- package/types/project-factory.d.ts +14 -0
- package/types/project.d.ts +158 -0
- package/types/repository.d.ts +996 -0
- package/types/task.d.ts +202 -0
- package/types/tools.d.ts +29 -0
- package/types/usecases/actions.d.ts +7 -0
- package/types/usecases/get-imdone-url.d.ts +1 -0
- package/types/usecases/get-project-tags.d.ts +1 -0
- package/types/usecases/get-tasks-in-file.d.ts +4 -0
- package/types/usecases/index.d.ts +4 -0
- package/vitest.config.js +13 -0
- package/cli.js +0 -74
- package/index.js +0 -1
- package/lib/adapters/readers/FileSystemProjectReader.js +0 -45
- package/lib/context/StreamingApplicationContext.js +0 -31
- package/lib/controlers/SaveViewController.js +0 -10
- package/lib/domain/entities/FileProjectContext.js +0 -10
- package/lib/domain/usecases/OpenProjectUsecase.js +0 -13
|
@@ -1,53 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
{ loadYAML, dumpYAML } = require('../adapters/yaml')
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
module.exports = mixin
|
|
1
|
+
import _path from 'path'
|
|
2
|
+
import _cloneDeep from 'lodash.clonedeep'
|
|
3
|
+
import _isFunction from 'lodash.isfunction'
|
|
4
|
+
import _isUndefined from 'lodash.isundefined'
|
|
5
|
+
import _assign from 'lodash.assign'
|
|
6
|
+
import _remove from 'lodash.remove'
|
|
7
|
+
import _union from 'lodash.union'
|
|
8
|
+
import { eachLimit } from 'async'
|
|
9
|
+
import { computeChecksum } from '../checksum.js'
|
|
10
|
+
import { constants } from '../constants.js'
|
|
11
|
+
import debug from 'debug'
|
|
12
|
+
const log = debug('imdone-mixins:repo-fs-store.js')
|
|
13
|
+
import { File } from '../file.js'
|
|
14
|
+
import { Config } from '../config.js'
|
|
15
|
+
import { languages } from '../languages.js'
|
|
16
|
+
import { isBinaryFile } from 'isbinaryfile'
|
|
17
|
+
import eol from 'eol'
|
|
18
|
+
const _eol = String(eol.auto)
|
|
19
|
+
import readdirp from 'readdirp'
|
|
20
|
+
import _ignore from 'ignore'
|
|
21
|
+
import { sort } from 'fast-sort'
|
|
22
|
+
import { buildMigrateConfig } from '../migrate-config.js'
|
|
23
|
+
import { loadYAML, dumpYAML } from '../adapters/yaml.js';
|
|
24
|
+
import realFs, { readFileSync } from 'fs'
|
|
25
|
+
import { preparePathForWriting, readFile, writeFile, stat, lstat, unlink } from '../adapters/file-gateway.js'
|
|
30
26
|
|
|
31
27
|
const {
|
|
32
|
-
CONFIG_DIR,
|
|
33
28
|
CONFIG_FILE,
|
|
34
29
|
CONFIG_FILE_YML,
|
|
35
|
-
DEFAULT_CONFIG,
|
|
36
30
|
ASYNC_LIMIT,
|
|
37
|
-
|
|
31
|
+
DEFAULT_IGNORE_PATHS,
|
|
38
32
|
DEFAULT_IGNORE_EXTS,
|
|
39
33
|
IGNORE_FILE,
|
|
40
34
|
SORT_FILE,
|
|
41
35
|
ERRORS,
|
|
42
36
|
} = constants
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
const { DEFAULT_CONFIG } = Config
|
|
39
|
+
|
|
40
|
+
export function fileSystemStoreMixin(repo, fs = realFs) {
|
|
46
41
|
repo.allFiles = []
|
|
47
42
|
|
|
48
43
|
function getIgnorePatterns() {
|
|
49
44
|
var ignoreFile = _path.join(repo.path, IGNORE_FILE)
|
|
50
|
-
let patterns =
|
|
45
|
+
let patterns = DEFAULT_IGNORE_PATHS
|
|
51
46
|
if (fs.existsSync(ignoreFile))
|
|
52
47
|
patterns = patterns + _eol + fs.readFileSync(ignoreFile).toString()
|
|
53
48
|
|
|
@@ -61,28 +56,13 @@ function mixin(repo, fs = require('fs')) {
|
|
|
61
56
|
return !dirent.isSymbolicLink() && !IG.ignores(path)
|
|
62
57
|
}
|
|
63
58
|
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
.catch((error) => cb(error, []))
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function ls(root, cb) {
|
|
75
|
-
getAllFilePaths(root, function (error, files) {
|
|
76
|
-
if (error) {
|
|
77
|
-
console.error(`Error reading dir: ${root} `, error)
|
|
78
|
-
}
|
|
79
|
-
cb(
|
|
80
|
-
null,
|
|
81
|
-
files
|
|
82
|
-
.filter((res) => repo.shouldInclude(res.path))
|
|
83
|
-
.map((res) => res.fullPath)
|
|
84
|
-
)
|
|
85
|
-
})
|
|
59
|
+
repo.getAllFilePaths = async function (root) {
|
|
60
|
+
const entries = []
|
|
61
|
+
for await (const entry of readdirp(root, { lstat: true, fileFilter: shouldIncludeFile })) {
|
|
62
|
+
entries.push(entry)
|
|
63
|
+
}
|
|
64
|
+
return entries.filter((res) => repo.shouldInclude(res.path))
|
|
65
|
+
.map((res) => res.fullPath)
|
|
86
66
|
}
|
|
87
67
|
|
|
88
68
|
repo.addFilePath = async function (path) {
|
|
@@ -104,38 +84,32 @@ function mixin(repo, fs = require('fs')) {
|
|
|
104
84
|
return repo.allFiles
|
|
105
85
|
}
|
|
106
86
|
|
|
107
|
-
const _init = repo.init
|
|
108
87
|
repo.migrateConfig = buildMigrateConfig(repo)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
88
|
+
// READY Refactor init to use async/await
|
|
89
|
+
// #esm-migration #important #urgent
|
|
90
|
+
// <!--
|
|
91
|
+
// order:-270
|
|
92
|
+
// -->
|
|
93
|
+
repo.init = async function () {
|
|
94
|
+
const stats = await stat(repo.path)
|
|
95
|
+
if (!stats.isDirectory()) {
|
|
96
|
+
var error = new Error(
|
|
97
|
+
`Path must be an existing directory on the file system: ${repo.path}`
|
|
98
|
+
)
|
|
99
|
+
repo.emit('error', error)
|
|
100
|
+
throw error
|
|
101
|
+
}
|
|
121
102
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (err && repo.destroyed) return cb(err)
|
|
133
|
-
repo.emit('initialized', { ok: true, lists: repo.getTasksByList() })
|
|
134
|
-
cb(err, files)
|
|
135
|
-
})
|
|
136
|
-
})
|
|
137
|
-
})
|
|
138
|
-
})
|
|
103
|
+
await repo.loadConfig()
|
|
104
|
+
repo.migrateConfig()
|
|
105
|
+
await repo.saveConfig()
|
|
106
|
+
repo.emit('config.loaded')
|
|
107
|
+
repo.createListeners()
|
|
108
|
+
|
|
109
|
+
const files = await repo.readFiles()
|
|
110
|
+
const lists = repo.getTasksByList()
|
|
111
|
+
repo.emit('fs-store-initialized', { ok: true, lists })
|
|
112
|
+
return files
|
|
139
113
|
}
|
|
140
114
|
|
|
141
115
|
repo.loadIgnore = function () {
|
|
@@ -143,79 +117,62 @@ function mixin(repo, fs = require('fs')) {
|
|
|
143
117
|
repo.setIgnores(patterns)
|
|
144
118
|
}
|
|
145
119
|
|
|
146
|
-
repo.fileOK = function (file, includeDirs
|
|
120
|
+
repo.fileOK = async function (file, includeDirs = false) {
|
|
147
121
|
if (File.isFile(file)) file = file.path
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
includeDirs = false
|
|
151
|
-
}
|
|
152
|
-
cb = tools.cb(cb)
|
|
153
|
-
try {
|
|
154
|
-
if (!file || !this.shouldInclude(file)) return cb(null, false)
|
|
155
|
-
} catch (e) {
|
|
156
|
-
cb(e)
|
|
157
|
-
}
|
|
122
|
+
if (!file || !this.shouldInclude(file)) return false
|
|
123
|
+
|
|
158
124
|
var fullPath = repo.getFullPath(file)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
125
|
+
try {
|
|
126
|
+
const stats = await lstat(fullPath)
|
|
127
|
+
|
|
128
|
+
if (!stats) return false
|
|
129
|
+
|
|
130
|
+
if (/\.\.(\/|\\)/.test(file) || (!includeDirs && stats.isDirectory()))
|
|
131
|
+
return false
|
|
132
|
+
|
|
133
|
+
const content = await readFile(fullPath)
|
|
134
|
+
|
|
135
|
+
if (await isBinaryFile(content, stats.size) ) {
|
|
136
|
+
return false
|
|
163
137
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
cb(null, stat)
|
|
170
|
-
})
|
|
171
|
-
} else if (includeDirs && stat.isDirectory()) {
|
|
172
|
-
cb(null, stat)
|
|
173
|
-
} else cb(null, false)
|
|
174
|
-
})
|
|
138
|
+
|
|
139
|
+
return stats
|
|
140
|
+
} catch (err) {
|
|
141
|
+
return false
|
|
142
|
+
}
|
|
175
143
|
}
|
|
176
144
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
145
|
+
// READY Refactor saveSort to use async/await
|
|
146
|
+
// #esm-migration #important
|
|
147
|
+
// TODO readSort and saveSort are no longer used
|
|
148
|
+
repo.saveSort = async function (sort) {
|
|
149
|
+
writeFile(repo.getFullPath(SORT_FILE), JSON.stringify(sort), 'utf8')
|
|
180
150
|
}
|
|
181
151
|
|
|
182
|
-
repo.readSort = function (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
repo.sort = JSON.parse(data)
|
|
186
|
-
cb(null, repo.sort)
|
|
187
|
-
})
|
|
152
|
+
repo.readSort = async function () {
|
|
153
|
+
const data = readFile(repo.getFullPath(SORT_FILE))
|
|
154
|
+
repo.sort = JSON.parse(data)
|
|
188
155
|
}
|
|
189
156
|
|
|
190
|
-
repo.saveConfig = function (
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
repo.savingConfig = false
|
|
195
|
-
cb(err, resp)
|
|
196
|
-
}
|
|
197
|
-
var dir = repo.getFullPath(CONFIG_DIR)
|
|
198
|
-
var file = repo.getFullPath(CONFIG_FILE_YML)
|
|
199
|
-
fs.exists(dir, function (exists) {
|
|
157
|
+
repo.saveConfig = async function () {
|
|
158
|
+
try {
|
|
159
|
+
repo.savingConfig = true
|
|
160
|
+
const file = repo.getFullPath(CONFIG_FILE_YML)
|
|
200
161
|
const data = { ...repo.getConfig() }
|
|
201
162
|
delete data.cardActionsFunction
|
|
202
163
|
delete data.boardActionsFunction
|
|
203
164
|
delete data.cardPropertiesFunction
|
|
204
165
|
delete data.path
|
|
205
166
|
if (data.lists) data.lists.forEach((list) => delete list.tasks)
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
fs.writeFile(file, yaml, _cb)
|
|
213
|
-
})
|
|
214
|
-
}
|
|
215
|
-
})
|
|
167
|
+
const yaml = dumpYAML(data)
|
|
168
|
+
await preparePathForWriting(file)
|
|
169
|
+
await writeFile(file, yaml)
|
|
170
|
+
} finally {
|
|
171
|
+
repo.savingConfig = false
|
|
172
|
+
}
|
|
216
173
|
}
|
|
217
174
|
|
|
218
|
-
repo.updateConfig = function (loadedConfig
|
|
175
|
+
repo.updateConfig = async function (loadedConfig) {
|
|
219
176
|
var baseConfig = _cloneDeep(DEFAULT_CONFIG)
|
|
220
177
|
var include_lists = baseConfig.code.include_lists
|
|
221
178
|
const currentConfig = repo.config
|
|
@@ -232,38 +189,42 @@ function mixin(repo, fs = require('fs')) {
|
|
|
232
189
|
_assign({}, baseConfig, repo.config, loadedConfig, { path: repo.path })
|
|
233
190
|
)
|
|
234
191
|
|
|
235
|
-
repo.migrateTasksByConfig(currentConfig, newConfig
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
cb(null, repo.config)
|
|
244
|
-
})
|
|
192
|
+
await repo.migrateTasksByConfig(currentConfig, newConfig)
|
|
193
|
+
repo.config = newConfig
|
|
194
|
+
repo.config.code.include_lists = include_lists
|
|
195
|
+
var _languages = _cloneDeep(languages)
|
|
196
|
+
repo.languages = repo.config.languages
|
|
197
|
+
? _assign(_languages, repo.config.languages)
|
|
198
|
+
: _languages
|
|
199
|
+
return repo.config
|
|
245
200
|
}
|
|
246
201
|
|
|
247
|
-
|
|
202
|
+
// READY Refactor loadConfig to use async/await
|
|
203
|
+
// #esm-migration
|
|
204
|
+
// <!--
|
|
205
|
+
// order:-255
|
|
206
|
+
// -->
|
|
207
|
+
repo.loadConfig = async function (cb) {
|
|
248
208
|
// BACKLOG If a config is bad move it to config.json.bak and save a new one with defaults gh:2 id:9 +enhancement +standup +chore
|
|
249
209
|
// <!--
|
|
250
210
|
// order:-670
|
|
251
211
|
// -->
|
|
252
|
-
cb = tools.cb(cb)
|
|
253
212
|
repo.loadIgnore()
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
repo.
|
|
213
|
+
const configData = (!repo.config || repo.config.dirty)
|
|
214
|
+
? await this.getYamlConfig()
|
|
215
|
+
: repo.config || {}
|
|
216
|
+
|
|
217
|
+
return await repo.updateConfig(configData)
|
|
257
218
|
}
|
|
258
219
|
|
|
259
220
|
repo.getConfigFile = function () {
|
|
260
221
|
return repo.getFullPath(CONFIG_FILE)
|
|
261
222
|
}
|
|
262
223
|
|
|
263
|
-
repo.getYamlConfig = function () {
|
|
224
|
+
repo.getYamlConfig = async function () {
|
|
264
225
|
const filePath = repo.getFullPath(CONFIG_FILE_YML)
|
|
265
226
|
if (!fs.existsSync(filePath)) return
|
|
266
|
-
const configData =
|
|
227
|
+
const configData = await readFile(filePath, 'utf-8')
|
|
267
228
|
let configLike = {}
|
|
268
229
|
try {
|
|
269
230
|
configLike = loadYAML(configData.toString())
|
|
@@ -273,151 +234,125 @@ function mixin(repo, fs = require('fs')) {
|
|
|
273
234
|
return configLike
|
|
274
235
|
}
|
|
275
236
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
repo.writeFile = function (file, emitFileUpdate, cb) {
|
|
286
|
-
if (_isFunction(emitFileUpdate)) {
|
|
287
|
-
cb = emitFileUpdate
|
|
288
|
-
emitFileUpdate = false
|
|
289
|
-
}
|
|
290
|
-
cb = tools.cb(cb)
|
|
291
|
-
|
|
292
|
-
if (!File.isFile(file)) return cb(new Error(ERRORS.NOT_A_FILE))
|
|
293
|
-
if (file.deleted) return cb(null, file)
|
|
237
|
+
// READY Refactor writeFile to use async/await
|
|
238
|
+
// #esm-migration #important
|
|
239
|
+
// <!--
|
|
240
|
+
// order:-280
|
|
241
|
+
// -->
|
|
242
|
+
repo.writeFile = async (file, emitFileUpdate) => {
|
|
243
|
+
if (!File.isFile(file)) throw new Error(ERRORS.NOT_A_FILE)
|
|
244
|
+
if (file.deleted) return file
|
|
294
245
|
|
|
295
|
-
|
|
246
|
+
if (/\.\.(\/|\\)/.test(file.path)) throw new Error('Unable to write file:' + file.path)
|
|
296
247
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
file.checksum = checksum(file.getContentForFile())
|
|
301
|
-
fs.writeFile(
|
|
302
|
-
filePath,
|
|
303
|
-
file.getContentForFile(),
|
|
304
|
-
'utf8',
|
|
305
|
-
function (err) {
|
|
306
|
-
if (err) {
|
|
307
|
-
file.checksum = oldChecksum
|
|
308
|
-
return cb([new Error('Unable to write file:' + filePath), err])
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
fs.stat(filePath, function (err, stats) {
|
|
312
|
-
if (err)
|
|
313
|
-
return cb([new Error('Unable to stat file:' + filePath), err])
|
|
314
|
-
|
|
315
|
-
file.setModifiedTime(stats.mtime)
|
|
316
|
-
file.modified = false
|
|
317
|
-
repo.addFilePath(filePath)
|
|
318
|
-
if (emitFileUpdate) repo.emit('file.saved', file)
|
|
319
|
-
cb(null, file)
|
|
320
|
-
})
|
|
321
|
-
}
|
|
322
|
-
)
|
|
323
|
-
}
|
|
248
|
+
const filePath = repo.getFullPath(file)
|
|
249
|
+
|
|
250
|
+
await preparePathForWriting(filePath)
|
|
324
251
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
252
|
+
const oldChecksum = file.checksum
|
|
253
|
+
file.checksum = computeChecksum(file.getContentForFile())
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
await writeFile(filePath, file.getContentForFile(), 'utf8')
|
|
257
|
+
} catch (err) {
|
|
258
|
+
file.checksum = oldChecksum
|
|
259
|
+
throw new Error('Unable to write file:' + filePath, {cause: err})
|
|
260
|
+
}
|
|
329
261
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
262
|
+
try {
|
|
263
|
+
const stats = await stat(filePath)
|
|
264
|
+
file.setModifiedTime(stats.mtime)
|
|
265
|
+
file.modified = false
|
|
266
|
+
repo.addFilePath(filePath)
|
|
267
|
+
if (emitFileUpdate) repo.emit('file.saved', file)
|
|
268
|
+
} catch (err) {
|
|
269
|
+
throw new Error('Unable to stat file:' + filePath, {cause: err})
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return file
|
|
335
273
|
}
|
|
336
274
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
file.isDir = stat.isDirectory()
|
|
374
|
-
files.push(file)
|
|
375
|
-
}
|
|
376
|
-
log('err=%j', err, null)
|
|
377
|
-
log('stat=%j', stat, null)
|
|
378
|
-
log('processed=%d allPaths.length=%d', processed, allPaths.length)
|
|
379
|
-
_cb() // stack-1 repo-fs-store.js:270:11
|
|
275
|
+
// READY Refactor getFilesInPath to use async/await
|
|
276
|
+
// #esm-migration #important #urgent
|
|
277
|
+
// <!--
|
|
278
|
+
// order:-20
|
|
279
|
+
// -->
|
|
280
|
+
repo.getFilesInPath = async function (includeDirs) {
|
|
281
|
+
const allPaths = await repo.getAllFilePaths(repo.path)
|
|
282
|
+
const files = []
|
|
283
|
+
let processed = 0
|
|
284
|
+
log('allPaths=', allPaths)
|
|
285
|
+
if (allPaths.length === 0) return files
|
|
286
|
+
await eachLimit(
|
|
287
|
+
allPaths,
|
|
288
|
+
ASYNC_LIMIT,
|
|
289
|
+
async (path) => {
|
|
290
|
+
if (!path) return
|
|
291
|
+
path = repo.getRelativePath(path)
|
|
292
|
+
const stat = await repo.fileOK(path, includeDirs)
|
|
293
|
+
processed++
|
|
294
|
+
repo.emit('file.processed', {
|
|
295
|
+
file: path,
|
|
296
|
+
ok: stat !== false,
|
|
297
|
+
total: allPaths.length,
|
|
298
|
+
processed: processed + 1,
|
|
299
|
+
repoId: repo.getId(),
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
if (stat) {
|
|
303
|
+
log('%s is ok %j', path, stat)
|
|
304
|
+
var file = new File({
|
|
305
|
+
repoId: repo.getId(),
|
|
306
|
+
filePath: path,
|
|
307
|
+
modifiedTime: stat.mtime,
|
|
308
|
+
createdTime: stat.birthtime,
|
|
309
|
+
languages: repo.languages,
|
|
310
|
+
project: repo.project,
|
|
380
311
|
})
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
cb(err, fastSort(files).asc(u => u.path))
|
|
312
|
+
file.isDir = stat.isDirectory()
|
|
313
|
+
files.push(file)
|
|
384
314
|
}
|
|
385
|
-
|
|
386
|
-
|
|
315
|
+
log('stat=%j', stat, null)
|
|
316
|
+
log('processed=%d allPaths.length=%d', processed, allPaths.length)
|
|
317
|
+
})
|
|
318
|
+
return sort(files).asc(u => u.path)
|
|
387
319
|
}
|
|
388
320
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
321
|
+
// READY Refactor readFileContent to use async/await
|
|
322
|
+
// #esm-migration #important #urgent
|
|
323
|
+
// <!--
|
|
324
|
+
// order:-40
|
|
325
|
+
// -->
|
|
326
|
+
repo.readFileContent = async function (file) {
|
|
327
|
+
if (!File.isFile(file)) throw new Error(ERRORS.NOT_A_FILE)
|
|
392
328
|
var filePath = repo.getFullPath(file)
|
|
393
329
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
fs.readFile(filePath, 'utf8', function (err, data) {
|
|
398
|
-
if (err) return cb([new Error('Unable to read file:' + filePath), err])
|
|
330
|
+
const stats = await stat(filePath)
|
|
331
|
+
if (!stats.isFile()) return file
|
|
332
|
+
const data = await readFile(filePath, 'utf8')
|
|
399
333
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
334
|
+
file
|
|
335
|
+
.setContentFromFile(data)
|
|
336
|
+
.setModifiedTime(stats.mtime)
|
|
337
|
+
.setCreatedTime(stats.birthtime)
|
|
404
338
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
})
|
|
408
|
-
})
|
|
339
|
+
file.lineCount = eol.split(data).length
|
|
340
|
+
return file
|
|
409
341
|
}
|
|
410
342
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
343
|
+
// READY Refactor deleteFile to use async/await
|
|
344
|
+
// #esm-migration #important
|
|
345
|
+
repo.deleteFile = async function (path) {
|
|
346
|
+
const file = File.isFile(path) ? path : repo.getFile(path)
|
|
347
|
+
if (!file) throw new Error('Unable to delete:' + path)
|
|
348
|
+
|
|
349
|
+
try {
|
|
350
|
+
await unlink(repo.getFullPath(file))
|
|
351
|
+
repo.removeFile(file)
|
|
352
|
+
} catch (err) {
|
|
353
|
+
throw new Error('Unable to delete file:' + path, {cause: err})
|
|
354
|
+
}
|
|
355
|
+
|
|
421
356
|
}
|
|
422
357
|
|
|
423
358
|
return repo
|