@leverege/build-tools 2.51.4 → 2.51.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.51.4",
3
+ "version": "2.51.6",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -64,7 +64,7 @@
64
64
  "execa": "^9.4.0",
65
65
  "glob": "^11.0.0",
66
66
  "handlebars": "^4.7.8",
67
- "inquirer": "^11.0.1",
67
+ "inquirer": "^11.0.2",
68
68
  "js-yaml": "^4.1.0",
69
69
  "ms": "^2.1.3",
70
70
  "npm-registry-fetch": "^17.1.0",
@@ -73,7 +73,7 @@
73
73
  "read-pkg": "^9.0.1",
74
74
  "readline-sync": "^1.4.10",
75
75
  "semver": "^7.6.3",
76
- "simple-git": "^3.26.0",
76
+ "simple-git": "^3.27.0",
77
77
  "zx": "^8.1.7"
78
78
  },
79
79
  "devDependencies": {
@@ -0,0 +1,20 @@
1
+ registry:
2
+ - root: us-docker.pkg.dev
3
+ - repositories:
4
+ - name: stack
5
+ charts:
6
+ - api-server
7
+ - authz-server
8
+ - emailer
9
+ - message-processor
10
+ - name: leverege
11
+ charts:
12
+ - pubsub-pulse
13
+ - pusher
14
+ - overdose
15
+ - name: cox-health
16
+ charts:
17
+ - actions-server
18
+ - analytics-server
19
+ - centrak-healthz
20
+ - centrak-ingestor
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * chart-to-registry will...
4
+ */
5
+ import fs from 'node:fs'
6
+
7
+ import chalk from 'chalk'
8
+ import commandLineArgs from 'command-line-args'
9
+ import commandLineUsage from 'command-line-usage'
10
+ import { lt as semverLt } from 'semver'
11
+ import YAML from 'js-yaml'
12
+
13
+ import {
14
+ condir,
15
+ debug,
16
+ errorExit,
17
+ log,
18
+ warning,
19
+ getGitRootDirectory,
20
+ parsePackageJson,
21
+ parseHelmChart,
22
+ shellCmd } from './Utils.mjs'
23
+
24
+ const commandLineOptions = [ // Use commandLineOptions to tie into the Usage statements
25
+ /* eslint-disable max-len */
26
+ {
27
+ name : 'location',
28
+ type : String,
29
+ description : '{green the location of the artifact registry the chart will be pushed to (default us-docker.pkg.dev)}',
30
+ },
31
+ {
32
+ name : 'project',
33
+ type : String,
34
+ description : '{green the name of the google project containing the npmrc and slack config secrets (default leverege-registry)}',
35
+ },
36
+ {
37
+ name : 'repository',
38
+ type : String,
39
+ description : '{green the target repository to receive the pushed chart}',
40
+ },
41
+ {
42
+ name : 'dry-run',
43
+ type : Boolean,
44
+ description : '{yellow perform everything except the actual chart push}',
45
+ },
46
+ {
47
+ name : 'help',
48
+ type : Boolean,
49
+ description : '{green display this help screen}',
50
+ },
51
+ /* eslint-enable max-len */
52
+ ]
53
+
54
+ const sections = [
55
+ {
56
+ header : 'Leverege Helm Chart Compass (for helmup)',
57
+ content : `{green This tool helps helmup navigate the helm charts stored in the
58
+ artifact-registries.}`
59
+ },
60
+ { header : 'Options',
61
+ optionList : commandLineOptions,
62
+ },
63
+ ]
64
+
65
+ const args = commandLineArgs( commandLineOptions, { camelCase : true, partial : true } )
66
+ const usage = commandLineUsage( sections )
67
+
68
+ if ( args.help ) {
69
+ log( usage )
70
+ process.exit( 0 )
71
+ }
72
+
73
+ /* eslint-disable no-underscore-dangle */
74
+ if ( args._unknown ) {
75
+ log( usage )
76
+ log( `\nUnrecognized argument [${chalk.bold.red( args._unknown )}]\n` )
77
+ process.exit( 1 )
78
+ }
79
+ /* eslint-enable no-underscore-dangle */
80
+
81
+ const minNodejsVersion = '18.0.0'
82
+ if ( semverLt( process.version, minNodejsVersion ) ) {
83
+ errorExit( `\n***ERROR: must be running at least node ${minNodejsVersion}\n` )
84
+ }
85
+
86
+ // First of all, fail if we are not in a git repository
87
+ let gitRoot
88
+ try {
89
+ gitRoot = await getGitRootDirectory()
90
+ } catch ( error ) {
91
+ errorExit( chalk.red.bold( error ), { errorCode : 5 } )
92
+ }
93
+
94
+ const chartCompass = YAML.load( fs.readFileSync( './registry-compass.yaml', 'utf8' ) )
95
+
96
+ condir( { chartCompass }, '<==Navigation' )
@@ -17,6 +17,17 @@ config:
17
17
  # # timescale
18
18
  # PG_HOST: "cnpg-db-tsdb-basic-r.cnpg-operands"
19
19
 
20
+ # The settings on the left are for the "standard" legacy chart settings which
21
+ # specifiy the old k8s secrets setups and are the defaults values from the
22
+ # api-server helm chart.
23
+ psqlSecurity: # v----- these are for CNPG -----v
24
+ PSQL_SECRET_NAME: "authz-postgres" # "cnpg-db-psql-stack-postgres-pw"
25
+ PSQL_SECRET_KEY: "postgresql-password" # "password"
26
+ TSDB_SECRET_NAME: "postgresql-password" # "cnpg-db-tsdb-basic-postgres-pw"
27
+ TSDB_SECRET_KEY: "postgresql-password" # "password"
28
+ TSDB_DENSE_SECRET_NAME: "postgresql-password" # "cnpg-db-tsdb-dense-postgres-pw"
29
+ TSDB_DENSE_SECRET_KEY: "postgresql-password" # "password"
30
+
20
31
  autoscaling:
21
32
  minReplicas: 3
22
33
  maxReplicas: 12
@@ -1,3 +1,6 @@
1
1
  #!/bin/bash
2
2
 
3
+ # ensures the PG_PASSWORD secret exists and correct
4
+ ensureCnpgSecret PG_PASSWORD $SERVICE-postgres-pw
5
+
3
6
  kubectl apply -f cnpg-db-psql-stack/cluster.yaml $K8S_WHAT
@@ -1,3 +1,6 @@
1
1
  #!/bin/bash
2
- #
2
+
3
+ # ensures the TSDB_PASSWORD secret exists and correct
4
+ ensureCnpgSecret TSDB_PASSWORD $SERVICE-postgres-pw
5
+
3
6
  kubectl apply -f cnpg-db-tsdb-basic/cluster.yaml $K8S_WHAT
@@ -1,3 +1,6 @@
1
1
  #!/bin/bash
2
- #
2
+
3
+ # ensures the TSDB_DENSE_PASSWORD secret exists and correct
4
+ ensureCnpgSecret TSDB_DENSE_PASSWORD $SERVICE-postgres-pw
5
+
3
6
  kubectl apply -f cnpg-db-tsdb-dense/cluster.yaml $K8S_WHAT
package/src/helmup.sh CHANGED
@@ -671,6 +671,23 @@ EOSNAPSC
671
671
  sleep 2 # hold up processing for a moment to allow IAM mods to propagate
672
672
  }
