|
1
|
|
|
import fse from 'fs-extra' |
|
2
|
|
|
import path from 'path' |
|
3
|
|
|
|
|
4
|
|
|
import { |
|
5
|
|
|
config, |
|
6
|
|
|
abeExtend, |
|
7
|
|
|
cmsData, |
|
8
|
|
|
coreUtils, |
|
9
|
|
|
cmsOperations, |
|
10
|
|
|
Manager |
|
11
|
|
|
} from '../../' |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
export function remove(filePath) { |
|
15
|
|
|
filePath = coreUtils.slug.clean(filePath) |
|
16
|
|
|
filePath = abeExtend.hooks.instance.trigger('beforeDeleteFile', filePath) |
|
17
|
|
|
|
|
18
|
|
|
var revisions = cmsData.revision.getVersions(filePath) |
|
19
|
|
|
|
|
20
|
|
|
Array.prototype.forEach.call(revisions, (revision) => { |
|
21
|
|
|
cmsOperations.remove.removeFile(revision.path, revision.htmlPath) |
|
22
|
|
|
}) |
|
23
|
|
|
|
|
24
|
|
|
Manager.instance.updateList() |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
export function removeFile(file, json) { |
|
28
|
|
|
if(coreUtils.file.exist(file)) { |
|
29
|
|
|
fse.removeSync(file) |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if(coreUtils.file.exist(json)) { |
|
33
|
|
|
fse.removeSync(json) |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
export function olderRevisionByType(filePath, type) { |
|
38
|
|
|
|
|
39
|
|
|
const folder = path.dirname(filePath) |
|
40
|
|
|
const file = path.basename(filePath) |
|
41
|
|
|
const extension = path.extname(filePath) |
|
42
|
|
|
|
|
43
|
|
|
const files = coreUtils.file.getFiles(folder, false, extension) |
|
44
|
|
|
Array.prototype.forEach.call(files, (fileItem) => { |
|
45
|
|
|
const fname = cmsData.fileAttr.delete(fileItem) |
|
46
|
|
|
const ftype = cmsData.fileAttr.get(fileItem).s |
|
47
|
|
|
if(fname === file && ftype === type){ |
|
48
|
|
|
const fileDraft = fileItem.replace(/-abe-./, '-abe-d') |
|
49
|
|
|
cmsOperations.remove.removeFile(fileItem, coreUtils.file.changePath(fileItem, config.data.url).replace(extension, '.json')) |
|
50
|
|
|
cmsOperations.remove.removeFile(fileDraft, coreUtils.file.changePath(fileDraft, config.data.url).replace(extension, '.json')) |
|
51
|
|
|
} |
|
52
|
|
|
}) |
|
53
|
|
|
} |
|
54
|
|
|
|