@leverege/build-tools 2.16.1 → 2.17.0
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/lib/server/firebaseDeploy.js +116 -0
- package/lib/server/firebaseServe.js +116 -0
- package/lib/server/repo-init/config.tgz +0 -0
- package/lib/web/firebaseDeploy.js +116 -0
- package/lib/web/firebaseServe.js +116 -0
- package/package.json +7 -3
- package/src/firebaseDeploy.mjs +118 -0
- package/src/firebaseServe.mjs +118 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
var _enquirer = _interopRequireDefault(require("enquirer"));
|
|
8
|
+
|
|
9
|
+
var _zx = require("zx");
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
prompt
|
|
15
|
+
} = _enquirer.default; // This will preserve coloration from spawned child processes
|
|
16
|
+
|
|
17
|
+
process.env.FORCE_COLORS = 3;
|
|
18
|
+
process.env.FORCE_COLOR = '1';
|
|
19
|
+
let TARGET = _zx.argv._[0];
|
|
20
|
+
let exited = false;
|
|
21
|
+
const SECRETS_DIR = 'secrets';
|
|
22
|
+
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
|
+
|
|
25
|
+
if (!firebaserc) {
|
|
26
|
+
console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!firebaseJson) {
|
|
30
|
+
console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!firebaserc || !firebaseJson) {
|
|
34
|
+
process.exit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const firebasercContent = JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
|
|
38
|
+
encoding: 'utf-8'
|
|
39
|
+
}));
|
|
40
|
+
const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
|
|
41
|
+
Object.entries(config.hosting).forEach(([siteId, aliases]) => {
|
|
42
|
+
aliases.forEach(alias => {
|
|
43
|
+
prev[alias] = {
|
|
44
|
+
projectId,
|
|
45
|
+
siteId,
|
|
46
|
+
alias
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return prev;
|
|
51
|
+
}, {});
|
|
52
|
+
|
|
53
|
+
if (!TARGET) {
|
|
54
|
+
const {
|
|
55
|
+
targetEnv
|
|
56
|
+
} = await prompt({
|
|
57
|
+
type: 'autocomplete',
|
|
58
|
+
name: 'targetEnv',
|
|
59
|
+
message: 'To which environment would you like to deploy?',
|
|
60
|
+
choices: Object.keys(targets).map(t => ({
|
|
61
|
+
name: t,
|
|
62
|
+
value: t
|
|
63
|
+
}))
|
|
64
|
+
});
|
|
65
|
+
TARGET = targets[targetEnv];
|
|
66
|
+
} else {
|
|
67
|
+
TARGET = targets[TARGET];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!TARGET) {
|
|
71
|
+
console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
|
|
72
|
+
process.exit();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
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
|
+
if (!aliasFileExists && !siteIdFileExists) {
|
|
78
|
+
console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
|
|
79
|
+
process.exit();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const exec = [];
|
|
83
|
+
|
|
84
|
+
if (sharedFileExists) {
|
|
85
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
|
|
86
|
+
encoding: 'utf-8'
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (aliasFileExists) {
|
|
91
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
|
|
92
|
+
encoding: 'utf-8'
|
|
93
|
+
}));
|
|
94
|
+
} else {
|
|
95
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`), {
|
|
96
|
+
encoding: 'utf-8'
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = (await Promise.all(exec)).join('\n');
|
|
101
|
+
EXIT_EVENTS.forEach(event => {
|
|
102
|
+
process.on(event, () => {
|
|
103
|
+
if (!exited) {
|
|
104
|
+
exited = true;
|
|
105
|
+
|
|
106
|
+
_zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
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
|
+
} catch (err) {
|
|
115
|
+
console.error(err);
|
|
116
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
var _enquirer = _interopRequireDefault(require("enquirer"));
|
|
8
|
+
|
|
9
|
+
var _zx = require("zx");
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
prompt
|
|
15
|
+
} = _enquirer.default; // This will preserve coloration from spawned child processes
|
|
16
|
+
|
|
17
|
+
process.env.FORCE_COLORS = 3;
|
|
18
|
+
process.env.FORCE_COLOR = '1';
|
|
19
|
+
let TARGET = _zx.argv._[0];
|
|
20
|
+
let exited = false;
|
|
21
|
+
const SECRETS_DIR = 'secrets';
|
|
22
|
+
const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughtException', '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
|
+
|
|
25
|
+
if (!firebaserc) {
|
|
26
|
+
console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!firebaseJson) {
|
|
30
|
+
console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!firebaserc || !firebaseJson) {
|
|
34
|
+
process.exit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const firebasercContent = JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
|
|
38
|
+
encoding: 'utf-8'
|
|
39
|
+
}));
|
|
40
|
+
const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
|
|
41
|
+
Object.entries(config.hosting).forEach(([siteId, aliases]) => {
|
|
42
|
+
aliases.forEach(alias => {
|
|
43
|
+
prev[alias] = {
|
|
44
|
+
projectId,
|
|
45
|
+
siteId,
|
|
46
|
+
alias
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return prev;
|
|
51
|
+
}, {});
|
|
52
|
+
|
|
53
|
+
if (!TARGET) {
|
|
54
|
+
const {
|
|
55
|
+
targetEnv
|
|
56
|
+
} = await prompt({
|
|
57
|
+
type: 'autocomplete',
|
|
58
|
+
name: 'targetEnv',
|
|
59
|
+
message: 'Which environment would you like to serve?',
|
|
60
|
+
choices: Object.keys(targets).map(t => ({
|
|
61
|
+
name: t,
|
|
62
|
+
value: t
|
|
63
|
+
}))
|
|
64
|
+
});
|
|
65
|
+
TARGET = targets[targetEnv];
|
|
66
|
+
} else {
|
|
67
|
+
TARGET = targets[TARGET];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!TARGET) {
|
|
71
|
+
console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
|
|
72
|
+
process.exit();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
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
|
+
if (!aliasFileExists && !siteIdFileExists) {
|
|
78
|
+
console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
|
|
79
|
+
process.exit();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const exec = [];
|
|
83
|
+
|
|
84
|
+
if (sharedFileExists) {
|
|
85
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
|
|
86
|
+
encoding: 'utf-8'
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (aliasFileExists) {
|
|
91
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
|
|
92
|
+
encoding: 'utf-8'
|
|
93
|
+
}));
|
|
94
|
+
} else {
|
|
95
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`), {
|
|
96
|
+
encoding: 'utf-8'
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = (await Promise.all(exec)).join('\n');
|
|
101
|
+
EXIT_EVENTS.forEach(event => {
|
|
102
|
+
process.on(event, () => {
|
|
103
|
+
if (!exited) {
|
|
104
|
+
exited = true;
|
|
105
|
+
|
|
106
|
+
_zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
await (0, _zx.$)`DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} npm run serve --colors`;
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error(err);
|
|
116
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
var _enquirer = _interopRequireDefault(require("enquirer"));
|
|
8
|
+
|
|
9
|
+
var _zx = require("zx");
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
prompt
|
|
15
|
+
} = _enquirer.default; // This will preserve coloration from spawned child processes
|
|
16
|
+
|
|
17
|
+
process.env.FORCE_COLORS = 3;
|
|
18
|
+
process.env.FORCE_COLOR = '1';
|
|
19
|
+
let TARGET = _zx.argv._[0];
|
|
20
|
+
let exited = false;
|
|
21
|
+
const SECRETS_DIR = 'secrets';
|
|
22
|
+
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
|
+
|
|
25
|
+
if (!firebaserc) {
|
|
26
|
+
console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!firebaseJson) {
|
|
30
|
+
console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!firebaserc || !firebaseJson) {
|
|
34
|
+
process.exit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const firebasercContent = JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
|
|
38
|
+
encoding: 'utf-8'
|
|
39
|
+
}));
|
|
40
|
+
const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
|
|
41
|
+
Object.entries(config.hosting).forEach(([siteId, aliases]) => {
|
|
42
|
+
aliases.forEach(alias => {
|
|
43
|
+
prev[alias] = {
|
|
44
|
+
projectId,
|
|
45
|
+
siteId,
|
|
46
|
+
alias
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return prev;
|
|
51
|
+
}, {});
|
|
52
|
+
|
|
53
|
+
if (!TARGET) {
|
|
54
|
+
const {
|
|
55
|
+
targetEnv
|
|
56
|
+
} = await prompt({
|
|
57
|
+
type: 'autocomplete',
|
|
58
|
+
name: 'targetEnv',
|
|
59
|
+
message: 'To which environment would you like to deploy?',
|
|
60
|
+
choices: Object.keys(targets).map(t => ({
|
|
61
|
+
name: t,
|
|
62
|
+
value: t
|
|
63
|
+
}))
|
|
64
|
+
});
|
|
65
|
+
TARGET = targets[targetEnv];
|
|
66
|
+
} else {
|
|
67
|
+
TARGET = targets[TARGET];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!TARGET) {
|
|
71
|
+
console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
|
|
72
|
+
process.exit();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
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
|
+
if (!aliasFileExists && !siteIdFileExists) {
|
|
78
|
+
console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
|
|
79
|
+
process.exit();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const exec = [];
|
|
83
|
+
|
|
84
|
+
if (sharedFileExists) {
|
|
85
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
|
|
86
|
+
encoding: 'utf-8'
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (aliasFileExists) {
|
|
91
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
|
|
92
|
+
encoding: 'utf-8'
|
|
93
|
+
}));
|
|
94
|
+
} else {
|
|
95
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`), {
|
|
96
|
+
encoding: 'utf-8'
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = (await Promise.all(exec)).join('\n');
|
|
101
|
+
EXIT_EVENTS.forEach(event => {
|
|
102
|
+
process.on(event, () => {
|
|
103
|
+
if (!exited) {
|
|
104
|
+
exited = true;
|
|
105
|
+
|
|
106
|
+
_zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
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
|
+
} catch (err) {
|
|
115
|
+
console.error(err);
|
|
116
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
var _enquirer = _interopRequireDefault(require("enquirer"));
|
|
8
|
+
|
|
9
|
+
var _zx = require("zx");
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
prompt
|
|
15
|
+
} = _enquirer.default; // This will preserve coloration from spawned child processes
|
|
16
|
+
|
|
17
|
+
process.env.FORCE_COLORS = 3;
|
|
18
|
+
process.env.FORCE_COLOR = '1';
|
|
19
|
+
let TARGET = _zx.argv._[0];
|
|
20
|
+
let exited = false;
|
|
21
|
+
const SECRETS_DIR = 'secrets';
|
|
22
|
+
const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughtException', '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
|
+
|
|
25
|
+
if (!firebaserc) {
|
|
26
|
+
console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!firebaseJson) {
|
|
30
|
+
console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!firebaserc || !firebaseJson) {
|
|
34
|
+
process.exit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const firebasercContent = JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
|
|
38
|
+
encoding: 'utf-8'
|
|
39
|
+
}));
|
|
40
|
+
const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
|
|
41
|
+
Object.entries(config.hosting).forEach(([siteId, aliases]) => {
|
|
42
|
+
aliases.forEach(alias => {
|
|
43
|
+
prev[alias] = {
|
|
44
|
+
projectId,
|
|
45
|
+
siteId,
|
|
46
|
+
alias
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return prev;
|
|
51
|
+
}, {});
|
|
52
|
+
|
|
53
|
+
if (!TARGET) {
|
|
54
|
+
const {
|
|
55
|
+
targetEnv
|
|
56
|
+
} = await prompt({
|
|
57
|
+
type: 'autocomplete',
|
|
58
|
+
name: 'targetEnv',
|
|
59
|
+
message: 'Which environment would you like to serve?',
|
|
60
|
+
choices: Object.keys(targets).map(t => ({
|
|
61
|
+
name: t,
|
|
62
|
+
value: t
|
|
63
|
+
}))
|
|
64
|
+
});
|
|
65
|
+
TARGET = targets[targetEnv];
|
|
66
|
+
} else {
|
|
67
|
+
TARGET = targets[TARGET];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!TARGET) {
|
|
71
|
+
console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
|
|
72
|
+
process.exit();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
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
|
+
if (!aliasFileExists && !siteIdFileExists) {
|
|
78
|
+
console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
|
|
79
|
+
process.exit();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const exec = [];
|
|
83
|
+
|
|
84
|
+
if (sharedFileExists) {
|
|
85
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
|
|
86
|
+
encoding: 'utf-8'
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (aliasFileExists) {
|
|
91
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
|
|
92
|
+
encoding: 'utf-8'
|
|
93
|
+
}));
|
|
94
|
+
} else {
|
|
95
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`), {
|
|
96
|
+
encoding: 'utf-8'
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = (await Promise.all(exec)).join('\n');
|
|
101
|
+
EXIT_EVENTS.forEach(event => {
|
|
102
|
+
process.on(event, () => {
|
|
103
|
+
if (!exited) {
|
|
104
|
+
exited = true;
|
|
105
|
+
|
|
106
|
+
_zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
await (0, _zx.$)`DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} npm run serve --colors`;
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error(err);
|
|
116
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leverege/build-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
4
4
|
"description": "A collection of build / support tools for Leverege developers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -44,7 +44,9 @@
|
|
|
44
44
|
"pull-git": "src/pull-git",
|
|
45
45
|
"push-my-chart": "src/push-my-chart",
|
|
46
46
|
"repo-init": "lib/server/repo-init/index.js",
|
|
47
|
-
"unleash": "src/unleash.js"
|
|
47
|
+
"unleash": "src/unleash.js",
|
|
48
|
+
"firebaseDeploy": "src/firebaseDeploy.mjs",
|
|
49
|
+
"firebaseServe": "src/firebaseServe.mjs"
|
|
48
50
|
},
|
|
49
51
|
"author": "Leverege Devs",
|
|
50
52
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -55,6 +57,7 @@
|
|
|
55
57
|
"command-line-usage": "^6.1.3",
|
|
56
58
|
"deepmerge": "^4.2.2",
|
|
57
59
|
"dotenv": "^16.0.1",
|
|
60
|
+
"enquirer": "^2.3.6",
|
|
58
61
|
"execa": "^5.1.1",
|
|
59
62
|
"figlet": "^1.5.2",
|
|
60
63
|
"glob": "^7.2.3",
|
|
@@ -68,7 +71,8 @@
|
|
|
68
71
|
"parse-gitignore": "^1.0.1",
|
|
69
72
|
"readline-sync": "^1.4.10",
|
|
70
73
|
"semver": "^7.3.7",
|
|
71
|
-
"simple-git": "^3.
|
|
74
|
+
"simple-git": "^3.7.1",
|
|
75
|
+
"zx": "^7.0.2"
|
|
72
76
|
},
|
|
73
77
|
"devDependencies": {
|
|
74
78
|
"@babel/cli": "^7.17.10",
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
/* eslint-disable max-len */
|
|
4
|
+
import pkg from 'enquirer'
|
|
5
|
+
import { $, fs, argv, path, chalk } from 'zx'
|
|
6
|
+
|
|
7
|
+
const { prompt } = pkg
|
|
8
|
+
|
|
9
|
+
// This will preserve coloration from spawned child processes
|
|
10
|
+
process.env.FORCE_COLORS = 3
|
|
11
|
+
process.env.FORCE_COLOR = '1'
|
|
12
|
+
|
|
13
|
+
let TARGET = argv._[0]
|
|
14
|
+
let exited = false
|
|
15
|
+
|
|
16
|
+
const SECRETS_DIR = 'secrets'
|
|
17
|
+
const EXIT_EVENTS = [ 'SIGINT', 'exit', 'uncaughException', 'unhandledRejection' ]
|
|
18
|
+
|
|
19
|
+
const [
|
|
20
|
+
firebaserc,
|
|
21
|
+
firebaseJson
|
|
22
|
+
] = await Promise.all( [
|
|
23
|
+
fs.exists( path.join( process.cwd(), '.firebaserc' ) ),
|
|
24
|
+
fs.exists( path.join( process.cwd(), 'firebase.json' ) )
|
|
25
|
+
] )
|
|
26
|
+
|
|
27
|
+
if ( !firebaserc ) {
|
|
28
|
+
console.log( chalk.red( 'No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.' ) )
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if ( !firebaseJson ) {
|
|
32
|
+
console.log( chalk.red( 'No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.' ) )
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if ( !firebaserc || !firebaseJson ) {
|
|
36
|
+
process.exit()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const firebasercContent = JSON.parse( await fs.readFile( path.join( process.cwd(), '.firebaserc' ), { encoding : 'utf-8' } ) )
|
|
40
|
+
|
|
41
|
+
const targets = Object
|
|
42
|
+
.entries( firebasercContent.targets )
|
|
43
|
+
.reduce( ( prev, [ projectId, config ] ) => {
|
|
44
|
+
Object
|
|
45
|
+
.entries( config.hosting )
|
|
46
|
+
.forEach( ( [ siteId, aliases ] ) => {
|
|
47
|
+
aliases.forEach( ( alias ) => {
|
|
48
|
+
prev[alias] = {
|
|
49
|
+
projectId,
|
|
50
|
+
siteId,
|
|
51
|
+
alias
|
|
52
|
+
}
|
|
53
|
+
} )
|
|
54
|
+
} )
|
|
55
|
+
|
|
56
|
+
return prev
|
|
57
|
+
}, {} )
|
|
58
|
+
|
|
59
|
+
if ( !TARGET ) {
|
|
60
|
+
const { targetEnv } = await prompt( {
|
|
61
|
+
type : 'autocomplete',
|
|
62
|
+
name : 'targetEnv',
|
|
63
|
+
message : 'To which environment would you like to deploy?',
|
|
64
|
+
choices : Object.keys( targets ).map( t => ( { name : t, value : t } ) )
|
|
65
|
+
} )
|
|
66
|
+
|
|
67
|
+
TARGET = targets[targetEnv]
|
|
68
|
+
} else {
|
|
69
|
+
TARGET = targets[TARGET]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ( !TARGET ) {
|
|
73
|
+
console.log( chalk.red( 'No such target exists in .firebaserc config.' ) )
|
|
74
|
+
process.exit()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const [ aliasFileExists, siteIdFileExists, sharedFileExists ] = await Promise.all( [
|
|
78
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, `${TARGET.alias}.env` ) ),
|
|
79
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env` ) ),
|
|
80
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, 'shared.env' ) )
|
|
81
|
+
] )
|
|
82
|
+
|
|
83
|
+
if ( !aliasFileExists && !siteIdFileExists ) {
|
|
84
|
+
console.log( chalk.red( `No env file for ${TARGET.alias} exists. Check your secrets directory and try again` ) )
|
|
85
|
+
process.exit()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const exec = []
|
|
89
|
+
|
|
90
|
+
if ( sharedFileExists ) {
|
|
91
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, 'shared.env' ), { encoding : 'utf-8' } ) )
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ( aliasFileExists ) {
|
|
95
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, `${TARGET.alias}.env` ), { encoding : 'utf-8' } ) )
|
|
96
|
+
} else {
|
|
97
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env` ), { encoding : 'utf-8' } ) )
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = ( await Promise.all( exec ) ).join( '\n' )
|
|
101
|
+
|
|
102
|
+
EXIT_EVENTS
|
|
103
|
+
.forEach( ( event ) => {
|
|
104
|
+
process.on( event, () => {
|
|
105
|
+
if ( !exited ) {
|
|
106
|
+
exited = true
|
|
107
|
+
fs.removeSync( path.join( process.cwd(), '.env.temp' ) )
|
|
108
|
+
}
|
|
109
|
+
} )
|
|
110
|
+
} )
|
|
111
|
+
|
|
112
|
+
await fs.writeFile( path.join( process.cwd(), '.env.temp' ), envFileContent )
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await $`npm run clean && DOTENV_CONFIG_PATH=${path.join( process.cwd(), '.env.temp' )} npm run build && firebase use ${TARGET.projectId} && firebase deploy --only hosting:${TARGET.siteId}`
|
|
116
|
+
} catch ( err ) {
|
|
117
|
+
console.error( err )
|
|
118
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
/* eslint-disable max-len */
|
|
4
|
+
import pkg from 'enquirer'
|
|
5
|
+
import { $, fs, argv, path, chalk } from 'zx'
|
|
6
|
+
|
|
7
|
+
const { prompt } = pkg
|
|
8
|
+
|
|
9
|
+
// This will preserve coloration from spawned child processes
|
|
10
|
+
process.env.FORCE_COLORS = 3
|
|
11
|
+
process.env.FORCE_COLOR = '1'
|
|
12
|
+
|
|
13
|
+
let TARGET = argv._[0]
|
|
14
|
+
let exited = false
|
|
15
|
+
|
|
16
|
+
const SECRETS_DIR = 'secrets'
|
|
17
|
+
const EXIT_EVENTS = [ 'SIGINT', 'exit', 'uncaughtException', 'unhandledRejection' ]
|
|
18
|
+
|
|
19
|
+
const [
|
|
20
|
+
firebaserc,
|
|
21
|
+
firebaseJson
|
|
22
|
+
] = await Promise.all( [
|
|
23
|
+
fs.exists( path.join( process.cwd(), '.firebaserc' ) ),
|
|
24
|
+
fs.exists( path.join( process.cwd(), 'firebase.json' ) )
|
|
25
|
+
] )
|
|
26
|
+
|
|
27
|
+
if ( !firebaserc ) {
|
|
28
|
+
console.log( chalk.red( 'No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.' ) )
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if ( !firebaseJson ) {
|
|
32
|
+
console.log( chalk.red( 'No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.' ) )
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if ( !firebaserc || !firebaseJson ) {
|
|
36
|
+
process.exit()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const firebasercContent = JSON.parse( await fs.readFile( path.join( process.cwd(), '.firebaserc' ), { encoding : 'utf-8' } ) )
|
|
40
|
+
|
|
41
|
+
const targets = Object
|
|
42
|
+
.entries( firebasercContent.targets )
|
|
43
|
+
.reduce( ( prev, [ projectId, config ] ) => {
|
|
44
|
+
Object
|
|
45
|
+
.entries( config.hosting )
|
|
46
|
+
.forEach( ( [ siteId, aliases ] ) => {
|
|
47
|
+
aliases.forEach( ( alias ) => {
|
|
48
|
+
prev[alias] = {
|
|
49
|
+
projectId,
|
|
50
|
+
siteId,
|
|
51
|
+
alias
|
|
52
|
+
}
|
|
53
|
+
} )
|
|
54
|
+
} )
|
|
55
|
+
|
|
56
|
+
return prev
|
|
57
|
+
}, {} )
|
|
58
|
+
|
|
59
|
+
if ( !TARGET ) {
|
|
60
|
+
const { targetEnv } = await prompt( {
|
|
61
|
+
type : 'autocomplete',
|
|
62
|
+
name : 'targetEnv',
|
|
63
|
+
message : 'Which environment would you like to serve?',
|
|
64
|
+
choices : Object.keys( targets ).map( t => ( { name : t, value : t } ) )
|
|
65
|
+
} )
|
|
66
|
+
|
|
67
|
+
TARGET = targets[targetEnv]
|
|
68
|
+
} else {
|
|
69
|
+
TARGET = targets[TARGET]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ( !TARGET ) {
|
|
73
|
+
console.log( chalk.red( 'No such target exists in .firebaserc config.' ) )
|
|
74
|
+
process.exit()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const [ aliasFileExists, siteIdFileExists, sharedFileExists ] = await Promise.all( [
|
|
78
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, `${TARGET.alias}.env` ) ),
|
|
79
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env` ) ),
|
|
80
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, 'shared.env' ) )
|
|
81
|
+
] )
|
|
82
|
+
|
|
83
|
+
if ( !aliasFileExists && !siteIdFileExists ) {
|
|
84
|
+
console.log( chalk.red( `No env file for ${TARGET.alias} exists. Check your secrets directory and try again` ) )
|
|
85
|
+
process.exit()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const exec = []
|
|
89
|
+
|
|
90
|
+
if ( sharedFileExists ) {
|
|
91
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, 'shared.env' ), { encoding : 'utf-8' } ) )
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ( aliasFileExists ) {
|
|
95
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, `${TARGET.alias}.env` ), { encoding : 'utf-8' } ) )
|
|
96
|
+
} else {
|
|
97
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env` ), { encoding : 'utf-8' } ) )
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = ( await Promise.all( exec ) ).join( '\n' )
|
|
101
|
+
|
|
102
|
+
EXIT_EVENTS
|
|
103
|
+
.forEach( ( event ) => {
|
|
104
|
+
process.on( event, () => {
|
|
105
|
+
if ( !exited ) {
|
|
106
|
+
exited = true
|
|
107
|
+
fs.removeSync( path.join( process.cwd(), '.env.temp' ) )
|
|
108
|
+
}
|
|
109
|
+
} )
|
|
110
|
+
} )
|
|
111
|
+
|
|
112
|
+
await fs.writeFile( path.join( process.cwd(), '.env.temp' ), envFileContent )
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await $`DOTENV_CONFIG_PATH=${path.join( process.cwd(), '.env.temp' )} npm run serve --colors`
|
|
116
|
+
} catch ( err ) {
|
|
117
|
+
console.error( err )
|
|
118
|
+
}
|