google-spreadsheet-translation-sync 1.4.2 → 1.5.1

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 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('build', 'Production Build', function() {
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.4.2",
3
+ "version": "1.5.1",
4
4
  "description": "A plugin to read and write i18n translationsfrom and to google spreadsheets ",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -43,15 +43,16 @@
43
43
  "shell": "^0.5.0"
44
44
  },
45
45
  "dependencies": {
46
- "@inquirer/prompts": "^3.0.3",
46
+ "@inquirer/prompts": "^8.0.1",
47
47
  "async": "^2.6.3",
48
48
  "fast-csv": "^4.3",
49
49
  "gettext-parser": "^4.0.2",
50
- "google-spreadsheet": "^3.0.11",
51
- "js-yaml": "^4.1.0",
50
+ "google-auth-library": "^9.15.1",
51
+ "google-spreadsheet": "^4.1.4",
52
+ "js-yaml": "^4.1.1",
52
53
  "mkdirp": "^0.5.5",
53
54
  "properties-reader": "^2.2.0",
54
55
  "shelljs": "^0.8.5",
55
- "tmp": "^0.1.0"
56
+ "tmp": "^0.2.5"
56
57
  }
57
58
  }
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
- doc.useServiceAccountAuth(credentials).then(
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
- if (!sheet) {
28
- throw new Error('The sheet with the gid ' + sheetId + ' does not exist.');
29
- }
30
+ await doc.loadInfo(true).catch((err) => {
31
+ error = true;
32
+ callback(err);
33
+ });
30
34
 
31
- // console.log('Loaded doc: ' + doc.title + ' with ' + sheet.rowCount + ' rows');
35
+ if (!error) {
36
+ worksheetId = worksheetId ? worksheetId : '0';
37
+ const sheet = doc.sheetsById[worksheetId];
32
38
 
33
- callback(null, sheet);
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
- return true
43
+ console.log('Loaded doc: ' + doc.title + ' with ' + sheet.rowCount + ' rows');
44
+
45
+ callback(null, sheet);
46
+ }
44
47
  };
@@ -3,9 +3,6 @@
3
3
  * @param {{translationFormat: string, mode: string, spreadsheetId: string, gid : string, credentials: {}, keyId: string, fileBaseName: string, namespaces: boolean, defaultLocaleName: string}} options
4
4
  * @param {function} callback
5
5
  */
6
- const fs = require("fs");
7
- const async = require("async");
8
- const path = require("path");
9
6
 
10
7
  module.exports = async function () {
11
8
  const async= require('async')
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][options.keyId]).to.equal(csvData[1][0]);
201
- expect(rows[0]['pl # with comment']).to.equal(csvData[1][5]);
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].key).to.equal(csvData[2][0]);
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][options.keyId]).to.equal(csvData[1][0]);
280
- expect(rows[0]['pl # with comment']).to.equal(csvData[1][5]);
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].key).to.equal(csvData[2][0]);
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][options.keyId]).to.equal(csvData[1][0]);
581
- expect(rows[0]['pl # with comment']).to.equal(csvData[1][5]);
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].key).to.equal(csvData[2][0]);
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][options.keyId]).to.equal(csvData[1][0]);
694
- expect(rows[0]['pl # with comment']).to.equal(csvData[1][5]);
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].key).to.equal(csvData[2][0]);
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
  })