@leverege/build-tools 2.21.7 → 2.21.8

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.
@@ -2,22 +2,17 @@
2
2
  "use strict";
3
3
 
4
4
  const chalk = require('chalk');
5
-
6
5
  const cliArgs = require('command-line-args');
7
-
8
6
  const cliHelp = require('command-line-usage');
9
-
10
7
  const fs = require('fs');
11
-
12
8
  const npmRegistryFetch = require('npm-registry-fetch');
13
-
14
9
  const path = require('path');
15
-
16
10
  const semverLt = require('semver/functions/lt');
17
- /* eslint-disable no-console */
18
11
 
12
+ /* eslint-disable no-console */
19
13
 
20
- const optionList = [// Use optionList to tie into the Usage statements
14
+ const optionList = [
15
+ // Use optionList to tie into the Usage statements
21
16
  {
22
17
  name: 'root',
23
18
  type: Boolean,
@@ -63,46 +58,36 @@ const args = cliArgs(optionList, {
63
58
  });
64
59
  const help = cliHelp(sections);
65
60
  const repoRoot = path.dirname(__dirname);
66
-
67
61
  const thisPackage = require(`${repoRoot}/package.json`);
68
-
69
62
  const thisVersion = thisPackage.version;
70
-
71
63
  if (args.root) {
72
64
  console.log(repoRoot);
73
65
  process.exit(0);
74
66
  }
75
-
76
67
  if (args.bashfun) {
77
68
  console.log(`${repoRoot}/src/bash-funcs`);
78
69
  process.exit(0);
79
70
  }
80
-
81
71
  const checkForLatest = async (pkg = '@leverege/build-tools') => {
82
72
  const getToken = () => {
83
73
  const tokenFile = `${process.env.HOME}/.npmrc`;
84
-
85
74
  if (!fs.existsSync(tokenFile)) {
86
75
  console.error(`Cannot find token file ${tokenFile}`);
87
76
  process.exit(1);
88
77
  }
89
-
90
78
  try {
91
79
  const tokenLine = fs.readFileSync(tokenFile).toString();
92
80
  const tokenRegX = new RegExp('.*registry.npmjs.org\\/:\\w+=+(.*)');
93
81
  const tokenStr = tokenLine.match(tokenRegX);
94
-
95
82
  if (!tokenStr) {
96
83
  console.error(`\n***ERROR: malformed npm token in ${tokenFile}\n`);
97
84
  process.exit(1);
98
85
  }
99
-
100
86
  return tokenLine.match(tokenRegX)[1];
101
87
  } catch (err) {
102
88
  console.error(err);
103
89
  }
104
90
  };
105
-
106
91
  try {
107
92
  const list = await npmRegistryFetch.json(pkg, {
108
93
  '//registry.npmjs.org/:_authToken': getToken()
@@ -112,7 +97,6 @@ const checkForLatest = async (pkg = '@leverege/build-tools') => {
112
97
  console.log(err);
113
98
  }
114
99
  };
115
-
116
100
  const checkAndAnnounce = () => {
117
101
  checkForLatest().then(latestVersion => {
118
102
  if (semverLt(thisVersion, latestVersion)) {
@@ -126,23 +110,19 @@ const checkAndAnnounce = () => {
126
110
  }
127
111
  }).catch(err => {});
128
112
  };
129
-
130
113
  if (args.latest) {
131
114
  checkAndAnnounce();
132
115
  }
133
-
134
116
  if (args.version) {
135
117
  console.log(`build-tools version ${thisVersion}`);
136
118
  checkAndAnnounce();
137
119
  }
138
-
139
120
  if (args.help) {
140
121
  console.log(help);
141
122
  process.exit(0);
142
123
  }
143
- /* eslint-disable no-underscore-dangle */
144
-
145
124
 
125
+ /* eslint-disable no-underscore-dangle */
146
126
  if (args._unknown) {
147
127
  console.log(`\nUnrecognized argument [${args._unknown}] try --help\n`);
148
128
  process.exit(1);
@@ -1,19 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  // https://github.com/google/zx
3
-
4
3
  /* eslint-disable max-len */
5
4
  "use strict";
6
5
 
7
6
  var _enquirer = _interopRequireDefault(require("enquirer"));
8
-
9
7
  var _zx = require("zx");
10
-
11
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
-
13
9
  const {
14
10
  prompt
15
- } = _enquirer.default; // This will preserve coloration from spawned child processes
11
+ } = _enquirer.default;
16
12
 
13
+ // This will preserve coloration from spawned child processes
17
14
  process.env.FORCE_COLORS = 3;
18
15
  process.env.FORCE_COLOR = '1';
19
16
  let TARGET = _zx.argv._[0];
@@ -21,19 +18,15 @@ let exited = false;
21
18
  const SECRETS_DIR = 'secrets';
22
19
  const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughException', 'unhandledRejection'];
23
20
  const [firebaserc, firebaseJson] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), '.firebaserc')), _zx.fs.exists(_zx.path.join(process.cwd(), 'firebase.json'))]);
24
-
25
21
  if (!firebaserc) {
26
22
  console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
27
23
  }
28
-
29
24
  if (!firebaseJson) {
30
25
  console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
31
26
  }
32
-
33
27
  if (!firebaserc || !firebaseJson) {
34
28
  process.exit();
35
29
  }
36
-
37
30
  const firebasercContent = JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
38
31
  encoding: 'utf-8'
39
32
  }));
