wp-advads 1.0.4 → 1.0.6
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/package.json
CHANGED
|
@@ -57,9 +57,13 @@
|
|
|
57
57
|
<type>error</type>
|
|
58
58
|
</rule>
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
<!-- Disable short arrays: -->
|
|
61
|
+
<rule ref="WordPress-Extra">
|
|
62
|
+
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
|
|
63
|
+
</rule>
|
|
64
|
+
|
|
65
|
+
<!-- Enforce short arrays: -->
|
|
66
|
+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
|
|
63
67
|
|
|
64
68
|
<!-- Method names MUST NOT be prefixed with a single underscore to indicate protected or private visibility. That is, an underscore prefix explicitly has no meaning. -->
|
|
65
69
|
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
|
|
@@ -1,68 +1,101 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
2
3
|
|
|
3
4
|
// Packages.
|
|
4
|
-
const chalk = require(
|
|
5
|
-
const fs = require(
|
|
6
|
-
const { resolve } = require(
|
|
7
|
-
const async = require(
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const { resolve } = require('path');
|
|
8
|
+
const async = require('async');
|
|
8
9
|
|
|
9
10
|
// Settings.
|
|
10
|
-
const
|
|
11
|
+
const packageDetails = require('../package.json');
|
|
11
12
|
const BASEURL = 'https://translate.wpadvancedads.com/api/projects';
|
|
12
13
|
|
|
13
14
|
// Validation of settings.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
function validateSettings() {
|
|
16
|
+
if (
|
|
17
|
+
undefined === packageDetails.glotpress ||
|
|
18
|
+
Object.keys(packageDetails.glotpress).length < 1
|
|
19
|
+
) {
|
|
20
|
+
console.log(
|
|
21
|
+
chalk.bgRed.bold('Error:') +
|
|
22
|
+
' The GlotPress settings is not defined.'
|
|
23
|
+
);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (
|
|
28
|
+
undefined === packageDetails.glotpress.project ||
|
|
29
|
+
('' === undefined) === packageDetails.glotpress.project
|
|
30
|
+
) {
|
|
31
|
+
console.log(
|
|
32
|
+
chalk.bgRed.bold('Error:') +
|
|
33
|
+
' The GlotPress project name is not defined.'
|
|
34
|
+
);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (
|
|
39
|
+
undefined === packageDetails.glotpress.destination ||
|
|
40
|
+
('' === undefined) === packageDetails.glotpress.destination
|
|
41
|
+
) {
|
|
42
|
+
console.log(
|
|
43
|
+
chalk.bgRed.bold('Error:') +
|
|
44
|
+
' The destination directory is not defined.'
|
|
45
|
+
);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return true;
|
|
17
50
|
}
|
|
18
51
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if ( undefined === package.glotpress.destination || '' === undefined === package.glotpress.destination ) {
|
|
25
|
-
console.log( chalk.bgRed.bold("Error:") + " The destination directory is not defined." );
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const { glotpress } = package
|
|
30
|
-
const { project } = glotpress
|
|
31
|
-
let { potPrefix, destination } = glotpress
|
|
32
|
-
potPrefix = potPrefix ?? project
|
|
33
|
-
destination =resolve(destination)
|
|
52
|
+
const { glotpress } = packageDetails;
|
|
53
|
+
const { project } = glotpress;
|
|
54
|
+
let { potPrefix, destination } = glotpress;
|
|
55
|
+
potPrefix = potPrefix ?? project;
|
|
56
|
+
destination = resolve(destination);
|
|
34
57
|
|
|
35
58
|
if (!fs.existsSync(destination)) {
|
|
36
59
|
fs.mkdirSync(destination);
|
|
37
60
|
}
|
|
38
61
|
|
|
39
62
|
async function getGlotPressData() {
|
|
40
|
-
const response = await fetch(
|
|
63
|
+
const response = await fetch(
|
|
64
|
+
`${BASEURL}/${packageDetails.glotpress.project}`
|
|
65
|
+
);
|
|
41
66
|
const data = await response.json();
|
|
42
|
-
const sets = {}
|
|
67
|
+
const sets = {};
|
|
68
|
+
|
|
69
|
+
if (undefined !== data.success && !data.success) {
|
|
70
|
+
console.log(chalk.bgRed.bold('Error:') + ' ' + data.error);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
43
74
|
data.translation_sets.map((set) => {
|
|
44
|
-
if (
|
|
75
|
+
if (set.current_count > 0) {
|
|
45
76
|
let id = set.wp_locale;
|
|
46
|
-
if (
|
|
77
|
+
if ('default' !== set.slug) {
|
|
47
78
|
id += '_' + set.slug;
|
|
48
79
|
}
|
|
49
80
|
|
|
50
|
-
sets[
|
|
81
|
+
sets[id] = set;
|
|
51
82
|
}
|
|
52
|
-
})
|
|
53
83
|
|
|
54
|
-
|
|
84
|
+
return false;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return sets;
|
|
55
88
|
}
|
|
56
89
|
|
|
57
90
|
// Download Handler.
|
|
58
91
|
async function downloadFile(locale, data, format) {
|
|
59
|
-
console.log(
|
|
92
|
+
console.log(chalk.bold('Downloading: ' + format));
|
|
60
93
|
|
|
61
|
-
const target = `${destination}/${potPrefix}-${locale}.${format}
|
|
62
|
-
const endpoint = `${BASEURL}/${project}/${data.locale}/${data.slug}/export-translations?format=${format}
|
|
94
|
+
const target = `${destination}/${potPrefix}-${locale}.${format}`;
|
|
95
|
+
const endpoint = `${BASEURL}/${project}/${data.locale}/${data.slug}/export-translations?format=${format}`;
|
|
63
96
|
|
|
64
97
|
// Download.
|
|
65
|
-
const response = await fetch(endpoint)
|
|
98
|
+
const response = await fetch(endpoint);
|
|
66
99
|
const content = await response.text();
|
|
67
100
|
|
|
68
101
|
fs.writeFileSync(target, content);
|
|
@@ -71,25 +104,37 @@ async function downloadFile(locale, data, format) {
|
|
|
71
104
|
async function runCommand() {
|
|
72
105
|
const locales = await getGlotPressData();
|
|
73
106
|
|
|
107
|
+
if (false === locales) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
74
111
|
// Download files.
|
|
75
112
|
async.map(
|
|
76
113
|
Object.keys(locales),
|
|
77
114
|
(locale, callback) => {
|
|
78
|
-
const localeData = locales[locale]
|
|
79
|
-
|
|
80
|
-
console.log(
|
|
81
|
-
console.log(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
|
|
115
|
+
const localeData = locales[locale];
|
|
116
|
+
|
|
117
|
+
console.log('');
|
|
118
|
+
console.log(
|
|
119
|
+
chalk.bgGreen.bold('Updating Language:') +
|
|
120
|
+
` ${chalk.italic(localeData.name)}`
|
|
121
|
+
);
|
|
122
|
+
async.map(['mo', 'po'], (format) =>
|
|
123
|
+
downloadFile(locale, localeData, format)
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
callback(null, true);
|
|
88
127
|
},
|
|
89
|
-
function(
|
|
90
|
-
console.log(
|
|
91
|
-
console.log(
|
|
128
|
+
function () {
|
|
129
|
+
console.log('');
|
|
130
|
+
console.log(
|
|
131
|
+
chalk.bgGreen.bold('Success:') +
|
|
132
|
+
' All files has been downloaded.'
|
|
133
|
+
);
|
|
92
134
|
}
|
|
93
135
|
);
|
|
94
136
|
}
|
|
95
|
-
|
|
137
|
+
|
|
138
|
+
if (validateSettings()) {
|
|
139
|
+
runCommand();
|
|
140
|
+
}
|