backend-manager 2.0.9 → 2.0.12
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
package/src/cli/cli.js
CHANGED
|
@@ -87,6 +87,7 @@ Main.prototype.process = async function (args) {
|
|
|
87
87
|
console.log('cwd: ', this.firebaseProjectPath);
|
|
88
88
|
}
|
|
89
89
|
if (this.options.setup) {
|
|
90
|
+
await cmd_configGet(self).catch(e => log(chalk.red(`Failed to run config:get`)));
|
|
90
91
|
await self.setup();
|
|
91
92
|
}
|
|
92
93
|
if ((this.options.i || this.options.install) && (this.options.local || this.options.dev || this.options.development)) {
|
|
@@ -863,7 +864,7 @@ function getPkgVersion(package) {
|
|
|
863
864
|
console.error(error);
|
|
864
865
|
reject(error);
|
|
865
866
|
} else {
|
|
866
|
-
console.log(`Saving config to: ${self.firebaseProjectPath}/functions/.runtimeconfig.json`);
|
|
867
|
+
console.log(chalk.green(`Saving config to: ${self.firebaseProjectPath}/functions/.runtimeconfig.json`));
|
|
867
868
|
console.log(stdout);
|
|
868
869
|
resolve();
|
|
869
870
|
}
|
|
@@ -871,48 +872,80 @@ function getPkgVersion(package) {
|
|
|
871
872
|
});
|
|
872
873
|
}
|
|
873
874
|
|
|
874
|
-
async function cmd_configSet(self) {
|
|
875
|
+
async function cmd_configSet(self, newPath, newValue) {
|
|
875
876
|
return new Promise(async function(resolve, reject) {
|
|
876
877
|
// console.log(this.options);
|
|
877
878
|
// console.log(this.argv);
|
|
878
|
-
await inquirer
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
879
|
+
newPath = newPath || await inquirer.prompt([
|
|
880
|
+
{
|
|
881
|
+
type: 'input',
|
|
882
|
+
name: 'path',
|
|
883
|
+
default: 'service.key'
|
|
884
|
+
}
|
|
885
|
+
]).then(answers => answers.path)
|
|
886
|
+
|
|
887
|
+
try {
|
|
888
|
+
const object = JSON5.parse(newPath)
|
|
889
|
+
try {
|
|
890
|
+
if (typeof object === 'object') {
|
|
891
|
+
const keyify = (obj, prefix = '') =>
|
|
892
|
+
Object.keys(obj).reduce((res, el) => {
|
|
893
|
+
if( Array.isArray(obj[el]) ) {
|
|
894
|
+
return res;
|
|
895
|
+
} else if( typeof obj[el] === 'object' && obj[el] !== null ) {
|
|
896
|
+
return [...res, ...keyify(obj[el], prefix + el + '.')];
|
|
897
|
+
}
|
|
898
|
+
return [...res, prefix + el];
|
|
899
|
+
}, []);
|
|
900
|
+
const pathArray = keyify(object);
|
|
901
|
+
for (var i = 0; i < pathArray.length; i++) {
|
|
902
|
+
const pathName = pathArray[i];
|
|
903
|
+
const pathValue = _.get(object, pathName);
|
|
904
|
+
// console.log(chalk.blue(`Setting object: ${chalk.bold(pathName)} = ${chalk.bold(pathValue)}`));
|
|
905
|
+
console.log(chalk.blue(`Setting object: ${chalk.bold(pathName)}`));
|
|
906
|
+
await cmd_configSet(self, pathName, pathValue)
|
|
907
|
+
.catch(e => {
|
|
908
|
+
log(chalk.red(`Failed to save object path: ${e}`));
|
|
909
|
+
})
|
|
910
|
+
}
|
|
911
|
+
return resolve();
|
|
890
912
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
913
|
+
} catch (e) {
|
|
914
|
+
log(chalk.red(`Failed to save object: ${e}`));
|
|
915
|
+
return reject(e)
|
|
916
|
+
}
|
|
917
|
+
} catch (e) {
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
newValue = newValue || await inquirer.prompt([
|
|
921
|
+
{
|
|
922
|
+
type: 'input',
|
|
923
|
+
name: 'value',
|
|
924
|
+
default: '123-abc'
|
|
925
|
+
}
|
|
926
|
+
]).then(answers => answers.value)
|
|
927
|
+
|
|
928
|
+
let isInvalid = false;
|
|
929
|
+
if (newPath !== newPath.toLowerCase()) {
|
|
930
|
+
isInvalid = true;
|
|
931
|
+
newPath = newPath.replace(/([A-Z])/g, '_$1').trim().toLowerCase();
|
|
932
|
+
}
|
|
933
|
+
log(chalk.yellow(`Saving to ${chalk.bold(newPath)}...`));
|
|
934
|
+
let cmd = exec(`firebase functions:config:set ${newPath}="${newValue}"`, function (error, stdout, stderr) {
|
|
935
|
+
if (error) {
|
|
936
|
+
log(chalk.red(`Failed to save ${chalk.bold(newPath)}: ${error}`));
|
|
937
|
+
reject(error);
|
|
938
|
+
} else {
|
|
939
|
+
console.log(stdout);
|
|
940
|
+
if (isInvalid) {
|
|
941
|
+
log(chalk.red(`!!! Your path contained an invalid uppercase character`));
|
|
942
|
+
log(chalk.red(`!!! It was set to: ${chalk.bold(newPath)}`));
|
|
943
|
+
} else {
|
|
944
|
+
log(chalk.green(`Successfully saved to ${chalk.bold(newPath)}`));
|
|
901
945
|
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
reject();
|
|
906
|
-
} else {
|
|
907
|
-
console.log(stdout);
|
|
908
|
-
if (isInvalid) {
|
|
909
|
-
log(chalk.red(`!!! Your path contained an invalid uppercase character`));
|
|
910
|
-
log(chalk.red(`!!! It was set to: ${chalk.bold(newPath)}`));
|
|
911
|
-
}
|
|
912
|
-
resolve();
|
|
913
|
-
}
|
|
914
|
-
});
|
|
915
|
-
});
|
|
946
|
+
resolve();
|
|
947
|
+
}
|
|
948
|
+
});
|
|
916
949
|
});
|
|
917
950
|
}
|
|
918
951
|
|
|
@@ -932,13 +965,14 @@ function getPkgVersion(package) {
|
|
|
932
965
|
.then(answers => {
|
|
933
966
|
// Use user feedback for... whatever!!
|
|
934
967
|
// console.log('answer', answers);
|
|
935
|
-
log(chalk.yellow(`
|
|
968
|
+
log(chalk.yellow(`Deleting ${chalk.bold(answers.path)}...`));
|
|
936
969
|
let cmd = exec(`firebase functions:config:unset ${answers.path}`, function (error, stdout, stderr) {
|
|
937
970
|
if (error) {
|
|
938
|
-
|
|
939
|
-
reject();
|
|
971
|
+
log(chalk.red(`Failed to delete ${chalk.bold(answers.path)}: ${error}`));
|
|
972
|
+
reject(error);
|
|
940
973
|
} else {
|
|
941
974
|
console.log(stdout);
|
|
975
|
+
log(chalk.green(`Successfully deleted ${chalk.bold(answers.path)}`));
|
|
942
976
|
resolve();
|
|
943
977
|
}
|
|
944
978
|
});
|
|
@@ -5,14 +5,12 @@ function Module() {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
Module.prototype.init = async function (s, payload) {
|
|
8
|
-
console.log('*******1 payload', payload);
|
|
9
8
|
const self = this;
|
|
10
9
|
self.Api = s;
|
|
11
10
|
self.Manager = s.Manager;
|
|
12
11
|
self.libraries = s.Manager.libraries;
|
|
13
12
|
self.assistant = s.Manager.assistant;
|
|
14
13
|
self.payload = payload;
|
|
15
|
-
console.log('*******2 self.payload', self.payload);
|
|
16
14
|
|
|
17
15
|
return self;
|
|
18
16
|
};
|
|
@@ -22,14 +20,10 @@ Module.prototype.main = function () {
|
|
|
22
20
|
const Manager = self.Manager;
|
|
23
21
|
const assistant = self.assistant;
|
|
24
22
|
const payload = self.payload;
|
|
25
|
-
console.log('*******3 self.payload', self.payload);
|
|
26
|
-
console.log('*******3 payload', payload);
|
|
27
23
|
|
|
28
24
|
return new Promise(async function(resolve, reject) {
|
|
29
25
|
|
|
30
26
|
let result = '';
|
|
31
|
-
console.log('*******4 self.payload', self.payload);
|
|
32
|
-
console.log('*******4 payload', payload);
|
|
33
27
|
payload.data.payload.namespace = payload.data.payload.namespace || Manager.config.backend_manager.namespace;
|
|
34
28
|
payload.data.payload.version = `${payload.data.payload.version || '5'}`.replace('v', '');
|
|
35
29
|
payload.data.payload.name = payload.data.payload.name || payload.data.payload.input;
|
|
@@ -44,9 +44,7 @@ Module.prototype.main = function() {
|
|
|
44
44
|
try {
|
|
45
45
|
const lib = new (require(commandPath))();
|
|
46
46
|
try {
|
|
47
|
-
console.log('++++++1 self.payload', self.payload);
|
|
48
47
|
await lib.init(self, self.payload);
|
|
49
|
-
console.log('++++++2 self.payload', self.payload);
|
|
50
48
|
await lib.main()
|
|
51
49
|
.then(r => {
|
|
52
50
|
self.payload.response.status = r.status || 200;
|
|
@@ -56,7 +54,6 @@ Module.prototype.main = function() {
|
|
|
56
54
|
self.payload.response.status = e.code || 500;
|
|
57
55
|
self.payload.response.error = e || new Error('Unknown error occured');
|
|
58
56
|
})
|
|
59
|
-
console.log('++++++3 self.payload', self.payload);
|
|
60
57
|
} catch (e) {
|
|
61
58
|
self.payload.response.status = 500;
|
|
62
59
|
self.payload.response.error = e || new Error('Unknown error occured');
|