@@ -49,7 +42,6 @@ const targets = Object.entries(firebasercContent.targets).reduce((prev, [project
49
42
  });
50
43
  return prev;
51
44
  }, {});
52
-
53
45
  if (!TARGET) {
54
46
  const {
55
47
  targetEnv
@@ -66,27 +58,21 @@ if (!TARGET) {
66
58
  } else {
67
59
  TARGET = targets[TARGET];
68
60
  }
69
-
70
61
  if (!TARGET) {
71
62
  console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
72
63
  process.exit();
73
64
  }
74
-
75
65
  const [aliasFileExists, siteIdFileExists, sharedFileExists] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'))]);
76
-
77
66
  if (!aliasFileExists && !siteIdFileExists) {
78
67
  console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
79
68
  process.exit();
80
69
  }
81
-
82
70
  const exec = [];
83
-
84
71
  if (sharedFileExists) {
85
72
  exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
86
73
  encoding: 'utf-8'
87
74
  }));
88
75
  }
89
-
90
76
  if (aliasFileExists) {
91
77
  exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
92
78
  encoding: 'utf-8'
@@ -96,19 +82,16 @@ if (aliasFileExists) {
96
82
  encoding: 'utf-8'
97
83
  }));
98
84
  }
99
-
100
85
  const envFileContent = (await Promise.all(exec)).join('\n');
101
86
  EXIT_EVENTS.forEach(event => {
102
87
  process.on(event, () => {
103
88
  if (!exited) {
104
89
  exited = true;
105
-
106
90
  _zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
107
91
  }
108
92
  });
109
93
  });
110
94
  await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
111
-
112
95
  try {
113
96
  await (0, _zx.$)`npm run clean && DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} npm run build && firebase use ${TARGET.projectId} && firebase deploy --only hosting:${TARGET.siteId}`;
114
97
  } catch (err) {
@@ -1,19 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  // https://github.com/google/zx
3
-
4
3
  /* eslint-disable max-len */
5
4
  "use strict";
6
5
 
7
6
  var _enquirer = _interopRequireDefault(require("enquirer"));
8
-
9
7
  var _zx = require("zx");
10
-
11
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
-
13
9
  const {
14
10
  prompt
15
- } = _enquirer.default; // This will preserve coloration from spawned child processes
11
+ } = _enquirer.default;
16
12
 
13
+ // This will preserve coloration from spawned child processes
17
14
  process.env.FORCE_COLORS = 3;
18
15
  process.env.FORCE_COLOR = '1';
19
16
  let TARGET = _zx.argv._[0];
@@ -21,35 +18,29 @@ let exited = false;
21
18
  const SECRETS_DIR = 'secrets';
22
19
  const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughtException', 'unhandledRejection'];
23
20
  const [firebaserc, firebaseJson, hasLocalConfig] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), '.firebaserc')), _zx.fs.exists(_zx.path.join(process.cwd(), 'firebase.json')), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, 'local.env'))]);
24
-
25
21
  if (!hasLocalConfig) {
26
22
  if (!firebaserc) {
27
23
  console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
28
24
  }
29
-
30
25
  if (!firebaseJson) {
31
26
  console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
32
27
  }
33
-
34
28
  if (!firebaserc || !firebaseJson) {
35
29
  process.exit();
36
30
  }
37
31
  }
38
-
39
32
  const firebasercContent = firebaserc ? JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
40
33
  encoding: 'utf-8'
41
34
  })) : {
42
35
  targets: {}
43
36
  };
44
37
  const defaultTargets = {};
45
-
46
38
  if (hasLocalConfig) {
47
39
  defaultTargets.local = {
48
40
  siteId: 'local',
49
41
  alias: 'local'
50
42
  };
51
43
  }
52
-
53
44
  const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