673
673
 
674
+ function ensureCnpgSecret() {
675
+ local mgrSecret=$1
676
+ local k8sSecret=$2
677
+
678
+ service-man --from-helmup --sync-secrets ${mgrSecret}=${k8sSecret}
679
+
680
+ if [ $? -ne 0 ];
681
+ then
682
+ cat<<BAD_SECRETS
683
+ `color r "There appears to be a problem with one, or both of the secrets. Please
684
+ rectify the situation and try again."`
685
+
686
+ BAD_SECRETS
687
+ exit 1
688
+ fi
689
+ }
690
+
674
691
  function installVeleroEnvironment() {
675
692
  # Follows instructions => https://github.com/vmware-tanzu/velero-plugin-for-gcp
676
693
  showInstalling "Velero Backup Management"
Binary file
@@ -1,138 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- const fs = require('node:fs');
5
- const path = require('node:path');
6
- const chalk = require('chalk');
7
- const cliArgs = require('command-line-args');
8
- const cliHelp = require('command-line-usage');
9
- const npmRegistryFetch = require('npm-registry-fetch');
10
- const semverLt = require('semver/functions/lt');
11
-
12
- /* eslint-disable no-console */
13
-
14
- const optionList = [
15
- // Use optionList to tie into the Usage statements
16
- {
17
- name: 'root',
18
- type: Boolean,
19
- default: false,
20
- description: 'returns the root of the build-tools installation'
21
- }, {
22
- name: 'latest',
23
- type: Boolean,
24
- default: false,
25
- description: 'verifies the latest build-tools are installed'
26
- }, {
27
- name: 'bashfun',
28
- type: Boolean,
29
- default: false,
30
- description: 'source the output to define common bash helper functions'
31
- }, {
32
- name: 'reporoot',
33
- type: Boolean,
34
- default: false,
35
- description: 'the root of the build-tools repo - for finding other config files'
36
- }, {
37
- name: 'help',
38
- type: Boolean,
39
- default: false,
40
- description: 'display this help screen'
41
- }, {
42
- name: 'version',
43
- type: Boolean,
44
- default: false,
45
- description: 'returns the build-tools repo version'
46
- }, {
47
- name: 'verbose',
48
- alias: 'v',
49
- type: Boolean,
50
- default: false,
51
- description: 'emit additional info at run time'
52
- }];
53
- const sections = [{
54
- header: 'A collection of build / support tools for all Leverege code',
55
- content: `README: {green https://bitbucket.org/leverege/build-tools/src/development}
56
- `
57
- }, {
58
- header: 'Options',
59
- optionList
60
- }];
61
- const args = cliArgs(optionList, {
62
- partial: true
63
- });
64
- const help = cliHelp(sections);
65
- const repoRoot = path.dirname(__dirname);
66
- const thisPackage = require(`${repoRoot}/package.json`);
67
- const thisVersion = thisPackage.version;
68
- if (args.root) {
69
- console.log(repoRoot);
70
- process.exit(0);
71
- }
72
- if (args.bashfun) {
73
- console.log(`${repoRoot}/src/bash-funcs`);
74
- process.exit(0);
75
- }
76
- if (args.reporoot) {
77
- console.log(`${repoRoot}`);
78
- process.exit(0);
79
- }
80
- const checkForLatest = async (pkg = '@leverege/build-tools') => {
81
- const getToken = () => {
82
- const tokenFile = `${process.env.HOME}/.npmrc`;
83
- if (!fs.existsSync(tokenFile)) {
84
- console.error(`Cannot find token file ${tokenFile}`);
85
- process.exit(1);
86
- }
87
- try {
88
- const tokenLine = fs.readFileSync(tokenFile).toString();
89
- const tokenRegX = new RegExp('.*registry.npmjs.org\\/:\\w+=+(.*)');
90
- const tokenStr = tokenLine.match(tokenRegX);
91
- if (!tokenStr) {
92
- console.error(`\n***ERROR: malformed npm token in ${tokenFile}\n`);
93
- process.exit(1);
94
- }
95
- return tokenLine.match(tokenRegX)[1];
96
- } catch (err) {
97
- console.error(err);
98
- }
99
- };
100
- try {
101
- const list = await npmRegistryFetch.json(pkg, {
102
- '//registry.npmjs.org/:_authToken': getToken()
103
- });
104
- return list['dist-tags'].latest;
105
- } catch (err) {
106
- console.log(err);
107
- }
108
- };
109
- const checkAndAnnounce = () => {
110
- checkForLatest().then(latestVersion => {
111
- if (semverLt(thisVersion, latestVersion)) {
112
- console.log(chalk.white`
113
- Update available ${chalk.grey(thisVersion)} \u2b62 ${chalk.green(latestVersion)}
114
- Run ${chalk.cyan('npm i -g @leverege/build-tools')} to update
115
- `);
116
- process.exit(1);
117
- } else {
118
- process.exit(0);
119
- }
120
- }).catch(err => {});
121
- };
122
- if (args.latest) {
123
- checkAndAnnounce();
124
- }
125
- if (args.version) {
126
- console.log(`build-tools version ${thisVersion}`);
127
- checkAndAnnounce();
128
- }
129
- if (args.help) {
130
- console.log(help);
131
- process.exit(0);
132
- }
133
-
134
- /* eslint-disable no-underscore-dangle */
135
- if (args._unknown) {
136
- console.log(`\nUnrecognized argument [${args._unknown}] try --help\n`);
137
- process.exit(1);
138
- }
@@ -1,195 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable no-console */
3
- // https://github.com/google/zx
4
- /* eslint-disable max-len */
5
- "use strict";
6
-
7
- var _enquirer = _interopRequireDefault(require("enquirer"));
8
- var _ansiColors = _interopRequireDefault(require("ansi-colors"));
9
- var _zx = require("zx");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- const {
12
- prompt
13
- } = _enquirer.default;
14
-
15
- // This will preserve coloration from spawned child processes
16
- process.env.FORCE_COLORS = 3;
17
- process.env.FORCE_COLOR = '1';
18
- let TARGET;
19
- let CHANNEL;
20
-
21
- // A single unnamed parameter is assumed to be a deploy target.
22
- // If named parameters exist, they may not be stored in argv,
23
- // so don't look for a larger length of argv to decide whether to look for named paramters
24
- if (_zx.argv._.length === 1) {
25
- TARGET = _zx.argv._[0];
26
- } else {
27
- TARGET = _zx.argv.target;
28
- if (_zx.argv.channelName) {
29
- CHANNEL = {};
30
- CHANNEL.name = _zx.argv.channelName;
31
- CHANNEL.expiration = _zx.argv.channelExpiration ?? '7d';
32
- }
33
- }
34
-
35
- // If target has not been defined on the command line,
36
- // then enter interactive mode
37
- const INTERACTIVE_MODE = !TARGET;
38
- let exited = false;
39
- const SECRETS_DIR = 'secrets';
40
- const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughException', 'unhandledRejection'];
41
- const [firebaserc, firebaseJson, gitBranch] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), '.firebaserc')), _zx.fs.exists(_zx.path.join(process.cwd(), 'firebase.json')), (0, _zx.$)`git rev-parse --abbrev-ref HEAD -C ${process.cwd()}`.then(({
42
- stdout
43
- }) => {
44
- return stdout.split('\n')[0];
45
- })]);
46
- if (!firebaserc) {
47
- console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
48
- }
49
- if (!firebaseJson) {
50
- console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
51
- }
52
- if (!firebaserc || !firebaseJson) {
53
- process.exit();
54
- }
55
- const firebasercContent = JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
56
- encoding: 'utf-8'
57
- }));
58
- let maxSiteIdLength = 0;
59
- const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
60
- Object.entries(config.hosting).forEach(([siteId, aliases]) => {
61
- aliases.forEach(alias => {
62
- // Store the longest length of site id for formatting later on
63
- maxSiteIdLength = Math.max(siteId.length, maxSiteIdLength);
64
- prev[alias] = {
65
- projectId,
66
- siteId,
67
- alias,
68
- production: config.production
69
- };
70
- });
71
- });
72
- return prev;
73
- }, {});
74
- if (INTERACTIVE_MODE) {
75
- const {
76
- targetEnv
77
- } = await prompt([{
78
- type: 'autocomplete',
79
- name: 'targetEnv',
80
- message: 'To which environment would you like to deploy?',
81
- choices: Object.values(targets).map(t => {
82
- const productionLabel = t.production ? _ansiColors.default.bold.red('--PRODUCTION--') : '';
83
- return {
84
- message: `${_ansiColors.default.bold.cyan('Site: ')}${t.siteId.padEnd(maxSiteIdLength)} ${_ansiColors.default.bold.green('Project: ')}${t.projectId} ${productionLabel}`,
85
- value: t.alias
86
- };
87
- })
88
- }]);
89
- TARGET = targets[targetEnv];
90
- if (TARGET.production) {
91
- const {
92
- confirmProductionDeploy
93
- } = await prompt([{
94
- type: 'confirm',
95
- name: 'confirmProductionDeploy',
96
- message: `${_ansiColors.default.bold.red('WARNING: ')} This is a ${_ansiColors.default.bold.yellow('PRODUCTION')} environment. Are you sure you want to deploy here?`
97
- }]);
98
- if (!confirmProductionDeploy) {
99
- console.log('Cancelling deployment...');
100
- process.exit();
101
- }
102
- }
103
- const {
104
- useChannel
105
- } = await prompt([{
106
- type: 'confirm',
107
- name: 'useChannel',
108
- message: 'Do you want to deploy to a temporary preview channel?'
109
- }]);
110
- if (useChannel) {
111
- const {
112
- channelName,
113
- channelExpiration
114
- } = await prompt([{
115
- type: 'input',
116
- name: 'channelName',
117
- message: 'To which channel would you like to deploy?',
118
- initial: gitBranch ?? 'temp-deploy'
119
- }, {
120
- type: 'input',
121
- name: 'channelExpiration',
122
- message: 'When should the channel expire?',
123
- initial: '7d'
124
- }]);
125
- CHANNEL = {
126
- name: channelName,
127
- expiration: channelExpiration
128
- };
129
- }
130
- } else {
131
- TARGET = targets[TARGET];
132
- }
133
- if (!TARGET) {
134
- console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
135
- process.exit();
136
- }
137
- 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'))]);
138
- if (!aliasFileExists && !siteIdFileExists) {
139
- console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
140
- process.exit();
141
- }
142
- const exec = [];
143
- if (sharedFileExists) {
144
- exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
145
- encoding: 'utf-8'
146
- }));
147
- }
148
- if (aliasFileExists) {
149
- exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
150
- encoding: 'utf-8'
151
- }));
152
- } else {
153
- exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`), {
154
- encoding: 'utf-8'
155
- }));
156
- }
157
- console.log(`\n\n\n${_ansiColors.default.bold.green('====== Deployment Summary ======')}`);
158
- console.log(`${_ansiColors.default.blue('Firebase project:')} ${TARGET.projectId} ${TARGET.production ? _ansiColors.default.yellow('--PRODUCTION--') : ''}`);
159
- console.log(`${_ansiColors.default.blue('Site ID:')} ${TARGET.siteId}`);
160
- console.log(`${_ansiColors.default.blue('Channel Name:')} ${CHANNEL?.name ?? _ansiColors.default.italic.gray('(none)')}`);
161
- console.log(`${_ansiColors.default.blue('Channel Expiration date:')} ${CHANNEL?.name ? CHANNEL.expiration ?? _ansiColors.default.italic.gray('(none)') : _ansiColors.default.italic.gray('(n/a)')}`);
162
- console.log(`${_ansiColors.default.blue('Shared .env file:')} ${sharedFileExists ? `${SECRETS_DIR}/shared.env` : _ansiColors.default.italic.gray('(none)')}`);
163
- console.log(`${_ansiColors.default.blue('Additional .env overrides:')} ${aliasFileExists ? `${SECRETS_DIR}/${TARGET.alias}.env` : `${SECRETS_DIR}/${TARGET.siteId}.env`}`);
164
- console.log(`${_ansiColors.default.bold.green('===============================')}`);
165
- if (INTERACTIVE_MODE) {
166
- const {
167
- confirmSelections
168
- } = await prompt([{
169
- type: 'confirm',
170
- name: 'confirmSelections',
171
- message: 'Proceed with this deployment?'
172
- }]);
173
- if (!confirmSelections) {
174
- console.log('Cancelling deployment...');
175
- process.exit();
176
- }
177
- }
178
- const envFileContent = (await Promise.all(exec)).join('\n');
179
- EXIT_EVENTS.forEach(event => {
180
- process.on(event, () => {
181
- if (!exited) {
182
- exited = true;
183
- _zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
184
- }
185
- });
186
- });
187
- await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
188
- try {
189
- // deploying to a channel requires slightly different parameter structure
190
- const deployType = CHANNEL ? `hosting:channel:deploy ${CHANNEL.name} ${CHANNEL.expiration ? `--expires ${CHANNEL.expiration}` : ''}`.split(' ') : 'deploy';
191
- const hostingPrefix = CHANNEL ? '' : 'hosting:';
192
- await (0, _zx.$)`npm run clean && DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} DEPLOYMENT_TARGET=${TARGET.siteId} npm run build && firebase use ${TARGET.projectId} && firebase ${deployType} --only ${hostingPrefix}${TARGET.siteId}`;
193
- } catch (err) {
194
- console.error(err);
195
- }
@@ -1,116 +0,0 @@
1
- #!/usr/bin/env node
2
- // https://github.com/google/zx
3
- /* eslint-disable max-len */
4
- /* eslint-disable no-console */
5
- "use strict";
6
-
7
- var _enquirer = _interopRequireDefault(require("enquirer"));
8
- var _zx = require("zx");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- const {
11
- prompt
12
- } = _enquirer.default;
13
-
14
- // This will preserve coloration from spawned child processes
15
- process.env.FORCE_COLORS = 3;
16
- process.env.FORCE_COLOR = '1';
17
- let TARGET = _zx.argv._[0];
18
- let exited = false;
19
- const SECRETS_DIR = 'secrets';
20
- const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughtException', 'unhandledRejection'];
21
- 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'))]);
22
- if (!hasLocalConfig) {
23
- if (!firebaserc) {
24
- console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
25
- }
26
- if (!firebaseJson) {
27
- console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
28
- }
29
- if (!firebaserc || !firebaseJson) {
30
- process.exit();
31
- }
32
- }
33
- const firebasercContent = firebaserc ? JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
34
- encoding: 'utf-8'
35
- })) : {
36
- targets: {}
37
- };
38
- const defaultTargets = {};
39
- if (hasLocalConfig) {
40
- defaultTargets.local = {
41
- siteId: 'local',
42
- alias: 'local'
43
- };
44
- }
45
- const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
46
- Object.entries(config.hosting).forEach(([siteId, aliases]) => {
47
- aliases.forEach(alias => {
48
- prev[alias] = {
49
- projectId,
50
- siteId,
51
- alias
52
- };
53
- });
54
- });
55
- return prev;
56
- }, defaultTargets);
57
- if (!TARGET) {
58
- const choices = Object.keys(targets).map(t => ({
59
- name: t,
60
- value: t
61
- }));
62
- let targetEnv;
63
- if (choices.length > 1) {
64
- const res = await prompt({
65
- type: 'autocomplete',
66
- name: 'targetEnv',
67
- message: 'Which environment would you like to serve?',
68
- choices
69
- });
70
- targetEnv = res.targetEnv;
71
- } else {
72
- targetEnv = choices[0].value;
73
- }
74
- TARGET = targets[targetEnv];
75
- } else {
76
- TARGET = targets[TARGET];
77
- }
78
- if (!TARGET) {
79
- console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
80
- process.exit();
81
- }
82
- 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'))]);
83
- if (!aliasFileExists && !siteIdFileExists) {
84
- console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
85
- process.exit();
86
- }
87
- const exec = [];
88
- if (sharedFileExists) {
89
- exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
90
- encoding: 'utf-8'
91
- }));
92
- }
93
- if (aliasFileExists) {
94
- exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
95
- encoding: 'utf-8'
96
- }));
97
- } else {
98
- exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`), {
99
- encoding: 'utf-8'
100
- }));
101
- }
102
- const envFileContent = (await Promise.all(exec)).join('\n');
103
- EXIT_EVENTS.forEach(event => {
104
- process.on(event, () => {
105
- if (!exited) {
106
- exited = true;
107
- _zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
108
- }
109
- });
110
- });
111
- await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
112
- try {
113
- await (0, _zx.$)`DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} DEPLOYMENT_TARGET=${TARGET.siteId} npm run serve --colors`;
114
- } catch (err) {
115
- console.error(err);
116
- }
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * This script parses a firebase config into something useful.
5
- *
6
- * firebase --project leverege-dev-john apps:sdkconfig | getfbcfg
7
- */
8
- "use strict";
9
-
10
- const stdbuf = [];
11
-
12
- /* eslint-disable no-console */
13
- process.stdin.on('data', d => {
14
- stdbuf.push(d);
15
- }).on('end', () => {
16
- const rawCfg = stdbuf.join('').replace(/["\n\r]/g, '');
17
- const keyVals = rawCfg.match(/\{(.*)\}/)[1].split(',');
18
- const lastLine = keyVals.length - 1;
19
- console.log('{');
20
- for (let i = 0; i <= lastLine; i++) {
21
- const kv = keyVals[i].trim().split(' ');
22
- console.log(` "${kv[0].replace(/:/, '')}": "${kv[1]}"${i < lastLine ? ',' : ''}`);
23
- }
24
- console.log('}');
25
- }).setEncoding('utf8');