@leverege/build-tools 2.21.7 → 2.21.9-nick.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/.firebaserc +47 -0
- package/.vscode/launch.json +18 -0
- package/firebase.json +180 -0
- package/lib/server/build-tools.js +4 -24
- package/lib/server/firebaseDeploy.js +89 -32
- package/lib/server/firebaseServe.js +2 -23
- package/lib/server/getfbcfg.js +1 -3
- package/lib/server/getjson.js +3 -7
- package/lib/server/npm-scripts/postinstall.js +0 -4
- package/lib/server/overwhelm.js +68 -90
- package/lib/server/unleash.js +2 -10
- package/lib/web/build-tools.js +4 -24
- package/lib/web/firebaseDeploy.js +89 -32
- package/lib/web/firebaseServe.js +2 -23
- package/lib/web/getfbcfg.js +1 -3
- package/lib/web/getjson.js +3 -7
- package/lib/web/npm-scripts/postinstall.js +0 -4
- package/lib/web/overwhelm.js +68 -90
- package/lib/web/unleash.js +2 -10
- package/package.json +7 -6
- package/src/firebaseDeploy.mjs +83 -11
- package/src/helmup +1 -1
package/.firebaserc
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"projects": {
|
|
3
|
+
"default": "leverege-sandbox",
|
|
4
|
+
"dev-keys": "leverege-dev-nick",
|
|
5
|
+
"prd-indoor-zoning" : "prd-indoor-zoning"
|
|
6
|
+
},
|
|
7
|
+
"targets": {
|
|
8
|
+
"leverege-sandbox": {
|
|
9
|
+
"hosting": {
|
|
10
|
+
"dev-izg": [
|
|
11
|
+
"dev-izg"
|
|
12
|
+
],
|
|
13
|
+
"dev-olive-indoor-zoning": [
|
|
14
|
+
"dev-olive-indoor-zoning"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"leverege-dev-nick": {
|
|
19
|
+
"hosting": {
|
|
20
|
+
"dev-keys": [
|
|
21
|
+
"dev-keys"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"prd-indoor-zoning": {
|
|
26
|
+
"hosting": {
|
|
27
|
+
"prd-indoor-zoning-ui": [
|
|
28
|
+
"prd-indoor-zoning-ui"
|
|
29
|
+
],
|
|
30
|
+
"prd-olive-indoor-zoning-ui": [
|
|
31
|
+
"prd-olive-indoor-zoning-ui"
|
|
32
|
+
],
|
|
33
|
+
"prd-keys": [
|
|
34
|
+
"prd-keys"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"production": true
|
|
38
|
+
},
|
|
39
|
+
"stg-indoor-zoning-pen-test": {
|
|
40
|
+
"hosting": {
|
|
41
|
+
"stg-indoor-zoning-ui": [
|
|
42
|
+
"stg-indoor-zoning-ui"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"type": "node",
|
|
9
|
+
"request": "launch",
|
|
10
|
+
"name": "firebase deploy",
|
|
11
|
+
"skipFiles": [
|
|
12
|
+
"<node_internals>/**"
|
|
13
|
+
],
|
|
14
|
+
"program": "${workspaceFolder}/src/firebaseDeploy.mjs",
|
|
15
|
+
"console": "integratedTerminal"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/firebase.json
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hosting": [
|
|
3
|
+
{
|
|
4
|
+
"site":"dev-izg",
|
|
5
|
+
"public": "dist",
|
|
6
|
+
"ignore": [
|
|
7
|
+
"firebase.json",
|
|
8
|
+
"**/.*",
|
|
9
|
+
"**/node_modules/**"
|
|
10
|
+
],
|
|
11
|
+
"rewrites": [
|
|
12
|
+
{
|
|
13
|
+
"source": "**",
|
|
14
|
+
"destination": "/index.html"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"headers": {
|
|
18
|
+
"X-Content-Type-Options": "nosniff",
|
|
19
|
+
"X-XSS-Protection": "1; mode=block",
|
|
20
|
+
"X-Frame-Options": "deny",
|
|
21
|
+
"Content-Security-Policy": "default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: leverege-sandbox-imagine-api.leverege.com *.mapbox.com *.firebaseio.com wss://*.firebaseio.com *.googleapis.com *.intercom.io wss://*.intercom.io maxcdn.bootstrapcdn.com *.intercomcdn.com *.gstatic.com;",
|
|
22
|
+
"Referrer-Policy":"no-referrer"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"site":"dev-keys",
|
|
27
|
+
"public": "dist",
|
|
28
|
+
"ignore": [
|
|
29
|
+
"firebase.json",
|
|
30
|
+
"**/.*",
|
|
31
|
+
"**/node_modules/**"
|
|
32
|
+
],
|
|
33
|
+
"rewrites": [
|
|
34
|
+
{
|
|
35
|
+
"source": "**",
|
|
36
|
+
"destination": "/index.html"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"headers": {
|
|
40
|
+
"X-Content-Type-Options": "nosniff",
|
|
41
|
+
"X-XSS-Protection": "1; mode=block",
|
|
42
|
+
"X-Frame-Options": "deny",
|
|
43
|
+
"Content-Security-Policy": "default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: leverege-sandbox-imagine-api.leverege.com *.mapbox.com *.firebaseio.com wss://*.firebaseio.com *.googleapis.com *.intercom.io wss://*.intercom.io maxcdn.bootstrapcdn.com *.intercomcdn.com *.gstatic.com;",
|
|
44
|
+
"Referrer-Policy":"no-referrer"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"site":"dev-keys",
|
|
49
|
+
"public": "dist",
|
|
50
|
+
"ignore": [
|
|
51
|
+
"firebase.json",
|
|
52
|
+
"**/.*",
|
|
53
|
+
"**/node_modules/**"
|
|
54
|
+
],
|
|
55
|
+
"rewrites": [
|
|
56
|
+
{
|
|
57
|
+
"source": "**",
|
|
58
|
+
"destination": "/index.html"
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"headers": {
|
|
62
|
+
"X-Content-Type-Options": "nosniff",
|
|
63
|
+
"X-XSS-Protection": "1; mode=block",
|
|
64
|
+
"X-Frame-Options": "deny",
|
|
65
|
+
"Content-Security-Policy": "default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: leverege-sandbox-imagine-api.leverege.com *.mapbox.com *.firebaseio.com wss://*.firebaseio.com *.googleapis.com *.intercom.io wss://*.intercom.io maxcdn.bootstrapcdn.com *.intercomcdn.com *.gstatic.com;",
|
|
66
|
+
"Referrer-Policy":"no-referrer"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"site":"dev-olive-indoor-zoning",
|
|
71
|
+
"public": "dist",
|
|
72
|
+
"ignore": [
|
|
73
|
+
"firebase.json",
|
|
74
|
+
"**/.*",
|
|
75
|
+
"**/node_modules/**"
|
|
76
|
+
],
|
|
77
|
+
"rewrites": [
|
|
78
|
+
{
|
|
79
|
+
"source": "**",
|
|
80
|
+
"destination": "/index.html"
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"headers": {
|
|
84
|
+
"X-Content-Type-Options": "nosniff",
|
|
85
|
+
"X-XSS-Protection": "1; mode=block",
|
|
86
|
+
"X-Frame-Options": "deny",
|
|
87
|
+
"Content-Security-Policy": "default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: leverege-sandbox-imagine-api.leverege.com *.mapbox.com *.firebaseio.com wss://*.firebaseio.com *.googleapis.com *.intercom.io wss://*.intercom.io maxcdn.bootstrapcdn.com *.intercomcdn.com *.gstatic.com;",
|
|
88
|
+
"Referrer-Policy":"no-referrer"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"site":"prd-indoor-zoning-ui",
|
|
93
|
+
"public": "dist",
|
|
94
|
+
"ignore": [
|
|
95
|
+
"firebase.json",
|
|
96
|
+
"**/.*",
|
|
97
|
+
"**/node_modules/**"
|
|
98
|
+
],
|
|
99
|
+
"rewrites": [
|
|
100
|
+
{
|
|
101
|
+
"source": "**",
|
|
102
|
+
"destination": "/index.html"
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
"headers": {
|
|
106
|
+
"X-Content-Type-Options": "nosniff",
|
|
107
|
+
"X-XSS-Protection": "1; mode=block",
|
|
108
|
+
"X-Frame-Options": "deny",
|
|
109
|
+
"Content-Security-Policy": "default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: leverege-sandbox-imagine-api.leverege.com *.mapbox.com *.firebaseio.com wss://*.firebaseio.com *.googleapis.com *.intercom.io wss://*.intercom.io maxcdn.bootstrapcdn.com *.intercomcdn.com *.gstatic.com;",
|
|
110
|
+
"Referrer-Policy":"no-referrer"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"site":"prd-keys",
|
|
115
|
+
"public": "dist",
|
|
116
|
+
"ignore": [
|
|
117
|
+
"firebase.json",
|
|
118
|
+
"**/.*",
|
|
119
|
+
"**/node_modules/**"
|
|
120
|
+
],
|
|
121
|
+
"rewrites": [
|
|
122
|
+
{
|
|
123
|
+
"source": "**",
|
|
124
|
+
"destination": "/index.html"
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
"headers": {
|
|
128
|
+
"X-Content-Type-Options": "nosniff",
|
|
129
|
+
"X-XSS-Protection": "1; mode=block",
|
|
130
|
+
"X-Frame-Options": "deny",
|
|
131
|
+
"Content-Security-Policy": "default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: leverege-sandbox-imagine-api.leverege.com *.mapbox.com *.firebaseio.com wss://*.firebaseio.com *.googleapis.com *.intercom.io wss://*.intercom.io maxcdn.bootstrapcdn.com *.intercomcdn.com *.gstatic.com;",
|
|
132
|
+
"Referrer-Policy":"no-referrer"
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"site":"prd-olive-indoor-zoning-ui",
|
|
137
|
+
"public": "dist",
|
|
138
|
+
"ignore": [
|
|
139
|
+
"firebase.json",
|
|
140
|
+
"**/.*",
|
|
141
|
+
"**/node_modules/**"
|
|
142
|
+
],
|
|
143
|
+
"rewrites": [
|
|
144
|
+
{
|
|
145
|
+
"source": "**",
|
|
146
|
+
"destination": "/index.html"
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
"headers": {
|
|
150
|
+
"X-Content-Type-Options": "nosniff",
|
|
151
|
+
"X-XSS-Protection": "1; mode=block",
|
|
152
|
+
"X-Frame-Options": "deny",
|
|
153
|
+
"Content-Security-Policy": "default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: leverege-sandbox-imagine-api.leverege.com *.mapbox.com *.firebaseio.com wss://*.firebaseio.com *.googleapis.com *.intercom.io wss://*.intercom.io maxcdn.bootstrapcdn.com *.intercomcdn.com *.gstatic.com;",
|
|
154
|
+
"Referrer-Policy":"no-referrer"
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"site":"stg-indoor-zoning-ui",
|
|
159
|
+
"public": "dist",
|
|
160
|
+
"ignore": [
|
|
161
|
+
"firebase.json",
|
|
162
|
+
"**/.*",
|
|
163
|
+
"**/node_modules/**"
|
|
164
|
+
],
|
|
165
|
+
"rewrites": [
|
|
166
|
+
{
|
|
167
|
+
"source": "**",
|
|
168
|
+
"destination": "/index.html"
|
|
169
|
+
}
|
|
170
|
+
],
|
|
171
|
+
"headers": {
|
|
172
|
+
"X-Content-Type-Options": "nosniff",
|
|
173
|
+
"X-XSS-Protection": "1; mode=block",
|
|
174
|
+
"X-Frame-Options": "deny",
|
|
175
|
+
"Content-Security-Policy": "default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: leverege-sandbox-imagine-api.leverege.com *.mapbox.com *.firebaseio.com wss://*.firebaseio.com *.googleapis.com *.intercom.io wss://*.intercom.io maxcdn.bootstrapcdn.com *.intercomcdn.com *.gstatic.com;",
|
|
176
|
+
"Referrer-Policy":"no-referrer"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
}
|
|
@@ -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 = [
|
|
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,92 +1,151 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
2
3
|
// https://github.com/google/zx
|
|
3
|
-
|
|
4
4
|
/* eslint-disable max-len */
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
7
|
var _enquirer = _interopRequireDefault(require("enquirer"));
|
|
8
|
-
|
|
8
|
+
var _ansiColors = _interopRequireDefault(require("ansi-colors"));
|
|
9
9
|
var _zx = require("zx");
|
|
10
|
-
|
|
11
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
|
|
13
11
|
const {
|
|
14
12
|
prompt
|
|
15
|
-
} = _enquirer.default;
|
|
13
|
+
} = _enquirer.default;
|
|
16
14
|
|
|
15
|
+
// This will preserve coloration from spawned child processes
|
|
17
16
|
process.env.FORCE_COLORS = 3;
|
|
18
17
|
process.env.FORCE_COLOR = '1';
|
|
19
|
-
let TARGET
|
|
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 use the length of argv to decide whether to look for them
|
|
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
|
+
}
|
|
20
34
|
let exited = false;
|
|
21
35
|
const SECRETS_DIR = 'secrets';
|
|
22
36
|
const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughException', 'unhandledRejection'];
|
|
23
|
-
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
|
-
|
|
37
|
+
const [firebaserc, firebaseJson, git] = 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(), '.git/HEAD'))]);
|
|
25
38
|
if (!firebaserc) {
|
|
26
39
|
console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
27
40
|
}
|
|
28
|
-
|
|
29
41
|
if (!firebaseJson) {
|
|
30
42
|
console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
31
43
|
}
|
|
32
|
-
|
|
33
44
|
if (!firebaserc || !firebaseJson) {
|
|
34
45
|
process.exit();
|
|
35
46
|
}
|
|
36
|
-
|
|
37
47
|
const firebasercContent = JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
|
|
38
48
|
encoding: 'utf-8'
|
|
39
49
|
}));
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
|
|
51
|
+
// If in a git repo, fetch the name of the git branch to use as a default
|
|
52
|
+
// name in case a deployment channel is needed
|
|
53
|
+
let gitBranch;
|
|
54
|
+
if (git) {
|
|
55
|
+
const gitContent = (await _zx.fs.readFile(_zx.path.join(process.cwd(), '.git/HEAD'), {
|
|
56
|
+
encoding: 'utf-8'
|
|
57
|
+
}))?.split('/');
|
|
58
|
+
gitBranch = gitContent[gitContent?.length - 1]?.trimEnd('\n');
|
|
59
|
+
}
|
|
60
|
+
let maxPadding = 0;
|
|
61
|
+
const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config, production]) => {
|
|
62
|
+
Object.entries(config.hosting).forEach(([siteId, aliases, production]) => {
|
|
42
63
|
aliases.forEach(alias => {
|
|
64
|
+
maxPadding = Math.max(siteId.length, maxPadding);
|
|
43
65
|
prev[alias] = {
|
|
44
66
|
projectId,
|
|
45
67
|
siteId,
|
|
46
|
-
alias
|
|
68
|
+
alias,
|
|
69
|
+
production: config.production
|
|
47
70
|
};
|
|
48
71
|
});
|
|
49
72
|
});
|
|
50
73
|
return prev;
|
|
51
74
|
}, {});
|
|
52
|
-
|
|
53
75
|
if (!TARGET) {
|
|
54
76
|
const {
|
|
55
77
|
targetEnv
|
|
56
|
-
} = await prompt({
|
|
57
|
-
type: '
|
|
78
|
+
} = await prompt([{
|
|
79
|
+
type: 'select',
|
|
58
80
|
name: 'targetEnv',
|
|
59
81
|
message: 'To which environment would you like to deploy?',
|
|
60
|
-
choices: Object.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
82
|
+
choices: Object.values(targets).map(t => {
|
|
83
|
+
const productionLabel = t.production ? _ansiColors.default.bold.red('--PRODUCTION--') : '';
|
|
84
|
+
return {
|
|
85
|
+
message: `${_ansiColors.default.bold.cyan('Site: ')}${t.siteId.padEnd(maxPadding)} ${_ansiColors.default.bold.green('Project: ')}${t.projectId} ${productionLabel}`,
|
|
86
|
+
value: t.siteId
|
|
87
|
+
};
|
|
88
|
+
})
|
|
89
|
+
}]);
|
|
65
90
|
TARGET = targets[targetEnv];
|
|
91
|
+
if (TARGET.production) {
|
|
92
|
+
const {
|
|
93
|
+
confirmProductionDeploy
|
|
94
|
+
} = await prompt([{
|
|
95
|
+
type: 'confirm',
|
|
96
|
+
name: 'confirmProductionDeploy',
|
|
97
|
+
message: `${_ansiColors.default.bold.red('WARNING: ')} This is a ${_ansiColors.default.bold.yellow('PRODUCTION')} deployment target. Are you sure you want to proceed?`
|
|
98
|
+
}]);
|
|
99
|
+
if (!confirmProductionDeploy) {
|
|
100
|
+
console.log('Cancelling deployment...');
|
|
101
|
+
process.exit();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const {
|
|
105
|
+
useChannel
|
|
106
|
+
} = await prompt([{
|
|
107
|
+
type: 'confirm',
|
|
108
|
+
name: 'useChannel',
|
|
109
|
+
message: 'Do you want to deploy to a temporary preview channel?'
|
|
110
|
+
}]);
|
|
111
|
+
if (useChannel) {
|
|
112
|
+
const {
|
|
113
|
+
channelName,
|
|
114
|
+
channelExpiration
|
|
115
|
+
} = await prompt([{
|
|
116
|
+
type: 'input',
|
|
117
|
+
name: 'channelName',
|
|
118
|
+
message: 'To which channel would you like to deploy?',
|
|
119
|
+
initial: gitBranch ?? 'temp-deploy'
|
|
120
|
+
}, {
|
|
121
|
+
type: 'input',
|
|
122
|
+
name: 'channelExpiration',
|
|
123
|
+
message: 'When should the channel expire?',
|
|
124
|
+
initial: '7d'
|
|
125
|
+
}]);
|
|
126
|
+
CHANNEL = {
|
|
127
|
+
name: channelName,
|
|
128
|
+
expiration: channelExpiration
|
|
129
|
+
};
|
|
130
|
+
}
|
|
66
131
|
} else {
|
|
67
132
|
TARGET = targets[TARGET];
|
|
68
133
|
}
|
|
69
|
-
|
|
70
134
|
if (!TARGET) {
|
|
71
135
|
console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
|
|
72
136
|
process.exit();
|
|
73
137
|
}
|
|
74
|
-
|
|
75
138
|
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
139
|
if (!aliasFileExists && !siteIdFileExists) {
|
|
78
140
|
console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
|
|
79
141
|
process.exit();
|
|
80
142
|
}
|
|
81
|
-
|
|
82
143
|
const exec = [];
|
|
83
|
-
|
|
84
144
|
if (sharedFileExists) {
|
|
85
145
|
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
|
|
86
146
|
encoding: 'utf-8'
|
|
87
147
|
}));
|
|
88
148
|
}
|
|
89
|
-
|
|
90
149
|
if (aliasFileExists) {
|
|
91
150
|
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
|
|
92
151
|
encoding: 'utf-8'
|
|
@@ -96,21 +155,19 @@ if (aliasFileExists) {
|
|
|
96
155
|
encoding: 'utf-8'
|
|
97
156
|
}));
|
|
98
157
|
}
|
|
99
|
-
|
|
100
158
|
const envFileContent = (await Promise.all(exec)).join('\n');
|
|
101
159
|
EXIT_EVENTS.forEach(event => {
|
|
102
160
|
process.on(event, () => {
|
|
103
161
|
if (!exited) {
|
|
104
162
|
exited = true;
|
|
105
|
-
|
|
106
163
|
_zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
|
|
107
164
|
}
|
|
108
165
|
});
|
|
109
166
|
});
|
|
110
167
|
await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
|
|
111
|
-
|
|
112
168
|
try {
|
|
113
|
-
|
|
169
|
+
const deployType = CHANNEL ? `hosting:channel:deploy ${CHANNEL.name} --expires ${CHANNEL.expiration}` : 'deploy';
|
|
170
|
+
await (0, _zx.$)`npm run clean && DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} npm run build && firebase use ${TARGET.projectId} && firebase ${deployType} --only hosting:${TARGET.siteId}`;
|
|
114
171
|
} catch (err) {
|
|
115
172
|
console.error(err);
|
|
116
173
|
}
|
|
@@ -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;
|
|
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) {
|