1
|
|
|
import path from 'path' |
2
|
|
|
import fse from 'fs-extra' |
3
|
|
|
|
4
|
|
|
import { |
5
|
|
|
Hooks, |
6
|
|
|
cmsData, |
7
|
|
|
coreUtils, |
8
|
|
|
cmsOperations, |
9
|
|
|
Manager |
10
|
|
|
} from '../../' |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
export function remove(filePath) { |
14
|
|
|
filePath = coreUtils.slug.clean(filePath) |
15
|
|
|
filePath = Hooks.instance.trigger('beforeDeleteFile', filePath) |
16
|
|
|
|
17
|
|
|
var revisions = cmsData.revision.getVersions(filePath) |
18
|
|
|
|
19
|
|
|
Array.prototype.forEach.call(revisions, (revision) => { |
20
|
|
|
cmsOperations.remove.removeFile(revision.path, revision.htmlPath) |
21
|
|
|
}) |
22
|
|
|
|
23
|
|
|
Manager.instance.updateList() |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
export function removeFile(file, json) { |
27
|
|
|
if(coreUtils.file.exist(file)) { |
28
|
|
|
fse.removeSync(file) |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
if(coreUtils.file.exist(json)) { |
32
|
|
|
fse.removeSync(json) |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
export function olderRevisionByType(fileName, type) { |
37
|
|
|
var folder = fileName.split('/') |
38
|
|
|
var file = folder.pop() |
39
|
|
|
var extension = file.replace(/.*?\./, '') |
40
|
|
|
folder = folder.join('/') |
41
|
|
|
var stat = fse.statSync(folder) |
42
|
|
|
if(stat){ |
43
|
|
|
var files = FileParser.getFiles(folder, true, 1, new RegExp('\\.' + extension)) |
|
|
|
|
44
|
|
|
files.forEach(function (fileItem) { |
45
|
|
|
var fname = cmsData.fileAttr.delete(fileItem.cleanPath) |
46
|
|
|
var ftype = cmsData.fileAttr.get(fileItem.cleanPath).s |
47
|
|
|
if(fname === file && ftype === type){ |
48
|
|
|
var fileDraft = fileItem.path.replace(/-abe-./, '-abe-d') |
49
|
|
|
cmsOperations.remove.removeFile(fileItem.path, FileParser.changePathEnv(fileItem.path, config.data.url).replace(new RegExp('\\.' + extension), '.json')) |
|
|
|
|
50
|
|
|
cmsOperations.remove.removeFile(fileDraft, FileParser.changePathEnv(fileDraft, config.data.url).replace(new RegExp('\\.' + extension), '.json')) |
51
|
|
|
} |
52
|
|
|
}) |
53
|
|
|
} |
54
|
|
|
} |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.