@cloudcommerce/cli 0.0.21 → 0.0.24

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.
@@ -1,5 +1,5 @@
1
- @cloudcommerce/cli:build: cache hit, replaying output 19308ae00f3ef339
1
+ @cloudcommerce/cli:build: cache hit, replaying output f832de01e0f20333
2
2
  @cloudcommerce/cli:build: 
3
- @cloudcommerce/cli:build: > @cloudcommerce/cli@0.0.20 build /home/leo/code/ecomplus/cloud-commerce/packages/cli
3
+ @cloudcommerce/cli:build: > @cloudcommerce/cli@0.0.23 build /home/leo/code/ecomplus/cloud-commerce/packages/cli
4
4
  @cloudcommerce/cli:build: > sh ../../scripts/build-lib.sh
5
5
  @cloudcommerce/cli:build: 
package/lib/index.js CHANGED
@@ -2,8 +2,32 @@ import url from 'url';
2
2
  import path from 'path';
3
3
  import { $, argv, fs } from 'zx';
4
4
 
5
+ const { FIREBASE_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS } = process.env;
5
6
  const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
6
7
  const pwd = process.cwd();
8
+ let projectId = FIREBASE_PROJECT_ID;
9
+ if (projectId) {
10
+ if (!fs.existsSync(path.join(pwd, '.firebaserc'))) {
11
+ fs.writeFileSync(path.join(pwd, '.firebaserc'), JSON.stringify({ projects: { default: projectId } }, null, 2));
12
+ }
13
+ } else {
14
+ if (GOOGLE_APPLICATION_CREDENTIALS) {
15
+ try {
16
+ const gac = fs.readJSONSync(path.join(pwd, GOOGLE_APPLICATION_CREDENTIALS));
17
+ projectId = gac.project_id;
18
+ } catch (e) {
19
+ //
20
+ }
21
+ }
22
+ if (!projectId) {
23
+ try {
24
+ const firebaserc = fs.readJSONSync(path.join(pwd, '.firebaserc'));
25
+ projectId = firebaserc.projects.default;
26
+ } catch (e) {
27
+ projectId = 'ecom2-hello';
28
+ }
29
+ }
30
+ }
7
31
 
8
32
  export default async () => {
9
33
  fs.copySync(path.join(__dirname, '..', 'config'), pwd);
@@ -14,7 +38,9 @@ export default async () => {
14
38
  }
15
39
  return opts;
16
40
  }, '');
17
- const $firebase = async (cmd) => $`npx firebase-tools ${cmd}${options}`;
41
+ const $firebase = async (cmd) => {
42
+ return $`firebase --project=${projectId} ${cmd}${options}`;
43
+ };
18
44
  if (argv._.includes('serve')) {
19
45
  return $firebase('emulators:start');
20
46
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/cli",
3
3
  "type": "module",
4
- "version": "0.0.21",
4
+ "version": "0.0.24",
5
5
  "description": "E-Com Plus Cloud Commerce CLI tools",
6
6
  "bin": {
7
7
  "cloudcommerce": "./bin/run.mjs"
package/src/index.ts CHANGED
@@ -2,9 +2,41 @@ import url from 'url';
2
2
  import path from 'path';
3
3
  import { $, argv, fs } from 'zx';
4
4
 
5
+ const {
6
+ FIREBASE_PROJECT_ID,
7
+ GOOGLE_APPLICATION_CREDENTIALS,
8
+ } = process.env;
9
+
5
10
  const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
6
11
  const pwd = process.cwd();
7
12
 
13
+ let projectId = FIREBASE_PROJECT_ID;
14
+ if (projectId) {
15
+ if (!fs.existsSync(path.join(pwd, '.firebaserc'))) {
16
+ fs.writeFileSync(
17
+ path.join(pwd, '.firebaserc'),
18
+ JSON.stringify({ projects: { default: projectId } }, null, 2),
19
+ );
20
+ }
21
+ } else {
22
+ if (GOOGLE_APPLICATION_CREDENTIALS) {
23
+ try {
24
+ const gac = fs.readJSONSync(path.join(pwd, GOOGLE_APPLICATION_CREDENTIALS));
25
+ projectId = gac.project_id;
26
+ } catch (e) {
27
+ //
28
+ }
29
+ }
30
+ if (!projectId) {
31
+ try {
32
+ const firebaserc = fs.readJSONSync(path.join(pwd, '.firebaserc'));
33
+ projectId = firebaserc.projects.default;
34
+ } catch (e) {
35
+ projectId = 'ecom2-hello';
36
+ }
37
+ }
38
+ }
39
+
8
40
  export default async () => {
9
41
  fs.copySync(path.join(__dirname, '..', 'config'), pwd);
10
42
 
@@ -15,7 +47,9 @@ export default async () => {
15
47
  }
16
48
  return opts;
17
49
  }, '');
18
- const $firebase = async (cmd: string) => $`npx firebase-tools ${cmd}${options}`;
50
+ const $firebase = async (cmd: string) => {
51
+ return $`firebase --project=${projectId} ${cmd}${options}`;
52
+ };
19
53
 
20
54
  if (argv._.includes('serve')) {
21
55
  return $firebase('emulators:start');