-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCrowdin.js
100 lines (84 loc) · 2.99 KB
/
Crowdin.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const path = require('path')
const uploadSource = require('./src/actions/uploadSource')
const uploadTranslations = require('./src/actions/uploadTranslations')
const downloadTranslations = require('./src/actions/downloadTranslations')
const pushDiff = require('./src/actions/pushDiff')
const pullDiff = require('./src/actions/pullDiff')
const getPojectInfo = require('./src/services/getPojectInfo')
const deleteBranch = require('./src/actions/deleteBranch')
const createTask = require('./src/actions/createTask')
const lint = require('./src/actions/lint')
const validateConfig = require('./src/utils/validateConfig')
const abort = require('./src/utils/abort')
const Branch = require('./src/branch')
const config = require('./src/config')
const params = require('./src/params')
class Crowdin {
constructor (branch, projectData) {
this._branch = branch
this._projectData = projectData
}
static async init () {
validateConfig()
const branch = await Branch.init()
const projectData = await getPojectInfo()
return new Crowdin(branch, projectData)
}
checkIsPossibleToUpdateBranch () {
const providedBranch = params.b || params.branch
if (!config.useGitBranchAsDefault || providedBranch) return
if (this._branch.gitName === 'master') {
abort('Cannot run this command from master branch. Provide branch name "-b master" or use another git branch.')
}
}
pushDiff () {
this.checkIsPossibleToUpdateBranch()
return pushDiff(this._branch, this._projectData)
}
pullDiff () {
this.checkIsPossibleToUpdateBranch()
return pullDiff(this._branch, this._projectData)
}
async uploadAll () {
this.checkIsPossibleToUpdateBranch()
await uploadSource(this._branch, this._projectData)
return uploadTranslations(this._branch, this._projectData)
}
async downloadAll () {
this.checkIsPossibleToUpdateBranch()
return downloadTranslations(this._branch, this._projectData)
}
task () {
this.checkIsPossibleToUpdateBranch()
return createTask(this._branch, this._projectData)
}
deleteBranch () {
this.checkIsPossibleToUpdateBranch()
return deleteBranch(this._branch)
}
lint () {
return lint(this._branch, this._projectData)
}
uploadSource () {
this.checkIsPossibleToUpdateBranch()
return uploadSource(this._branch, this._projectData)
}
uploadTranslations () {
this.checkIsPossibleToUpdateBranch()
return uploadTranslations(this._branch, this._projectData)
}
// Dot't use comands/getters below.
// Just added for comability with old versions
async sync () {
this.checkIsPossibleToUpdateBranch()
await uploadSource(this._branch, this._projectData)
await uploadTranslations(this._branch, this._projectData)
return downloadTranslations(this._branch, this._projectData)
}
get branch () { return this._branch }
get files () {
const { filesToTranslate } = this._projectData
return filesToTranslate.map(({ filePath }) => path.join(config.baseDir, filePath))
}
}
module.exports = Crowdin