54
45
  Object.entries(config.hosting).forEach(([siteId, aliases]) => {
55
46
  aliases.forEach(alias => {
@@ -62,14 +53,12 @@ const targets = Object.entries(firebasercContent.targets).reduce((prev, [project
62
53
  });
63
54
  return prev;
64
55
  }, defaultTargets);
65
-
66
56
  if (!TARGET) {
67
57
  const choices = Object.keys(targets).map(t => ({
68
58
  name: t,
69
59
  value: t
70
60
  }));
71
61
  let targetEnv;
72
-
73
62
  if (choices.length > 1) {
74
63
  const res = await prompt({
75
64
  type: 'autocomplete',
@@ -81,32 +70,25 @@ if (!TARGET) {
81
70
  } else {
82
71
  targetEnv = choices[0].value;
83
72
  }
84
-
85
73
  TARGET = targets[targetEnv];
86
74
  } else {
87
75
  TARGET = targets[TARGET];
88
76
  }
89
-
90
77
  if (!TARGET) {
91
78
  console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
92
79
  process.exit();
93
80
  }
94
-
95
81
  const [aliasFileExists, siteIdFileExists, sharedFileExists] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'))]);
96
-
97
82
  if (!aliasFileExists && !siteIdFileExists) {
98
83
  console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
99
84
  process.exit();
100
85
  }
101
-
102
86
  const exec = [];
103
-
104
87
  if (sharedFileExists) {
105
88
  exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
106
89
  encoding: 'utf-8'
107
90
  }));
108
91
  }
109
-
110
92
  if (aliasFileExists) {
111
93
  exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
112
94
  encoding: 'utf-8'
@@ -116,19 +98,16 @@ if (aliasFileExists) {
116
98
  encoding: 'utf-8'
117
99
  }));
118
100
  }
119
-
120
101
  const envFileContent = (await Promise.all(exec)).join('\n');
121
102
  EXIT_EVENTS.forEach(event => {
122
103
  process.on(event, () => {
123
104
  if (!exited) {
124
105
  exited = true;
125
-
126
106
  _zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
127
107
  }
128
108
  });
129
109
  });
130
110
  await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
131
-
132
111
  try {
133
112
  await (0, _zx.$)`DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} npm run serve --colors`;
134
113
  } catch (err) {
@@ -6,8 +6,8 @@
6
6
  "use strict";
7
7
 
8
8
  const stdbuf = [];
9
- /* eslint-disable no-console */
10
9
 
10
+ /* eslint-disable no-console */
11
11
  process.stdin.on('data', d => {
12
12
  stdbuf.push(d);
13
13
  }).on('end', () => {
@@ -15,11 +15,9 @@ process.stdin.on('data', d => {
15
15
  const keyVals = rawCfg.match(/\{(.*)\}/)[1].split(',');
16
16
  const lastLine = keyVals.length - 1;
17
17
  console.log('{');
18
-
19
18
  for (let i = 0; i <= lastLine; i++) {
20
19
  const kv = keyVals[i].trim().split(' ');
21
20
  console.log(` "${kv[0].replace(/:/, '')}": "${kv[1]}"${i < lastLine ? ',' : ''}`);
22
21
  }
23
-
24
22
  console.log('}');
25
23
  }).setEncoding('utf8');
@@ -21,14 +21,12 @@
21
21
  "use strict";
22
22
 
23
23
  const fs = require('fs');
24
-
25
24
  const cliArgs = require('command-line-args');
26
-
27
25
  const cliHelp = require('command-line-usage');
28
- /* eslint-disable no-console */
29
-
30
26
 
31
- const optionList = [// Use optionList to tie into the Usage statements
27
+ /* eslint-disable no-console */
28
+ const optionList = [
29
+ // Use optionList to tie into the Usage statements
32
30
  {
33
31
  name: 'file',
34
32
  type: String,
@@ -57,13 +55,11 @@ const args = cliArgs(optionList, {
57
55
  partial: true
58
56
  });
59
57
  const help = cliHelp(sections);
60
-
61
58
  if (!args.file) {
62
59
  console.error('\n***ERROR: Missing a --file param\n');
63
60
  console.log(help);
64
61
  process.exit(1);
65
62
  }
66
-
67
63
  try {
68
64
  const json = JSON.parse(fs.readFileSync(args.file, 'utf8'));
69
65
  const value = json[args.key];
@@ -2,9 +2,7 @@
2
2
  "use strict";
3
3
 
4
4
  const execa = require('execa');
5
-
6
5
  const fs = require('fs');
7
-
8
6
  const untarConfigTarball = async (subdir, tarball) => {
9
7
  if (fs.existsSync(subdir)) {
10
8
  process.chdir(subdir);
@@ -12,9 +10,7 @@ const untarConfigTarball = async (subdir, tarball) => {
12
10
  await execa('tar', ['xf', tarball]);
13
11
  }
14
12
  };
15
-
16
13
  const awaiter = async (subdir, tarball) => {
17
14
  await untarConfigTarball(subdir, tarball);
18
15
  };
19
-
20
16
  awaiter('lib/server/repo-init', 'config.tgz');