backend-manager 2.0.10 → 2.0.11

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli/cli.js +75 -41
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "2.0.10",
3
+ "version": "2.0.11",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
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
- .prompt([
880
- /* Pass your questions in here */
881
- {
882
- type: 'input',
883
- name: 'path',
884
- default: 'service.key'
885
- },
886
- {
887
- type: 'input',
888
- name: 'value',
889
- default: '123-abc'
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
- .then(answers => {
893
- // Use user feedback for... whatever!!
894
- // console.log('answer', answers);
895
- log(chalk.yellow(`Saving...`));
896
- let newPath = answers.path;
897
- let isInvalid = false;
898
- if (newPath !== newPath.toLowerCase()) {
899
- isInvalid = true;
900
- newPath = newPath.replace(/([A-Z])/g, '_$1').trim().toLowerCase();
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
- let cmd = exec(`firebase functions:config:set ${newPath}="${answers.value}"`, function (error, stdout, stderr) {
903
- if (error) {
904
- console.error(error);
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(`Saving...`));
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
- console.error(error);
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
  });