@leverege/build-tools 2.99.1 → 2.99.2-quinn.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/leverege-build-tools-2.21.13.tgz +0 -0
- package/lib/server/build-tools.js +138 -0
- package/lib/server/firebaseDeploy.js +195 -0
- package/lib/server/firebaseServe.js +116 -0
- package/lib/server/getfbcfg.js +25 -0
- package/lib/server/getjson.js +70 -0
- package/lib/server/overwhelm.js +447 -0
- package/lib/server/push-my-chart.js +18 -0
- package/lib/server/refresh-npm-token.js +135 -0
- package/lib/server/tag-release.js +681 -0
- package/lib/server/unleash.js +50 -0
- package/lib/web/build-tools.js +138 -0
- package/lib/web/firebaseDeploy.js +195 -0
- package/lib/web/firebaseServe.js +116 -0
- package/lib/web/getfbcfg.js +25 -0
- package/lib/web/getjson.js +70 -0
- package/lib/web/overwhelm.js +447 -0
- package/lib/web/push-my-chart.js +18 -0
- package/lib/web/refresh-npm-token.js +135 -0
- package/lib/web/tag-release.js +681 -0
- package/lib/web/unleash.js +50 -0
- package/package.json +3 -3
- package/src/helm-charts/prom-operator/prometheus-stack.yaml.ovh +2 -1
- package/src/helm-charts/prom-operator/rules/prometheus-rules.yaml +2 -2
|
Binary file
|
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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');
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This script will allow the user to grab a value from a JSON file and
|
|
5
|
+
* optionally apply a regular expression to it. Given this test.json file:
|
|
6
|
+
*
|
|
7
|
+
* {
|
|
8
|
+
* "name": "@leverege/packagename",
|
|
9
|
+
* "main": "lib/index.js"
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* and invoking as:
|
|
13
|
+
* ./getjson --file ./test.json --key name --regex "^@\w{3}"
|
|
14
|
+
*
|
|
15
|
+
* will yield an output of: @lev
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get a command line switch parser.
|
|
20
|
+
*/
|
|
21
|
+
"use strict";
|
|
22
|
+
|
|
23
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
24
|
+
var _commandLineArgs = _interopRequireDefault(require("command-line-args"));
|
|
25
|
+
var _commandLineUsage = _interopRequireDefault(require("command-line-usage"));
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
/* eslint-disable no-console */
|
|
28
|
+
const optionList = [
|
|
29
|
+
// Use optionList to tie into the Usage statements
|
|
30
|
+
{
|
|
31
|
+
name: 'file',
|
|
32
|
+
type: String,
|
|
33
|
+
alias: 'f',
|
|
34
|
+
description: 'file to parse JSON from'
|
|
35
|
+
}, {
|
|
36
|
+
name: 'key',
|
|
37
|
+
type: String,
|
|
38
|
+
alias: 'k',
|
|
39
|
+
description: 'JSON key whose value to grab'
|
|
40
|
+
}, {
|
|
41
|
+
name: 'regex',
|
|
42
|
+
type: String,
|
|
43
|
+
alias: 'r',
|
|
44
|
+
description: 'regular expression to apply to the value'
|
|
45
|
+
}];
|
|
46
|
+
const sections = [{
|
|
47
|
+
header: 'JSON variable fetching script',
|
|
48
|
+
content: ` This script is intended to give shell scripts a simple JSON
|
|
49
|
+
parsing capability.`
|
|
50
|
+
}, {
|
|
51
|
+
header: 'Options',
|
|
52
|
+
optionList
|
|
53
|
+
}];
|
|
54
|
+
const args = (0, _commandLineArgs.default)(optionList, {
|
|
55
|
+
partial: true
|
|
56
|
+
});
|
|
57
|
+
const help = (0, _commandLineUsage.default)(sections);
|
|
58
|
+
if (!args.file) {
|
|
59
|
+
console.error('\n***ERROR: Missing a --file param\n');
|
|
60
|
+
console.log(help);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const json = JSON.parse(_fs.default.readFileSync(args.file, 'utf8'));
|
|
65
|
+
const value = json[args.key];
|
|
66
|
+
const match = new RegExp(args.regex || '.*').exec(value);
|
|
67
|
+
console.log(match ? match[match.length - 1] : '');
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.log(e);
|
|
70
|
+
}
|