@enplug/scripts 1.11.6 → 1.11.7-dev1

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.
@@ -1,10 +1,45 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const chalk = require('chalk');
4
+ const rootPath = process.cwd();
1
5
  const AWS = require('aws-sdk');
2
6
 
7
+ function getAwsPrivateFile() {
8
+ const fileName = 'aws.private.json';
9
+ let prefix = '';
10
+ let file = null;
11
+ let maxDepth = 2;
12
+ do {
13
+ file = path.resolve(rootPath, prefix + fileName);
14
+ prefix += '../';
15
+ } while (!fs.existsSync(file) && maxDepth--);
16
+
17
+ return file;
18
+ }
19
+
3
20
  function createS3Client(pkg) {
21
+ let creds;
4
22
  const s3Options = Object.assign({}, pkg.config.aws.s3);
23
+ const credsFile = getAwsPrivateFile();
24
+
25
+ try {
26
+ creds = JSON.parse(fs.readFileSync(credsFile, 'utf8'));
27
+ } catch (e) {
28
+ console.error(`Error finding/parsing ${chalk.default.cyan(credsFile)}`);
29
+ return;
30
+ }
31
+
32
+ if (creds.accessKeyId == null || creds.secretAccessKey == null) {
33
+ console.error(`Error could not fine accessKeyId or secretAccessKey in ${chalk.default.cyan(credsFile)} file.`);
34
+ return;
35
+ }
5
36
 
6
- const credentials = new AWS.SharedIniFileCredentials({ profile: pkg.config.aws.profile });
7
- AWS.config.credentials = credentials;
37
+ // Setting up the credentials globally
38
+ AWS.config.update({
39
+ accessKeyId: creds.accessKeyId,
40
+ secretAccessKey: creds.secretAccessKey,
41
+ maxRetries: 3,
42
+ });
8
43
 
9
44
  return new AWS.S3(s3Options);
10
45
  }
@@ -35,6 +35,7 @@ async function validateTranslations() {
35
35
  async function syncTranslations(s3Client, bucket) {
36
36
  let credentials, config;
37
37
  const isProduction = determineEnv(bucket) === 'production';
38
+ const isStaging = determineEnv(bucket) === 'staging'
38
39
 
39
40
  if (!s3Client) { s3Client = createS3Client(getPackageJson()); }
40
41
 
@@ -50,7 +51,7 @@ async function syncTranslations(s3Client, bucket) {
50
51
  }
51
52
 
52
53
  if (credentials && config) {
53
- const { confirmUpload } = await promptUpload(config.crowdinPath, isProduction);
54
+ const { confirmUpload } = await promptUpload(config.crowdinPath, isProduction || isStaging);
54
55
 
55
56
  if (confirmUpload) {
56
57
  const s3EnPath = path.join('/i18n/', config.crowdinPath);
@@ -60,7 +61,7 @@ async function syncTranslations(s3Client, bucket) {
60
61
 
61
62
  await uploadTranslationToS3(s3Client, bucket, s3EnPath, enTranslation);
62
63
 
63
- if (isProduction) {
64
+ if (isProduction || isStaging) {
64
65
  const crowdinPath = config.crowdinPath.startsWith('/') ? config.crowdinPath.substr(1) : config.crowdinPath;
65
66
  const crowdinPathSections = crowdinPath.split('/');
66
67
  const appName = crowdinPathSections[1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enplug/scripts",
3
- "version": "1.11.6",
3
+ "version": "1.11.7-dev1",
4
4
  "description": "Enplug scripts",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -27,7 +27,7 @@
27
27
  "check-packages": "bin/check-packages.js"
28
28
  },
29
29
  "dependencies": {
30
- "aws-sdk": "2.1692.0",
30
+ "aws-sdk": "^2.474.0",
31
31
  "axios": "^0.19.2",
32
32
  "chalk": "2.4.1",
33
33
  "command-line-args": "5.0.2",