google-spreadsheet-translation-sync 1.4.2 → 1.5.0
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/Gruntfile.js +1 -1
- package/package.json +3 -2
- package/src/connector.js +24 -21
- package/test/test.js +34 -30
package/Gruntfile.js
CHANGED
|
@@ -97,7 +97,7 @@ module.exports = function(grunt) {
|
|
|
97
97
|
grunt.loadNpmTasks('grunt-bump');
|
|
98
98
|
grunt.loadNpmTasks('grunt-shell');
|
|
99
99
|
|
|
100
|
-
grunt.registerTask('
|
|
100
|
+
grunt.registerTask('release', 'Production Build', function() {
|
|
101
101
|
grunt.task.run('prompt', 'bump', 'shell:publish_npm', 'shell:merge');
|
|
102
102
|
});
|
|
103
103
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "google-spreadsheet-translation-sync",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A plugin to read and write i18n translationsfrom and to google spreadsheets ",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"async": "^2.6.3",
|
|
48
48
|
"fast-csv": "^4.3",
|
|
49
49
|
"gettext-parser": "^4.0.2",
|
|
50
|
-
"google-
|
|
50
|
+
"google-auth-library": "^9.15.1",
|
|
51
|
+
"google-spreadsheet": "^4.1.4",
|
|
51
52
|
"js-yaml": "^4.1.0",
|
|
52
53
|
"mkdirp": "^0.5.5",
|
|
53
54
|
"properties-reader": "^2.2.0",
|
package/src/connector.js
CHANGED
|
@@ -1,44 +1,47 @@
|
|
|
1
1
|
const { GoogleSpreadsheet } = require('google-spreadsheet');
|
|
2
|
+
const { JWT } = require('google-auth-library');
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* connects to a google spreadsheet and returns the first sheet
|
|
5
6
|
*
|
|
6
7
|
* @param {string} sheetId
|
|
7
|
-
* @param {string|null} worksheetId
|
|
8
|
+
* @param {string|null} [worksheetId='0']
|
|
8
9
|
* @param credentials
|
|
9
10
|
* @param callback
|
|
10
11
|
* @returns {boolean}
|
|
11
12
|
*/
|
|
12
|
-
module.exports = function (sheetId, worksheetId, credentials, callback) {
|
|
13
|
+
module.exports = async function (sheetId, worksheetId, credentials, callback) {
|
|
13
14
|
|
|
14
15
|
if (typeof callback !== "function") {
|
|
15
16
|
throw new Error('Please provide a callback');
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
const serviceAccountAuth = new JWT({
|
|
20
|
+
email: credentials.client_email,
|
|
21
|
+
key: credentials.private_key,
|
|
22
|
+
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
|
|
23
|
+
});
|
|
24
|
+
|
|
18
25
|
// docu: https://www.npmjs.com/package/google-spreadsheet
|
|
19
|
-
const doc = new GoogleSpreadsheet(sheetId);
|
|
26
|
+
const doc = new GoogleSpreadsheet(sheetId, serviceAccountAuth);
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
function () {
|
|
23
|
-
doc.loadInfo(true).then(function () {
|
|
24
|
-
const sheetId = worksheetId ? worksheetId : '0';
|
|
25
|
-
const sheet = doc.sheetsById[sheetId];
|
|
28
|
+
let error = false;
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
await doc.loadInfo(true).catch((err) => {
|
|
31
|
+
error = true;
|
|
32
|
+
callback(err);
|
|
33
|
+
});
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
if (!error) {
|
|
36
|
+
worksheetId = worksheetId ? worksheetId : '0';
|
|
37
|
+
const sheet = doc.sheetsById[worksheetId];
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
function (err) {
|
|
36
|
-
callback(err);
|
|
37
|
-
});
|
|
39
|
+
if (!sheet) {
|
|
40
|
+
callback('The sheet with the gid ' + worksheetId + ' does not exist.');
|
|
38
41
|
}
|
|
39
|
-
).catch(function (err) {
|
|
40
|
-
callback(err);
|
|
41
|
-
});
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
console.log('Loaded doc: ' + doc.title + ' with ' + sheet.rowCount + ' rows');
|
|
44
|
+
|
|
45
|
+
callback(null, sheet);
|
|
46
|
+
}
|
|
44
47
|
};
|
package/test/test.js
CHANGED
|
@@ -197,18 +197,22 @@ const tests = [
|
|
|
197
197
|
limit: (csvData.length - 1) * namespaces.length + 1
|
|
198
198
|
}).then(function (rows) {
|
|
199
199
|
expect(rows).to.have.lengthOf((csvData.length - 1) * 2);
|
|
200
|
-
expect(rows[0]
|
|
201
|
-
expect(rows[0]
|
|
202
|
-
expect(rows[0].default).to.equal(csvData[1][1]);
|
|
203
|
-
expect(rows[0].hu).to.equal('Elfogadom');
|
|
204
|
-
expect(rows[0].namespace).to.equal(namespaces[0]);
|
|
205
|
-
expect(rows[1].default).to.equal(csvData[2][1]);
|
|
206
|
-
expect(rows[1].de).to.equal(csvData[2][2]);
|
|
207
|
-
expect(rows[1].
|
|
200
|
+
expect(rows[0].get(options.keyId)).to.equal(csvData[1][0]);
|
|
201
|
+
expect(rows[0].get('pl # with comment')).to.equal(csvData[1][5]);
|
|
202
|
+
expect(rows[0].get('default')).to.equal(csvData[1][1]);
|
|
203
|
+
expect(rows[0].get('hu')).to.equal('Elfogadom');
|
|
204
|
+
expect(rows[0].get('namespace')).to.equal(namespaces[0]);
|
|
205
|
+
expect(rows[1].get('default')).to.equal(csvData[2][1]);
|
|
206
|
+
expect(rows[1].get('de')).to.equal(csvData[2][2]);
|
|
207
|
+
expect(rows[1].get(options.keyId)).to.equal(csvData[2][0]);
|
|
208
208
|
// this should be already the next namespace
|
|
209
|
-
expect(rows[entryLength].namespace).to.equal(namespaces[1]);
|
|
209
|
+
expect(rows[entryLength].get('namespace')).to.equal(namespaces[1]);
|
|
210
210
|
rimraf.sync(tempFolder.name);
|
|
211
211
|
done()
|
|
212
|
+
}).catch(err => {
|
|
213
|
+
console.log(err);
|
|
214
|
+
expect(err).to.be.null;
|
|
215
|
+
done()
|
|
212
216
|
})
|
|
213
217
|
})
|
|
214
218
|
} else {
|
|
@@ -276,13 +280,13 @@ const tests = [
|
|
|
276
280
|
limit: csvData.length - 1
|
|
277
281
|
}).then(function (rows) {
|
|
278
282
|
expect(rows).to.have.lengthOf(csvData.length - 1);
|
|
279
|
-
expect(rows[0]
|
|
280
|
-
expect(rows[0]
|
|
281
|
-
expect(rows[0].default).to.equal(csvData[1][1]);
|
|
282
|
-
expect(rows[0].hu).to.equal('Elfogadom'); // this was not part of the upload and should not be overwrittem
|
|
283
|
-
expect(rows[1].default).to.equal(csvData[2][1]);
|
|
284
|
-
expect(rows[1].de).to.equal(csvData[2][2]);
|
|
285
|
-
expect(rows[1].
|
|
283
|
+
expect(rows[0].get(options.keyId)).to.equal(csvData[1][0]);
|
|
284
|
+
expect(rows[0].get('pl # with comment')).to.equal(csvData[1][5]);
|
|
285
|
+
expect(rows[0].get('default')).to.equal(csvData[1][1]);
|
|
286
|
+
expect(rows[0].get('hu')).to.equal('Elfogadom'); // this was not part of the upload and should not be overwrittem
|
|
287
|
+
expect(rows[1].get('default')).to.equal(csvData[2][1]);
|
|
288
|
+
expect(rows[1].get('de')).to.equal(csvData[2][2]);
|
|
289
|
+
expect(rows[1].get(options.keyId)).to.equal(csvData[2][0]);
|
|
286
290
|
rimraf.sync(tempFolder.name);
|
|
287
291
|
done()
|
|
288
292
|
})
|
|
@@ -577,13 +581,13 @@ const tests = [
|
|
|
577
581
|
limit: csvData.length - 1
|
|
578
582
|
}).then(function (rows) {
|
|
579
583
|
expect(rows).to.have.lengthOf(csvData.length - 1);
|
|
580
|
-
expect(rows[0]
|
|
581
|
-
expect(rows[0]
|
|
582
|
-
expect(rows[0].default).to.equal(csvData[1][1]);
|
|
583
|
-
expect(rows[0].hu).to.equal('Elfogadom'); // this was not part of the upload and should not be overwrittem
|
|
584
|
-
expect(rows[1].default).to.equal(csvData[2][1]);
|
|
585
|
-
expect(rows[1].de).to.equal(csvData[2][2]);
|
|
586
|
-
expect(rows[1].
|
|
584
|
+
expect(rows[0].get(options.keyId)).to.equal(csvData[1][0]);
|
|
585
|
+
expect(rows[0].get('pl # with comment')).to.equal(csvData[1][5]);
|
|
586
|
+
expect(rows[0].get('default')).to.equal(csvData[1][1]);
|
|
587
|
+
expect(rows[0].get('hu')).to.equal('Elfogadom'); // this was not part of the upload and should not be overwrittem
|
|
588
|
+
expect(rows[1].get('default')).to.equal(csvData[2][1]);
|
|
589
|
+
expect(rows[1].get('de')).to.equal(csvData[2][2]);
|
|
590
|
+
expect(rows[1].get(options.keyId)).to.equal(csvData[2][0]);
|
|
587
591
|
rimraf.sync(tempFolder.name);
|
|
588
592
|
done()
|
|
589
593
|
})
|
|
@@ -690,13 +694,13 @@ const tests = [
|
|
|
690
694
|
limit: csvData.length - 1
|
|
691
695
|
}).then(function (rows) {
|
|
692
696
|
expect(rows).to.have.lengthOf(csvData.length - 1);
|
|
693
|
-
expect(rows[0]
|
|
694
|
-
expect(rows[0]
|
|
695
|
-
expect(rows[0].default).to.equal(csvData[1][1]);
|
|
696
|
-
expect(rows[0].hu).to.equal('Elfogadom'); // this was not part of the upload and should not be overwrittem
|
|
697
|
-
expect(rows[1].default).to.equal(csvData[2][1]);
|
|
698
|
-
expect(rows[1].de).to.equal(csvData[2][2]);
|
|
699
|
-
expect(rows[1].
|
|
697
|
+
expect(rows[0].get(options.keyId)).to.equal(csvData[1][0]);
|
|
698
|
+
expect(rows[0].get('pl # with comment')).to.equal(csvData[1][5]);
|
|
699
|
+
expect(rows[0].get('default')).to.equal(csvData[1][1]);
|
|
700
|
+
expect(rows[0].get('hu')).to.equal('Elfogadom'); // this was not part of the upload and should not be overwrittem
|
|
701
|
+
expect(rows[1].get('default')).to.equal(csvData[2][1]);
|
|
702
|
+
expect(rows[1].get('de')).to.equal(csvData[2][2]);
|
|
703
|
+
expect(rows[1].get(options.keyId)).to.equal(csvData[2][0]);
|
|
700
704
|
rimraf.sync(tempFolder.name);
|
|
701
705
|
done()
|
|
702
706
|
})
|